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

ParameterTypeRequiredDefaultDescription
funcCallableyes-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

ParameterTypeRequiredDefaultDescription
array_heightintyes-Total height of the array to slice
slice_heightintyes-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

ParameterTypeRequiredDefaultDescription
data_objectAnyyes-The Python object to save in the MATLAB file.
filenamestryes-The name for the MATLAB file (without .mat extension).
filepathUnion[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

ParameterTypeRequiredDefaultDescription
path_to_deleteUnion[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

ParameterTypeRequiredDefaultDescription
path_to_zip_fileUnion[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

ParameterTypeRequiredDefaultDescription
prodToDeleteUnion[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

ParameterTypeRequiredDefaultDescription
cmdstryes-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

ParameterTypeRequiredDefaultDescription
rootinferred from implementationyes-The root element of the XML tree or subtree to iterate.
val_dictdictyes-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

ParameterTypeRequiredDefaultDescription
folderPathyes-Path to the SAFE folder to search in.
polstryes-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

ParameterTypeRequiredDefaultDescription
file_pathstryes-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

ParameterTypeRequiredDefaultDescription
--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

ParameterTypeRequiredDefaultDescription
--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

ParameterTypeRequiredDefaultDescription
--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

ParameterTypeRequiredDefaultDescription
figsizeTuple[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.