From 27efaa31602d98164d3c7b742ef17e201d9f0229 Mon Sep 17 00:00:00 2001 From: Sarthak Kapoor Date: Mon, 27 Jan 2025 14:41:03 +0100 Subject: [PATCH] Remove transmission schema, parser, entrypoint, dep --- pyproject.toml | 2 - .../characterization/__init__.py | 20 +- .../characterization/parser.py | 50 ----- .../characterization/schema.py | 199 ------------------ 4 files changed, 1 insertion(+), 270 deletions(-) delete mode 100644 src/nomad_ikz_plugin/characterization/parser.py diff --git a/pyproject.toml b/pyproject.toml index a6970b8..9b156df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] @@ -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" diff --git a/src/nomad_ikz_plugin/characterization/__init__.py b/src/nomad_ikz_plugin/characterization/__init__.py index 58b8443..4f61c2b 100644 --- a/src/nomad_ikz_plugin/characterization/__init__.py +++ b/src/nomad_ikz_plugin/characterization/__init__.py @@ -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): @@ -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$', -) diff --git a/src/nomad_ikz_plugin/characterization/parser.py b/src/nomad_ikz_plugin/characterization/parser.py deleted file mode 100644 index 65a4237..0000000 --- a/src/nomad_ikz_plugin/characterization/parser.py +++ /dev/null @@ -1,50 +0,0 @@ -# -# Copyright The NOMAD Authors. -# -# This file is part of NOMAD. See https://nomad-lab.eu for further info. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from typing import TYPE_CHECKING - -from nomad.parsing import MatchingParser -from transmission.schema import RawFileTransmissionData -from transmission.utils import create_archive - -from nomad_ikz_plugin.characterization.schema import IKZELNUVVisNirTransmission - -if TYPE_CHECKING: - from nomad.datamodel.datamodel import ( - EntryArchive, - ) - - -class TransmissionParser(MatchingParser): - """ - Parser for matching files from Transmission Spectrophotometry and - creating instances of ELN. - """ - - def parse( - self, mainfile: str, archive: 'EntryArchive', logger=None, child_archives=None - ) -> None: - data_file = mainfile.split('/')[-1] - entry = IKZELNUVVisNirTransmission.m_from_dict( - IKZELNUVVisNirTransmission.m_def.a_template - ) - entry.data_file = data_file - file_name = f'{".".join(data_file.split(".")[:-1])}.archive.json' - archive.data = RawFileTransmissionData( - measurement=create_archive(entry, archive, file_name) - ) - archive.metadata.entry_name = f'{data_file} data file' diff --git a/src/nomad_ikz_plugin/characterization/schema.py b/src/nomad_ikz_plugin/characterization/schema.py index f962fbf..ef0ddf4 100644 --- a/src/nomad_ikz_plugin/characterization/schema.py +++ b/src/nomad_ikz_plugin/characterization/schema.py @@ -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' ) @@ -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__()