Added .update_file() method, which enables complementary data structure updates to existing file with same name as append_dir's head.
This commit is contained in:
@ -8,6 +8,7 @@ import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
import utils.g5505_utils as utils
|
||||
import src.hdf5_lib as hdf5_lib
|
||||
import logging
|
||||
import datetime
|
||||
|
||||
@ -354,6 +355,34 @@ class HDF5DataOpsManager():
|
||||
|
||||
#return np.array(timestamps)
|
||||
return dt_column_data.to_numpy()
|
||||
|
||||
def update_file(self, path_to_append_dir):
|
||||
# Split the reference file path and the append directory path into directories and filenames
|
||||
ref_tail, ref_head = os.path.split(self.file_path)
|
||||
tail, head = os.path.split(path_to_append_dir)
|
||||
head_filename, head_ext = os.path.splitext(head)
|
||||
|
||||
# Ensure the append directory is in the same directory as the reference file and has the same name (without extension)
|
||||
if not (ref_tail == tail and ref_head == head_filename):
|
||||
raise ValueError("The append directory must be in the same directory as the reference HDF5 file and have the same name without the extension.")
|
||||
|
||||
# Close the file if it's already open
|
||||
if self.file_obj is not None:
|
||||
self.close_file()
|
||||
|
||||
# Attempt to open the file in 'r+' mode for appending
|
||||
try:
|
||||
hdf5_lib.create_hdf5_file_from_filesystem_path(path_to_append_dir, mode='r+')
|
||||
except FileNotFoundError:
|
||||
raise FileNotFoundError(f"Reference HDF5 file '{self.file_path}' not found.")
|
||||
except OSError as e:
|
||||
raise OSError(f"Error opening HDF5 file: {e}")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user