Skip to content

Commit

Permalink
Merge pull request #38 from IKZ-Berlin/remove-transmission
Browse files Browse the repository at this point in the history
Remove transmission schema, parser, entrypoint, dep
  • Loading branch information
ka-sarthak authored Jan 27, 2025
2 parents 60ccd3b + 27efaa3 commit 9a0d8b3
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 270 deletions.
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ dependencies = [
'nomad-analysis', # develop branch
'lakeshore-nomad-plugin @ git+https://github.com/IKZ-Berlin/lakeshore-nomad-plugin.git@69a6deb3f0e99d7b0dc66714105dd62a56f157e9',
'laytec_epitt_plugin @ git+https://github.com/IKZ-Berlin/laytec_epitt_nomad_plugin.git@f4953ac4ecb55b7003dee323d7d7f473e49ab4e3',
'transmission @ git+https://github.com/FAIRmat-NFDI/AreaA-data_modeling_and_schemas.git@2b2c38809e63e3578ef63d8c1d1fe9e27aa7a321#subdirectory=transmission/transmission_plugin/uv_vis_nir_transmission_plugin',
]

[project.optional-dependencies]
Expand Down Expand Up @@ -144,7 +143,6 @@ where = ["src"]
[project.entry-points.'nomad.plugin']
general_schema = "nomad_ikz_plugin.general:schema"
characterization_schema = "nomad_ikz_plugin.characterization:schema"
characterization_transmission_parser = "nomad_ikz_plugin.characterization:transmission_parser"
pld_schema = "nomad_ikz_plugin.pld:schema"
movpe_schema = "nomad_ikz_plugin.movpe:schema"
movpe2_growth_excel_parser = "nomad_ikz_plugin.movpe.movpe2.growth_excel:parser"
Expand Down
20 changes: 1 addition & 19 deletions src/nomad_ikz_plugin/characterization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

from nomad.config.models.plugins import ParserEntryPoint, SchemaPackageEntryPoint
from nomad.config.models.plugins import SchemaPackageEntryPoint


class CharacterizationEntryPoint(SchemaPackageEntryPoint):
Expand All @@ -25,25 +25,7 @@ def load(self):
return m_package


class TransmissionParserEntryPoint(ParserEntryPoint):
"""
Entry point for lazy loading of the TransmissionParser.
"""

def load(self):
from nomad_ikz_plugin.characterization.parser import TransmissionParser

return TransmissionParser(**self.dict())


schema = CharacterizationEntryPoint(
name='CharacterizationSchema',
description='Schema package for general characterization methods used at IKZ.',
)

transmission_parser = TransmissionParserEntryPoint(
name='Transmission Parser',
description='Parser for data from Transmission Spectrophotometry.',
mainfile_mime_re='text/.*|application/zip',
mainfile_name_re='^.*\.asc$',
)
50 changes: 0 additions & 50 deletions src/nomad_ikz_plugin/characterization/parser.py

This file was deleted.

199 changes: 0 additions & 199 deletions src/nomad_ikz_plugin/characterization/schema.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
from typing import TYPE_CHECKING

import numpy as np
import plotly.express as px
from nomad.config import config
from nomad.datamodel.data import EntryData
from nomad.datamodel.metainfo.annotations import (
ELNAnnotation,
Filter,
SectionProperties,
)
from nomad.datamodel.metainfo.basesections import (
Measurement,
MeasurementResult,
)
from nomad.datamodel.metainfo.plot import (
PlotlyFigure,
)
from nomad.metainfo import Datetime, MEnum, Quantity, SchemaPackage, Section, SubSection
from transmission.schema import (
ELNUVVisNirTransmission,
UVVisNirTransmissionResult,
UVVisNirTransmissionSettings,
)

from nomad_ikz_plugin.general.schema import (
IKZCategory,
SubstratePreparationStep,
)

if TYPE_CHECKING:
from nomad.datamodel.datamodel import EntryArchive
from structlog.stdlib import BoundLogger


configuration = config.get_plugin_entry_point(
'nomad_ikz_plugin.characterization:schema'
)
Expand Down Expand Up @@ -157,182 +136,4 @@ class LightMicroscope(Measurement, SubstratePreparationStep, EntryData):
)


class IKZUVVisNirTransmissionSettings(UVVisNirTransmissionSettings):
"""
A specialized section for IKZ based on the `UVVisNirTransmissionSettings` section.
"""

ordinate_type = Quantity(
type=MEnum(['%T', 'A']),
description=(
'Specifies whether the ordinate (y-axis) of the measurement data is '
'percent transmittance (%T) or absorbance (A).'
),
a_eln={'component': 'EnumEditQuantity'},
)


