radio-astro-tools / spectral-cube

Library for reading and analyzing astrophysical spectral data cubes
http://spectral-cube.rtfd.org
BSD 3-Clause "New" or "Revised" License
98 stars 65 forks source link

Test error with spectral-cube 0.4.4: Minor axis greater than major axis #591

Closed smaret closed 4 years ago

smaret commented 4 years ago

I'm getting the following error during the tests in spectral-cube 0.4.4:

============================= test session starts ==============================
platform darwin -- Python 3.7.5, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
rootdir: /private/var/folders/r2/zwnv7zsd4bd99mqkn4mhqxn800034l/T/nix-build-python3.7-spectral-cube-0.4.4.drv-0/spectral-cube-0.4.4, inifile: setup.cfg
plugins: doctestplus-0.4.0, remotedata-0.3.2, openfiles-0.4.0, arraydiff-0.3
collecting ... /nix/store/assnrg5cx9k6fh1x8yvp71bzygh0141m-python3.7-astropy-3.2.2/lib/python3.7/site-packages/astropy/config/configuration.py:532: ConfigurationMissingWarning: Configuration defaults will be used due to FileNotFoundError:2 on None
  warn(ConfigurationMissingWarning(msg))
WARNING: AstropyDeprecationWarning: astropy.extern.six will be removed in 4.0, use the six module directly if it is still needed [astropy.extern.six]
collected 721 items                                                            

spectral_cube/lower_dimensional_structures.py .                          [  0%]
spectral_cube/spectral_axis.py .                                         [  0%]
spectral_cube/tests/test_analysis_functions.py .........                 [  1%]
spectral_cube/tests/test_casafuncs.py ss                                 [  1%]
spectral_cube/tests/test_cube_utils.py F

=================================== FAILURES ===================================
______________________________ test_largest_beam _______________________________

    def test_largest_beam():

>       cube, data = cube_and_raw('522_delta_beams.fits')

spectral_cube/tests/test_cube_utils.py:9: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
spectral_cube/tests/test_spectral_cube.py:59: in cube_and_raw
    c = SpectralCube.read(p, format='fits', mode='readonly')
spectral_cube/spectral_cube.py:2146: in read
    cube = read(filename, format=format, hdu=hdu, **kwargs)
spectral_cube/io/core.py:33: in read
    return load_fits_cube(filename, hdu=hdu, **kwargs)
spectral_cube/io/fits.py:167: in load_fits_cube
    beam_table=beam_table)
spectral_cube/spectral_cube.py:3359: in __init__
    for row in beam_data_table],
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'radio_beam.multiple_beams.Beams'>
major = <Quantity [0.1, 0.2, 0.3, 0.4, 0.5] arcsec>
minor = <Quantity [0.5, 0.4, 0.3, 0.2, 0.1] arcsec>
pa = <Quantity [ 0., 45., 60., 30.,  0.] deg>, areas = None
default_unit = Unit("arcsec")
meta = [{'CHAN': 0, 'POL': 0}, {'CHAN': 0, 'POL': 0}, {'CHAN': 0, 'POL': 0}, {'CHAN': 0, 'POL': 0}, {'CHAN': 0, 'POL': 0}]
beams = None

    def __new__(cls, major=None, minor=None, pa=None,
                areas=None, default_unit=u.arcsec, meta=None,
                beams=None):
        """
        Create a new set of Gaussian beams

        Parameters
        ----------
        major : :class:`~astropy.units.Quantity` with angular equivalency
            The FWHM major axes
        minor : :class:`~astropy.units.Quantity` with angular equivalency
            The FWHM minor axes
        pa : :class:`~astropy.units.Quantity` with angular equivalency
            The beam position angles
        area : :class:`~astropy.units.Quantity` with steradian equivalency
            The area of the beams.  This is an alternative to specifying the
            major/minor/PA, and will create those values assuming a circular
            Gaussian beam.
        default_unit : :class:`~astropy.units.Unit`
            The unit to impose on major, minor if they are specified as floats
        beams : List of :class:`~radio_beam.Beam` objects
            List of individual `Beam` objects. The resulting `Beams` object will
            have major and minor axes in degrees.
        """

        # improve to some kwargs magic later

        # error checking

        if beams is not None:
            major = [beam.major.to(u.deg).value for beam in beams] * u.deg
            minor = [beam.major.to(u.deg).value for beam in beams] * u.deg
            pa = [beam.pa.to(u.deg).value for beam in beams] * u.deg

        # ... given an area make a round beam assuming it is Gaussian
        if areas is not None:
            rad = np.sqrt(areas / (2 * np.pi)) * u.deg
            major = rad * SIGMA_TO_FWHM
            minor = rad * SIGMA_TO_FWHM
            pa = np.zeros_like(areas) * u.deg

        # give specified values priority
        if major is not None:
            if u.deg.is_equivalent(major.unit):
                pass
            else:
                warnings.warn("Assuming major axes has been specified in degrees")
                major = major * u.deg
        if minor is not None:
            if u.deg.is_equivalent(minor.unit):
                pass
            else:
                warnings.warn("Assuming minor axes has been specified in degrees")
                minor = minor * u.deg
        if pa is not None:
            if len(pa) != len(major):
                raise ValueError("Number of position angles must match number of major axis lengths")
            if u.deg.is_equivalent(pa.unit):
                pass
            else:
                warnings.warn("Assuming position angles has been specified in degrees")
                pa = pa * u.deg
        else:
            pa = np.zeros_like(major.value) * u.deg

        # some sensible defaults
        if minor is None:
            minor = major
        elif len(minor) != len(major):
            raise ValueError("Minor and major axes must have same number of values")

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

/nix/store/m6bhm2pyygrsdqsqsr42p7187v4k8bnf-python3.7-radio_beam-0.3.2/lib/python3.7/site-packages/radio_beam/multiple_beams.py:91: ValueError
=================== 1 failed, 11 passed, 2 skipped in 2.92s ====================

I'm running Python 3.7.5 with pytest-5.2.1, astropy-3.2.2 and radio_beam-0.3.2.

keflavich commented 4 years ago

Thanks for the report. This is indeed a bug in v0.4.4, but it is fixed in master. We don't have a new release scheduled right now, but if you need one, we can probably create one in short order.

smaret commented 4 years ago

Thanks for your answer. I'm trying to fix the Nix package for astroquery that fails to build because of this test failure. If the test failure has been fixed in a single commit, I can easily apply this commit in the Nix package on top of v.0.4.4. However if several commits need to be applied to fix the tests than it would be much easier for me if you would make a new release.

keflavich commented 4 years ago

We issued a new release. It's been a while, this was needed.

smaret commented 4 years ago

I've just built v0.4.5 and the tests run fine. Thanks!