Fit a non-LTE spectrum with multiple fit parameters using new fitting module

With the new fitting module introduced in fit_spectrum() function, and in the example of Tgas fitting using new fitting module, we can see its 1-temperature fitting performance for equilibrium condition.

This example features how new fitting module can fit non-equilibrium spectrum, with multiple fit parameters, such as vibrational/rotational temperatures, or mole fraction, etc.

This is a real fitting case introduced by Mr. Corentin Grimaldi, a scientist and member of RADIS community. This case features CO molecule emitting on a wide range of spectrum. This case also includes a user-defined trapezoid slit function, which is accounted by the distortion (dispersion) of the slit, as a result of the influences from experimental parameters and spectrometer dispersion parameters during the experiment.

  • plot newfitting Trot Tvib molfrac
  • plot newfitting Trot Tvib molfrac
======================= COMMENCE FITTING PROCESS =======================

Successfully retrieved the experimental data in 0.0009868144989013672s.

Acquired spectral quantity 'radiance' from the spectrum.
NaN values successfully purged.Number of data points left: 1479 points.
Successfully refined the experimental data in 0.0003924369812011719s.

Commence fitting process for non-LTE spectrum!
/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/misc/warning.py:427: PerformanceWarning:

'gu' was recomputed although 'gp' already in DataFrame. All values are equal

[[Fit Statistics]]
    # fitting method   = L-BFGS-B
    # function evals   = 188
    # data points      = 1
    # variables        = 3
    chi-square         = 1.1070e-21
    reduced chi-square = 1.1070e-21
    Akaike info crit   = -42.2526499
    Bayesian info crit = -48.2526499
##  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]]
    Tvib:           4193.06781 (init = 6000)
    Trot:           4033.49909 (init = 4000)
    mole_fraction:  0.07216532 (init = 0.05)

Successfully finished the fitting process in 17.85886573791504s.
/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


======================== END OF FITTING PROCESS ========================


Residual history:

