Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions src/calibration_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import traceback
import pickle
from utils import (
toc, toc_anchor, toc_entry, toc_link, toc_heading, toc_collapsible
toc, toc_anchor, toc_entry, toc_link, toc_heading, toc_collapsible,
get_config_units
)
import glob


# + tags=["parameters"]
Expand All @@ -30,7 +32,7 @@
_config = load_config(os.path.join(config_root, config_templates))
warnings.filterwarnings('ignore')

def plot_model(calmodel, entry, laser_wl, optical_path, spe_sils=None):
def plot_model(calmodel, entry, laser_wl, optical_path, spe_sils=None, spe_units=None):
fig, (ax, ax1, ax2) = plt.subplots(1, 3, figsize=(15, 3))
# print(modelfile, tags)
calmodel.components[0].model.plot(ax=ax)
Expand All @@ -41,7 +43,7 @@ def plot_model(calmodel, entry, laser_wl, optical_path, spe_sils=None):
ax1.axvline(x=si_peak, color='black', linestyle='--', linewidth=2, label="Si peak {:.3f} nm".format(si_peak))
if spe_sils is not None:
for spe_sil in spe_sils:
sil_calibrated = calmodel.apply_calibration_x(spe_sil)
sil_calibrated = calmodel.apply_calibration_x(spe_sil, spe_units=spe_units )
try:
fitres, cand = find_peaks(sil_calibrated,
profile="Pearson4",
Expand Down Expand Up @@ -107,22 +109,33 @@ def plot_distances(pairwise_distances, identifiers):
for modelfile in pkl_files:
tags = os.path.basename(modelfile).replace(".pkl", "").split("_")
optical_path = tags[2]
laser_wl = int(tags[1])
laser_wl = int(tags[1])
calmodel = CalibrationModel.from_file(os.path.join(folder_path, modelfile))

if mode == "xy":
with open(os.path.join(folder_path_ycal, f"ycalmodel_{laser_wl}_{optical_path}.pkl"), "rb") as f:
ycalmodel = pickle.load(f)
pattern = os.path.join(folder_path_ycal, f"ycalmodel_{laser_wl}_{optical_path}_*.pkl")
pkl_files = glob.glob(pattern)
ycalmodels = []
for pkl_file in pkl_files:
print(pkl_file)
with open(pkl_file, "rb") as f:
ycalmodels.append(pickle.load(f))
print(f"[{key}] Number of relative intensity calibration models: {len(ycalmodels)}")
if len(ycalmodels) == 0:
continue
else:
ycalmodel = None
ycalmodels = None

op_data = df_bkg_substracted.loc[df_bkg_substracted["optical_path"] == optical_path]
spe_sum = None
spe_sil = average_spe(op_data, si_tag).trim_axes(method='x-axis',
boundaries=(520.45-50, 520.45+50))
spe_sil = average_spe(op_data, si_tag)
if spe_sil is None:
continue
plot_model(calmodel, entry, laser_wl, optical_path, [spe_sil])
si_units = get_config_units(_config, key, tag="si")
if si_units == "cm-1":
spe_sil = spe_sil.trim_axes(method='x-axis', boundaries=(520.45-50, 520.45+50))

plot_model(calmodel, entry, laser_wl, optical_path, [spe_sil],spe_units=si_units )
fig, (ax, ax1, ax2, ax3) = plt.subplots(1, 4, figsize=(15, 3))
_id = f"[{entry}] {laser_wl}nm {optical_path}"
fig.suptitle(_id)
Expand Down Expand Up @@ -157,9 +170,10 @@ def plot_distances(pairwise_distances, identifiers):
# x calibration
spe_xcalibrated = calmodel.apply_calibration_x(spe)
# y calibration
if ycalmodel is None:
if ycalmodels is None:
spe_calibrated = spe_xcalibrated
else:
ycalmodel = ycalmodels[0]
spe_xcalibrated = spe_xcalibrated.trim_axes(method="x-axis", boundaries=ycalmodel.ref.raman_shift)
spe_calibrated = ycalmodel.process(spe_xcalibrated)

Expand Down
Loading
Loading