Skip to content

Commit

Permalink
add results section to nrvs schema
Browse files Browse the repository at this point in the history
  • Loading branch information
schumannj committed May 29, 2024
1 parent 3a64663 commit f85a4e8
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions src/nomad_unisyscat/schema_packages/mypackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
TYPE_CHECKING,
)

import numpy as np

if TYPE_CHECKING:
from nomad.datamodel.datamodel import (
EntryArchive,
Expand All @@ -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'
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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])
Expand Down

0 comments on commit f85a4e8

Please sign in to comment.