[1.2732990358113976e-10, 1.27329905559213e-10, 1.2732990171904906e-10, 1.2732990760986793e-10, 3.896601757605693e-10, 3.8966017509570395e-10, 3.8966017618218785e-10, 3.896601731282261e-10, 9.06506301867885e-11, 9.065063013312198e-11, 9.06506308299874e-11, 9.06506284086053e-11, 8.589997214403783e-11, 8.589997278846656e-11, 8.589997210169128e-11, 8.589997213479261e-11, 8.486604387979725e-11, 8.486604450506385e-11, 8.486604386943292e-11, 8.486604378846494e-11, 8.079637509071399e-11, 8.079637558943574e-11, 8.079637524068202e-11, 8.079637460809528e-11, 7.518657663217275e-11, 7.518657546436919e-11, 7.518657781137394e-11, 7.518657384374808e-11, 6.384849816204576e-11, 6.384849806252196e-11, 6.38484987352425e-11, 6.384849676752567e-11, 4.8786633899625125e-11, 4.8786630364271246e-11, 4.878663533081506e-11, 4.8786631517904387e-11, 4.666822613352741e-11, 4.6668225830137035e-11, 4.666822664438326e-11, 4.666822496547851e-11, 5.7839151151435546e-11, 5.7839146733034866e-11, 5.7839152543611446e-11, 5.7839149045374744e-11, 3.945756280781085e-11, 3.945756146370979e-11, 3.9457563509488477e-11, 3.9457561348146826e-11, 3.973925007572968e-11, 3.973925244244228e-11, 3.9739248702091635e-11, 3.9739251490866544e-11, 3.547740530032008e-11, 3.5477405722813e-11, 3.5477404990132845e-11, 3.547740534169467e-11, 3.531219330891795e-11, 3.5312192638923744e-11, 3.531219331712518e-11, 3.531219286280563e-11, 3.493074389262077e-11, 3.493074385151889e-11, 3.493074370331382e-11, 3.493074374870746e-11, 3.479872557446613e-11, 3.479872561876452e-11, 3.479872535967892e-11, 3.479872548646488e-11, 3.369374558975691e-11, 3.3693746008021855e-11, 3.3693745332629777e-11, 3.369374577952901e-11, 3.331076596631411e-11, 3.3310766132774316e-11, 3.331076586729458e-11, 3.3310766058573495e-11, 3.3273975969930227e-11, 3.327397598688432e-11, 3.3273975953354904e-11, 3.3273975989510335e-11, 3.3271718259605e-11, 3.327171826959948e-11, 3.327171825320448e-11, 3.327171826888003e-11, 3.32713938746756e-11, 3.327139387828051e-11, 3.3271393874235455e-11, 3.327139387697954e-11, 3.327134129759137e-11, 3.327134129863814e-11, 3.3271341297861894e-11, 3.3271341298284506e-11, 3.3271376358284866e-11, 3.327137635853876e-11, 3.327137635786587e-11, 3.327137635748467e-11, 3.327133834596867e-11, 3.327133834693547e-11, 3.327133834610876e-11, 3.3271338346101443e-11, 3.327133810899602e-11, 3.3271338107524964e-11, 3.327133810917014e-11, 3.3271338108299994e-11, 3.3271334387574e-11, 3.327133438706078e-11, 3.3271334387385e-11, 3.327133438742913e-11, 3.327137305119489e-11, 3.3271373054611824e-11, 3.327137305115768e-11, 3.3271373051868214e-11, 3.3271334833868555e-11, 3.3271334834469896e-11, 3.327133483399318e-11, 3.327133483394505e-11, 3.327133435791695e-11, 3.327133435815062e-11, 3.3271334357952755e-11, 3.3271334357609055e-11, 3.327133392097529e-11, 3.327133392138282e-11, 3.327133392125466e-11, 3.327133392105724e-11, 3.327133383536128e-11, 3.327133383543025e-11, 3.3271333835614875e-11, 3.327133383545138e-11, 3.3271333926465705e-11, 3.3271333926778586e-11, 3.327133392666674e-11, 3.3271333926511393e-11, 3.327133391250879e-11, 3.327133391261333e-11, 3.327133391227276e-11, 3.327133391223861e-11, 3.327133390781814e-11, 3.3271333908000565e-11, 3.327133390805986e-11, 3.327133390793352e-11, 3.327133390639041e-11, 3.327133390659793e-11, 3.327133390647774e-11, 3.327133390647458e-11, 3.327133407757168e-11, 3.327133407748776e-11, 3.3271334077393015e-11, 3.327133407744178e-11, 3.327133394782893e-11, 3.327133394773855e-11, 3.3271333947837047e-11, 3.3271333947546836e-11, 3.3271333918274536e-11, 3.3271333918345925e-11, 3.3271333918458726e-11, 3.327133391845923e-11, 3.3271333907830844e-11, 3.327133390820987e-11, 3.3271333907719246e-11, 3.327133390798324e-11, 3.3271333906860006e-11, 3.327133390673148e-11, 3.327133390684091e-11, 3.327133390669839e-11, 3.3271333906550155e-11, 3.327133390693055e-11, 3.3271333906559364e-11, 3.32713339069274e-11, 3.327133390665126e-11, 3.327133390648969e-11, 3.327133390668729e-11, 3.3271333906519246e-11, 3.327133390636554e-11, 3.3271333906635684e-11, 3.3271333906571294e-11, 3.327133390647209e-11, 3.327133390640956e-11, 3.327133390652676e-11, 3.327133390656338e-11, 3.3271333906487807e-11, 3.32713339063693e-11, 3.327133390664157e-11, 3.3271333906580606e-11, 3.327133390649798e-11, 3.327133390636554e-11, 3.3271333906635684e-11, 3.3271333906571294e-11, 3.327133390647209e-11, 3.327133390636554e-11]

Fitted values history:

