From b7b1f722bbbe35ca7dfa04b2ce862a7aa611ae7c Mon Sep 17 00:00:00 2001 From: Evgeniy Marinov Date: Mon, 5 Aug 2024 09:57:33 +0300 Subject: [PATCH] fix reset for y calibration and minor other changes --- src/pages/load_or_create_calibration.py | 83 ++++++++++++++++--------- 1 file changed, 53 insertions(+), 30 deletions(-) diff --git a/src/pages/load_or_create_calibration.py b/src/pages/load_or_create_calibration.py index 5b80232..52e6d4e 100644 --- a/src/pages/load_or_create_calibration.py +++ b/src/pages/load_or_create_calibration.py @@ -192,7 +192,8 @@ def load_calibration_spectrum_neon(): ) if uploaded_neon_spec: - neon_spe = process_file_spe([uploaded_neon_spec], label="Neon", units=units) + neon_spe = process_file_spe( + [uploaded_neon_spec], label="Neon", units=units) # meta_dct = target_spe.meta st.session_state["cache_dicts"]["spectra_x"]["neon"] = neon_spe @@ -318,7 +319,7 @@ def create_x_calibration_sidebar_expander(): def create_y_calibration_sidebar_expander(): expander = st.expander("Create Y-Calibration", expanded=False) with expander: - st.error("Under development!") + # st.error("Under development!") # material_settings_expander() if "config_certs" not in st.session_state["cache_dicts"]["material_settings"]: @@ -516,14 +517,15 @@ def process_x_calibration_neon_creation(): with col0: # This is to adjust the position of the button st.write("") - submit_neon_crop_btn = st.form_submit_button( + submit_crop_btn = st.form_submit_button( label="Update", # disabled=not use_crop ) with col1: min_val = ( - settings_crop.crop_min if settings_crop.crop_min else min(spe.x) + settings_crop.crop_min if settings_crop.crop_min else min( + spe.x) ) print("Min val: ", min_val) @@ -540,7 +542,8 @@ def process_x_calibration_neon_creation(): ) with col2: max_val = ( - settings_crop.crop_max if settings_crop.crop_max else max(spe.x) + settings_crop.crop_max if settings_crop.crop_max else max( + spe.x) ) # print('Max val: ', max_val) @@ -568,12 +571,12 @@ def process_x_calibration_neon_creation(): settings_crop.crop_min = min_val settings_crop.crop_max = max_val - if submit_neon_crop_btn: - spe_croped = spe.trim_axes( - method="x-axis", boundaries=(min_val, max_val) - ) + # if submit_crop_btn: + # spe_croped = spe.trim_axes( + # method="x-axis", boundaries=(min_val, max_val) + # ) - if use_crop: + if use_crop or submit_crop_btn: # if not submit_neon_crop_btn: spe_croped = spe.trim_axes( method="x-axis", boundaries=(min_val, max_val) @@ -581,14 +584,19 @@ def process_x_calibration_neon_creation(): # st.session_state["cache_dicts"]["spectra_x_current"][ # "neon" # ] = spe_croped - st.session_state["cache_dicts"]["spectra_x_last"]["neon"] = spe_croped + # st.session_state["cache_dicts"]["spectra_x_last"]["neon"] = spe_croped - st.session_state["cache_dicts"]["spectra_x_crop"]["neon"] = spe_croped + # st.session_state["cache_dicts"]["spectra_x_crop"]["neon"] = spe_croped state_settings.crop = settings_crop - if use_crop or submit_neon_crop_btn: + # if use_crop or submit_neon_crop_btn: ax = spe_croped.plot(ax=ax, label="Neon crop", color="red") + if submit_crop_btn: + st.session_state["cache_dicts"]["spectra_x_last"]["neon"] = spe_croped + + st.session_state["cache_dicts"]["spectra_x_crop"]["neon"] = spe_croped + fig = ax.get_figure() st.pyplot(fig) @@ -679,7 +687,8 @@ def process_x_calibration_neon_creation(): red_patch = mpatches.Patch(color="blue", label="Neon") - blue_patch = mpatches.Patch(color="red", label="Neon normalized") + blue_patch = mpatches.Patch( + color="red", label="Neon normalized") ax2.legend(handles=[red_patch, blue_patch]) @@ -747,7 +756,8 @@ def process_x_calibration_neon_creation(): "window_length_neon", settings_peak_find.value_wlen ) - callback_change_value("width_neon", settings_peak_find.value_width) + callback_change_value( + "width_neon", settings_peak_find.value_width) # callback_change_value( # "hht_chain_neon", settings_peak_find.value_hht_chain # ) @@ -853,7 +863,8 @@ def process_x_calibration_neon_creation(): key="strategy_neon", label="strategy", options=options_strategy, - index=options_strategy.index(settings_peak_find.value_strategy), + index=options_strategy.index( + settings_peak_find.value_strategy), # on_change=update_x_calibration_btn("submitted_std1_btn"), ) @@ -872,7 +883,8 @@ def process_x_calibration_neon_creation(): # fig, ax = plt.subplots() - neon_peak_candidates.plot(ax=axs[1], fmt=":", label="Neon peaks") + neon_peak_candidates.plot( + ax=axs[1], fmt=":", label="Neon peaks") axs[1].set_xlabel(xlabel) fig = axs[1].get_figure() @@ -1247,7 +1259,8 @@ def process_x_calibration_si_creation(): baseline_current = settings_baseline.baseline_corr_type if set_default_btn: - callback_change_value("select_baseline_si", baseline_current) + callback_change_value( + "select_baseline_si", baseline_current) # callback_change_value('min_crop_input', min_val) options = [ @@ -1494,7 +1507,8 @@ def process_x_calibration_si_creation(): "window_length_si", settings_peak_find.value_wlen ) - callback_change_value("width_si", settings_peak_find.value_width) + callback_change_value( + "width_si", settings_peak_find.value_width) # callback_change_value( # "hht_chain_si", settings_peak_find.value_hht_chain # ) @@ -1599,7 +1613,8 @@ def process_x_calibration_si_creation(): key="strategy_si", label="strategy", options=options_strategy, - index=options_strategy.index(settings_peak_find.value_strategy), + index=options_strategy.index( + settings_peak_find.value_strategy), # on_change=update_x_calibration_btn("submitted_std2_btn"), ) @@ -1768,7 +1783,8 @@ def upload_y_calibration_ref_spe(): import time print( - "BEFORE TABS SRM REF, --- time: {} ---------".format(time.strftime("%X %x %Z")) + "BEFORE TABS SRM REF, --- time: {} ---------".format( + time.strftime("%X %x %Z")) ) with load_srm: @@ -1799,7 +1815,8 @@ def upload_y_calibration_ref_spe(): srm_spe = st.session_state["cache_dicts"]["spectra_y_last"]["srm_ref"] spe_units = srm_spe.meta["units"] - label, xlabel = "Reference spectrum", r"Raman shift [{}]".format(spe_units) + label, xlabel = "Reference spectrum", r"Raman shift [{}]".format( + spe_units) ax = srm_spe.plot(label=label, linestyle="dashed", color="blue") ax.set_xlabel(xlabel) @@ -1834,9 +1851,9 @@ def upload_y_calibration_ref_spe(): ) if set_default_btn: - state_settings.crop = default_state_neon.crop + state_settings.crop = default_state_srm_ref.crop st.session_state["cache_dicts"]["spectrum_settings"][ - "neon" + "srm_ref" ] = state_settings settings_crop: StateCrop = state_settings.crop @@ -1858,7 +1875,8 @@ def upload_y_calibration_ref_spe(): with col1: min_val = ( - settings_crop.crop_min if settings_crop.crop_min else min(spe.x) + settings_crop.crop_min if settings_crop.crop_min else min( + spe.x) ) print("Min val: ", min_val) @@ -1875,7 +1893,8 @@ def upload_y_calibration_ref_spe(): ) with col2: max_val = ( - settings_crop.crop_max if settings_crop.crop_max else max(spe.x) + settings_crop.crop_max if settings_crop.crop_max else max( + spe.x) ) # print('Max val: ', max_val) @@ -1944,7 +1963,8 @@ def upload_y_calibration_ref_spe(): srm_spe = st.session_state["cache_dicts"]["spectra_y"]["srm_ref"] spe_units = srm_spe.meta["units"] - label, xlabel = "Reference spectrum", r"Raman shift [{}]".format(spe_units) + label, xlabel = "Reference spectrum", r"Raman shift [{}]".format( + spe_units) ax = srm_spe.plot(label=label, linestyle="dashed", color="blue") ax.set_xlabel(xlabel) # ax.set_ylabel("Si", color="blue") @@ -2017,7 +2037,8 @@ def upload_y_calibration_ref_spe(): index_method = method_options.index(settings_smooth.method) if set_default_btn: - index_method = method_options.index(settings_smooth.method) + index_method = method_options.index( + settings_smooth.method) callback_change_value( "select_box_srm_method", default_state_srm_ref.smooth.method ) @@ -2073,7 +2094,8 @@ def upload_y_calibration_ref_spe(): color="red", ) - red_patch = mpatches.Patch(color="blue", label="Reference spectrum") + red_patch = mpatches.Patch( + color="blue", label="Reference spectrum") blue_patch = mpatches.Patch(color="red", label="Ref smooth") @@ -2380,7 +2402,8 @@ def update_x_calibraiton_val(): path = str(rpath / "data" / xcalibration_filename) calmodel.save(path) - st.write("Saved X-calibration model in ", "./data/" + xcalibration_filename) + st.write("Saved X-calibration model in ", + "./data/" + xcalibration_filename) elif x_calib_btn == "btn_save_material_certificate":