Skip to content

Commit

Permalink
Fixed issues in the LabView ETO class, separated out the ACT from the…
Browse files Browse the repository at this point in the history
… ETO
  • Loading branch information
JonathanNoky committed Dec 10, 2024
1 parent 5db029a commit 4cf88e4
Show file tree
Hide file tree
Showing 6 changed files with 437 additions and 67 deletions.
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ package-dir = { "" = "src" }
where = ["src"]

[project.entry-points.'nomad.plugin']
parser_entry_point_data = "cpfs_ppms.parsers:parser_entry_point_data"
parser_entry_point_data_eto_default = "cpfs_ppms.parsers:parser_entry_point_data_eto_default"
parser_entry_point_data_eto_labview = "cpfs_ppms.parsers:parser_entry_point_data_eto_labview"
parser_entry_point_data_act_default = "cpfs_ppms.parsers:parser_entry_point_data_act_default"
parser_entry_point_sqc = "cpfs_ppms.parsers:parser_entry_point_sqc"
schema_entry_point_eto_default = "cpfs_ppms.schema_packages:schema_entry_point_eto_default"
schema_entry_point_eto_labview = "cpfs_ppms.schema_packages:schema_entry_point_eto_labview"
schema_entry_point_act_default = "cpfs_ppms.schema_packages:schema_entry_point_act_default"



Expand Down
122 changes: 81 additions & 41 deletions src/cpfs_ppms/cpfsppmsdatastruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,36 +346,20 @@ def normalize(self, archive, logger: BoundLogger) -> None: # noqa: PLR0912, PLR
from plotly.subplots import make_subplots

for data in self.data:
if self.software.startswith('ACTRANSPORT'):
if data.measurement_type == 'field':
resistivity_ch1 = px.scatter(
x=data.magnetic_field, y=data.channels[0].resistivity
)
resistivity_ch2 = px.scatter(
x=data.magnetic_field, y=data.channels[1].resistivity
)
if data.measurement_type == 'temperature':
resistivity_ch1 = px.scatter(
x=data.temperature, y=data.channels[0].resistivity
)
resistivity_ch2 = px.scatter(
x=data.temperature, y=data.channels[1].resistivity
)
if self.software.startswith('Electrical Transport Option'):
if data.measurement_type == 'field':
resistivity_ch1 = px.scatter(
x=data.magnetic_field, y=data.channels[0].resistance
)
resistivity_ch2 = px.scatter(
x=data.magnetic_field, y=data.channels[1].resistance
)
if data.measurement_type == 'temperature':
resistivity_ch1 = px.scatter(
x=data.temperature, y=data.channels[0].resistance
)
resistivity_ch2 = px.scatter(
x=data.temperature, y=data.channels[1].resistance
)
if data.measurement_type == 'field':
resistivity_ch1 = px.scatter(
x=data.magnetic_field, y=data.channels[0].resistance
)
resistivity_ch2 = px.scatter(
x=data.magnetic_field, y=data.channels[1].resistance
)
if data.measurement_type == 'temperature':
resistivity_ch1 = px.scatter(
x=data.temperature, y=data.channels[0].resistance
)
resistivity_ch2 = px.scatter(
x=data.temperature, y=data.channels[1].resistance
)
figure1 = make_subplots(rows=2, cols=1, shared_xaxes=True)
figure1.add_trace(resistivity_ch1.data[0], row=1, col=1)
figure1.add_trace(resistivity_ch2.data[0], row=2, col=1)
Expand All @@ -385,17 +369,18 @@ def normalize(self, archive, logger: BoundLogger) -> None: # noqa: PLR0912, PLR
)

# find measurement modes, for now coming from sample.comment
modelist = []
for channel in ['Ch1_', 'Ch2_']:
if channel + 'TMR' in self.samples[0].comment:
modelist.append('TMR')
elif channel + 'Hall' in self.samples[0].comment:
modelist.append('Hall')
else:
modelist.append('undefined')
self.channel_measurement_type = modelist

if self.software.startswith('Electrical Transport Option'):
if self.samples[0].comment:
modelist = []
for channel in ['Ch1_', 'Ch2_']:
if channel + 'TMR' in self.samples[0].comment:
modelist.append('TMR')
elif channel + 'Hall' in self.samples[0].comment:
modelist.append('Hall')
else:
modelist.append('undefined')
self.channel_measurement_type = modelist

if 'Hall' in self.channel_measurement_type and 'TMR' in self.channel_measurement_type:
# find biggest fitlength
maxfield = 90000 * ureg('gauss')
fitlength = 0
Expand Down Expand Up @@ -777,3 +762,58 @@ def normalize(self, archive, logger: BoundLogger) -> None: # noqa: PLR0912, PLR
PlotlyFigure(label='AHC', figure=figure3.to_plotly_json())
)

class CPFSPPMSACTMeasurement(CPFSPPMSMeasurement, PlotSection, EntryData):

