argCheck method prevents creating ion objects by name only
We would like to use the latest ChiantiPy for the package Carsus https://github.com/tardis-sn/carsus. However, in the process of upgrading, I found that it is no longer possible to create an ion object without a defined temperature. Is this intended? The ion object states the temperature is optional, and it is None by default.
Output is:
self = <carsus.io.tests.test_chianti.TestChiantiIonReader object at 0x7f49994531d0>
request = <SubRequest 'ch_ion_reader' for <Function test_chianti_bound_levels[ne_2]>>
@pytest.fixture(scope="class", params=["ne_2", "n_5"])
def ch_ion_reader(self, request):
> return ChiantiIonReader(request.param)
carsus/io/tests/test_chianti.py:9:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
carsus/io/chianti_/chianti_.py:112: in __init__
self.ion = ch.ion(ion_name)
../miniforge3/envs/carsus/lib/python3.12/site-packages/ChiantiPy/core/Ion.py:160: in __init__
self.argCheck(temperature, eDensity, pDensity, em)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ChiantiPy.core.Ion.ion object at 0x7f4998f2b440>, temperature = None
eDensity = None, pDensity = 'default', em = None, verbose = 0
def argCheck(self, temperature=None, eDensity=None, pDensity='default', em = None, verbose=0):
''' to check the compatibility of the three arguments
and put them into numpy arrays of atleast_1d
and create attributes to the object
'''
if temperature is not None:
self.Temperature = np.atleast_1d(temperature)
if isinstance(self.Temperature[0], str):
raise ValueError(' temperature can not be a string')
if np.any(self.Temperature <= 0.):
raise ValueError(' all temperatures must be positive')
self.Ntemp = self.Temperature.size
else:
> raise ValueError('temperature not defined')
E ValueError: temperature not defined
../miniforge3/envs/carsus/lib/python3.12/site-packages/ChiantiPy/base/_IonTrails.py:33: ValueError
I will look into it. I used to work that way
There is a workaround- give the ion class a temperature of 1 as an init value.
If that works for you, I will not make any changes just yet
It's not ideal, but it seems to pass our tests
I have updated the ion class so that if you invoke:
fe14 = ch.ion('fe_14', setup=False)
then no error occurs but the various attributes are available.
I have not yet done a new release but will do one in the near future
Thank you! That's greatly appreciated.