[6000.0, 4000.0, 0.05]
[6000.0000199999995, 4000.0, 0.05]
[6000.0, 4000.0000244948974, 0.05]
[6000.0, 4000.0, 0.0500000005]
[5085.545603162275, 4952.147214358158, 0.013133452168762844]
[5085.545627466876, 4952.147214358158, 0.013133452168762844]
[5085.545603162275, 4952.147238945883, 0.013133452168762844]
[5085.545603162275, 4952.147214358158, 0.013133452506528693]
[5841.758648006694, 4178.652704366572, 0.042193268802800075]
[5841.758669100967, 4178.652704366572, 0.042193268802800075]
[5841.758648006694, 4178.652729159183, 0.042193268802800075]
[5841.758648006694, 4178.652704366572, 0.042193269296667966]
[5854.3260624735785, 4134.178382770393, 0.04451765078312588]
[5854.326083487385, 4134.178382770393, 0.04451765078312588]
[5854.3260624735785, 4134.178407501295, 0.04451765078312588]
[5854.3260624735785, 4134.178382770393, 0.044517651280111176]
[5820.631396386806, 4133.891738183207, 0.04471109434545228]
[5820.6314176139895, 4133.891738183207, 0.04471109434545228]
[5820.631396386806, 4133.891762913683, 0.04471109434545228]
[5820.631396386806, 4133.891738183207, 0.04471109484264715]
[5682.578757534426, 4132.745209057051, 0.04548564022669978]
[5682.578779560563, 4132.745209057051, 0.04548564022669978]
[5682.578757534426, 4132.745233785828, 0.04548564022669978]
[5682.578757534426, 4132.745209057051, 0.04548564072465766]
[5088.128418568722, 4128.159884426423, 0.048592881515506704]
[5088.128442867086, 4128.159884426423, 0.048592881515506704]
[5088.128418568722, 4128.159909148346, 0.048592881515506704]
[5088.128418568722, 4128.159884426423, 0.04859288201530867]
[5123.707404404498, 4083.999052114494, 0.05060863699334783]
[5123.707428613978, 4083.999052114494, 0.05060863699334783]
[5123.707404404498, 4083.999076765951, 0.05060863699334783]
[5123.707404404498, 4083.999052114494, 0.05060863749331079]
[4167.109665879703, 3864.8846188817934, 0.06561059586887188]
[4167.10969065708, 3864.8846188817934, 0.06561059586887188]
[4167.109665879703, 3864.884643061596, 0.06561059586887188]
[4167.109665879703, 3864.8846188817934, 0.06561059634387813]
[4683.285797598917, 3981.9192286775933, 0.05765464421996811]
[4683.285822531639, 3981.9192286775933, 0.05765464421996811]
[4683.285797598917, 3981.9192531348876, 0.05765464421996811]
[4683.285797598917, 3981.9192286775933, 0.05765464471407401]
[3903.902507823639, 3689.0974262748205, 0.07046334237591477]
[3903.9025321025756, 3689.0974262748205, 0.07046334237591477]
[3903.902507823639, 3689.0974499231547, 0.07046334237591477]
[3903.902507823639, 3689.0974262748205, 0.07046334283212212]
[4379.210862989788, 3867.3155084698165, 0.0627340205410419]
[4379.210887960591, 3867.3155084698165, 0.0627340205410419]
[4379.210862989788, 3867.315532655991, 0.0627340205410419]
[4379.210862989788, 3867.3155084698165, 0.06273402102455453]
[4188.295423076396, 3666.5907325262906, 0.06966186356248173]
[4188.295447881315, 3666.5907325262906, 0.06966186356248173]
[4188.295423076396, 3666.590756096248, 0.06966186356248173]
[4188.295423076396, 3666.5907325262906, 0.06966186402220025]
[4290.471807069318, 3773.539787776941, 0.06599164253672557]
[4290.471831981358, 3773.539787776941, 0.06599164253672557]
[4290.471807069318, 3773.539811698177, 0.06599164253672557]
[4290.471807069318, 3773.539787776941, 0.06599164301046256]
[4169.029790010816, 3732.9547134286513, 0.06815915804463751]
[4169.029814790765, 3732.9547134286513, 0.06815915804463751]
[4169.029790010816, 3732.9547372228562, 0.06815915804463751]
[4169.029790010816, 3732.9547134286513, 0.0681591585104964]
[4220.405191266212, 3757.580126632247, 0.06745879777190641]
[4220.405216109373, 3757.580126632247, 0.06745879777190641]
[4220.405191266212, 3757.5801505044337, 0.06745879777190641]
[4220.405191266212, 3757.580126632247, 0.067458798240435]
[4221.909848836586, 3768.036857049188, 0.0676343936636447]
[4221.909873681436, 3768.036857049188, 0.0676343936636447]
[4221.909848836586, 3768.0368809536435, 0.0676343936636447]
[4221.909848836586, 3768.036857049188, 0.06763439413151522]
[4214.604963073325, 3903.738282076525, 0.07006039348749067]
[4214.604987909891, 3903.738282076525, 0.07006039348749067]
[4214.604963073325, 3903.7383063550587, 0.07006039348749067]
[4214.604963073325, 3903.738282076525, 0.07006039394548419]
[4192.125175507558, 3994.4357612846934, 0.07181386617688337]
[4192.125200317259, 3994.4357612846934, 0.07181386617688337]
[4192.125175507558, 3994.435785768167, 0.07181386617688337]
[4192.125175507558, 3994.4357612846934, 0.0718138666267895]
[4187.616686847837, 4029.2177224357765, 0.07230771616147756]
[4187.616711651903, 4029.2177224357765, 0.07230771616147756]
[4187.616686847837, 4029.2177469885037, 0.07230771616147756]
[4187.616686847837, 4029.2177224357765, 0.07230771660895556]
[4191.325570392906, 4034.477336872007, 0.07224772597756238]
[4191.325595201614, 4034.477336872007, 0.07224772597756238]
[4191.325570392906, 4034.4773614347605, 0.07224772597756238]
[4191.325570392906, 4034.477336872007, 0.07224772642533897]
[4193.08745258345, 4035.384651384372, 0.07219391864233075]
[4193.087477394343, 4035.384651384372, 0.07219391864233075]
[4193.08745258345, 4035.3846759488433, 0.07219391864233075]
[4193.08745258345, 4035.384651384372, 0.07219391909037429]
[4193.22404659365, 4034.1456265909455, 0.07216995135385465]
[4193.224071404713, 4034.1456265909455, 0.07216995135385465]
[4193.22404659365, 4034.1456511530705, 0.07216995135385465]
[4193.22404659365, 4034.1456265909455, 0.07216995180201681]
[4193.357569355552, 4032.283634468764, 0.07213861775585582]
[4193.3575941667805, 4032.283634468764, 0.07213861775585582]
[4193.357569355552, 4032.2836590273496, 0.07213861775585582]
[4193.357569355552, 4032.283634468764, 0.07213861820417285]
[4193.257588786151, 4033.6778500040073, 0.07216208105359721]
[4193.257613597256, 4033.6778500040073, 0.07216208105359721]
[4193.257588786151, 4033.6778745652446, 0.07216208105359721]
[4193.257588786151, 4033.6778500040073, 0.0721620815017983]
[4192.928209321278, 4033.0699745667253, 0.07216255883465737]
[4192.928234131975, 4033.0699745667253, 0.07216255883465737]
[4192.928209321278, 4033.0699991268075, 0.07216255883465737]
[4192.928209321278, 4033.0699745667253, 0.07216255928285611]
[4193.056249313982, 4033.377232899573, 0.07216381476962296]
[4193.056274124839, 4033.377232899573, 0.07216381476962296]
[4193.056249313982, 4033.377257460239, 0.07216381476962296]
[4193.056249313982, 4033.377232899573, 0.07216381521781548]
[4193.5877777973255, 4034.7342269035507, 0.07216784912023225]
[4193.587802608838, 4034.7342269035507, 0.07216784912023225]
[4193.5877777973255, 4034.7342514667907, 0.07216784912023225]
[4193.5877777973255, 4034.7342269035507, 0.0721678495684048]
[4193.13241098137, 4033.571667365908, 0.07216439286134199]
[4193.13243579232, 4033.571667365908, 0.07216439286134199]
[4193.13241098137, 4033.5716919269435, 0.07216439286134199]
[4193.13241098137, 4033.571667365908, 0.07216439330953164]
[4193.085668440725, 4033.4523372489757, 0.07216403807101905]
[4193.085693251618, 4033.4523372489757, 0.07216403807101905]
[4193.085668440725, 4033.4523618097846, 0.07216403807101905]
[4193.085668440725, 4033.4523372489757, 0.07216403851921047]
[4193.056948928561, 4033.7050165996006, 0.07216866076052396]
[4193.056973739417, 4033.7050165996006, 0.07216866076052396]
[4193.056948928561, 4033.70504116089, 0.07216866076052396]
[4193.056948928561, 4033.7050165996006, 0.0721686612086925]
[4193.071694409074, 4033.575282590662, 0.07216628735823898]
[4193.071719219948, 4033.575282590662, 0.07216628735823898]
[4193.071694409074, 4033.5753071517042, 0.07216628735823898]
[4193.071694409074, 4033.575282590662, 0.07216628780641926]
[4193.075748371061, 4033.5396151784685, 0.07216563483024717]
[4193.075773181941, 4033.5396151784685, 0.07216563483024717]
[4193.075748371061, 4033.539639739443, 0.07216563483024717]
[4193.075748371061, 4033.5396151784685, 0.07216563527843067]
[4193.064833074306, 4033.4839235763793, 0.07216520060677879]
[4193.064857885172, 4033.4839235763793, 0.07216520060677879]
[4193.064833074306, 4033.4839481372483, 0.07216520060677879]
[4193.064833074306, 4033.4839235763793, 0.07216520105496446]
[4193.070735604103, 4033.514039208062, 0.07216543541671189]
[4193.070760414976, 4033.514039208062, 0.07216543541671189]
[4193.070735604103, 4033.5140637689883, 0.07216543541671189]
[4193.070735604103, 4033.514039208062, 0.07216543586489639]
[4193.067805781911, 4033.4990907886113, 0.07216531886484742]
[4193.067830592781, 4033.4990907886113, 0.07216531886484742]
[4193.067805781911, 4033.499115349509, 0.07216531886484742]
[4193.067805781911, 4033.4990907886113, 0.0721653193130325]
[4193.059407561655, 4033.4346534555516, 0.07216457170162238]
[4193.0594323725145, 4033.4346534555516, 0.07216457170162238]
[4193.059407561655, 4033.434678016327, 0.07216457170162238]
[4193.059407561655, 4033.4346534555516, 0.07216457214981115]
[4193.064939892301, 4033.477101539062, 0.07216506389639596]
[4193.064964703167, 4033.477101539062, 0.07216506389639596]
[4193.064939892301, 4033.4771260999178, 0.07216506389639596]
[4193.064939892301, 4033.477101539062, 0.0721650643445823]
[4193.066855719186, 4033.4918011926848, 0.07216523434108153]
[4193.066880530055, 4033.4918011926848, 0.07216523434108153]
[4193.066855719186, 4033.491825753569, 0.07216523434108153]
[4193.066855719186, 4033.4918011926848, 0.07216523478926704]
[4193.067685102016, 4033.4981648414655, 0.07216530812838282]
[4193.067709912886, 4033.4981648414655, 0.07216530812838282]
[4193.067685102016, 4033.4981894023613, 0.07216530812838282]
[4193.067685102016, 4033.4981648414655, 0.07216530857656793]
[4193.067780217645, 4033.4988946402855, 0.07216531659048499]
[4193.067805028515, 4033.4988946402855, 0.07216531659048499]
[4193.067780217645, 4033.4989192011826, 0.07216531659048499]
[4193.067780217645, 4033.4988946402855, 0.07216531703867007]
[4193.067798971513, 4033.499038534105, 0.07216531825895041]
[4193.067823782383, 4033.499038534105, 0.07216531825895041]
[4193.067798971513, 4033.4990630950024, 0.07216531825895041]
[4193.067798971513, 4033.499038534105, 0.07216531870713548]
[4193.067805027136, 4033.49908499741, 0.07216531879769776]
[4193.067829838006, 4033.49908499741, 0.07216531879769776]
[4193.067805027136, 4033.4991095583073, 0.07216531879769776]
[4193.067805027136, 4033.49908499741, 0.07216531924588286]
[4193.067805763854, 4033.4990906500616, 0.07216531886324092]
[4193.067830574724, 4033.4990906500616, 0.07216531886324092]
[4193.067805763854, 4033.499115210959, 0.07216531886324092]
[4193.067805763854, 4033.4990906500616, 0.07216531931142599]
[4193.067805736285, 4033.499090438532, 0.07216531886078821]
[4193.067830547155, 4033.499090438532, 0.07216531886078821]
[4193.067805736285, 4033.4991149994294, 0.07216531886078821]
[4193.067805736285, 4033.499090438532, 0.07216531930897328]
[4193.067805763589, 4033.4990906480252, 0.07216531886321731]
[4193.067830574459, 4033.4990906480252, 0.07216531886321731]
[4193.067805763589, 4033.4991152089233, 0.07216531886321731]
[4193.067805763589, 4033.4990906480252, 0.07216531931140238]
[4193.067805763854, 4033.4990906500616, 0.07216531886324092]
[4193.067830574724, 4033.4990906500616, 0.07216531886324092]
[4193.067805763854, 4033.499115210959, 0.07216531886324092]
[4193.067805763854, 4033.4990906500616, 0.07216531931142599]
[4193.067805763854, 4033.4990906500616, 0.07216531886324092]

