DataWriter#
- class pyvisgen.io.datawriters.DataWriter(output_path: Path, dataset_type: str, *args, **kwargs)[source]#
Bases:
ABCAbstract base class for data writers in pyvisgen.
This class contains methods to get half images and test the shapes of the data prior to writing. It also supports a context manager protocol.
Subclasses must implement the __init__ and write methods to define writing behavior.
- Parameters:
- output_pathstr or Path
Path where the dataset will be written.
- dataset_typestr
Type of dataset being written (e.g., ‘train’, ‘test’, ‘validation’).
- *args
Variable length argument list passed to subclass implementations.
- **kwargs
Arbitrary keyword arguments passed to subclass implementations.
Examples
>>> class MyWriter(DataWriter): ... def __init__(self, output_path, dataset_type): ... self.output_path = output_path ... self.dataset_type = dataset_type ... ... def write(self, data): ... # Implementation here ... pass >>> >>> with MyWriter("output_file", dataset_type="train") as writer: ... writer.write(data)
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(*args, **kwargs)Write data to the output destination.
Methods Documentation
- get_half_image(x: ndarray, y: ndarray, overlap: int = 5) tuple[ndarray][source]#
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[source]#
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.
- abstractmethod write(*args, **kwargs) None[source]#
Write data to the output destination.
This method must be implemented by subclasses to handle the actual writing of data to the specified output format.
- Parameters:
- *args
Data and parameters required for writing, defined by subclass.
- **kwargs
Additional options for writing, defined by subclass.