Skip to content

Commit

Permalink
update on CV, ED and electrolyte solution
Browse files Browse the repository at this point in the history
GarzonDiegoFEUP committed Sep 26, 2024
1 parent 9a4e7fa commit 695c4db
Showing 6 changed files with 532 additions and 51 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -111,9 +111,10 @@ package-dir = { "" = "src" }
where = ["src"]

[project.entry-points.'nomad.plugin']
parser_entry_point = "nomad_inl_base.parsers:parser_entry_point"
CVarser_entry_point = "nomad_inl_base.parsers:CV_parser_entry_point"
EDparser_entry_point1 = "nomad_inl_base.parsers:ED_parser_entry_point"
schema_package_entry_point = "nomad_inl_base.schema_packages:schema_package_entry_point"
cyclyc_voltammetry_entry_point = "nomad_inl_base.schema_packages:cyclyc_voltammetry_entry_point"
cyclic_voltammetry_entry_point = "nomad_inl_base.schema_packages:cyclic_voltammetry_entry_point"



29 changes: 20 additions & 9 deletions src/nomad_inl_base/parsers/__init__.py
Original file line number Diff line number Diff line change
@@ -2,17 +2,28 @@
from pydantic import Field


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

class CVConfigurationParserEntryPoint(ParserEntryPoint):
def load(self):
from nomad_inl_base.parsers.parser import NewParser
from nomad_inl_base.parsers.parser import CVParser

return CVParser(**self.dict())

return NewParser(**self.dict())
CV_parser_entry_point = CVConfigurationParserEntryPoint(
name='CVParser',
description='New parser for getting the data from a CV.',
mainfile_name_re=r'.*mVs\.xlsx',
mainfile_mime_re='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
)

class EDConfigurationParserEntryPoint(ParserEntryPoint):
def load(self):
from nomad_inl_base.parsers.parser import EDParser

return EDParser(**self.dict())

