From f85a4e80d0f1c89302b791586b35ea13029b9ee1 Mon Sep 17 00:00:00 2001 From: Julia Schumann <32182254+schumannj@users.noreply.github.com> Date: Wed, 29 May 2024 08:29:53 +0000 Subject: [PATCH] add results section to nrvs schema --- .../schema_packages/mypackage.py | 54 ++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/src/nomad_unisyscat/schema_packages/mypackage.py b/src/nomad_unisyscat/schema_packages/mypackage.py index fa3106d..76ea5fb 100644 --- a/src/nomad_unisyscat/schema_packages/mypackage.py +++ b/src/nomad_unisyscat/schema_packages/mypackage.py @@ -3,6 +3,8 @@ TYPE_CHECKING, ) +import numpy as np + if TYPE_CHECKING: from nomad.datamodel.datamodel import ( EntryArchive, @@ -11,14 +13,13 @@ BoundLogger, ) +import plotly.express as px from nomad.config import config -from nomad.datamodel.data import Schema, EntryData +from nomad.datamodel.data import EntryData, Schema from nomad.datamodel.metainfo.annotations import ELNAnnotation, ELNComponentEnum -from nomad.metainfo import Quantity, SchemaPackage -from nomad.datamodel.metainfo.basesections import Measurement - -from nomad.datamodel.metainfo.plot import PlotSection, PlotlyFigure -import plotly.express as px +from nomad.datamodel.metainfo.basesections import Measurement, MeasurementResult +from nomad.datamodel.metainfo.plot import PlotlyFigure, PlotSection +from nomad.metainfo import Quantity, SchemaPackage, Section configuration = config.get_plugin_entry_point( 'nomad_unisyscat.schema_packages:mypackage' @@ -27,6 +28,34 @@ m_package = SchemaPackage() +class NRVSResult(MeasurementResult): + m_def = Section() + + array_index = Quantity( + type=np.float64, + shape=['*'], + description=( + 'A placeholder for the indices of vectorial quantities. ' + 'Used as x-axis for plots within quantities.' + ), + a_display={'visible': False}, + ) + intensity = Quantity( + type=np.float64, + shape=['*'], + unit='dimensionless', + description='The count at each wavenumber value, dimensionless', + a_plot={'x': 'array_index', 'y': 'intensity'}, + ) + wavenumber = Quantity( + type=np.float64, + shape=['*'], + unit='1/cm', + description='The wavenumber range of the sprectrum', + a_plot={'x': 'array_index', 'y': 'wavenumber'}, + ) + + class NRVSpectroscopy(Measurement, PlotSection, EntryData): measurement_data_file = Quantity( type=str, @@ -54,9 +83,18 @@ class NRVSpectroscopy(Measurement, PlotSection, EntryData): a_eln=dict( component='StringEditQuantity', default='nuclear resonance vibrational spectroscopy', + props=dict( + suggestions=[ + 'experimental nuclear resonance vibrational spectroscopy', + 'simulated nuclear resonance vibrational spectroscopy', + ] + ), ), ) + results = Measurement.results.m_copy() + results.section_def = NRVSResult + def normalize(self, archive, logger): super().normalize(archive, logger) if self.measurement_data_file is None: @@ -74,7 +112,11 @@ def normalize(self, archive, logger): col_names = ['wavenumber, cm-1', '57Fe PVDOS'] data = pd.read_csv(f.name, header=None, names=col_names) + self.results.wavenumber = data['wavenumber, cm-1'] + self.results.intensity = data['57Fe PVDOS'] + self.figures = [] + fig = px.line(x=data['wavenumber, cm-1'], y=data['57Fe PVDOS']) fig.update_xaxes(title_text=col_names[0]) fig.update_yaxes(title_text=col_names[1])