Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple updates , use position instead of center, nexusformat notebook #192

Merged
merged 22 commits into from
Nov 25, 2024
Merged
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
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ dependencies:
- pip
- pip:
- jupyter
- ploomber
- pytest
- -e .

176 changes: 0 additions & 176 deletions examples/legacy/nexusformat.ipynb

This file was deleted.

826 changes: 563 additions & 263 deletions examples/publication/demo.ipynb

Large diffs are not rendered by default.

422 changes: 422 additions & 0 deletions examples/publication/nexusformat.ipynb

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions examples/publication/pipeline_demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Run with

> ploomber build
1 change: 1 addition & 0 deletions examples/publication/pipeline_demo/env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file: "../../../src/ramanchada2/auxiliary/spectra/datasets2/ICV_BW532/PST02_iRPlus532_Z050_100_2500msx5.txt"
52 changes: 52 additions & 0 deletions examples/publication/pipeline_demo/nexusformat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import ramanchada2 as rc2
import pyambit.datamodel as mx
from pyambit.nexus_spectra import spe2ambit
import nexusformat.nexus.tree as nx
import uuid
import os.path

# + tags=["parameters"]
upstream = ["read_preprocess"]
product = None
sample = None
laser_wl = None
instrument_make = None
instrument_model = None
data_provider = None
# -

spe_raw = rc2.spectrum.from_chada(upstream["read_preprocess"]["cha"], dataset="/raw")
spe_raw.plot()

prefix = "DEMO"

substances = []
substance = mx.SubstanceRecord(name=sample, publicname=sample, ownerName="TEST")
substance.i5uuid = "{}-{}".format(prefix, uuid.uuid5(uuid.NAMESPACE_OID, sample))
protocol_application = spe2ambit(
x=spe_raw.x,
y=spe_raw.y,
meta=spe_raw.meta,
instrument=(instrument_make, instrument_model),
wavelength=laser_wl,
provider=data_provider,
investigation="My experiment",
sample=sample,
sample_provider="CHARISMA",
prefix=prefix,
endpointtype="RAW_DATA",
unit="cm-1",
)
substance.study = [protocol_application]
substances.append(substance)

output_file = product["nxs"]

substances = mx.Substances(substance=substances)
nxroot = nx.NXroot()
nxroot.attrs["pyambit"] = "0.0.1"
nxroot.attrs["file_name"] = os.path.basename(output_file)
substances.to_nexus(nxroot)

print(nxroot.tree)
nxroot.save(output_file, mode="w")
19 changes: 19 additions & 0 deletions examples/publication/pipeline_demo/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
tasks:

- source: read_preprocess.py
product:
nb: "products/read_preprocess.ipynb"
cha: "products/spectrum.cha"
params:
input_file: "{{file}}"

- source: nexusformat.py
product:
nb: "products/nexusformat.ipynb"
nxs: "products/spectrum.nxs"
params:
sample: "PST"
laser_wl: 532
instrument_make: "BWTek"
instrument_model: "iRamanPlus"
data_provider: "ICV"
22 changes: 22 additions & 0 deletions examples/publication/pipeline_demo/read_preprocess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os.path
import ramanchada2 as rc2

# + tags=["parameters"]
upstream = []
product = None
input_file = None
# -

file = os.path.abspath(input_file)

# load spectrum from file system
spe = rc2.spectrum.from_local_file(file)
spe.plot()

if os.path.isfile(product["cha"]):
os.remove(product["cha"])

spe.write_cha(product["cha"], dataset="/raw")

spe.subtract_baseline_rc1_snip(niter=40)
spe.write_cha(product["cha"], dataset="/baseline")
Binary file added examples/publication/spectra_demo.nxs
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):


class CalibrationComponent(Plottable):
nonmonotonic: Literal["ignore", "nan", "error"] = "nan"
nonmonotonic: Literal["ignore", "nan", "error", "drop"] = "error"

def __init__(self, laser_wl, spe, spe_units, ref, ref_units, sample=None):
super(CalibrationComponent, self).__init__()
Expand Down
8 changes: 4 additions & 4 deletions src/ramanchada2/protocols/calibration/calibration_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class CalibrationModel(ProcessingModel, Plottable):
nonmonotonic: Literal["ignore", "nan", "error"] = "nan"
nonmonotonic: Literal["ignore", "nan", "error", "drop"] = "nan"

"""
A class representing a calibration model for Raman spectrum.
Expand Down Expand Up @@ -210,7 +210,7 @@ def derive_model_curve(
name=name,
match_method=match_method,
interpolator_method=interpolator_method,
extrapolate=True,
extrapolate=extrapolate,
)

def _derive_model_zero(
Expand Down Expand Up @@ -315,8 +315,8 @@ def calibration_model_factory(
should_fit=False,
prominence_coeff=3,
si_profile="Pearson4",
match_method: Literal["cluster", "argmin2d", "assignment"] = "cluster",
interpolator_method: Literal["rbf", "pchip", "cubic_spline"] = "rbf",
match_method: Literal["cluster", "argmin2d", "assignment"] = "argmin2d",
interpolator_method: Literal["rbf", "pchip", "cubic_spline"] = "pchip",
extrapolate=True,
):
if neon_wl is None:
Expand Down
Loading
Loading