temperature_tolerance = Quantity(
type=float,
unit='kelvin',
a_eln=ELNAnnotation(
component='NumberEditQuantity', defaultDisplayUnit='kelvin'
),
)

field_tolerance = Quantity(
type=float,
unit='gauss',
a_eln=ELNAnnotation(component='NumberEditQuantity', defaultDisplayUnit='gauss'),
)

def normalize(self, archive, logger: BoundLogger) -> None: # noqa: PLR0912, PLR0915
super().normalize(archive, logger)

### Start of the PPMSMeasurement normalizer

if archive.data.sequence_file:
logger.info('Parsing PPMS sequence file.')
with archive.m_context.raw_file(self.sequence_file, 'r') as file:
sequence = file.readlines()
self.steps = find_ppms_steps_from_sequence(sequence)



# Now create the according plots
import plotly.express as px
from plotly.subplots import make_subplots

for data in self.data:
if data.measurement_type == 'field':
resistivity_ch1 = px.scatter(
x=data.magnetic_field, y=data.channels[0].resistivity
)
resistivity_ch2 = px.scatter(
x=data.magnetic_field, y=data.channels[1].resistivity
)
if data.measurement_type == 'temperature':
resistivity_ch1 = px.scatter(
x=data.temperature, y=data.channels[0].resistivity
)
resistivity_ch2 = px.scatter(
x=data.temperature, y=data.channels[1].resistivity
)
figure1 = make_subplots(rows=2, cols=1, shared_xaxes=True)
figure1.add_trace(resistivity_ch1.data[0], row=1, col=1)
figure1.add_trace(resistivity_ch2.data[0], row=2, col=1)
figure1.update_layout(height=400, width=716, title_text=data.name)
self.figures.append(
PlotlyFigure(label=data.name, figure=figure1.to_plotly_json())
)
42 changes: 38 additions & 4 deletions src/cpfs_ppms/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,56 @@
from pydantic import Field


class DataParserEntryPoint(ParserEntryPoint):
class DataParserEntryPointETODefault(ParserEntryPoint):
parameter: int = Field(0, description='Custom configuration parameter')

def load(self):
from cpfs_ppms.parsers.parser import CPFSPPMSParser
from cpfs_ppms.parsers.parser import CPFSPPMSETOParserDefault

return CPFSPPMSParser(**self.dict())
return CPFSPPMSETOParserDefault(**self.dict())


parser_entry_point_data = DataParserEntryPoint(
parser_entry_point_data_eto_default = DataParserEntryPointETODefault(
name='DataParser',
description='New parser entry point configuration.',
mainfile_name_re='^.+\.dat$',
mainfile_mime_re='application/x-wine-extension-ini',
mainfile_contents_re='BYAPP, Electrical Transport Option'
)

class DataParserEntryPointETOLabview(ParserEntryPoint):
parameter: int = Field(0, description='Custom configuration parameter')

def load(self):
from cpfs_ppms.parsers.parser import CPFSPPMSETOParserLabview

return CPFSPPMSETOParserLabview(**self.dict())


parser_entry_point_data_eto_labview = DataParserEntryPointETOLabview(
name='DataParser',
description='New parser entry point configuration.',
#mainfile_name_re='^.+\.dat$',
mainfile_mime_re='text/plain',
mainfile_contents_re='; LABVIEW measurement file V2.6'
)

class DataParserEntryPointACTDefault(ParserEntryPoint):
parameter: int = Field(0, description='Custom configuration parameter')

def load(self):
from cpfs_ppms.parsers.parser import CPFSPPMSACTParserDefault

return CPFSPPMSACTParserDefault(**self.dict())


parser_entry_point_data_act_default = DataParserEntryPointACTDefault(
name='DataParser',
description='New parser entry point configuration.',
mainfile_name_re='^.+\.dat$',
mainfile_mime_re='application/x-wine-extension-ini',
mainfile_contents_re='BYAPP,\s*ACTRANSPORT'
)

class SqcParserEntryPoint(ParserEntryPoint):
parameter: int = Field(0, description='Custom configuration parameter')
Expand Down
75 changes: 65 additions & 10 deletions src/cpfs_ppms/parsers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
from nomad.search import search
from nomad_material_processing.utils import create_archive

from cpfs_ppms.schema_packages.schema_package import CPFSPPMSETOMeasurementDefault
from cpfs_ppms.schema_packages.schema_package import (
CPFSPPMSETOMeasurementDefault,
CPFSPPMSETOMeasurementLabview,
CPFSPPMSACTMeasurementDefault,
)

if TYPE_CHECKING:
from nomad.datamodel.datamodel import (
Expand All @@ -47,7 +51,13 @@
)

configuration = config.get_plugin_entry_point(
'cpfs_ppms.parsers:parser_entry_point_data'
'cpfs_ppms.parsers:parser_entry_point_data_eto_default'
)
configuration = config.get_plugin_entry_point(
'cpfs_ppms.parsers:parser_entry_point_data_eto_labview'
)
configuration = config.get_plugin_entry_point(
'cpfs_ppms.parsers:parser_entry_point_data_act_default'
)
configuration = config.get_plugin_entry_point(
'cpfs_ppms.parsers:parser_entry_point_sqc'
Expand All @@ -63,14 +73,7 @@ class CPFSPPMSFile(EntryData):
)


class CPFSPPMSParser(MatchingParser):
# def __init__(self):
# super().__init__(
# name='NOMAD PPMS schema and parser plugin for the CPFS',
# code_name='cpfs_ppms_data',
# code_homepage='https://github.com/FAIRmat-NFDI/AreaA-data_modeling_and_schemas',
# supported_compressions=['gz', 'bz2', 'xz'],
# )
class CPFSPPMSETOParserDefault(MatchingParser):

def parse(self, mainfile: str, archive: EntryArchive, logger) -> None:
timethreshold = 15
Expand Down Expand Up @@ -108,6 +111,58 @@ def parse(self, mainfile: str, archive: EntryArchive, logger) -> None:
)
archive.metadata.entry_name = data_file + ' measurement file'

