radis / radis-examples

Interactive In-the-browser (and more) examples to calculate spectra with RADIS (HITRAN Online access, etc.)
http://radis.readthedocs.io/
6 stars 4 forks source link

exp overflow in radiative_forcing_co2.py #4

Closed Anjum48 closed 3 years ago

Anjum48 commented 3 years ago

Hi All,

I'm seeing exp overflow errors in radiative_forcing_co2.py presumably due to extreme values of absorbance in eq_spectrum and some other functions at certain slabs in the middle of the atmosphere.

Any ideas on how to workaround this? Happy to submit a PR if it's an easy fix

HAPI version: 1.1.2.0
To get the most up-to-date version please check http://hitran.org/hapi
ATTENTION: Python versions of partition sums from TIPS-2017 are now available in HAPI code

           It is free to use HAPI. If you use HAPI in your research or software development,
           please cite it using the following reference:
           R.V. Kochanov, I.E. Gordon, L.S. Rothman, P. Wcislo, C. Hill, J.S. Wilzewski,
           HITRAN Application Programming Interface (HAPI): A comprehensive approach
           to working with spectroscopic data, J. Quant. Spectrosc. Radiat. Transfer 177, 15-30 (2016)
           DOI: 10.1016/j.jqsrt.2016.03.005
Calculating Atmosphere layers
(58s)   39.1%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\lbl\factory.py:798: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
(60s)   40.2%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\lbl\factory.py:798: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
(62s)   41.4%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\lbl\factory.py:798: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
(64s)   42.5%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\lbl\factory.py:798: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
(65s)   43.7%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\lbl\factory.py:798: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
(67s)   44.8%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\lbl\factory.py:798: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
(69s)   46.0%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\lbl\factory.py:798: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
(71s)   47.1%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\lbl\factory.py:798: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
(73s)   48.3%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\lbl\factory.py:798: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
(75s)   49.4%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\lbl\factory.py:798: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
(168s)  100.0%
Solving radiative transfer equation
C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\los\slabs.py:250: RuntimeWarning: overflow encountered in multiply
  quantities["radiance_noslit"] = (w, I * Tn + In)
C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\los\slabs.py:254: RuntimeWarning: invalid value encountered in multiply
  quantities["transmittance_noslit"] = (w, Tn * T)
C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\los\slabs.py:314: UserWarning: Nans detected in Spectrum object for multi-slab operation. Results may be wrong!
  warn(
Calculating Reference Atmosphere
(1s)    42.5%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\spectrum\rescale.py:721: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\spectrum\rescale.py:730: RuntimeWarning: invalid value encountered in true_divide
  radiance_noslit[~b] / (1 - transmittance_noslit[~b]) * abscoeff[~b]
(1s)    43.7%C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\spectrum\rescale.py:721: RuntimeWarning: overflow encountered in exp
  transmittance_noslit = exp(-absorbance)
C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\spectrum\rescale.py:730: RuntimeWarning: invalid value encountered in true_divide
  radiance_noslit[~b] / (1 - transmittance_noslit[~b]) * abscoeff[~b]
(3s)    100.0%
Solving radiative transfer equation
C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\los\slabs.py:250: RuntimeWarning: overflow encountered in multiply
  quantities["radiance_noslit"] = (w, I * Tn + In)
C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\los\slabs.py:254: RuntimeWarning: invalid value encountered in multiply
  quantities["transmittance_noslit"] = (w, Tn * T)
C:\Users\anjum\Miniconda3\envs\zeus\lib\site-packages\radis\los\slabs.py:314: UserWarning: Nans detected in Spectrum object for multi-slab operation. Results may be wrong!
  warn(
Upward radiation @278 ppm: nan W/m2
Upward radiation @400 ppm: nan W/m2
erwanp commented 3 years ago

Hello @Anjum48 , thank you for reporting !!

I didn't have these errors before (this example is not part of the automated tests! ), and it seems it was introduced in 0.9.21 when the new lineshape algorithm became the default RADIS method.

We'll investigate further (I'll open an Issue in the main RADIS).

In the meantime I switched back to non-optimization for this example. On my laptop, it also makes computations 2x faster : the new lineshape algorithm can add extra overhead, but is about ~constant with the number of lines. Therefore it's extremely fast at high temperatures and large molecules. For CO2 at low temperatures as in an atmosphere the overhead doesn't seem required (for your CH4 example try with and without the optimization=parameter). Please pull, test again and :

Anjum48 commented 3 years ago

Thanks for the quick reply @erwanp! Yes setting optimization=None and removing the chunksize arg seemed to get things moving for CO2. I'll play around with CH4 and let you know if there are any issues