parser_entry_point = NewParserEntryPoint(
name='NewParser',
description='New parser entry point configuration.',
mainfile_name_re='.*\.newmainfilename',
ED_parser_entry_point = EDConfigurationParserEntryPoint(
name='EDParser',
description='New parser for getting the data from a ED.',
mainfile_name_re=r'.*ED\.xlsx',
mainfile_mime_re='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
)
168 changes: 155 additions & 13 deletions src/nomad_inl_base/parsers/parser.py
Original file line number Diff line number Diff line change
@@ -13,20 +13,162 @@
from nomad.config import config
from nomad.datamodel.metainfo.workflow import Workflow
from nomad.parsing.parser import MatchingParser
import pandas as pd
from nomad.datamodel.data import EntryData
from nomad.datamodel.datamodel import EntryArchive, EntryMetadata
from nomad_inl_base.utils import fill_quantity, create_archive, get_hash_ref
from nomad_inl_base.schema_packages.cyclic_voltammetry import *
from nomad.units import ureg

class RawFile_(EntryData):
m_def = Section(a_eln=None, label='Raw File EPIC')
name = Quantity(
type=str,
a_eln=ELNAnnotation(
component='StringEditQuantity',
),
)
file_ = Quantity(
type=str,
a_eln=ELNAnnotation(
component='FileEditQuantity',
),
a_browser={'adaptor': 'RawFileAdaptor'},
description='EPIC log file list',
)

class EDParser(MatchingParser):

def parse(self, mainfile: str, archive: EntryArchive, logger) -> None:
filetype = 'yaml'
data_file = mainfile.split('/')[-1].split('.xlsx')[0].replace(' ', '_')
xlsx = pd.ExcelFile(mainfile)

data = pd.read_excel(xlsx)
if 'WE(1).Current (A)' in data.columns:
data.rename(columns={'Corrected time (s)':'Time',
'WE(1).Current (A)':'Current'}, inplace=True)
else:
data.rename(columns={'Column 1':'t',
'Column 2':'Current',
'Column 3':'Time',
'Column 4':'Index',
'Column 5':'Current range'}, inplace=True)

#Dummy archive for the data file
file_reference = get_hash_ref(archive.m_context.upload_id, data_file)


#create a ED archive
ED_measurement = ChronoamperometryMeasurement()
ED_measurement.current = CurrentTimeSeries()
ED_measurement.current.value = fill_quantity(data, 'Current', 'ampere')
ED_measurement.current.time = fill_quantity(data, 'Time', 'seconds')

#create a ED archive
ED_filename = f'{data_file}.ED_measurement.archive.{filetype}'

if archive.m_context.raw_path_exists(ED_filename):
logger.warn(f'Process archive already exists: {ED_filename}')
else:
ED_archive = EntryArchive(
data=ED_measurement if ED_filename else ChronoamperometryMeasurement(),
# m_context=archive.m_context,
metadata=EntryMetadata(upload_id=archive.m_context.upload_id),
)


create_archive(
ED_archive.m_to_dict(),
archive.m_context,
ED_filename,
filetype,
logger,
)


archive.data = RawFile_(
name=data_file + '_raw',
file_=file_reference,
)
archive.metadata.entry_name = data_file.replace('.xlsx', '')


class CVParser(MatchingParser):

def parse(self, mainfile: str, archive: EntryArchive, logger) -> None:
filetype = 'yaml'
data_file = mainfile.split('/')[-1].split('.xlsx')[0].replace(' ', '_')
xlsx = pd.ExcelFile(mainfile)

data = pd.read_excel(xlsx)
if 'WE(1).Potential (V)' in data.columns:
data.rename(columns={'WE(1).Potential (V)':'Potential',
'WE(1).Current (A)':'Current'}, inplace=True)
else:
data.rename(columns={'Column 1':'Potential applied (V)',
'Column 2':'Time (s)',
'Column 3':'Current',
'Column 4':'Potential',
'Column 5':'Scan',
'Column 6':'Index',
'Column 7': 'Q+',
'Column 8':'Q-'}, inplace=True)

rate = float(mainfile.split('.xlsx')[0].split('-')[-1].replace(' ','').replace('mVs', ''))

#create a CV archive

CV_measurement = PotentiostatMeasurement()
CV_measurement.voltage = VoltageTimeSeries()
CV_measurement.current = CurrentTimeSeries()
CV_measurement.scan = ScanTimeSeries()
CV_measurement.rate = ureg.Quantity(
rate,
ureg('millivolt/second'),
)

#Dummy archive for the data file
file_reference = get_hash_ref(archive.m_context.upload_id, data_file)

#CV_measurement.data_file = file_reference

CV_measurement.voltage.value = fill_quantity(data, 'Potential', 'volt')
CV_measurement.current.value = fill_quantity(data, 'Current', 'ampere')
CV_measurement.scan.value = fill_quantity(data, 'Scan')
for values in [CV_measurement.voltage, CV_measurement.current, CV_measurement.scan]:
values.time = fill_quantity(data, 'Time (s)', 'seconds')

#create a CV archive
CV_filename = f'{data_file}.CV_measurement.archive.{filetype}'

if archive.m_context.raw_path_exists(CV_filename):
logger.warn(f'Process archive already exists: {CV_filename}')
else:
CV_archive = EntryArchive(
data=CV_measurement if CV_filename else PotentiostatMeasurement(),
# m_context=archive.m_context,
metadata=EntryMetadata(upload_id=archive.m_context.upload_id),
)

create_archive(
CV_archive.m_to_dict(),
archive.m_context,
CV_filename,
filetype,
logger,
)




archive.data = RawFile_(
name=data_file + '_raw',
file_=file_reference,
)
archive.metadata.entry_name = data_file.replace('.xlsx', '')


configuration = config.get_plugin_entry_point(
'nomad_inl_base.parsers:parser_entry_point'
)


class NewParser(MatchingParser):
def parse(
self,
mainfile: str,
archive: 'EntryArchive',
logger: 'BoundLogger',
child_archives: dict[str, 'EntryArchive'] = None,
) -> None:
logger.info('NewParser.parse', parameter=configuration.parameter)

archive.workflow2 = Workflow(name='test')
3 changes: 2 additions & 1 deletion src/nomad_inl_base/schema_packages/__init__.py
Original file line number Diff line number Diff line change
@@ -25,7 +25,8 @@ def load(self):
return m_package


schema_package_entry_point = CyclicVoltammetryPackageEntryPoint(
cyclic_voltammetry_entry_point = CyclicVoltammetryPackageEntryPoint(
name='CyclicVoltammetry',
description='CyclicVoltammetry entry point configuration.',
)

Loading

0 comments on commit 695c4db

Please sign in to comment.