Total fitting time:
17.85886573791504 s

import astropy.units as u
import numpy as np

from radis import load_spec
from radis.test.utils import getTestFile
from radis.tools.new_fitting import fit_spectrum

# The following script is for Mr. Correnti Grimaldi's cases, used for his own slit settings.
# This is not native to current fitting modules.

# ----------------------- Begin of Mr. Grimaldi's script ----------------------- #


def slit_dispersion(w):
    phi = -6.33
    f = 750
    gr = 300
    m = 1
    phi *= -2 * np.pi / 360
    d = 1e-3 / gr
    disp = (
        w
        / (2 * f)
        * (-np.tan(phi) + np.sqrt((2 * d / m / (w * 1e-9) * np.cos(phi)) ** 2 - 1))
    )
    return disp  # nm/mm


slit = 1500  # µm
pitch = 20  # µm
top_slit_um = slit - pitch  # µm
base_slit_um = slit + pitch  # µm
center_slit = 5090
dispersion = slit_dispersion(center_slit)
top_slit_nm = top_slit_um * 1e-3 * dispersion
base_slit_nm = base_slit_um * 1e-3 * dispersion * 1.33

# ------------------------ End of Mr. Grimaldi's script ------------------------ #


# ------------------------------------ Step 1. Load experimental spectrum ------------------------------------ #


