From 617a923fb69876e086ffa2d4ff0fc79232dc0b5d Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Thu, 19 Jun 2025 20:41:17 +0200 Subject: [PATCH] Add processing_Script and processing_data and actris_level to output metadata --- instruments/readers/structured_file_reader.py | 2 +- instruments/readers/xps_ibw_reader.py | 36 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/instruments/readers/structured_file_reader.py b/instruments/readers/structured_file_reader.py index 094c6ab..70d87a0 100644 --- a/instruments/readers/structured_file_reader.py +++ b/instruments/readers/structured_file_reader.py @@ -32,7 +32,7 @@ def read_structured_file_as_dict(path_to_file): _, path_head = os.path.split(path_to_file) file_dict['name'] = path_head - file_dict['attributes_dict'] = {} + file_dict['attributes_dict'] = {'actris_level': 0, 'processing_date': utils.created_at(), 'processing_script' : os.path.relpath(thisFilePath,dimaPath)} file_dict['datasets'] = [] try: diff --git a/instruments/readers/xps_ibw_reader.py b/instruments/readers/xps_ibw_reader.py index cdb022c..f59a775 100644 --- a/instruments/readers/xps_ibw_reader.py +++ b/instruments/readers/xps_ibw_reader.py @@ -1,10 +1,27 @@ -import os import sys +import os + +try: + thisFilePath = os.path.abspath(__file__) +except NameError: + print("Error: __file__ is not available. Ensure the script is being run from a file.") + print("[Notice] Path to DIMA package may not be resolved properly.") + thisFilePath = os.getcwd() # Use current directory or specify a default + +dimaPath = os.path.normpath(os.path.join(thisFilePath, "..",'..','..')) # Move up to project root + +if dimaPath not in sys.path: # Avoid duplicate entries + sys.path.insert(0,dimaPath) + + + import h5py from igor2.binarywave import load as loadibw import logging import argparse +import utils.g5505_utils as utils + def read_xps_ibw_file_as_dict(filename): """ @@ -49,7 +66,7 @@ def read_xps_ibw_file_as_dict(filename): # Group name and attributes file_dict['name'] = path_head - file_dict['attributes_dict'] = {} + file_dict['attributes_dict'] = {'actris_level': 0, 'processing_date':utils.created_at(), 'processing_script' : os.path.relpath(thisFilePath,dimaPath)} # Convert notes of bytes class to string class and split string into a list of elements separated by '\r'. notes_list = file_obj['wave']['note'].decode("utf-8").split('\r') @@ -85,22 +102,11 @@ def read_xps_ibw_file_as_dict(filename): if __name__ == "__main__": - - try: - thisFilePath = os.path.abspath(__file__) - except NameError: - print("Error: __file__ is not available. Ensure the script is being run from a file.") - print("[Notice] Path to DIMA package may not be resolved properly.") - thisFilePath = os.getcwd() # Use current directory or specify a default - - dimaPath = os.path.normpath(os.path.join(thisFilePath, "..",'..','..')) # Move up to project root - - if dimaPath not in sys.path: # Avoid duplicate entries - sys.path.insert(0,dimaPath) - from src.hdf5_ops import save_file_dict_to_hdf5 from utils.g5505_utils import created_at + + # Set up argument parsing parser = argparse.ArgumentParser(description="Data ingestion process to HDF5 files.") parser.add_argument('dst_file_path', type=str, help="Path to the target HDF5 file.")