Module: sarpyx.utils.io
File: sarpyx/utils/io.py
No module docstring available; module purpose is inferred from implementation.
Exported Symbols (__all__)
No explicit __all__ list. Public symbols inferred from implementation.
Public Functions (10)
gc_collect function
Decorator to perform garbage collection after function execution.
File location: sarpyx/utils/io.py:17
Signature
gc_collect(func: Callable) -> Callable
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
func | Callable | yes | - | The function to decorate. |
Return Type
Callable
Callable: The wrapped function with garbage collection.
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.io import gc_collect
result = gc_collect(func=<func>)
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
calculate_slice_indices function
Calculate slice indices and drop information for array slicing.
File location: sarpyx/utils/io.py:193
Signature
calculate_slice_indices(array_height: int, slice_height: int) -> List[dict]
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
array_height | int | yes | - | Total height of the array to slice |
slice_height | int | yes | - | Height of each slice portion |
Return Type
List[dict]
List[dict]: List of dictionaries containing slice information with keys: - slice_index: Index of the slice - original_start: Original starting row - original_end: Original ending row - actual_start: Actual starting row after drops - actual_end: Actual ending row after drops - is_first: Whether this is the first slice - is_last: Whether this is the last slice - drop_start: Number of rows dropped from start - drop_end: Number of rows dropped from end - original_height: Height of original slice - actual_height: Height after drops
Exceptions
ValueError
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.io import calculate_slice_indices
result = calculate_slice_indices(array_height=<array_height>, slice_height=<slice_height>)
Edge Cases
May raise: ValueError.
save_matlab_mat function
Saves a Python object to a MATLAB .mat file.
File location: sarpyx/utils/io.py:375
Signature
save_matlab_mat(data_object: Any, filename: str, filepath: Union[str, Path]) -> bool
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
data_object | Any | yes | - | The Python object to save in the MATLAB file. |
filename | str | yes | - | The name for the MATLAB file (without .mat extension). |
filepath | Union[str, Path] | yes | - | Path to the directory where the file will be saved. |
Return Type
bool
True if save was successful, False otherwise.
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- io
Example Usage
>>> save_matlab_mat(my_array, "data", "path/to/dir")
Saved MATLAB file to: path/to/dir/data.mat
True
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
delete function
Deletes a file or directory.
File location: sarpyx/utils/io.py:402
Signature
delete(path_to_delete: Union[str, Path])
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
path_to_delete | Union[str, Path] | yes | - | The path to the file or directory to delete. |
Return Type
inferred from implementation
inferred from implementation.
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.io import delete
result = delete(path_to_delete=<path_to_delete>)
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
unzip function
Unzips a file to its parent directory.
File location: sarpyx/utils/io.py:418
Signature
unzip(path_to_zip_file: Union[str, Path])
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
path_to_zip_file | Union[str, Path] | yes | - | The path to the zip file to extract. |
Return Type
inferred from implementation
inferred from implementation.
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.io import unzip
result = unzip(path_to_zip_file=<path_to_zip_file>)
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
delProd function
Deletes a SNAP product (.dim file and associated .data directory).
File location: sarpyx/utils/io.py:430
Signature
delProd(prodToDelete: Union[str, Path])
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
prodToDelete | Union[str, Path] | yes | - | The path to the .dim file of the product to delete. |
Return Type
inferred from implementation
inferred from implementation.
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.io import delProd
result = delProd(prodToDelete=<prodToDelete>)
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
command_line function
Executes a command line process and prints its output.
File location: sarpyx/utils/io.py:446
Signature
command_line(cmd: str)
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
cmd | str | yes | - | The command string to execute in the shell. |
Return Type
inferred from implementation
inferred from implementation.
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- io
- subprocess
Example Usage
from sarpyx.utils.io import command_line
result = command_line(cmd=<cmd>)
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
iterNodes function
Recursively iterates through XML nodes and extracts tag/text pairs.
File location: sarpyx/utils/io.py:465
Signature
iterNodes(root, val_dict: dict) -> dict
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
root | inferred from implementation | yes | - | The root element of the XML tree or subtree to iterate. |
val_dict | dict | yes | - | A dictionary to store the extracted tag/text pairs. |
Return Type
dict
The dictionary containing the extracted tag/text pairs.
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.io import iterNodes
result = iterNodes(root=<root>, val_dict=<val_dict>)
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
find_dat_file function
Find the .dat file in a SAFE folder for a specific polarization using recursive search.
File location: sarpyx/utils/io.py:490
Signature
find_dat_file(folder: Path, pol: str) -> Path
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
folder | Path | yes | - | Path to the SAFE folder to search in. |
pol | str | yes | - | Polarization string to match (e.g., 'vh', 'vv'). |
Return Type
Path
Path: Path to the matching .dat file.
Exceptions
FileNotFoundError
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.io import find_dat_file
result = find_dat_file(folder=<folder>, pol=<pol>)
Edge Cases
May raise: FileNotFoundError.
read_h5 function
Read an HDF5 file and return its contents and metadata as dictionaries.
File location: sarpyx/utils/io.py:516
Signature
read_h5(file_path: str) -> tuple[dict, dict]
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
file_path | str | yes | - | Path to the HDF5 file to read. |
Return Type
tuple[dict, dict]
Tuple containing: - Dictionary with datasets and their values from the HDF5 file - Dictionary with metadata (attributes) from the HDF5 file
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.io import read_h5
result = read_h5(file_path=<file_path>)
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
Public Classes (1)
ArraySlicer class
Class for slicing arrays into overlapping portions with specific drop rules. This class implements a sophisticated slicing strategy where: - First slice drops last 30% of rows - Subsequent slices start at 50% overlap and drop 30% from both ends - Final slice preserves the end portion - All slices are merged without gaps - Optional processing function can be applied to each slice before dropping Args: array (np.ndarray): Input array to be sliced slice_height (int): Height of each slice portion processing_func (Optional[callable]): Function to apply to each slice before dropping
File location: sarpyx/utils/io.py:36
Class Signature
class ArraySlicer
Constructor Parameters
Return Type
ArraySlicer instances.
Exceptions
Construction/runtime exceptions are inferred from implementation and method-level documentation.
Side Effects
See method-level side effects below.
Example Usage
from sarpyx.utils.io import ArraySlicer
obj = ArraySlicer(...) # inferred from implementation
Edge Cases
No class-level edge-case section is explicitly documented; rely on method-level checks and raised exceptions.
Public Methods (4)
ArraySlicer.slice_array method
Perform the complete slicing operation using calculate_slice_indices.
File location: sarpyx/utils/io.py:79
Signature
slice_array(self) -> List[np.ndarray]
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
- | - | no | - | No explicit public parameters; behavior inferred from implementation. |
Return Type
List[np.ndarray]
List[np.ndarray]: List of sliced array portions
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- io
Example Usage
from sarpyx.utils.io import ArraySlicer
# Constructor arguments are inferred from implementation.
obj = ArraySlicer(...) # inferred from implementation
result = obj.slice_array()
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
ArraySlicer.merge_slices method
Merge all slices back into a single array without gaps.
File location: sarpyx/utils/io.py:115
Signature
merge_slices(self) -> np.ndarray
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
- | - | no | - | No explicit public parameters; behavior inferred from implementation. |
Return Type
np.ndarray
np.ndarray: Merged array
Exceptions
ValueError
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.io import ArraySlicer
# Constructor arguments are inferred from implementation.
obj = ArraySlicer(...) # inferred from implementation
result = obj.merge_slices()
Edge Cases
May raise: ValueError.
ArraySlicer.get_slice_info method
Get detailed information about each slice.
File location: sarpyx/utils/io.py:126
Signature
get_slice_info(self) -> List[dict]
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
- | - | no | - | No explicit public parameters; behavior inferred from implementation. |
Return Type
List[dict]
List[dict]: Information about each slice
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.io import ArraySlicer
# Constructor arguments are inferred from implementation.
obj = ArraySlicer(...) # inferred from implementation
result = obj.get_slice_info()
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
ArraySlicer.visualize_slicing method
Visualize the slicing process.
File location: sarpyx/utils/io.py:134
Signature
visualize_slicing(self, figsize: Tuple[int, int]=(12, 8)) -> None
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
figsize | Tuple[int, int] | no | (12, 8) | Figure size for the plot |
Return Type
None
inferred from implementation.
Exceptions
ValueError
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.io import ArraySlicer
# Constructor arguments are inferred from implementation.
obj = ArraySlicer(...) # inferred from implementation
result = obj.visualize_slicing()
Edge Cases
May raise: ValueError. Includes optional parameters with implementation-defined fallback behavior.