Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent h5 failing #36

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions src/nomad_catalysis/schema_packages/catalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,11 @@ def map_and_assign_attributes(self, logger, mapping, target, obj=None) -> None:
)


threshold_conc = 1.1


def check_if_concentration_in_percentage(self, conc_array, logger) -> None:
if conc_array is not None and any(y > 1.0 for y in conc_array):
if conc_array is not None and any(y > threshold_conc for y in conc_array):
logger.error(
f'Gas concentration for reagent "{self.name}" is above 1, '
f'but should be given as fraction.'
Expand Down Expand Up @@ -748,15 +751,21 @@ def normalize(self, archive, logger):
check_if_concentration_in_percentage(self, self.fraction_in, logger)
try:
if (
not self.fraction_in
and self.flow_rate
and self.m_parent
and getattr(self.m_parent, 'set_total_flow_rate', None)
self.fraction_in is None
and self.flow_rate is not None
and self.m_parent is not None
and getattr(self.m_parent, 'set_total_flow_rate', None) is not None
):
total_flow = getattr(self.m_parent, 'set_total_flow_rate', None)
self.fraction_in = self.flow_rate / total_flow
except (TypeError, ValueError): # because truth value of array is ambiguous
pass
except (
TypeError,
ValueError,
) as e: # because truth value of array is ambiguous
logger.info(
f'Could not calculate fraction_in for reagent {self.name} '
f'from flow rate and total flow rate. Error: {e}'
)
if self.name is None:
return
if self.name in ['C5-1', 'C6-1', 'nC5', 'nC6', 'Unknown', 'inert', 'P>=5C']:
Expand Down Expand Up @@ -1108,7 +1117,7 @@ class ReagentBatch(Reagent):
m_def = Section(
label_quantity='name',
description='A reagent in a batch reaction.',
a_eln={'hide': ['fraction_in', 'flow_rate']},
a_eln={'hide': ['flow_rate']},
)

amount = Quantity(
Expand Down Expand Up @@ -1817,7 +1826,7 @@ def read_haber_data(self, archive, logger): # noqa: PLR0912, PLR0915

def check_and_read_data_file(self, archive, logger):
"""This functions checks the format of the data file and assigns the right
reader function to read the data file or logs an error if the format is not
reader function to read the data file or logs a warning if the format is not
supported.
"""
if self.data_file is None:
Expand All @@ -1830,14 +1839,23 @@ def check_and_read_data_file(self, archive, logger):
if self.data_file.endswith('NH3_Decomposition.h5'):
self.read_haber_data(archive, logger)
else:
logger.info("""This h5 file format might currently not be supported.
Pleasecontact the plugin developers if you want to add support for this.
""")
self.read_haber_data(archive, logger)
try:
self.read_haber_data(archive, logger)
except KeyError:
logger.warning(
"""No data is extracted from this h5 data file as the file is
either missing or the format is not (yet) supported.
This file contains a different data
structure or object names from currently supported h5 files for
catalysis. Please check if you can modify the structure or
contact the plugin developers if you want to add support for
this."""
)
else:
logger.error(
"""Data file format not supported. Please provide a
.csv, .xlsx or .h5 file."""
logger.warning(
"""Data file format not supported. No data is extracted from the
provided file. Please provide a standadized .csv, .xlsx or .h5 file,
if you want direct data extraction into the schema."""
)
return

Expand Down Expand Up @@ -2470,7 +2488,7 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:

if self.data_file is not None:
self.check_and_read_data_file(archive, logger)
logger.info('Data file read successfully.')
logger.info('Data file processed.')

self.normalize_reaction_conditions(archive, logger)
if self.pretreatment is not None:
Expand Down
Loading