Here is the API reference for the sarxarray package.
SLC stack module
sarxarray.stack.Stack
Methods:
-
mrm–Compute a Mean Reflection Map (MRM).
-
multi_look–Perform multi-looking on a Stack, and return a Stack.
-
point_selection–Select pixels from a Stack, and return a Space-Time Matrix.
mrm
multi_look
Perform multi-looking on a Stack, and return a Stack.
Parameters:
-
data(Dataset) –The data to be multi-looked.
-
window_size(tuple) –Window size for multi-looking, in the format of (azimuth, range)
-
method(str, default:'coarsen') –Method of multi-looking, by default "coarsen"
-
statistics(str, default:'mean') –Statistics method for multi-looking, by default "mean"
-
compute(bool, default:True) –Whether to compute the result, by default True. If False, the result will be
dask.delayed.Delayed. This is useful when the multi_look is used as an intermediate result.
Returns:
-
Dataset–An
xarray.Datasetwith coarsen shape ifcomputeis True, otherwise adask.delayed.Delayedobject.
Source code in sarxarray/stack.py
point_selection
Select pixels from a Stack, and return a Space-Time Matrix.
The selection method is defined by method and threshold.
The selected pixels will be reshaped to (space, time), where space is
the number of selected pixels. The unselected pixels will be discarded.
The original azimuth and range coordinates will be persisted.
Parameters:
-
threshold(float) –Threshold value for selection
-
method(str, default:'amplitude_dispersion') –Method of selection, by default "amplitude_dispersion"
-
chunks(int, default:1000) –Chunk size in the space dimension, by default 1000
Returns:
-
Dataset–An xarray.Dataset with two dimensions: (space, time).
Source code in sarxarray/stack.py
I/O module
sarxarray._io.from_dataset
Create a SLC stack or from an Xarray Dataset.
This function create tasks graph converting the two data variables of complex data:
real and imag, to three variables: complex, amplitude, and phase.
The function is intended for an SLC stack in xr.Dataset loaded from a Zarr file.
For other datasets, such as lat, lon, etc., please use xr.open_zarr directly.
Parameters:
-
ds(Dataset) –SLC stack loaded from a Zarr file. Must have three dimensions:
(azimuth, range, time). Must have two variables:realandimag.
Returns:
-
Dataset–Converted SLC stack. An xarray.Dataset with three dimensions:
(azimuth, range, time), and three variables:complex,amplitude,phase.
Raises:
-
ValueError–The input dataset should have three dimensions:
(azimuth, range, time). -
ValueError–The input dataset should have the following variables:
('real', 'imag').
Source code in sarxarray/_io.py
sarxarray._io.from_binary
from_binary(slc_files: list[str | Path], shape: tuple[int, int], vlabel: str = 'complex', dtype: dtype = complex64, chunks: tuple[int, int] | None = None, ratio: float = 1)
Read a SLC stack or related variables from binary files.
Parameters:
-
slc_files(Iterable) –Paths to the SLC files.
-
shape(Tuple) –Shape of each SLC file, in (n_azimuth, n_range)
-
vlabel(str, default:'complex') –Name of the variable to read, by default "complex".
-
dtype(dtype, default:complex64) –Data type of the file to read, by default np.float32
-
chunks(list, default:None) –2-D chunk size, by default None
-
ratio(float, default:1) –Ratio of resolutions (azimuth/range), by default 1
Returns:
-
Dataset–An xarray.Dataset with three dimensions: (azimuth, range, time).
Source code in sarxarray/_io.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
sarxarray._io.read_metadata
read_metadata(files: str | list | Path, driver: Literal['doris4', 'doris5', 'snap'] = 'doris5', ifg_file_name: str = 'ifgs.res') -> dict
Read metadata of a coregistered interferogram stack.
This function reads metadata from one or more metadata files from a coregistered interferogram stack, and returns the metadata as a dictionary format.
This function supports three drivers: "doris4" for DORIS4 metadata files, e.g. coregistration results from TerraSAR-X; "doris5" for DORIS5 metadata files, e.g. coregistration results from Sentinel-1; "snap" for SNAP metadata files. More support for other drivers will be added in the future.
For drivers "doris4" and "doris5", it parses the metadata with predefined regular expressions, returning a dictionary with predefined keys. Check conf.py for available keys and regular expressions.
Specifically for the "doris5" driver, it is assumed that there is a "ifgs.res" file next to the input metadata file, which contains the interferogram size information. If the "ifgs.res" file is not found, the interferogram size information will not be included in the metadata.
If a single file is provided, it reads the metadata from that file.
If multiple files are provided, the function will read the metadata from each file, and combine the results based on the following rules: - If a metadata key has values in string format or integer format, it combines the values into a set. - If a metadata key has values in float format, and the standard deviation is less than 1% of the mean, it takes the average of the values. - For the two Doris drivers "doris4" or "doris5", if the metadata key is TIME_STAMP_KEY, it treats it as the timestamp of acquisition and converts it to a numpy array of datetime64 format, sorted in ascending order.
Parameters:
-
files(str | list | Path) –Path(s) to the metadata files.
-
driver(str, default:'doris5') –The driver to use for reading metadata. Supported drivers are "doris4" and "doris5" and "snap". Default is "doris5".
-
ifg_file_name(str, default:'ifgs.res') –The name of the interferogram size file for the "doris5" driver. We assume this file is next to each metadata file and use it to read the interferogram size information. if it is not found, the size information will not be included in the metadata. Default is "ifgs.res".
Returns:
-
dict–Dictionary containing the metadata read from the files.
Raises:
-
NotImplementedError–If the driver is not "doris4" or "doris5".
Source code in sarxarray/_io.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
sarxarray._io.to_binary
to_binary(output_path: str, data: Dataset | DataArray, data_var_name: str | None = None, allow_overwrite: bool = False)
Write a zarr data layer to a binary file.
The dtype and shape of the resulting binary file will be the same as the input data.
Parameters:
-
output_path(str) –Path to where the binary data file should be stored
-
data(Dataset | DataArray) –Dataset or DataArray containing the data variable that should be written to the binary data file. If
datais anxr.Dataset, the argumentdata_var_nameis required to indicate which data variable should be written. -
data_var_name(str | None, default:None) –Name of the data variable that should be written to the binary file. Only used if
datais anxr.Dataset, otherwise ignored. Default isNone -
allow_overwrite(bool, default:False) –Whether or not to allow overwriting the file specified by
output_pathwhen that file already exists. Ifoutput_pathexists andallow_overwrite=False, an OSError is raised. Ifoutput_pathexists andallow_overwrite=True, the file inoutput_pathis overwritten. Ifoutput_pathdoes not exist, this input argument is ignored. Default isFalse
Raises:
-
ValueError–- When
datais anxr.Datasetbutdata_var_nameisNone - When
datais not anxr.Datasetorxr.DataArray
- When
-
KeyError–When
datais anxr.Datasetanddata_var_nameis not a data variable indata -
OSError–When
output_pathexists andallow_overwriteis set toFalse
Source code in sarxarray/_io.py
Utility
sarxarray.utils.multi_look
Perform multi-looking on a Stack, and return a Stack.
Parameters:
-
data(Dataset or DataArray) –The data to be multi-looked.
-
window_size(tuple) –Window size for multi-looking, in the format of (azimuth, range)
-
method(str, default:'coarsen') –Method of multi-looking, by default "coarsen"
-
statistics(str, default:'mean') –Statistics method for multi-looking, by default "mean"
-
compute(bool, default:True) –Whether to compute the result, by default True. If False, the result will be
dask.delayed.Delayed. This is useful when the multi_look is used as an intermediate result.
Returns:
-
Dataset or DataArray–An
xarray.Datasetorxarray.DataArraywith coarsen shape ifcomputeis True, otherwise adask.delayed.Delayedobject.
Source code in sarxarray/utils.py
sarxarray.utils.complex_coherence
Calculate complex coherence of two images.
Assume two images reference (R) and other (O), the complex coherence is
defined as:
numerator = mean(R * O) in a window
denominator = mean(R * R) * mean(O * O`) in a window
coherence = abs( numerator / sqrt(denominator) ),
See the equation in chapter 28 in doris
documentation
Parameters:
-
reference(DataArray) –The reference image to calculate complex coherence with.
-
other(DataArray) –The other image to calculate complex coherence with.
-
window_size(tuple) –Window size for multi-looking, in the format of (azimuth, range)
-
compute(bool, default:True) –Whether to compute the result, by default True. If False, the result will be
dask.delayed.Delayed. This is useful when the complex_coherence is used as an intermediate result.
Returns:
-
DataArray–An
xarray.DataArrayifcomputeis True, otherwise adask.delayed.Delayedobject.
Source code in sarxarray/utils.py
sarxarray.utils.crop
Crop a radar image or stack of radar images to the bounding box of a polygon.
Parameters:
-
data(Dataset | DataArray) –The dataset or data array to be cropped in azimuth and range
-
geom(Polygon | tuple) –shapely.geometry.Polygon in radar coordinates of the area that should be kept, in [azimuth, range] format, OR a tuple of the bounding box of the crop in (min_azimuth, min_range, max_azimuth, max_range) format
Returns:
-
Dataset | DataArray–The dataset or data array cropped to the area of interest
Raises:
-
ValueError–- If the azimuth or range coordinate does not exist in
data - If
geomis notshapely.geometry.Polygonortuple
- If the azimuth or range coordinate does not exist in
-
AssertionError–- When a tuple is passed to
geomthat falls in one of three categories: - The tuple does not have exactly 4 entries
- The minimum azimuth coordinate is larger than or equal to the maximum azimuth coordinate
- The minimum range coordinate is larger than or equal to the maximum range coordinate
- When a tuple is passed to