UVH5Writer#
- class pyvisgen.io.datawriters.UVH5Writer(output_path: Path, dataset_type: str, **kwargs)[source]#
Bases:
DataWriterHDF5 file writer for UV-plane simulation data.
This writer saves visibilities, UVW coordinates, LMN coordinates, and the simulated sky to a single HDF5 file per sample. The file layout is:
{dataset_type}_{index}.uvh5 ├── visibilities/ │ ├── V_11 (complex128) │ ├── V_22 (complex128) │ ├── V_12 (complex128) │ ├── V_21 (complex128) │ └── weights (float64) ├── uvw/ │ ├── u │ ├── v │ ├── w │ └── st_id_pairs (int64, shape n_baselines x 2) ├── lmn/ │ ├── l │ ├── m │ └── n ├── frequency_bands └── sky/ └── SI- Parameters:
- output_pathstr or Path
Directory path where HDF5 files will be written.
- dataset_typestr
Type of dataset being written (e.g., ‘train’, ‘test’, ‘validation’). Used in the output filename pattern.
Examples
>>> writer = UVH5Writer(output_path="./data", dataset_type="train") >>> writer.write(vis_data, obs, index=0, sky=SI)
Or as a context manager:
>>> with UVH5Writer(output_path="./data", dataset_type="train") as writer: ... writer.write(vis_data, obs, index=0, sky=SI)
Methods Summary
get_half_image(x, y[, overlap])Extract half height of every image with a small overlap.
test_shapes(array, name)Validate the shape of input arrays.
write(vis_data, obs, index[, sky])Write simulation data to an HDF5 file.
Methods Documentation
- get_half_image(x: ndarray, y: ndarray, overlap: int = 5) tuple[ndarray]#
Extract half height of every image with a small overlap.
- Parameters:
- xnp.ndarray
Simulated data array with shape (B, C, H, W).
- ynp.ndarray
Ground truth array with shape (B, C, H, W).
- Returns:
- tuple[np.ndarray, np.ndarray]
Tuple containing the cropped x and y arrays.
- test_shapes(array: ndarray, name: str) None#
Validate the shape of input arrays.
Arrays should have the shape (B, C, H, W), where B is the batch size, C the number of channels (2), and W and H the width and height of the images.
- Parameters:
- arraynp.ndarray
Array to validate.
- namestr
Name of the array for error reporting.
- Raises:
- ValueError
If array axis 1 is not size 2.
- ValueError
If array does not have exactly 4 dimensions.
- write(vis_data, obs, index: int, sky=None, **kwargs) None[source]#
Write simulation data to an HDF5 file.
Creates a new HDF5 file for each sample with pattern
uvh5_{dataset_type}_{index}.uvh5.- Parameters:
- vis_dataVisibilities
Visibilities dataclass object from
vis_loop(), containing V_11, V_22, V_12, V_21, u, v, w, and related tensors.- obsObservation
Observation object from
Observation. Used to retrieve the LMN coordinate grid viaobs.lm.- indexint
Sample index used in the output filename.
- skytorch.Tensor or np.ndarray, optional
Sky intensity distribution (SI) passed to the visibility simulation, with shape
(C, H, W). IfNone, thesky/group is omitted from the output file.
Examples
>>> writer = UVH5Writer(output_path="./data", dataset_type="train") >>> writer.write(vis_data, obs, index=0, sky=SI)