Issue with getTemDen using ANN in PyNeb 1.1.23

33 views
Skip to first unread message

Corina Castañeda

unread,
Feb 6, 2025, 8:12:41 PMFeb 6
to PyNeb
Hello!
 
I recently updated to PyNeb 1.1.23 and encountered an issue when using getTemDen with the ANN method. For example, the following command:

S2.getTemDen(int_ratio=[1.2], tem=[9000], method='ANN', to_eval='L(6716)/L(6731)')

returns the following error:

ERROR Atom S2: _getTemDen_ANN cannot be used if ai4neb is not imported. Try to run pn.config.import_AI4Neb().

---------------------------------------------------------------------------
PyNebError                                Traceback (most recent call last)
Cell In[6], line 5
      2 S2 = pn.Atom('S', 2)  # Define the SII ion in PyNeb
      4 # Create a quick density map to estimate c(Hβ) (reddening coefficient)
----> 5 denS2 = S2.getTemDen(
      6     line_info['SII6717'][0] / line_info['SII6731'][0],  # Line ratio of [SII] 6717 / 6731
      7     tem=9000,  # Assumed temperature in Kelvin (9000 K)
      8     method='ANN',  # Use Artificial Neural Networks for calculations
      9     to_eval='L(6716) / L(6731)',  # Expression to evaluate the line ratio
     10     start_x=1.0,  # Expecting minimal log density (log n_e) in cm^-3
     11     end_x=5.0  # Expecting maximal log density (log n_e) in cm^-3
     12 )

File ~/anaconda3/envs/ML3/lib/python3.11/site-packages/pyneb/core/pynebcore.py:2478, in Atom.getTemDen(self, int_ratio, tem, den, lev_i1, lev_j1, lev_i2, lev_j2, wave1, wave2, maxError, method, log, start_x, end_x, to_eval, nCut, maxIter)
   2434 """
   2435 Return either the temperature or the density given the other variable for a selected line ratio
   2436     of known intensity.
   (...)
   2475     O3.getTemDen([0.02, 0.04], den=[1.e4, 1.1e4], to_eval="I(5, 4) / (I(4, 3) + I(4, 2))")
   2476 """
   2477 if method == 'ANN':
-> 2478     return self._getTemDen_ANN(int_ratio=int_ratio, tem=tem, den=den, lev_i1=lev_i1, lev_j1=lev_j1, lev_i2=lev_i2, lev_j2=lev_j2,
   2479           wave1=wave1, wave2=wave2, log=log, start_x=start_x, end_x=end_x, to_eval=to_eval)      
   2480 elif config._use_mp:
   2481     return self._getTemDen_MP(int_ratio=int_ratio, tem=tem, den=den, lev_i1=lev_i1, lev_j1=lev_j1, lev_i2=lev_i2, lev_j2=lev_j2,
   2482           wave1=wave1, wave2=wave2, maxError=maxError, method=method, log=log, start_x=start_x,
   2483           end_x=end_x, to_eval=to_eval, nCut=nCut, maxIter=maxIter)

File ~/anaconda3/envs/ML3/lib/python3.11/site-packages/pyneb/core/pynebcore.py:2339, in Atom._getTemDen_ANN(self, int_ratio, tem, den, lev_i1, lev_j1, lev_i2, lev_j2, wave1, wave2, log, start_x, end_x, to_eval)
   2334 @profile
   2335 def _getTemDen_ANN(self, int_ratio, tem= -1, den= -1, lev_i1= -1, lev_j1= -1, lev_i2= -1, lev_j2= -1,
   2336               wave1= -1, wave2= -1, log=True, start_x= -1, end_x= -1, to_eval=None):
   2338     if not config.INSTALLED['ai4neb']:
-> 2339         self.log_.error('_getTemDen_ANN cannot be used if ai4neb is not imported. Try to run pn.config.import_AI4Neb().',
   2340                       calling=self.calling)
   2341         return None
   2343     self._test_lev(lev_i1)

File ~/anaconda3/envs/ML3/lib/python3.11/site-packages/pyneb/utils/logging.py:114, in my_logging.error(self, message, calling, exception)
    112     else:
    113         exception = SystemExit
--> 114 raise exception(message)

PyNebError: '_getTemDen_ANN cannot be used if ai4neb is not imported. Try to run pn.config.import_AI4Neb().'

However, the same command works correctly in PyNeb 1.1.21.

I tried explicitly importing ai4neb using pn.config.import_AI4Neb(), but the issue persists. Is there any change in how ANN-based calculations should be handled in the latest version?

Any guidance would be greatly appreciated.

Best regards,

Lesly Corina



Christophe Morisset

unread,
Feb 7, 2025, 10:25:31 AMFeb 7
to PyNeb
Helo Lesly,
I just released a new version of PyNeb (1.1.24) that should run OK if you use pn.config.import_AI4Neb() before any pyneb use.
Tell me if this is OK.
Christophe

Reply all
Reply to author
Forward
0 new messages