Skip to content

Commit

Permalink
Ad IR schema and test
Browse files Browse the repository at this point in the history
  • Loading branch information
schumannj committed May 29, 2024
1 parent de1ead1 commit be22b68
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 3 deletions.
96 changes: 93 additions & 3 deletions src/nomad_unisyscat/schema_packages/mypackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class NRVSResult(MeasurementResult):
type=np.float64,
shape=['*'],
unit='dimensionless',
description='The count at each wavenumber value, dimensionless',
description='The 57Fe PVDOS 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',
description='The wavenumber range of the spectrum',
a_eln=ELNAnnotation(defaultDisplayUnit='1/cm'),
a_plot={'x': 'array_index', 'y': 'wavenumber'},
)
Expand Down Expand Up @@ -116,10 +116,100 @@ def normalize(self, archive, logger):

self.figures = []

fig = px.line(x=data['wavenumber, cm-1'], y=data['57Fe PVDOS'])
fig = px.line(x=self.results.wavenumber, y=self.results.intensity)
fig.update_xaxes(title_text=col_names[0])
fig.update_yaxes(title_text=col_names[1])
self.figures.append(PlotlyFigure(label='NRVS', figure=fig.to_plotly_json()))


class IRResult(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 absorbance 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 spectrum',
a_eln=ELNAnnotation(defaultDisplayUnit='1/cm'),
a_plot={'x': 'array_index', 'y': 'wavenumber'},
)


class IRSpectroscopy(Measurement, PlotSection, Schema):
data_file = Quantity(
type=str,
description="""
csv data file ending .dat
""",
a_eln=ELNAnnotation(component='FileEditQuantity'),
a_browser=dict(adaptor='RawFileAdaptor'),
)

method = Quantity(
type=str,
description="""
name of the method
""",
a_eln=ELNAnnotation(
component='StringEditQuantity',
default='infra red vibrational spectroscopy',
props=dict(
suggestions=[
'experimental IR vibrational spectroscopy',
'simulated IR vibrational spectroscopy',
]
),
),
)

results = Measurement.results.m_copy()
results.section_def = IRResult

def normalize(self, archive, logger):
super().normalize(archive, logger)
if self.data_file is None:
return

if (self.data_file is not None) and (
os.path.splitext(self.data_file)[-1] != '.dat'
):
raise ValueError('Unsupported file format. Only .dat file')

if self.data_file.endswith('.dat'):
with archive.m_context.raw_file(self.data_file) as f:
import pandas as pd

col_names = ['wavenumber, cm-1', 'Absorbance']
data = pd.read_csv(f.name, header=None, names=col_names)
result = IRResult()
result.wavenumber = data['wavenumber, cm-1']
result.intensity = data['Absorbance']
results = []
results.append(result)
self.results = results

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])
self.figures.append(PlotlyFigure(label='IR', figure=fig.to_plotly_json()))


m_package.__init_metainfo__()
3 changes: 3 additions & 0 deletions tests/data/ir_test.archive.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data:
m_def: nomad_unisyscat.schema_packages.mypackage.IRSpectroscopy
measurement_data_file: ReRH_Nia-C_H_IR_exp.dat

0 comments on commit be22b68

Please sign in to comment.