class IKZUVVisNirTransmissionResult(UVVisNirTransmissionResult):
"""
A specialized section for IKZ based on the `UVVisNirTransmissionResult` section.
"""

m_def = Section(
a_eln=ELNAnnotation(
properties=SectionProperties(
order=[
'transmittance',
'absorbance',
'wavelength',
'extinction_coefficient',
],
visible=Filter(
exclude=[
'array_index',
],
),
)
)
)
extinction_coefficient = Quantity(
type=np.float64,
description=(
'Extinction coefficient calculated from transmittance and sample thickness '
'values: -log(T)/L. The coefficient includes the effects of '
'absorption, reflection, and scattering.'
),
shape=['*'],
unit='1/m',
a_plot={'x': 'array_index', 'y': 'extinction_coefficient'},
)

def generate_plots(self) -> list[PlotlyFigure]:
"""
Extends UVVisNirTransmissionResult.generate_plots() method to include the plotly
figures for the `IKZUVVisNirTransmissionResult` section.
Returns:
list[PlotlyFigure]: The plotly figures.
"""
figures = super().generate_plots()
if self.wavelength is None:
return figures

# generate plot for extinction coefficient
if self.extinction_coefficient is None:
return figures

x = self.wavelength.to('nm').magnitude
x_label = 'Wavelength'
xaxis_title = x_label + ' (nm)'

y = self.extinction_coefficient.to('1/cm').magnitude
y_label = 'Extinction coefficient'
yaxis_title = y_label + ' (1/cm)'

line_linear = px.line(x=x, y=y)

line_linear.update_layout(
title=f'{y_label} over {x_label}',
xaxis_title=xaxis_title,
yaxis_title=yaxis_title,
xaxis=dict(
fixedrange=False,
),
yaxis=dict(
fixedrange=False,
),
template='plotly_white',
)

figures.append(
PlotlyFigure(
label=f'{y_label} linear plot',
figure=line_linear.to_plotly_json(),
),
)

return figures

def calculate_extinction_coefficient(self, archive, logger):
"""
Calculate the extinction coefficient from the transmittance and sample
thickness. The formula used is: -log( T[%] / 100 ) / L.
Args:
archive (EntryArchive): The archive containing the section.
logger (BoundLogger): A structlog logger.
"""
self.extinction_coefficient = None
if not archive.data.samples:
logger.warning(
'Cannot calculate extinction coefficient as sample not found.'
)
return
if not archive.data.samples[0].thickness:
logger.warning(
'Cannot calculate extinction coefficient as sample thickness not found '
'or the value is 0.'
)
return

path_length = archive.data.samples[0].thickness
if self.transmittance is not None:
extinction_coeff = -np.log(self.transmittance) / path_length
# TODO: The if-block is a temperary fix to avoid processing of nans in
# the archive. The issue will be fixed in the future.
if np.any(np.isnan(extinction_coeff)):
logger.warning(
'Failed to save extinction coefficient. '
'Encountered NaN values in the calculation.'
)
return
self.extinction_coefficient = extinction_coeff

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
"""
The normalizer for the `IKZUVVisNirTransmissionResult` class.
Args:
archive (EntryArchive): The archive containing the section that is being
normalized.
logger (BoundLogger): A structlog logger.
"""
super().normalize(archive, logger)
self.calculate_extinction_coefficient(archive, logger)


class IKZELNUVVisNirTransmission(ELNUVVisNirTransmission):
"""
A specialized section for IKZ based on the `ELNUVVisNirTransmission` section.
"""

m_def = Section(
categories=[IKZCategory],
label='IKZ UV-Vis-NIR Transmission',
a_template={
'measurement_identifiers': {},
},
)
results = SubSection(
section_def=IKZUVVisNirTransmissionResult,
repeats=True,
)
transmission_settings = SubSection(
section_def=IKZUVVisNirTransmissionSettings,
)

def write_transmission_data(self, transmission, data_dict, archive, logger):
"""
Specialized method to write the transmission data for the IKZ plugin. The method
overrides the `write_transmission_data` method of the parent
`ELNUVVisNirTransmission` class.
"""
super().write_transmission_data(transmission, data_dict, archive, logger)
if data_dict['ordinate_type'] in ['%T', 'A']:
transmission.transmission_settings.ordinate_type = data_dict.get(
'ordinate_type'
)


m_package.__init_metainfo__()

0 comments on commit 9a0d8b3

Please sign in to comment.