Skip to content

Commit

Permalink
Clean-up unneeded equiv_unit
Browse files Browse the repository at this point in the history
  • Loading branch information
e-koch committed Oct 18, 2024
1 parent ad0e8bd commit 9cb9a82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions radio_beam/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def _to_area(major,minor):
u.arcmin: "'"}


def _with_default_unit(type_str, value, unit, equiv_unit=u.deg):
def _with_default_unit(type_str, value, unit):
if not hasattr(value, 'unit'):
return value * unit

if value.unit.is_equivalent(equiv_unit):
if value.unit.is_equivalent(unit):
return value
else:
raise u.UnitsError(f"{value.unit} for {type_str} is not equivalent to {equiv_unit}")
Expand Down Expand Up @@ -83,18 +83,18 @@ def __new__(cls, major=None, minor=None, pa=None, area=None,

# give specified values priority
if major is not None:
major = _with_default_unit("major", major, default_unit, equiv_unit=u.deg)
major = _with_default_unit("major", major, default_unit)

if pa is not None:
pa = _with_default_unit("pa", pa, u.deg, equiv_unit=u.deg)
pa = _with_default_unit("pa", pa, u.deg)
else:
pa = 0 * u.deg

# some sensible defaults
if minor is None:
minor = major
else:
minor = _with_default_unit("minor", minor, default_unit, equiv_unit=u.deg)
minor = _with_default_unit("minor", minor, default_unit)

if minor > major:
raise ValueError("Minor axis greater than major axis.")
Expand Down
6 changes: 3 additions & 3 deletions radio_beam/multiple_beams.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def __new__(cls, major=None, minor=None, pa=None,

# give specified values priority
if major is not None:
major = _with_default_unit("major", major, default_unit, equiv_unit=u.deg)
major = _with_default_unit("major", major, default_unit)


if pa is not None:
if len(pa) != len(major):
raise ValueError("Number of position angles must match number of major axis lengths")
pa = _with_default_unit("pa", pa, u.deg, equiv_unit=u.deg)
pa = _with_default_unit("pa", pa, u.deg)
else:
pa = np.zeros(major.shape) * u.deg

Expand All @@ -77,7 +77,7 @@ def __new__(cls, major=None, minor=None, pa=None,
elif len(minor) != len(major):
raise ValueError("Minor and major axes must have same number of values")
else:
minor = _with_default_unit("minor", minor, default_unit, equiv_unit=u.deg)
minor = _with_default_unit("minor", minor, default_unit)

if np.any(minor > major):
raise ValueError("Minor axis greater than major axis.")
Expand Down

0 comments on commit 9cb9a82

Please sign in to comment.