Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue generating beams #130

Closed
jpinedaf opened this issue Oct 18, 2024 · 2 comments
Closed

Issue generating beams #130

jpinedaf opened this issue Oct 18, 2024 · 2 comments

Comments

@jpinedaf
Copy link

I am using the latest version: radio-beam-0.3.8.dev12+g325cad3

I am trying to generate a simple circular beam as this:

import astropy.units as u
from radio_beam import Beam

bmaj = 14 * u.arcsec
bmin = 14 * u.arcsec
bpa = 0.0 * u.deg

beam = Beam(major=bmaj, minor=bmin, pa=bpa)

but I get the following error message

Cell In[40], line 8
      5 bmin = 14 * u.arcsec
      6 bpa = 0.0 * u.deg
----> 8 beam = Beam(major=bmaj, minor=bmin, pa=bpa)

File ~/code/python_code/radio_beam/radio_beam/beam.py:86, in Beam.__new__(cls, major, minor, pa, area, default_unit, meta)
     84         minor = minor * u.deg
     85 if pa is not None:
---> 86     if u.deg.is_equivalent(pa):
     87         pa = pa
     88     else:

File ~/miniconda3/envs/astro/lib/python3.11/site-packages/astropy/units/core.py:1013, in UnitBase.is_equivalent(self, other, equivalencies)
   1009     return any(self.is_equivalent(u, equivalencies) for u in other)
   1011 other = Unit(other, parse_strict="silent")
-> 1013 return self._is_equivalent(other, equivalencies)

File ~/miniconda3/envs/astro/lib/python3.11/site-packages/astropy/units/core.py:1024, in UnitBase._is_equivalent(self, other, equivalencies)
   1021 if isinstance(other, UnrecognizedUnit):
   1022     return False
-> 1024 if self._get_physical_type_id() == other._get_physical_type_id():
   1025     return True
   1026 elif len(equivalencies):

File ~/miniconda3/envs/astro/lib/python3.11/site-packages/astropy/units/core.py:695, in UnitBase._get_physical_type_id(self)
    688 """
    689 Returns an identifier that uniquely identifies the physical
    690 type of this unit.  It is comprised of the bases and powers of
    691 this unit, without the scale.  Since it is hashable, it is
    692 useful as a dictionary key.
    693 """
    694 if self._type_id is None:
--> 695     unit = self.decompose()
    696     self._type_id = tuple(zip((base.name for base in unit.bases), unit.powers))
    698 return self._type_id

File ~/miniconda3/envs/astro/lib/python3.11/site-packages/astropy/units/core.py:2485, in CompositeUnit.decompose(self, bases)
   2482         self._decomposed_cache = self
   2483     return self
-> 2485 x = CompositeUnit(
   2486     self.scale, self.bases, self.powers, decompose=True, decompose_bases=bases
   2487 )
   2488 if len(bases) == 0:
   2489     self._decomposed_cache = x

File ~/miniconda3/envs/astro/lib/python3.11/site-packages/astropy/units/core.py:2358, in CompositeUnit.__init__(self, scale, bases, powers, decompose, decompose_bases, _error_check)
   2356 if _error_check:
   2357     if scale == 0:
-> 2358         raise UnitScaleError("cannot create a unit with a scale of 0.")
   2359     for base in bases:
   2360         if not isinstance(base, UnitBase):

UnitScaleError: cannot create a unit with a scale of 0.

In [41]: 

It all gets solved if I use a PA different from 0

In [41]: import astropy.units as u
    ...: from radio_beam import Beam
    ...: 
    ...: bmaj = 14 * u.arcsec
    ...: bmin = 14 * u.arcsec
    ...: bpa = 1.0 * u.deg
    ...: 
    ...: beam = Beam(major=bmaj, minor=bmin, pa=bpa)

In [42]: 

Is there something wrong with what I am doing?

@e-koch
Copy link
Collaborator

e-koch commented Oct 18, 2024

thanks @jpinedaf! This will be fixed with #128.

@jpinedaf
Copy link
Author

yes, this works! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants