From d34b6a0958061d24762ab52e4df6796c598cfca3 Mon Sep 17 00:00:00 2001 From: Julia Schumann Date: Thu, 2 Jan 2025 13:40:25 +0100 Subject: [PATCH 1/3] improve logger warning for non compatible data files --- .../schema_packages/catalysis.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/nomad_catalysis/schema_packages/catalysis.py b/src/nomad_catalysis/schema_packages/catalysis.py index f015c41..8f521ea 100644 --- a/src/nomad_catalysis/schema_packages/catalysis.py +++ b/src/nomad_catalysis/schema_packages/catalysis.py @@ -1830,14 +1830,22 @@ 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 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 From 63d911f0177507263f5e35f025ed0ea1c7053539 Mon Sep 17 00:00:00 2001 From: Julia Schumann Date: Thu, 2 Jan 2025 20:51:02 +0100 Subject: [PATCH 2/3] fix true check for array for fraction_in calc; modify logger warning change concentration check to 1.1 --- .../schema_packages/catalysis.py | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/nomad_catalysis/schema_packages/catalysis.py b/src/nomad_catalysis/schema_packages/catalysis.py index 8f521ea..132e5c4 100644 --- a/src/nomad_catalysis/schema_packages/catalysis.py +++ b/src/nomad_catalysis/schema_packages/catalysis.py @@ -173,7 +173,7 @@ def map_and_assign_attributes(self, logger, mapping, target, obj=None) -> None: 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 > 1.1 for y in conc_array): logger.error( f'Gas concentration for reagent "{self.name}" is above 1, ' f'but should be given as fraction.' @@ -748,15 +748,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']: @@ -1108,7 +1114,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( @@ -1817,7 +1823,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: @@ -1834,8 +1840,9 @@ def check_and_read_data_file(self, archive, logger): self.read_haber_data(archive, logger) except KeyError: logger.warning( - """No data is extracted from this h5 data file as the format is - not (yet) supported. This file contains a different data + """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 @@ -2478,7 +2485,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: From d8f54079bf0a59b360ed665c297f0d4f4db0e44c Mon Sep 17 00:00:00 2001 From: Julia Schumann Date: Thu, 2 Jan 2025 20:59:37 +0100 Subject: [PATCH 3/3] fix ruff checks --- src/nomad_catalysis/schema_packages/catalysis.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nomad_catalysis/schema_packages/catalysis.py b/src/nomad_catalysis/schema_packages/catalysis.py index 132e5c4..b959707 100644 --- a/src/nomad_catalysis/schema_packages/catalysis.py +++ b/src/nomad_catalysis/schema_packages/catalysis.py @@ -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.1 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.'