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

indentation issue/logic issue in core/Ions.py #286

Open
jslavin opened this issue Oct 5, 2020 · 2 comments
Open

indentation issue/logic issue in core/Ions.py #286

jslavin opened this issue Oct 5, 2020 · 2 comments

Comments

@jslavin
Copy link
Contributor

jslavin commented Oct 5, 2020

Hi Ken et al.,

I think I found a bug in core/Ions.py
It's in the if block that starts on line 149:
if setup:
if self.IonStr in chdata.MasterList:
...
else:
if verbose:
print(' ion %s not in masterlist, just various attributes, ionization, recombination rates'%(self.IonStr))

So, currently if setup is False and verbose is True it will print a message that the ion is not in masterlist. I think what is intended is for that block to be indented one level more. Then there is the question of the indentation of the next statements, which as currently written execute only if setup is False:
if np.any(temperature) is not None:
self.Temperature = np.atleast_1d(temperature)
self.Ntemp = self.Temperature.size
self.setupIonrec()
Was it intended that these be executed when ion is not in masterlist?
I ran into this because if you create an instance of ion with 'mg_1' as the ion, and then invoke the recombRate() method, you get an exception because the temperature is not defined.
I'm not sure what the proper behavior in this case is, but it seems clear that the current code is not correct.

Jon

@jslavin
Copy link
Contributor Author

jslavin commented Oct 5, 2020

I think the piece of code I referred to needs to be changed such that if either setup is not True or the ion is not in the masterlist, then self.Temperature and self.Ntemp must be defined and setupIonrec() must be called. so here's my code snippet:

    if setup and self.IonStr in chdata.MasterList:
        self.IoneqAll = chdata.IoneqAll
        #  this needs to go after setting temperature and reading ionization
        #  equilibria
        #  needs to know self.NTempDens first
        self.argCheck(temperature, eDensity, pDensity, em)
        self.ioneqOne()

        self.setup()
    else:
        if verbose and (self.IonStr not in chdata.MasterList):
            print(f' ion {self.IonStr} not in masterlist, just various'
                    ' attributes, ionization, recombination rates')
        if np.any(temperature) is not None:
            self.Temperature = np.atleast_1d(temperature)
            self.Ntemp = self.Temperature.size
        self.setupIonrec()

I could make a pull request if you want.

Jon

@kdere
Copy link
Contributor

kdere commented Oct 5, 2020 via email

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