specName = (
    "Corentin_0_100cm_DownSampled_20cm_10pctCO2_1-wc-gw450-gr300-sl1500-acc5000-.spec"
)
s_experimental = load_spec(getTestFile(specName)).offset(-0.6, "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": "CO",  # Molecule ID
    "isotope": "1,2,3",  # Isotope ID, can have multiple at once
    "wmin": 2270
    * u.nm,  # Starting wavelength/wavenumber to be cropped out from the original experimental spectrum.
    "wmax": 2400 * u.nm,  # Ending wavelength/wavenumber for the cropping range.
    "pressure": 1.01325
    * u.bar,  # Total pressure of gas, in "bar" unit by default, but you can also use Astropy units.
    "path_length": 1
    / 195
    * u.cm,  # Experimental path length, in "cm" unit by default, but you can also use Astropy units.
    "slit": {  # Experimental slit. In simple form: "[value] [unit]", i.e. "-0.2 nm". In complex form: a dict with parameters of apply_slit()
        "slit_function": (top_slit_nm, base_slit_nm),
        "unit": "nm",
        "shape": "trapezoidal",
        "center_wavespace": center_slit,
        "slit_dispersion": slit_dispersion,
        "inplace": False,
    },
    "cutoff": 0,  # (RADIS native) Discard linestrengths that are lower that this to reduce calculation time, in cm-1.
    "databank": "hitemp",  # Databank used for calculation. Must be stated.
}

# List of parameters to be fitted, accompanied by its initial value
fit_parameters = {
    "Tvib": 6000,  # Vibrational temperature, in K.
    "Trot": 4000,  # Rotational temperature, in K.
    "mole_fraction": 0.05,  # Species mole fraction, from 0 to 1.
}

# 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 = {
    "Tvib": [2000, 7000],
    "Trot": [2000, 7000],
    "mole_fraction": [0, 0.1],
}

# 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": False,  # Either applying normalization on both spectra or not.
    "max_loop": 300,  # Max number of loops allowed. By default, 200.
    "tol": 1e-20,  # 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_best, 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.
)


# Now investigate the result logs for additional information about what's going on during the fitting process

print("\nResidual history: \n")
print(log["residual"])

print("\nFitted values history: \n")
for fit_val in log["fit_vals"]:
    print(fit_val)

print("\nTotal fitting time: ")
print(log["time_fitting"], end=" s\n")

Total running time of the script: (0 minutes 20.274 seconds)