multifit: jacobi ready, fighting bugs
Browse files- app.py +145 -127
- constants.py +46 -0
- fitmodels.py +40 -17
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from shiny.types import FileInfo
|
| 2 |
from shiny import * # App, Inputs, Outputs, Session, render, ui
|
| 3 |
# from shinywidgets import *
|
| 4 |
# import ipywidgets as widgets
|
|
@@ -50,127 +50,135 @@ app_ui = ui.page_fluid(
|
|
| 50 |
ui.row(
|
| 51 |
ui.column(4, ui.input_file("input_files", "Load your spectra", accept=["*.*"], multiple=True)),
|
| 52 |
ui.column(4, ui.input_text("text_comment", "Commented lines", value="//"))),
|
| 53 |
-
ui.row(ui.h2("Line by line fit")),
|
| 54 |
-
# this sidebar layout for marking which parameters to adjust and initial parameters values
|
| 55 |
-
ui.layout_sidebar(
|
| 56 |
-
ui.panel_sidebar(ui.h4("Mark adjustable"),
|
| 57 |
-
ui.input_checkbox_group("jac_check", "",
|
| 58 |
-
single_params_dict, selected=list(single_params_dict.keys())),
|
| 59 |
-
#ui.input_action_button("b_check", "Check"),
|
| 60 |
-
#ui.output_text_verbatim("jac_flag_out", placeholder=True)
|
| 61 |
-
),
|
| 62 |
-
ui.panel_main(ui.h4("Parameters and coefficients for initial values"),
|
| 63 |
-
ui.row(
|
| 64 |
-
ui.column(4, ui.input_numeric("I0", "Intensity, 1e-25 cm/mol", value=33.)),
|
| 65 |
-
ui.column(4, ui.input_numeric("elow", "Lower level energy, 1/cm", value=0.)),
|
| 66 |
-
ui.column(4, ui.input_numeric("molm", "Molecular mass, a.m.u.", value=28.))
|
| 67 |
-
),
|
| 68 |
-
ui.row(
|
| 69 |
-
ui.column(3, ui.input_numeric("f0", "Line center, MHz", value=115271.202)),
|
| 70 |
-
ui.column(3, ui.input_numeric("ngam", "T-dep power", value=0.75)
|
| 71 |
-
),
|
| 72 |
-
ui.row(
|
| 73 |
-
ui.column(3, ui.input_numeric("g0", "g0 self, MHz/Torr", value=3.375)),
|
| 74 |
-
ui.column(3, ui.input_numeric("g0f", "foreign, MHz/Torr", value=2.750))
|
| 75 |
-
),
|
| 76 |
-
ui.row(
|
| 77 |
-
ui.column(3, ui.input_numeric("g2", "g2 self, MHz/Torr", value=0.33)),
|
| 78 |
-
ui.column(3, ui.input_numeric("g2f", "foreign, MHz/Torr", value=0.28))
|
| 79 |
-
),
|
| 80 |
-
ui.row(
|
| 81 |
-
ui.column(3, ui.input_numeric("d2", "d2 self, MHz/Torr", value=0.00)),
|
| 82 |
-
ui.column(3, ui.input_numeric("d2f", "foreign, MHz/Torr", value=0.00))
|
| 83 |
-
),
|
| 84 |
-
ui.row(
|
| 85 |
-
ui.column(3, ui.input_numeric("y0", "y self, 1/Torr", value=7.e-6)),
|
| 86 |
-
ui.column(3, ui.input_numeric("y0f", "foreign, MHz/Torr", value=7.e-6))
|
| 87 |
-
),
|
| 88 |
-
ui.row(
|
| 89 |
-
ui.column(3, ui.input_numeric("nu", "N_vc self, MHz/Torr", value=0.15)),
|
| 90 |
-
ui.column(3, ui.input_numeric("nuf", "N_vc foreign, MHz/Torr", value=0.15))
|
| 91 |
-
),
|
| 92 |
-
)
|
| 93 |
-
)
|
| 94 |
-
),
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
ui.layout_sidebar(ui.panel_sidebar(ui.h4("Mark adjustable"),
|
| 124 |
ui.input_checkbox_group("jac_check_multi", "",
|
| 125 |
-
multi_params_dict,
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
)
|
| 175 |
|
| 176 |
|
|
@@ -551,7 +559,7 @@ def server(input, output, session):
|
|
| 551 |
|
| 552 |
|
| 553 |
# Download the results of the line-by-line fit (lineshape parameters)
|
| 554 |
-
@
|
| 555 |
def download_params():
|
| 556 |
if f_fit.get():
|
| 557 |
headers = list(single_params_dict.values())
|
|
@@ -584,7 +592,7 @@ def server(input, output, session):
|
|
| 584 |
|
| 585 |
|
| 586 |
# Download the results of the line-by-line fit (residuals)
|
| 587 |
-
@
|
| 588 |
def download_resid():
|
| 589 |
if f_fit.get():
|
| 590 |
with io.BytesIO() as buf:
|
|
@@ -1171,21 +1179,31 @@ def server(input, output, session):
|
|
| 1171 |
m_cur = model0[tmp_where]
|
| 1172 |
s_cur = sgnl[tmp_where]
|
| 1173 |
istart = n_const_par + ifil * n_add_par
|
| 1174 |
-
params0[istart] = np.max(s_cur)/np.max(m_cur)
|
| 1175 |
-
|
| 1176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1177 |
|
| 1178 |
tmp_resid_multi = []
|
| 1179 |
for ifil in range(nrecs.get()):
|
| 1180 |
tmp_where = aux_list[:, -1] == ifil
|
| 1181 |
-
m_cur =
|
| 1182 |
s_cur = sgnl[tmp_where]
|
| 1183 |
tmp_resid = s_cur - m_cur
|
| 1184 |
tmp_resid_multi.append(tmp_resid)
|
| 1185 |
|
| 1186 |
residuals_multi.set(tmp_resid_multi)
|
| 1187 |
-
params_fit_multi.set(
|
| 1188 |
-
uncert_fit_multi.set(
|
| 1189 |
|
| 1190 |
f_fit_multi.set(True)
|
| 1191 |
|
|
|
|
| 1 |
+
from shiny.types import FileInfo, NavSetArg
|
| 2 |
from shiny import * # App, Inputs, Outputs, Session, render, ui
|
| 3 |
# from shinywidgets import *
|
| 4 |
# import ipywidgets as widgets
|
|
|
|
| 50 |
ui.row(
|
| 51 |
ui.column(4, ui.input_file("input_files", "Load your spectra", accept=["*.*"], multiple=True)),
|
| 52 |
ui.column(4, ui.input_text("text_comment", "Commented lines", value="//"))),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
# Tab interface with two tabs for LBL and multifit treatment respectively
|
| 55 |
+
|
| 56 |
+
ui.navset_tab(
|
| 57 |
+
# tab for LBL
|
| 58 |
+
ui.nav_panel("Line-by-line treatment",
|
| 59 |
+
# this sidebar layout is for marking which parameters to adjust and initial parameters values
|
| 60 |
+
ui.layout_sidebar(
|
| 61 |
+
ui.panel_sidebar(ui.h4("Mark adjustable"),
|
| 62 |
+
ui.input_checkbox_group("jac_check", "",
|
| 63 |
+
single_params_dict,
|
| 64 |
+
selected=single_params_adjustable_init),
|
| 65 |
+
#ui.input_action_button("b_check", "Check"),
|
| 66 |
+
#ui.output_text_verbatim("jac_flag_out", placeholder=True)
|
| 67 |
+
),
|
| 68 |
+
ui.panel_main(ui.h4("Parameters and coefficients for initial values"),
|
| 69 |
+
ui.row(
|
| 70 |
+
ui.column(4, ui.input_numeric("I0", "Intensity, 1e-25 cm/mol", value=33.)),
|
| 71 |
+
ui.column(4, ui.input_numeric("elow", "Lower level energy, 1/cm", value=0.)),
|
| 72 |
+
ui.column(4, ui.input_numeric("molm", "Molecular mass, a.m.u.", value=28.))
|
| 73 |
+
),
|
| 74 |
+
ui.row(
|
| 75 |
+
ui.column(3, ui.input_numeric("f0", "Line center, MHz", value=115271.202)),
|
| 76 |
+
ui.column(3, ui.input_numeric("ngam", "T-dep power", value=0.75)
|
| 77 |
+
),
|
| 78 |
+
ui.row(
|
| 79 |
+
ui.column(3, ui.input_numeric("g0", "g0 self, MHz/Torr", value=3.375)),
|
| 80 |
+
ui.column(3, ui.input_numeric("g0f", "foreign, MHz/Torr", value=2.750))
|
| 81 |
+
),
|
| 82 |
+
ui.row(
|
| 83 |
+
ui.column(3, ui.input_numeric("g2", "g2 self, MHz/Torr", value=0.33)),
|
| 84 |
+
ui.column(3, ui.input_numeric("g2f", "foreign, MHz/Torr", value=0.28))
|
| 85 |
+
),
|
| 86 |
+
ui.row(
|
| 87 |
+
ui.column(3, ui.input_numeric("d2", "d2 self, MHz/Torr", value=0.00)),
|
| 88 |
+
ui.column(3, ui.input_numeric("d2f", "foreign, MHz/Torr", value=0.00))
|
| 89 |
+
),
|
| 90 |
+
ui.row(
|
| 91 |
+
ui.column(3, ui.input_numeric("y0", "y self, 1/Torr", value=7.e-6)),
|
| 92 |
+
ui.column(3, ui.input_numeric("y0f", "foreign, MHz/Torr", value=7.e-6))
|
| 93 |
+
),
|
| 94 |
+
ui.row(
|
| 95 |
+
ui.column(3, ui.input_numeric("nu", "N_vc self, MHz/Torr", value=0.15)),
|
| 96 |
+
ui.column(3, ui.input_numeric("nuf", "N_vc foreign, MHz/Torr", value=0.15))
|
| 97 |
+
),
|
| 98 |
+
)
|
| 99 |
+
)
|
| 100 |
+
),
|
| 101 |
+
ui.row(ui.input_action_button("b_preview", "Preview line-by-line")),
|
| 102 |
|
| 103 |
+
ui.output_plot("preview_spectrum"),
|
| 104 |
+
ui.output_text("preview_status"),
|
| 105 |
+
|
| 106 |
+
# an interface for fitting the model to the spectra and visualisation of the result
|
| 107 |
+
|
| 108 |
+
ui.input_action_button("b_fit", "Fit model to recordings"),
|
| 109 |
+
ui.output_text("fit_status"),
|
| 110 |
+
ui.output_plot("preview_fit"),
|
| 111 |
+
ui.output_ui("fit_result_table"),
|
| 112 |
+
ui.row(ui.column(3, ui.input_switch('s_foreign', "Foreign pressure")),
|
| 113 |
+
ui.column(3, ui.input_switch('s_normself', "Norm. to self P")),
|
| 114 |
+
ui.column(4, ui.input_numeric('f0_shift', "Unshifted center", value=115271.202))
|
| 115 |
+
),
|
| 116 |
+
ui.row(
|
| 117 |
+
ui.column(3, ui.input_action_button("b_coefs", "Plot vs pressure")),
|
| 118 |
+
ui.column(3, ui.download_button("download_params", "Download results")),
|
| 119 |
+
ui.column(3, ui.download_button("download_resid", "Download residuals")),
|
| 120 |
+
ui.column(3, ui.input_text("resid_prefix", "Residual file prefix", value="r_"))
|
| 121 |
+
),
|
| 122 |
+
|
| 123 |
+
ui.output_plot("preview_params", height="1200px")
|
| 124 |
+
),
|
| 125 |
+
# tab for multifit
|
| 126 |
+
ui.nav_panel("Multifit treatment",
|
| 127 |
+
ui.layout_sidebar(ui.panel_sidebar(ui.h4("Mark adjustable"),
|
|
|
|
|
|
|
| 128 |
ui.input_checkbox_group("jac_check_multi", "",
|
| 129 |
+
multi_params_dict,
|
| 130 |
+
selected=multi_params_adjustable_init)),
|
| 131 |
+
ui.panel_main(ui.h4("Multifit initial values"),
|
| 132 |
+
ui.row(ui.column(4, ui.input_numeric("mint", "Intensity, 1e-25 cm/mol", value=33.)),
|
| 133 |
+
ui.column(4, ui.input_numeric("melow", "Lower level energy, 1/cm", value=0.)),
|
| 134 |
+
ui.column(4, ui.input_numeric("mmolm", "Molecular mass, a.m.u.", value=28.))
|
| 135 |
+
),
|
| 136 |
+
ui.row(ui.column(4, ui.input_numeric("mf0", "Central frq", value=115271.202)),
|
| 137 |
+
ui.column(4, ui.input_numeric("mfrab", "Rabi frq", value=0.1))),
|
| 138 |
+
ui.row(ui.column(3, ui.input_numeric("mg0s", "Gamma0 self", value=3.375)),
|
| 139 |
+
ui.column(3, ui.input_numeric("mng0s", "n Gamma0 self", value=0.78)),
|
| 140 |
+
ui.column(3, ui.input_numeric("mg2s", "Gamma2 self", value=0.33)),
|
| 141 |
+
ui.column(3, ui.input_numeric("mng2s", "n Gamma2 self", value=0.78))),
|
| 142 |
+
ui.row(ui.column(3, ui.input_numeric("mg0f", "Gamma0 foreign", value=3.33)),
|
| 143 |
+
ui.column(3, ui.input_numeric("mng0f", "n Gamma0 foreign", value=0.78)),
|
| 144 |
+
ui.column(3, ui.input_numeric("mg2f", "Gamma2 foreign", value=0.33)),
|
| 145 |
+
ui.column(3, ui.input_numeric("mng2f", "n Gamma2 foreign", value=0.78))),
|
| 146 |
+
ui.row(ui.column(3, ui.input_numeric("md0s", "Delta0 self", value=-0.004)),
|
| 147 |
+
ui.column(3, ui.input_numeric("mnd0s", "n Delta0 self", value=0.78)),
|
| 148 |
+
ui.column(3, ui.input_numeric("md2s", "Delta2 self", value=0.00)),
|
| 149 |
+
ui.column(3, ui.input_numeric("mnd2s", "n Delta2 self", value=0.78))),
|
| 150 |
+
ui.row(ui.column(3, ui.input_numeric("md0f", "Delta0 foreign", value=-0.004)),
|
| 151 |
+
ui.column(3, ui.input_numeric("mnd0f", "n Delta0 foreign", value=0.78)),
|
| 152 |
+
ui.column(3, ui.input_numeric("md2f", "Delta2 foreign", value=0.00)),
|
| 153 |
+
ui.column(3, ui.input_numeric("mnd2f", "n Delta2 foreign", value=0.78))),
|
| 154 |
+
ui.row(ui.column(3, ui.input_numeric("my0s", "Mixing self", value=0.000006)),
|
| 155 |
+
ui.column(3, ui.input_numeric("mny0s", "n mixing self", value=0.78)),
|
| 156 |
+
ui.column(3, ui.input_numeric("my0f", "Mixing foreign", value=0.000006)),
|
| 157 |
+
ui.column(3, ui.input_numeric("mny0f", "n mixing foreign", value=0.78))),
|
| 158 |
+
ui.row(ui.column(3, ui.input_numeric("mnuvcs", "Vel.chn. rate self", value=0.15)),
|
| 159 |
+
ui.column(3, ui.input_numeric("mnnuvcs", "n nu_vc self", value=0.78)),
|
| 160 |
+
ui.column(3, ui.input_numeric("mnuvcf", "Vel.chn. rate foreign", value=0.15)),
|
| 161 |
+
ui.column(3, ui.input_numeric("mnnuvcf", "n nu_vc foreign", value=0.78))),
|
| 162 |
+
ui.row(ui.column(3, ui.input_numeric("mcs", "Continuum self", value=5.e-18)),
|
| 163 |
+
ui.column(3, ui.input_numeric("mncs", "n C self", value=0.0)),
|
| 164 |
+
ui.column(3, ui.input_numeric("mcf", "Continuum foreign", value=5.e-18)),
|
| 165 |
+
ui.column(3, ui.input_numeric("mncf", "n C foreign", value=0.0))),
|
| 166 |
+
ui.row(ui.column(6, ui.input_numeric("mpow", "power factor", value=0.)),
|
| 167 |
+
ui.column(6, ui.input_numeric("mscl", "scale factor", value=1.0)),),
|
| 168 |
+
ui.row(ui.column(3, ui.input_numeric("mbl0", "Baseline 0", value=0.0)),
|
| 169 |
+
ui.column(3, ui.input_numeric("mbl1", "Baseline 1", value=0.0)),
|
| 170 |
+
ui.column(3, ui.input_numeric("mbl2", "Baseline 2", value=0.0)),
|
| 171 |
+
ui.column(3, ui.input_numeric("mbl3", "Baseline 3", value=0.0))),
|
| 172 |
+
)
|
| 173 |
+
),
|
| 174 |
+
ui.input_action_button("b_preview_multifit", "Preview multifit"),
|
| 175 |
+
ui.output_plot("preview_spectrum_multifit"),
|
| 176 |
+
ui.input_action_button("b_fit_multifit", "Run multifit"),
|
| 177 |
+
ui.output_plot("preview_multifit"),
|
| 178 |
+
ui.output_ui("multifit_result_table")
|
| 179 |
+
),
|
| 180 |
+
|
| 181 |
+
)
|
| 182 |
)
|
| 183 |
|
| 184 |
|
|
|
|
| 559 |
|
| 560 |
|
| 561 |
# Download the results of the line-by-line fit (lineshape parameters)
|
| 562 |
+
@render.download(filename='fit_params.txt')
|
| 563 |
def download_params():
|
| 564 |
if f_fit.get():
|
| 565 |
headers = list(single_params_dict.values())
|
|
|
|
| 592 |
|
| 593 |
|
| 594 |
# Download the results of the line-by-line fit (residuals)
|
| 595 |
+
@render.download(filename='residuals.zip')
|
| 596 |
def download_resid():
|
| 597 |
if f_fit.get():
|
| 598 |
with io.BytesIO() as buf:
|
|
|
|
| 1179 |
m_cur = model0[tmp_where]
|
| 1180 |
s_cur = sgnl[tmp_where]
|
| 1181 |
istart = n_const_par + ifil * n_add_par
|
| 1182 |
+
params0[istart] = np.max(s_cur)/np.max(m_cur) # here the scale is fixed to the proper value
|
| 1183 |
+
|
| 1184 |
+
jac_flag_multi = [int(elem in input.jac_check_multi()) for elem in multi_params_dict]
|
| 1185 |
+
print(jac_flag_multi)
|
| 1186 |
+
|
| 1187 |
+
params1 = fit_params(frqs, sgnl, params0, mdl_multi, mdljac_multi, jac_flag_multi,
|
| 1188 |
+
1.e-4, 1.e-12, 1.e4, 10, aux_params=aux_list)
|
| 1189 |
+
uncert_1 = fit_uncertainties(frqs, sgnl,
|
| 1190 |
+
params1, mdl_multi, mdljac_multi, jac_flag_multi,
|
| 1191 |
+
aux_params=aux_list)
|
| 1192 |
+
|
| 1193 |
+
|
| 1194 |
+
model1 = mdl_multi(frqs, params1, aux_list)
|
| 1195 |
|
| 1196 |
tmp_resid_multi = []
|
| 1197 |
for ifil in range(nrecs.get()):
|
| 1198 |
tmp_where = aux_list[:, -1] == ifil
|
| 1199 |
+
m_cur = model1[tmp_where]
|
| 1200 |
s_cur = sgnl[tmp_where]
|
| 1201 |
tmp_resid = s_cur - m_cur
|
| 1202 |
tmp_resid_multi.append(tmp_resid)
|
| 1203 |
|
| 1204 |
residuals_multi.set(tmp_resid_multi)
|
| 1205 |
+
params_fit_multi.set(params1)
|
| 1206 |
+
uncert_fit_multi.set(uncert_1)
|
| 1207 |
|
| 1208 |
f_fit_multi.set(True)
|
| 1209 |
|
constants.py
CHANGED
|
@@ -33,6 +33,34 @@ single_params_dict = {"frq": "Central freq",
|
|
| 33 |
"bl2": "Baseline 2",
|
| 34 |
"bl3": "Baseline 3"}
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
multi_params_dict = {"mint": "Intensity",
|
| 37 |
"mf0": "Central freq",
|
| 38 |
"mg0s": "Gamma 0 self",
|
|
@@ -135,3 +163,21 @@ multi_params_numeric_deriv = ("mf0",
|
|
| 135 |
"mny0f",
|
| 136 |
"mnnuvcs",
|
| 137 |
"mnnuvcf")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
"bl2": "Baseline 2",
|
| 34 |
"bl3": "Baseline 3"}
|
| 35 |
|
| 36 |
+
single_params_adjustable_init = ["frq",
|
| 37 |
+
"int",
|
| 38 |
+
"g0",
|
| 39 |
+
"g2",
|
| 40 |
+
"y",
|
| 41 |
+
"bl0",
|
| 42 |
+
"bl1",
|
| 43 |
+
"bl2"]
|
| 44 |
+
|
| 45 |
+
single_params_adjustable_cav = ["frq",
|
| 46 |
+
"int",
|
| 47 |
+
"g0",
|
| 48 |
+
"g2",
|
| 49 |
+
"y",
|
| 50 |
+
"bl2"]
|
| 51 |
+
|
| 52 |
+
# preset of the adjustable parameters for LBL fit corresp. to RAD (and VID) recordings
|
| 53 |
+
# no mixing, no SD-shift, no Opt.Frq.
|
| 54 |
+
single_params_adjustable_rad = ["frq",
|
| 55 |
+
"int",
|
| 56 |
+
"g0",
|
| 57 |
+
"g2",
|
| 58 |
+
"pow",
|
| 59 |
+
"bl0",
|
| 60 |
+
"bl1",
|
| 61 |
+
"bl2"]
|
| 62 |
+
|
| 63 |
+
|
| 64 |
multi_params_dict = {"mint": "Intensity",
|
| 65 |
"mf0": "Central freq",
|
| 66 |
"mg0s": "Gamma 0 self",
|
|
|
|
| 163 |
"mny0f",
|
| 164 |
"mnnuvcs",
|
| 165 |
"mnnuvcf")
|
| 166 |
+
|
| 167 |
+
multi_params_adjustable_init = ["mf0" ,
|
| 168 |
+
"mg0s" ,
|
| 169 |
+
"mg2s" ,
|
| 170 |
+
"mg0f" ,
|
| 171 |
+
"mg2f" ,
|
| 172 |
+
"md0s" ,
|
| 173 |
+
"md0f" ,
|
| 174 |
+
"my0s" ,
|
| 175 |
+
"my0f" ,
|
| 176 |
+
"mcs" ,
|
| 177 |
+
"mcf" ,
|
| 178 |
+
"mfrab" ,
|
| 179 |
+
"mscl" ,
|
| 180 |
+
"mbl0" ,
|
| 181 |
+
"mbl1" ,
|
| 182 |
+
"mbl2" ,
|
| 183 |
+
"mbl3"]
|
fitmodels.py
CHANGED
|
@@ -122,6 +122,9 @@ def mdl_multi(frq: np.ndarray, params: np.ndarray, aux_params: np.ndarray) -> np
|
|
| 122 |
id_ns = multi_params_indx["mng0s"] # with more ore less intuitive keys
|
| 123 |
id_nf = multi_params_indx["mng0f"] # more code but also more clarity
|
| 124 |
|
|
|
|
|
|
|
|
|
|
| 125 |
tmpG0 = calc_g_simple(p_s, p_f, tmpr,
|
| 126 |
params[id_s], params[id_f], params[id_ns], params[id_nf])
|
| 127 |
if rtype in [1, 2, 3]:
|
|
@@ -232,28 +235,39 @@ def mdljac_multi(frq: np.ndarray, jac_flag: np.ndarray, params: np.ndarray, aux_
|
|
| 232 |
#jac[tmp_where][:, id_nf] = aux_params[tmp_where][:, 0] * aux_params[tmp_where][:, 1] * cs * (t_ref / aux_params[tmp_where][:, 2])**ncs * np.log(ncs)
|
| 233 |
|
| 234 |
### Derivatives by the individual recording parameters
|
| 235 |
-
nfil = int(max(aux_params[:, -1]))+1
|
| 236 |
|
| 237 |
### scaling factor
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
|
| 254 |
for ifil in range(nfil):
|
| 255 |
-
tmp_where = np.where(aux_params[:, -1] == ifil) # filter for the points related to some recording
|
| 256 |
-
i_start = n_const_par + n_add_par * ifil # index of first rec-related parameter
|
| 257 |
p_s = aux_params[tmp_where][0, 0] # self-pressure
|
| 258 |
p_f = aux_params[tmp_where][0, 1] # foreign-pressure
|
| 259 |
tmpr = aux_params[tmp_where][0, 2] # temperature
|
|
@@ -266,4 +280,13 @@ def mdljac_multi(frq: np.ndarray, jac_flag: np.ndarray, params: np.ndarray, aux_
|
|
| 266 |
tmpS *= 1.E5
|
| 267 |
else:
|
| 268 |
tmpS *= clen
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
return jac
|
|
|
|
| 122 |
id_ns = multi_params_indx["mng0s"] # with more ore less intuitive keys
|
| 123 |
id_nf = multi_params_indx["mng0f"] # more code but also more clarity
|
| 124 |
|
| 125 |
+
print('N = ', ifil, '!!!', p_s, p_f, tmpr,
|
| 126 |
+
params[id_s], params[id_f], params[id_ns], params[id_nf])
|
| 127 |
+
print(type(tmpr), type(t_ref), type(params[id_nf]))
|
| 128 |
tmpG0 = calc_g_simple(p_s, p_f, tmpr,
|
| 129 |
params[id_s], params[id_f], params[id_ns], params[id_nf])
|
| 130 |
if rtype in [1, 2, 3]:
|
|
|
|
| 235 |
#jac[tmp_where][:, id_nf] = aux_params[tmp_where][:, 0] * aux_params[tmp_where][:, 1] * cs * (t_ref / aux_params[tmp_where][:, 2])**ncs * np.log(ncs)
|
| 236 |
|
| 237 |
### Derivatives by the individual recording parameters
|
| 238 |
+
nfil = int(max(aux_params[:, -1]))+1 # number of recordings
|
| 239 |
|
| 240 |
### scaling factor
|
| 241 |
+
if jac_flag[n_const_par] == 1: # only if scaling factor is adjustable (scaling is 0-th additional parameter)
|
| 242 |
+
params2 = np.copy(params) # first we make copy of params but with scale equal to 1 (deriv by scale is just)
|
| 243 |
+
for ifil in range(nfil):
|
| 244 |
+
i_start = n_const_par + n_add_par * ifil # index of first rec-related parameter
|
| 245 |
+
params2[i_start] = 1.
|
| 246 |
+
params2[i_start+2] = 0.
|
| 247 |
+
params2[i_start+3] = 0.
|
| 248 |
+
params2[i_start+4] = 0.
|
| 249 |
+
params2[i_start+5] = 0.
|
| 250 |
+
model2 = mdl_multi(frq, params2, aux_params=aux_params)
|
| 251 |
+
for ifil in range(nfil):
|
| 252 |
+
i_start = n_const_par + n_add_par * ifil # index of first rec-related parameter
|
| 253 |
+
tmp_where = np.where(aux_params[:, -1] == ifil) # filter for the points related to some recording
|
| 254 |
+
jac[tmp_where][:, i_start] = model2[tmp_where]
|
| 255 |
+
|
| 256 |
+
### power factor (where applicable)
|
| 257 |
+
if jac_flag[n_const_par+1] == 1: # only if power factor is adjustable (1-th additional parameter)
|
| 258 |
+
for ifil in range(nfil):
|
| 259 |
+
rtype = int(aux_params[tmp_where][0, 4]) # record type
|
| 260 |
+
if rtype in [1, 2]: # only RAD and VID recs have power factor in model function
|
| 261 |
+
i_start = n_const_par + n_add_par * ifil # index of first rec-related parameter
|
| 262 |
+
params2 = np.copy(params)
|
| 263 |
+
params2[i_start+1] += dpar
|
| 264 |
+
model2 = mdl_multi(frq, params2, aux_params=aux_params)
|
| 265 |
+
tmp_where = np.where(aux_params[:, -1] == ifil) # filter for the points related to some recording
|
| 266 |
+
jac[tmp_where][:, i_start+1] = (model2[tmp_where] - model1[tmp_where]) / dpar
|
| 267 |
|
| 268 |
|
| 269 |
for ifil in range(nfil):
|
| 270 |
+
tmp_where = np.where(aux_params[:, -1] == ifil) # filter for the points related to some recording
|
|
|
|
| 271 |
p_s = aux_params[tmp_where][0, 0] # self-pressure
|
| 272 |
p_f = aux_params[tmp_where][0, 1] # foreign-pressure
|
| 273 |
tmpr = aux_params[tmp_where][0, 2] # temperature
|
|
|
|
| 280 |
tmpS *= 1.E5
|
| 281 |
else:
|
| 282 |
tmpS *= clen
|
| 283 |
+
i_start = n_const_par + n_add_par * ifil # index of first rec-related parameter
|
| 284 |
+
if jac_flag[n_const_par+2] == 1:
|
| 285 |
+
jac[tmp_where][:, i_start+2] = 1.
|
| 286 |
+
if jac_flag[n_const_par+3] == 1:
|
| 287 |
+
jac[tmp_where][:, i_start+3] = frq[tmp_where] - params[1]
|
| 288 |
+
if jac_flag[n_const_par+4] == 1:
|
| 289 |
+
jac[tmp_where][:, i_start+4] = (frq[tmp_where] - params[1])**2
|
| 290 |
+
if jac_flag[n_const_par+5] == 1:
|
| 291 |
+
jac[tmp_where][:, i_start+5] = (frq[tmp_where] - params[1])**3
|
| 292 |
return jac
|
requirements.txt
CHANGED
|
@@ -6,7 +6,7 @@ ipywidgets~=8.0.6
|
|
| 6 |
ipysheet~=0.7.0
|
| 7 |
numpy~=1.24.2
|
| 8 |
pandas~=1.5.3
|
| 9 |
-
shiny~=0.
|
| 10 |
shinywidgets~=0.2.0
|
| 11 |
matplotlib~=3.7.1
|
| 12 |
scipy~=1.10.1
|
|
|
|
| 6 |
ipysheet~=0.7.0
|
| 7 |
numpy~=1.24.2
|
| 8 |
pandas~=1.5.3
|
| 9 |
+
shiny~=0.7.0
|
| 10 |
shinywidgets~=0.2.0
|
| 11 |
matplotlib~=3.7.1
|
| 12 |
scipy~=1.10.1
|