Note
Run this example online :
Compare performance between old 1T fitting example and new fitting moduleΒΆ
This example will try to fit an experimental spectrum using two fitting pipelines:
Old fitting module of
fit_spectrum()
, which is the current RADIS fitting module. You can find the gallery example featuring it at1 temperature fit
.New fitting module of
fit_spectrum()
, a new fitting interface for a more practical and interactive fitting experience. See1 temperature fit using new module
With this, you can compare their overall performance, including number of loops, fitting time, and final residuals between experimental and best-fit spectra, as an indicator of fit accuracy.
Using database: HITRAN-CO2-TEST
'HITRAN-CO2-TEST':
{'info': 'HITRAN 2016 database, CO2, 1 main isotope (CO2-626), bandhead: 2380-2398 cm-1 (4165-4200 nm)', 'path': ['/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/hitran_co2_626_bandhead_4165_4200nm.par'], 'format': 'hitran', 'parfuncfmt': 'hapi', 'levelsfmt': 'radis'}
Reference databank (2391.79-2399.14cm-1) has 0 lines in range (2391.69-2399.15cm-1) for isotope 2. Change your range or isotope options
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/log.py:54: UserWarning:
Reference databank (2391.79-2399.14cm-1) has 0 lines in range (2391.69-2399.15cm-1) for isotope 2. Change your range or isotope options
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: LinestrengthCutoffWarning:
Estimated error after discarding lines is large: 0.07%. Consider reducing cutoff
Calculating Equilibrium Spectrum
Physical Conditions
----------------------------------------
Tgas 300 K
Trot 300 K
Tvib 300 K
isotope 1,2
mole_fraction 1
molecule CO2
overpopulation None
path_length 10 cm
pressure 0.001 bar
rot_distribution boltzmann
self_absorption True
state X
vib_distribution boltzmann
wavenum_max 2399.1537 cm-1
wavenum_min 2391.6923 cm-1
Computation Parameters
----------------------------------------
Tref 296 K
add_at_used cython
broadening_method voigt
cutoff 1e-25 cm-1/(#.cm-2)
dbformat hitran
dbpath /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/hitran_co2_...
diluent air
folding_thresh 1e-06
include_neighbouring_lines True
memory_mapping_engine auto
neighbour_lines 0 cm-1
optimization simple
parfuncfmt hapi
parsum_mode full summation
pseudo_continuum_threshold 0
sparse_ldm True
truncation 1 cm-1
waveunit cm-1
wstep 0.001 cm-1
zero_padding 7463
----------------------------------------
0.03s - Spectrum calculated
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: LinestrengthCutoffWarning:
Estimated error after discarding lines is large: 0.07%. Consider reducing cutoff
------------------------------
TYPICAL FIT CALCULATION TIME:
Fit (in progress) profiler :
spectrum_calculation 0.024s ββββββββββββββββ
check_line_databank 0.001s
reinitialize 0.002s β
copy_database 0.000s
memory_usage_warning 0.002s β
reset_population 0.000s
scaled_eq_linestrength 0.002s β
applied_linestrength_cutoff 0.001s
calc_lineshift 0.001s
calc_hwhm 0.004s ββ
generate_wavenumber_arrays 0.000s
calc_line_broadening 0.010s ββββββ
precompute_LDM_lineshapes 0.001s
LDM_Initialized_vectors 0.000s
LDM_closest_matching_line 0.000s
LDM_Distribute_lines 0.005s βββ
LDM_convolve 0.003s ββ
calc_other_spectral_quan 0.002s β
generate_spectrum_obj 0.000s
------------------------------
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: LinestrengthCutoffWarning:
Estimated error after discarding lines is large: 0.07%. Consider reducing cutoff
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Now starting the fitting process:
---------------------------------
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1150.0, Residual: 0.0105 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1170.0, Residual: 0.0098 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1150.0, Residual: 0.0105
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1170.0, Residual: 0.0098 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=2000.0, Residual: 0.0128
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1980.0, Residual: 0.0128
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1396.0, Residual: 0.0034 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1416.0, Residual: 0.0031 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1396.0, Residual: 0.0034
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1416.0, Residual: 0.0031 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1396.0, Residual: 0.0034
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1416.0, Residual: 0.0031 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1396.0, Residual: 0.0034
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1416.0, Residual: 0.0031 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1396.0, Residual: 0.0034
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1416.0, Residual: 0.0031 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1396.0, Residual: 0.0034
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1416.0, Residual: 0.0031 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1396.0, Residual: 0.0034
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1416.0, Residual: 0.0031 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1396.0, Residual: 0.0034
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1416.0, Residual: 0.0031 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1396.0, Residual: 0.0034
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1416.0, Residual: 0.0031 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1397.0, Residual: 0.0034
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1417.0, Residual: 0.0030 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1402.0, Residual: 0.0033
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1422.0, Residual: 0.0030 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1420.0, Residual: 0.0030
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1440.0, Residual: 0.0028 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1458.0, Residual: 0.0027 π
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Tgas=1478.0, Residual: 0.0028
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:
'object' type column found in database, calculations and memory usage would be faster with a numeric type. Possible solution is to not use 'save_memory' and convert the columns to dtype.
Init ['Tgas'] = [1150.]['']
Final ['Tgas'] = [1458.]['']
message: CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL
success: True
status: 0
fun: 0.002730027027336181
x: [ 1.458e+03]
nit: 4
jac: [ 3.178e-06]
nfev: 32
njev: 16
hess_inv: <1x1 LbfgsInvHessProduct with dtype=float64>
Best ['Tgas'] = [1457.50267416][''] reached at iteration 32/32
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:268: UserWarning:
First spectrum has more resolution than 2nd. Reverse your spectra in interpolation/comparison for a better accuracy
[[Fit Statistics]]
# fitting method = L-BFGS-B
# function evals = 36
# data points = 1
# variables = 1
chi-square = 2.6772e-07
reduced chi-square = 2.6772e-07
Akaike info crit = -13.1333192
Bayesian info crit = -15.1333192
## Warning: uncertainties could not be estimated:
this fitting method does not natively calculate uncertainties
and numdifftools is not installed for lmfit to do this. Use
`pip install numdifftools` for lmfit to estimate uncertainties
with this fitting method.
[[Variables]]
Tgas: 1464.09064 (init = 1150)
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/curve.py:241: UserWarning:
Presence of NaN in curve_divide!
Think about interpolation=2
==================== PERFORMANCE COMPARISON BETWEEN 2 FITTING METHODS ====================
1. LAST RESIDUAL
- Old 1T fitting example: 0.002730027027336181
- New fitting module: 0.0005174179496843738
2. NUMBER OF FITTING LOOPS
- Old 1T fitting example: 32 loops
- New fitting module: 36 loops
3. TOTAL TIME TAKEN (s)
- Old 1T fitting example: 2.0587642192840576 s
- New fitting module: 6.526666164398193 s
==========================================================================================
'\n\nFrom the comparative result above, which includes last residual, total time fitting and total number of\nfitting loops of each fitting method, we can see that under exactly the same ground-truth conditions,\nfitting method (L-BFGS-B) and fitting pipeline, we can see that the new fitting module provides a better\naccuracy, while requiring less fitting loops and time for execution.\n\nYou are free to change the experimental spectrum and its accompanied ground-truth conditions, but please\nmake sure to keep the same inputs between the two for a transparent comparative result.\n\n'
import time
import astropy.units as u
from radis import SpectrumFactory, load_spec, plot_diff
from radis.test.utils import getTestFile, setup_test_line_databases
from radis.tools.fitting import LTEModel
from radis.tools.new_fitting import fit_spectrum
# ------------------------------------ OLD 1-TEMPERATURE FITTING EXAMPLE ------------------------------------ #
setup_test_line_databases()
# fit range
wlmin = 4167
wlmax = 4180
s_exp = (
load_spec(getTestFile("CO2_measured_spectrum_4-5um.spec"))
.crop(wlmin, wlmax, "nm")
.normalize()
.sort()
.offset(-0.2, "nm")
)
def LTEModel_withslitnorm(factory, fit_parameters, fixed_parameters):
s = LTEModel(factory, fit_parameters, fixed_parameters)
# we could also have added a fittable parameter, such as an offset,
# or made the slit width a fittable parameter.
# ... any parameter in model_input will be fitted.
# s.offset(model_input["offset"], 'nm')
s.apply_slit(1.4, "nm")
return s.take("radiance").normalize()
sf = SpectrumFactory(
wlmin * u.nm,
wlmax * u.nm,
wstep=0.001, # cm-1
pressure=1 * 1e-3, # bar
cutoff=1e-25,
isotope="1,2",
path_length=10, # cm-1
mole_fraction=1,
truncation=1, # cm-1
)
sf.warnings["MissingSelfBroadeningWarning"] = "ignore"
sf.warnings["HighTemperatureWarning"] = "ignore"
sf.load_databank("HITRAN-CO2-TEST")
begin_time_mark = time.time()
s_best, best = sf.fit_spectrum(
s_exp.take("radiance"),
model=LTEModel_withslitnorm,
fit_parameters={
"Tgas": 300,
# "offset": 0
},
bounds={
"Tgas": [300, 2000],
# "offset": [-1, 1],
},
plot=True,
solver_options={
"maxiter": 15, # π increase to let the fit converge
"ftol": 1e-15,
},
verbose=2,
)
end_time_mark = time.time()
plot_diff(s_exp, s_best)
# Information to report later in comparison result
oldfitting_residual = best.fun
oldfitting_loops = best.nfev
oldfitting_time = end_time_mark - begin_time_mark
# ------------------------------------------------------------------------------------------------------------ #
# -------------------------------------------- NEW FITTING MODULE -------------------------------------------- #
# ------------------------------------ Step 1. Load experimental spectrum ------------------------------------ #
# Load an experimental spectrum. You can prepare yours, or fetch one of them in the radis/test/files directory.
my_spec = getTestFile("CO2_measured_spectrum_4-5um.spec")
s_experimental = load_spec(my_spec).offset(-0.2, "nm")
# ------------------------------------ Step 2. Fill ground-truths and data ------------------------------------ #
# Experimental conditions which will be used for spectrum modeling. Basically, these are known ground-truths.
experimental_conditions = {
"molecule": "CO2", # Molecule ID
"isotope": "1,2", # Isotope ID, can have multiple at once
"wmin": 4167
* u.nm, # Starting wavelength/wavenumber to be cropped out from the original experimental spectrum.
"wmax": 4180 * u.nm, # Ending wavelength/wavenumber for the cropping range.
"mole_fraction": 1, # Species mole fraction, from 0 to 1.
"pressure": 1
* 1e-3
* u.bar, # Total pressure of gas, in "bar" unit by default, but you can also use Astropy units.
"path_length": 10
* u.cm, # Experimental path length, in "cm" unit by default, but you can also use Astropy units.
"slit": "1.4 nm", # Experimental slit, must be a blank space separating slit amount and unit.
"wstep": 0.001, # Resolution of wavenumber grid, in cm-1.
"databank": "hitran", # Databank used for the spectrum calculation. Must be stated.
}
# List of parameters to be fitted, accompanied by their initial values.
fit_parameters = {
"Tgas": 1150, # Gas temperature, in K.
}
# List of bounding ranges applied for those fit parameters above.
# You can skip this step and let it use default bounding ranges, but this is not recommended.
# Bounding range must be at format [<lower bound>, <upper bound>].
bounding_ranges = {
"Tgas": [
300,
2000,
],
}
# Fitting pipeline setups.
fit_properties = {
"method": "lbfgsb", # Preferred fitting method. By default, "leastsq".
"fit_var": "radiance", # Spectral quantity to be extracted for fitting process, such as "radiance", "absorbance", etc.
"normalize": True, # Either applying normalization on both spectra or not.
"max_loop": 150, # Max number of loops allowed. By default, 200.
"tol": 1e-15, # Fitting tolerance, only applicable for "lbfgsb" method.
}
"""
For the fitting method, you can try one among 17 different fitting methods and algorithms of LMFIT,
introduced in `LMFIT method list <https://lmfit.github.io/lmfit-py/fitting.html#choosing-different-fitting-methods>`.
You can see the benchmark result of these algorithms here:
`RADIS Newfitting Algorithm Benchmark <https://github.com/radis/radis-benchmark/blob/master/manual_benchmarks/plot_newfitting_comparison_algorithm.py>`.
"""
# ------------------------------------ Step 3. Run the fitting and retrieve results ------------------------------------ #
# Conduct the fitting process!
s_bestfit, result, log = fit_spectrum(
s_exp=s_experimental, # Experimental spectrum.
fit_params=fit_parameters, # Fit parameters.
bounds=bounding_ranges, # Bounding ranges for those fit parameters.
model=experimental_conditions, # Experimental ground-truths conditions.
pipeline=fit_properties, # Fitting pipeline references.
verbose=False, # If you want a clean result, stay False. If you want to see more about each loop, True.
)
# Information to report later in comparison result
newfitting_residual = log["residual"][-1]
newfitting_loops = result.nfev
newfitting_time = log["time_fitting"]
# ---------------------------------------------------------------------------------------------------------------------- #
# ---------------------------------- PERFORMANCE COMPARISON BETWEEN 2 FITTING METHODS ---------------------------------- #
print(
"\n\n\n==================== PERFORMANCE COMPARISON BETWEEN 2 FITTING METHODS ===================="
)
print("\n1. LAST RESIDUAL\n")
print(f"- Old 1T fitting example: \t{oldfitting_residual}")
print(f"- New fitting module: \t{newfitting_residual}")
print("\n2. NUMBER OF FITTING LOOPS\n")
print(f"- Old 1T fitting example: \t{oldfitting_loops} loops")
print(f"- New fitting module: \t{newfitting_loops} loops")
print("\n3. TOTAL TIME TAKEN (s)\n")
print(f"- Old 1T fitting example: \t{oldfitting_time} s")
print(f"- New fitting module: \t{newfitting_time} s")
print(
"\n==========================================================================================\n"
)
"""
From the comparative result above, which includes last residual, total time fitting and total number of
fitting loops of each fitting method, we can see that under exactly the same ground-truth conditions,
fitting method (L-BFGS-B) and fitting pipeline, we can see that the new fitting module provides a better
accuracy, while requiring less fitting loops and time for execution.
You are free to change the experimental spectrum and its accompanied ground-truth conditions, but please
make sure to keep the same inputs between the two for a transparent comparative result.
"""
Total running time of the script: (0 minutes 12.793 seconds)