Merge branch 'main' of https://gitlab.psi.ch/5505/dima
This commit is contained in:
@ -1,7 +1,18 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
root_dir = os.path.abspath(os.curdir)
|
|
||||||
sys.path.append(root_dir)
|
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.append(dimaPath)
|
||||||
|
|
||||||
|
|
||||||
import h5py
|
import h5py
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@ -12,7 +23,6 @@ import src.hdf5_writer as hdf5_lib
|
|||||||
import logging
|
import logging
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import os
|
|
||||||
import h5py
|
import h5py
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
@ -640,17 +650,20 @@ def read_mtable_as_dataframe(filename):
|
|||||||
return output_dataframe
|
return output_dataframe
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) < 4:
|
if len(sys.argv) < 5:
|
||||||
print("Usage: python hdf5_ops.py serialize <path/to/target_file.hdf5> <format=json|yaml>")
|
print("Usage: python hdf5_ops.py serialize <path/to/target_file.hdf5> <folder_depth : int = 2> <format=json|yaml>")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if sys.argv[1] == 'serialize':
|
if sys.argv[1] == 'serialize':
|
||||||
input_hdf5_file = sys.argv[2]
|
input_hdf5_file = sys.argv[2]
|
||||||
file_format = sys.argv[3]
|
folder_depth = int(sys.argv[3])
|
||||||
|
file_format = sys.argv[4]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Call the serialize_metadata function and capture the output path
|
# Call the serialize_metadata function and capture the output path
|
||||||
path_to_file = serialize_metadata(input_hdf5_file, output_format=file_format)
|
path_to_file = serialize_metadata(input_hdf5_file,
|
||||||
|
folder_depth = folder_depth,
|
||||||
|
output_format=file_format)
|
||||||
print(f"Metadata serialized to {path_to_file}")
|
print(f"Metadata serialized to {path_to_file}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An error occurred during serialization: {e}")
|
print(f"An error occurred during serialization: {e}")
|
||||||
|
Reference in New Issue
Block a user