class CPFSPPMSETOParserLabview(MatchingParser):

def parse(self, mainfile: str, archive: EntryArchive, logger) -> None:
timethreshold = 15
data_file = mainfile.split('/')[-1]
data_file_with_path = mainfile.split('raw/')[-1]
entry = CPFSPPMSETOMeasurementLabview()
entry.data_file = data_file_with_path
file_name = f'{data_file[:-4]}.archive.json'
archive.data = CPFSPPMSFile(
measurement=create_archive(entry, archive, file_name)
)
archive.metadata.entry_name = data_file + ' measurement file'

class CPFSPPMSACTParserDefault(MatchingParser):

def parse(self, mainfile: str, archive: EntryArchive, logger) -> None:
timethreshold = 15
data_file = mainfile.split('/')[-1]
data_file_with_path = mainfile.split('raw/')[-1]
entry = CPFSPPMSACTMeasurementDefault()
entry.data_file = data_file_with_path
file_name = f'{data_file[:-4]}.archive.json'
# entry.normalize(archive, logger)
tic = perf_counter()
while True:
search_result = search(
owner='user',
query={
'results.eln.sections:any': ['CPFSPPMSSequenceFile'],
'upload_id:any': [archive.m_context.upload_id],
},
user_id=archive.metadata.main_author.user_id,
)
if len(search_result.data) > 0:
for sequence in search_result.data:
entry.sequence_file = sequence['search_quantities'][0]['str_value']
logger.info(sequence['search_quantities'][0]['str_value'])
break
sleep(0.1)
toc = perf_counter()
if toc - tic > timethreshold:
logger.warning(
"The Sequence File entry/ies in the current upload \
were not found and couldn't be referenced."
)
break
archive.data = CPFSPPMSFile(
measurement=create_archive(entry, archive, file_name)
)
archive.metadata.entry_name = data_file + ' measurement file'


class CPFSPPMSSequenceFile(BaseSection, EntryData):
file_path = Quantity(
Expand Down
29 changes: 27 additions & 2 deletions src/cpfs_ppms/schema_packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,41 @@
from pydantic import Field


class CPFSPPMSETOEntryPoint(SchemaPackageEntryPoint):
class CPFSPPMSETOEntryPointDefault(SchemaPackageEntryPoint):
parameter: int = Field(0, description='Custom configuration parameter')

def load(self):
from cpfs_ppms.schema_packages.schema_package import m_package_ppms_eto_default

return m_package_ppms_eto_default

class CPFSPPMSETOEntryPointLabview(SchemaPackageEntryPoint):
parameter: int = Field(0, description='Custom configuration parameter')

def load(self):
from cpfs_ppms.schema_packages.schema_package import m_package_ppms_eto_labview

return m_package_ppms_eto_labview

class CPFSPPMSACTEntryPointDefault(SchemaPackageEntryPoint):
parameter: int = Field(0, description='Custom configuration parameter')

def load(self):
from cpfs_ppms.schema_packages.schema_package import m_package_ppms_act_default

schema_entry_point_eto_default = CPFSPPMSETOEntryPoint(
return m_package_ppms_act_default

schema_entry_point_eto_default = CPFSPPMSETOEntryPointDefault(
name='CPFSPPMSETOEntryPoint',
description='New schema package entry point configuration.',
)

schema_entry_point_eto_labview = CPFSPPMSETOEntryPointLabview(
name='CPFSPPMSETOEntryPoint',
description='New schema package entry point configuration.',
)

schema_entry_point_act_default = CPFSPPMSACTEntryPointDefault(
name='CPFSPPMSACTEntryPoint',
description='New schema package entry point configuration.',
)
Loading

0 comments on commit 4cf88e4

Please sign in to comment.