Skip to content

Commit

Permalink
Merge pull request #113 from h2020charisma/calibration_updates
Browse files Browse the repository at this point in the history
documentation updates
  • Loading branch information
kerberizer authored Apr 23, 2024
2 parents d81c194 + b809425 commit e559868
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 15 deletions.
25 changes: 25 additions & 0 deletions CALIBRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# CHARISMA Calibration protocol

```python
# Create an instance of CalibrationModel
calmodel = CalibrationModel(laser_wl=785)
calmodel.derive_model_x(
spe_neon,
spe_neon_units='cm-1',
ref_neon=None,
ref_neon_units='nm',
spe_sil=None,
spe_sil_units='cm-1',
ref_sil=None,
ref_sil_units='cm-1'
)
# Store
calmodel.save(modelfile)
# Load
calmodel = CalibrationModel.from_file(modelfile)
# Apply to new spectrum
calmodel.apply_calibration_x(
spe_to_calibrate,
spe_units='m-1'
)
```
26 changes: 11 additions & 15 deletions src/ramanchada2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,11 @@
# File formats
## `.cha` vs USID/NSID
## `.cha`
[ramanchada][] software package introduced `.cha` file format, which is an [HDF5][]
with a specific architecture. Two spectroscopy specific file formats -- [USID][] and
[NSID][] -- were considered as successors of `.cha`. USID and NSID are provided
by [pycroscopy][] package as an extension of HDF5. Several jupyter notebooks were
created in order to assess the advantages and disadvantages of such a change. These
file formats are designed to handle multidimensional spectral data, keeping track
of the modifications. These file formats does not provide big advantage in our case,
so currently `ramanchada2` supports `.cha` file format and does not support USID
or NSID.
## Cache
with a simple layout.
### Cache in .cha files
The concept to keep previous variants of data is employed in `ramanchada2`. If
configured so, the software saves the data for all Spectrum instances to a
tree-organized `.cha` file. When a particular chain of operations is requested
Expand All @@ -75,18 +68,20 @@
uses [h5py][] library to access local hdf files. It is foreseen to have implementation
with [h5pyd][] that support network operations.
## Nexus format
The latest ramanchada2 package allows export of a spectrum to [NeXus][] format.
[CRYSTAL]: https://www.crystal.unito.it/index.php
[HDF5]: https://hdfgroup.org/
[LMFIT]: https://lmfit.github.io/lmfit-py/index.html
[NSID]: https://pycroscopy.github.io/pyNSID
[USID]: https://pycroscopy.github.io/USID
[VASP]: https://www.vasp.at/
[algorithm]: https://doi.org/10.1103/PhysRevB.54.7830
[h5py]: https://h5py.org/
[h5pyd]: https://github.com/HDFGroup/h5pyd
[pycroscopy]: https://pycroscopy.github.io/pycroscopy/
[ramanchada]: https://github.com/h2020charisma/ramanchada
[NeXus]: https://www.nexusformat.org/
"""

from __future__ import annotations
Expand All @@ -97,9 +92,10 @@
'auxiliary',
'io',
'misc',
'protocols',
'spectral_components',
'spectrum',
'theoretical_lines',
'theoretical_lines'
]
__version__ = '0.0.10'

Expand Down
Empty file.
56 changes: 56 additions & 0 deletions src/ramanchada2/protocols/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,62 @@ def process(self, old_spe: Spectrum, spe_units="nm", convert_back=False):


class CalibrationModel(ProcessingModel, Plottable):
"""
A class representing a calibration model for Raman spectrum.
Parameters:
laser_wl (int): The wavelength of the laser used for calibration.
Methods:
__init__(self, laser_wl)
Initializes a CalibrationModel instance.
set_laser_wavelength(self, laser_wl)
Sets the wavelength of the laser used for calibration.
clear(self)
Clears the calibration model.
save(self, filename)
Saves the calibration model to a file.
from_file(filename)
Loads a calibration model from a file.
derive_model_x(self, spe_neon, spe_neon_units="cm-1", ref_neon=None, ref_neon_units="nm",
spe_sil=None, spe_sil_units="cm-1", ref_sil=None, ref_sil_units="cm-1", find_kw={}, fit_kw={})
Derives x-calibration models using Neon and Silicon spectra.
apply_calibration_x(self, old_spe: Spectrum, spe_units="cm-1")
Applies the x-calibration model to Raman spectrum.
peaks(self, spe, profile='Gaussian', wlen=300, width=1)
Finds and fits peaks in the spectrum spe.
Example:
# Create an instance of CalibrationModel
calmodel = CalibrationModel(laser_wl=785)
calmodel.derive_model_x(
spe_neon,
spe_neon_units="cm-1",
ref_neon=None,
ref_neon_units="nm",
spe_sil=None,
spe_sil_units="cm-1",
ref_sil=None,
ref_sil_units="cm-1"
)
# Store
calmodel.save(modelfile)
# Load
calmodel = CalibrationModel.from_file(modelfile)
# Apply to new spectrum
calmodel.apply_calibration_x(
spe_to_calibrate,
spe_units="cm-1"
)
"""

def __init__(self, laser_wl: int):
super(ProcessingModel, self).__init__()
super(Plottable, self).__init__()
Expand Down

0 comments on commit e559868

Please sign in to comment.