Skip to content

Commit

Permalink
added download peaks and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evg-mar committed Aug 27, 2024
1 parent 2a699f0 commit b5865db
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
12 changes: 8 additions & 4 deletions src/pages/apply_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def load_tabs_target_spectrum():
x_calib = st.session_state["cache_bools"]["x_calib"]
y_calib = st.session_state["cache_bools"]["y_calib"]

print(x_calib, y_calib)
target_spe = st.session_state["cache_dicts"]["page01_load_spe"][
"target_spe_current"
]
Expand Down Expand Up @@ -484,9 +485,9 @@ def load_tabs_target_spectrum():
file_name="xcalibrated_spectrum.csv",
)

spe_target = target_calibrated
target_spe = target_calibrated

if x_calib:
if y_calib:

ycalmodel = st.session_state["cache_dicts"]["y_calibration"][
"ycalibration_model"
Expand All @@ -495,12 +496,15 @@ def load_tabs_target_spectrum():

ax = spe_srm.plot(label="SRM experimental", color="red")

spe_target.plot(ax=ax, label="Target spectrum", color="blue")
target_spe.plot(ax=ax, label="Target spectrum", color="blue")

spe_ycalibrated = ycalmodel.process(spe_target)
spe_ycalibrated = ycalmodel.process(target_spe)

spe_ycalibrated.plot(label="Y-calibrated", color="green", ax=ax.twinx())
fig = ax.get_figure()

spe_units = target_spe.meta["units"]
ax.set_xlabel(r"Raman shift " + spe_units)
st.pyplot(fig)

csv = io_write_csv(spe_ycalibrated.x, spe_ycalibrated.y)
Expand Down
41 changes: 21 additions & 20 deletions src/pages/load_instrument_settings.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
#!/usr/bin/env python3
import streamlit_pydantic as sp
from pydantic import BaseModel, Field, ValidationError, parse_obj_as
from typing import Set
from enum import Enum
from collections import defaultdict
from copy import deepcopy
from enum import Enum

import pandas as pd

from typing import TypedDict
from typing import Set, TypedDict

from pydantic import BaseModel, Field
import pandas as pd

import streamlit as st
import streamlit_pydantic as sp
from front_end.htmlTemplates import css

from modules.navigation_bar import navbar
Expand All @@ -25,6 +21,8 @@
update_session_state,
)

from pydantic import BaseModel, Field, parse_obj_as, ValidationError

from ramanchada2.protocols.calibration import (
CalibrationModel,
CertificatesDict,
Expand All @@ -34,8 +32,6 @@
YCalibrationComponent,
)

from ramanchada2.protocols.calibration import CalibrationModel


# class InstrumentsMandatory(BaseModel):
# laser_wavelength: int = 532
Expand All @@ -46,23 +42,29 @@
settings = st.session_state["cache_dicts"]["instrument_settings"]["settings"]
else:
settings = defaultdict(str)
settings['laser_wavelength'] = 532
settings["laser_wavelength"] = 532


class InstrumentSettings(BaseModel):
make_and_model_of_the_instrument: str | None = settings['make_and_model_of_the_instrument']
serial_number_of_the_instrument: str = settings['serial_number_of_the_instrument']
laser_wavelength: int = settings['laser_wavelength']
make_and_model_of_the_instrument: str | None = settings[
"make_and_model_of_the_instrument"
]
serial_number_of_the_instrument: str = settings["serial_number_of_the_instrument"]
laser_wavelength: int = Field(
settings["laser_wavelength"],
description="Units: nm",
title="Lazer wavelength (nm)",
)
# serial_number: str | None = settings['serial_number']
# description: str | None = settings['description']
# Another
# instrument_model: str | None = settings['instrument_model']
device_type: str | None = settings['device_type']
device_type: str | None = settings["device_type"]
# Optical path details
# laser_waveletgth: str
numerical_aperture: str | None = settings['numerical_aperture']
grating: str | None = settings['grating']
slit: str | None = settings['slit']
numerical_aperture: str | None = settings["numerical_aperture"]
grating: str | None = settings["grating"]
slit: str | None = settings["slit"]
# pinhole: str | None = settings[]
# # Acquisition parameters
# exposure_time: str | None = settings[]
Expand Down Expand Up @@ -146,8 +148,7 @@ class InstrumentSettings(BaseModel):

data = sp.pydantic_input(key="my_form", model=InstrumentSettings)
if data:
st.session_state["cache_dicts"]["instrument_settings"]["settings"] = dict(
data)
st.session_state["cache_dicts"]["instrument_settings"]["settings"] = dict(data)
# if True:
# print('Delete AFTER ')
# keys = [k for k in st.session_state.keys() if 'my_form' in k]
Expand Down
12 changes: 12 additions & 0 deletions src/pages/load_or_create_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,12 @@ def process_x_calibration_neon_creation():
axs[1].set_xlabel(xlabel)
fig = axs[1].get_figure()

st.download_button(
"Download Peaks found (JSON)",
data=neon_peak_candidates.json(),
file_name="neon_peaks_found.json",
)

if use_peak_find:
st.session_state["cache_dicts"]["spectra_x_peak_candidates"][
"neon"
Expand Down Expand Up @@ -1627,6 +1633,12 @@ def process_x_calibration_si_creation():
axs[1].set_xlabel(xlabel)
fig = axs[1].get_figure()

st.download_button(
"Download Peaks found (JSON)",
data=si_peak_candidates.json(),
file_name="si_peaks_found.json",
)

if use_peak_find:
st.session_state["cache_dicts"]["spectra_x_peak_candidates"][
"si"
Expand Down

0 comments on commit b5865db

Please sign in to comment.