Skip to content

Possible bug in virgo.py #34

Description

@gwsteffens-az

I believe I found a bug in virgo.py. Line 693 has the following:
ra_dec = tuple(map(str, headers[i].split('=')[1].split(' ')))

I believe it should be:
ra_dec = tuple(map(float, headers[i].split('=')[1].split(' ')))

The difference is specifying "float" instead of "str" in the map function.

To reproduce the problem:

  1. Specify the object 'ra_dec' in the obs dictionary :
obs = {
    'dev_args': 'rtl=0,bias=1',
    'rf_gain': 50, 
    'if_gain': 25,
    'bb_gain': 18,  
    'frequency': 1420.4e6,
    'bandwidth': 2.40e6,
    'channels': 1024, 
    't_sample': 1,     
    'duration': 60,
    'loc': '-108.8 35.5 800.0', 
    'ra_dec': '204.25383 -29.865761111',   
    'az_alt': ''
}
  1. Make the call to virgo.observe passing the obs dictionary for the obs_parameters argument
    virgo.observe(obs_parameters=obs, obs_file='observation.dat')

  2. Plot the observation but don't include the obs_parameters argument ('calibration.dat' was created earlier):

virgo.plot(n=20, m=35, f_rest=1420.4057517667e6,
           vlsr=True, meta=True, avg_ylim=(-5,15), cal_ylim=(-20,260),
           obs_file='observation.dat', cal_file='calibration.dat', 
           dB=True, spectra_csv='spectrum.csv', plot_file='plot.png')

This is the error messages you will see:

TypeError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 virgo.plot(n=20, m=35, f_rest=1420.4057517667e6,
      2            vlsr=True, meta=True, avg_ylim=(-5,15), cal_ylim=(-20,260),
      3            obs_file='observation.dat', cal_file='calibration.dat', 
      4            dB=True, spectra_csv='spectrum.csv', plot_file='plot.png')

File ~/.local/lib/python3.12/site-packages/virgo/virgo.py:721, in plot(obs_parameters, n, m, f_rest, slope_correction, dB, vlsr, meta, avg_ylim, cal_ylim, rfi, xlim, ylim, dm, obs_file, cal_file, waterfall_fits, spectra_csv, power_csv, plot_file)
    719 	print (obs_coord)
    720 elif ra_dec:
--> 721 	obs_coord = SkyCoord(ra=ra_dec[0]*u.degree, dec=ra_dec[1]*u.degree, frame='icrs')
    722 else:
    723 	obs_coord = None

File ~/.local/lib/python3.12/site-packages/astropy/coordinates/sky_coordinate.py:231, in SkyCoord.__init__(self, copy, *args, **kwargs)
    227 # Parse the args and kwargs to assemble a sanitized and validated
    228 # kwargs dict for initializing attributes for this object and for
    229 # creating the internal self._sky_coord_frame object
    230 args = list(args)  # Make it mutable
--> 231 skycoord_kwargs, components, info = _parse_coordinate_data(
    232     frame_cls(**frame_kwargs), args, kwargs
    233 )
    235 # In the above two parsing functions, these kwargs were identified
    236 # as valid frame attributes for *some* frame, but not the frame that
    237 # this SkyCoord will have. We keep these attributes as special
    238 # skycoord frame attributes:
    239 for attr in skycoord_kwargs:
    240     # Setting it will also validate it.

File ~/.local/lib/python3.12/site-packages/astropy/coordinates/sky_coordinate_parsers.py:229, in _parse_coordinate_data(frame, args, kwargs)
    225 units = _get_representation_component_units(args, kwargs)
    227 # Grab any frame-specific attr names like `ra` or `l` or `distance` from
    228 # kwargs and move them to valid_components.
--> 229 valid_components = _get_representation_attrs(frame, units, kwargs)
    231 # Error if anything is still left in kwargs
    232 if kwargs:
    233     # The next few lines add a more user-friendly error message to a
    234     # common and confusing situation when the user specifies, e.g.,
    235     # `pm_ra` when they really should be passing `pm_ra_cosdec`. The
    236     # extra error should only turn on when the positional representation
    237     # is spherical, and when the component 'pm_<lon>' is passed.

File ~/.local/lib/python3.12/site-packages/astropy/coordinates/sky_coordinate_parsers.py:566, in _get_representation_attrs(frame, units, kwargs)
    564 if value is not None:
    565     try:
--> 566         valid_kwargs[frame_attr_name] = repr_attr_class(value, unit=unit)
    567     except u.UnitConversionError as err:
    568         error_message = (
    569             f"Unit '{unit}' ({unit.physical_type}) could not be applied to"
    570             f" '{frame_attr_name}'. This can occur when passing units for some"
   (...)    574             " components."
    575         )

File ~/.local/lib/python3.12/site-packages/astropy/coordinates/angles/core.py:724, in Longitude.__new__(cls, angle, unit, wrap_angle, **kwargs)
    718 if isinstance(angle, Latitude) or (
    719     isinstance(angle, str) and angle.endswith(("N", "S"))
    720 ):
    721     raise TypeError(
    722         "A Longitude angle cannot be created from a Latitude angle."
    723     )
--> 724 self = super().__new__(cls, angle, unit=unit, **kwargs)
    725 if wrap_angle is None:
    726     wrap_angle = getattr(angle, "wrap_angle", self._default_wrap_angle)

File ~/.local/lib/python3.12/site-packages/astropy/coordinates/angles/core.py:194, in Angle.__new__(cls, angle, unit, dtype, copy, **kwargs)
    191     elif np.iterable(angle):
    192         angle = [cls(x, unit, copy=COPY_IF_NEEDED) for x in angle]
--> 194 return super().__new__(cls, angle, unit, dtype=dtype, copy=copy, **kwargs)

File ~/.local/lib/python3.12/site-packages/astropy/units/quantity.py:545, in Quantity.__new__(cls, value, unit, dtype, copy, order, subok, ndmin)
    541 # check that array contains numbers or long int objects
    542 if value.dtype.kind in "OSU" and not (
    543     value.dtype.kind == "O" and isinstance(value.item(0), numbers.Number)
    544 ):
--> 545     raise TypeError("The value must be a valid Python or Numpy numeric type.")
    547 # by default, cast any integer, boolean, etc., to float
    548 if float_default and value.dtype.kind in "iuO":

TypeError: The value must be a valid Python or Numpy numeric type.

Replacing "str" with "float" on line 693 fixes the issue and the RA and Dec appear correctly on the plot.

I'm running on Linux Mint with Python 3.12.3. The command was run within Jupyter.

Let me know if you need any more information. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions