Frame Utilities
This page documents the frame assembly helpers from nbs/02_frame_utils.py.
Normalize RAW Axis Order
import numpy as np
from mertisreader.frame_utils import normalize_raw_axis_order, get_frame_dimensions, detect_interpolation_target, assemble_frames
raw_arr = np.arange(24, dtype=np.float64).reshape(2, 3, 4)
normalized = normalize_raw_axis_order(raw_arr)
print(raw_arr.shape)
print(normalized.shape)
Describe Frame Dimensions
frames_dict = {
"sample_a": np.ones((2, 3, 4), dtype=np.float64),
"sample_b": np.zeros((2, 3, 2), dtype=np.float64),
}
dims = get_frame_dimensions(frames_dict)
target = detect_interpolation_target(frames_dict, mode="up")
print(dims)
print(target)
n_files n_pixels n_spectrals
sample_a 4 3 2
sample_b 2 3 2
{'n_spectrals': 2, 'n_pixels': 3, 'mode_applied': 'up', 'reason': 'Upsampling to largest frame'}
Assemble Frames
cube, metadata = assemble_frames(frames_dict, interp_mode="up")
print(cube.shape)
print(metadata)
(2, 3, 6)
{'interpolation_mode': 'up', 'interpolation_order': 1, 'target_n_spectrals': 2, 'target_n_pixels': 3, 'n_temporal_samples': 6, 'reason': 'Upsampling to largest frame', 'file_keys': ['sample_a', 'sample_b'], 'file_indices': [(0, 4), (4, 6)]}
Notes
The module keeps the axis handling explicit so RAW, CAL, and PAR data can be normalized and assembled with the same downstream workflow.