Skip to content

Commit

Permalink
use plural
Browse files Browse the repository at this point in the history
  • Loading branch information
nvaytet committed Oct 3, 2024
1 parent be6bc9c commit b879dd9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
28 changes: 14 additions & 14 deletions src/tof/chopper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ class Chopper:
The opening angles of the chopper cutouts.
close:
The closing angles of the chopper cutouts.
center:
The center of the chopper cutouts.
width:
The width of the chopper cutouts.
centers:
The centers of the chopper cutouts.
widths:
The widths of the chopper cutouts.
name:
The name of the chopper.
Notes
-----
Either `open` and `close` or `center` and `width` must be provided, but not both.
Either `open` and `close` or `centers` and `widths` must be provided, but not both.
"""

def __init__(
Expand All @@ -61,8 +61,8 @@ def __init__(
phase: sc.Variable,
open: sc.Variable | None = None,
close: sc.Variable | None = None,
center: sc.Variable | None = None,
width: sc.Variable | None = None,
centers: sc.Variable | None = None,
widths: sc.Variable | None = None,
direction: Direction = Clockwise,
name: str = "",
):
Expand All @@ -76,18 +76,18 @@ def __init__(
)
self.direction = direction
# Check that either open/close or center/width are provided, but not both
if tuple(x for x in (open, close, center, width) if x is not None) not in (
if tuple(x for x in (open, close, centers, widths) if x is not None) not in (
(open, close),
(center, width),
(centers, widths),
):
raise ValueError(
"Either open/close or center/width must be provided, got"
f" open={open}, close={close}, center={center}, width={width}."
"Either open/close or centers/widths must be provided, got"
f" open={open}, close={close}, center={centers}, width={widths}."
)
if open is None:
half_width = width * 0.5
open = center - half_width
close = center + half_width
half_width = widths * 0.5
open = centers - half_width
close = centers + half_width

self.open = (open if open.dims else open.flatten(to='cutout')).to(
dtype=float, copy=False
Expand Down
18 changes: 9 additions & 9 deletions tests/chopper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,17 @@ def test_bad_direction_raises():

def test_chopper_create_from_centers_and_widths():
f = 10.0 * Hz
center = sc.array(dims=['cutout'], values=[15.0, 46.0], unit='deg')
width = sc.array(dims=['cutout'], values=[10.0, 16.0], unit='deg')
centers = sc.array(dims=['cutout'], values=[15.0, 46.0], unit='deg')
widths = sc.array(dims=['cutout'], values=[10.0, 16.0], unit='deg')
chopper = tof.Chopper(
frequency=f,
center=center,
width=width,
centers=centers,
widths=widths,
phase=0.0 * deg,
distance=5.0 * meter,
)
assert sc.allclose(chopper.open, center - width / 2)
assert sc.allclose(chopper.close, center + width / 2)
assert sc.allclose(chopper.open, centers - widths / 2)
assert sc.allclose(chopper.close, centers + widths / 2)

expected = tof.Chopper(
frequency=f,
Expand All @@ -320,14 +320,14 @@ def test_chopper_create_from_centers_and_widths():

def test_chopper_create_raises_when_both_edges_and_centers_are_supplied():
with pytest.raises(
ValueError, match="Either open/close or center/width must be provided"
ValueError, match="Either open/close or centers/widths must be provided"
):
tof.Chopper(
frequency=10.0 * Hz,
open=10.0 * deg,
close=20.0 * deg,
center=15.0 * deg,
width=10.0 * deg,
centers=15.0 * deg,
widths=10.0 * deg,
phase=0.0 * deg,
distance=5.0 * meter,
)

0 comments on commit b879dd9

Please sign in to comment.