From 712f75ff9680994ccf3d309118e2e977cf6129bf Mon Sep 17 00:00:00 2001 From: Braden Date: Thu, 21 Mar 2024 13:09:43 -0600 Subject: [PATCH] Added HDF5 IO Abstract class inheritance to SpatialOrientation --- opencsp/app/sofast/lib/SpatialOrientation.py | 51 ++++++++++++-------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/opencsp/app/sofast/lib/SpatialOrientation.py b/opencsp/app/sofast/lib/SpatialOrientation.py index 25afdeac7..56bdda614 100644 --- a/opencsp/app/sofast/lib/SpatialOrientation.py +++ b/opencsp/app/sofast/lib/SpatialOrientation.py @@ -2,12 +2,10 @@ from opencsp.common.lib.geometry.TransformXYZ import TransformXYZ from opencsp.common.lib.geometry.Vxyz import Vxyz -from opencsp.common.lib.tool import hdf5_tools +import opencsp.common.lib.tool.hdf5_tools as ht -# TODO: Add HDF5 abstract class inheritance - -class SpatialOrientation: +class SpatialOrientation(ht.HDF5_IO_Abstract): """Holds relative orientations of camera, screen, and optic for deflectometry systems""" def __init__( @@ -155,7 +153,6 @@ def save_to_hdf(self, file: str, prefix: str = '') -> None: HDF file to save to prefix : str Prefix to append to folder path within HDF file (folders must be separated by "/") - """ datasets = [ prefix + 'SpatialOrientation/r_cam_screen', @@ -164,7 +161,7 @@ def save_to_hdf(self, file: str, prefix: str = '') -> None: data = [self.r_cam_screen.as_rotvec(), self.v_cam_screen_cam.data] - hdf5_tools.save_hdf5_datasets(data, datasets, file) + ht.save_hdf5_datasets(data, datasets, file) def save_all_to_hdf(self, file: str, prefix: str = '') -> None: """Saves all data to HDF file. Data is stored as prefix + SpatialOrientation/... @@ -191,30 +188,46 @@ def save_all_to_hdf(self, file: str, prefix: str = '') -> None: self.v_cam_optic_cam.data, ] - hdf5_tools.save_hdf5_datasets(data, datasets, file) + ht.save_hdf5_datasets(data, datasets, file) @classmethod - def load_from_hdf(cls, file: str) -> 'SpatialOrientation': - """Loads camera-screen orientation data from HDF file""" + def load_from_hdf(cls, file: str, prefix: str = '') -> 'SpatialOrientation': + """Loads data from given file. Assumes data is stored as: PREFIX + SpatialOrientation/... + + Parameters + ---------- + file : str + HDF file to save to + prefix : str + Prefix to append to folder path within HDF file (folders must be separated by "/") + """ datasets = [ - 'SpatialOrientation/r_cam_screen', - 'SpatialOrientation/v_cam_screen_cam', + prefix + 'SpatialOrientation/r_cam_screen', + prefix + 'SpatialOrientation/v_cam_screen_cam', ] - data = hdf5_tools.load_hdf5_datasets(datasets, file) + data = ht.load_hdf5_datasets(datasets, file) r_cam_screen = Rotation.from_rotvec(data['r_cam_screen']) v_cam_screen_cam = Vxyz(data['v_cam_screen_cam']) return cls(r_cam_screen, v_cam_screen_cam) @classmethod - def load_all_from_hdf(cls, file: str) -> 'SpatialOrientation': - """Loads all data from HDF file""" + def load_all_from_hdf(cls, file: str, prefix: str = '') -> 'SpatialOrientation': + """Loads data from given file. Assumes data is stored as: PREFIX + SpatialOrientation/... + + Parameters + ---------- + file : str + HDF file to save to + prefix : str + Prefix to append to folder path within HDF file (folders must be separated by "/") + """ datasets = [ - 'SpatialOrientation/r_cam_screen', - 'SpatialOrientation/v_cam_screen_cam', - 'SpatialOrientation/r_cam_optic', - 'SpatialOrientation/v_cam_optic_cam', + prefix + 'SpatialOrientation/r_cam_screen', + prefix + 'SpatialOrientation/v_cam_screen_cam', + prefix + 'SpatialOrientation/r_cam_optic', + prefix + 'SpatialOrientation/v_cam_optic_cam', ] - data = hdf5_tools.load_hdf5_datasets(datasets, file) + data = ht.load_hdf5_datasets(datasets, file) r_cam_screen = Rotation.from_rotvec(data['r_cam_screen']) v_cam_screen_cam = Vxyz(data['v_cam_screen_cam'])