Skip to content

Commit

Permalink
Added HDF5 IO Abstract class inheritance to SpatialOrientation
Browse files Browse the repository at this point in the history
  • Loading branch information
braden6521 committed Mar 21, 2024
1 parent be9d36f commit 712f75f
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions opencsp/app/sofast/lib/SpatialOrientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -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',
Expand All @@ -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/...
Expand All @@ -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'])
Expand Down

0 comments on commit 712f75f

Please sign in to comment.