Skip to content

Commit

Permalink
fix reset for y calibration and minor other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
evg-mar committed Aug 5, 2024
1 parent 5d6522d commit b7b1f72
Showing 1 changed file with 53 additions and 30 deletions.
83 changes: 53 additions & 30 deletions src/pages/load_or_create_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"]:
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -568,27 +571,32 @@ 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)
)
# 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)

Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -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
# )
Expand Down Expand Up @@ -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"),
)

Expand All @@ -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()

Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
# )
Expand Down Expand Up @@ -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"),
)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit b7b1f72

Please sign in to comment.