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

argCheck method prevents creating ion objects by name only #466

Open
andrewfullard opened this issue Sep 9, 2024 · 4 comments
Open

argCheck method prevents creating ion objects by name only #466

andrewfullard opened this issue Sep 9, 2024 · 4 comments

Comments

@andrewfullard
Copy link

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
@kdere
Copy link
Contributor

kdere commented Sep 9, 2024

I will look into it. I used to work that way

@andrewfullard
Copy link
Author

There is a workaround- give the ion class a temperature of 1 as an init value.

@kdere
Copy link
Contributor

kdere commented Sep 10, 2024

If that works for you, I will not make any changes just yet

@andrewfullard
Copy link
Author

It's not ideal, but it seems to pass our tests

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