SNEWS2 / snewpy

A Python package for working with supernova neutrinos
https://snewpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
26 stars 19 forks source link

Loading `Kuroda_2020` model fails with certain versions of astropy #188

Closed sgriswol closed 2 years ago

sgriswol commented 2 years ago

Attempting to initialize the Kuroda_2020 model with code like the following, while using astropy v4.2.1 yields a rather uninformative error. This error seems to involve a data column that is expected to have astropy units, but doesn't when the model file is actually loaded. This same error is thrown for all three Kuroda_2020 models. Note that the line numbers displayed below may not correspond to the main branch, but do correspond to Kuroda_2020.__init__.

I will note, running the same code in astropy 4.3.1 yields no errors. Would it be appropriate/sufficient to add a version requirement (astropy >= 4.3.1) to the requirements.txt?

Example Code:

>>> from snewpy.models.ccsn import Kuroda_2020
>>> Kuroda_2020('/path/to/snewpy/models/Kuroda_2020/LnuR00B00.dat')

Error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_7249/1500263364.py in <module>
      1 from snewpy.models.ccsn import Kuroda_2020
----> 2 Kuroda_2020('/path/to/snewpy/models/Kuroda_2020/LnuR00B00.dat')

~/Code/SNEWS/snewpy/python/snewpy/models/base.py in _wrapper(self, *arg, **kwargs)
     16     @wraps(init)
     17     def _wrapper(self, *arg, **kwargs):
---> 18         init(self, *arg, **kwargs)
     19         check(self)
     20     return _wrapper

~/Code/SNEWS/snewpy/python/snewpy/models/ccsn.py in __init__(self, filename, eos, mass)
    433             simtab[f'E_{f.name}'] = simtab[f'<E{fkey}>'] << u.MeV
    434             # There is no pinch parameter so use alpha=2.0.
--> 435             simtab[f'ALPHA_{f.name}'] = np.full_like(simtab[f'E_{f.name}'].value, 2.)
    436 
    437         super().__init__(simtab, metadata)

AttributeError: 'Column' object has no attribute 'value'
JostMigenda commented 2 years ago

Here’s the corresponding astropy PR; it looks like this was added in astropy 4.3. Hopefully, for most users pip will install the latest astropy version, so they won’t run into this problem; but making this version requirement explicit in requirements.txt can’t hurt. (In particular, astropy 4.3 supports the same Python versions as 4.2 (namely, Python 3.7 and higher) so there should be no compatibility issues in that regard.