Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerkuou authored Oct 21, 2024
1 parent 3eb5626 commit 934c4f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions examples/scripts/script_ps_selection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Example script for secting PS from SLCs.
"""Example script for selecting PS from SLCs.
This .py script is designed to be executed with a Dask SLURMCluster on a SLURM managed HPC system.
It should be executed through a SLURM script by `sbatch` command.
Expand Down Expand Up @@ -47,20 +47,20 @@ def get_free_port():
path_figure = Path("./figure") # Output path for figure
path_figure.mkdir(exist_ok=True) # Make figure directory if not exists

path_ps_zarr = Path("./ps.zarr")
path_ps_zarr = Path("./ps.zarr") # output file for selected PS


# ---- Config 2: Dask configuration ----

# Option 1: Intiate a new SLURMCluster
# Option 1: Initiate a new SLURMCluster
# Uncomment the following part to setup a new Dask SLURMCluster
# N_WORKERS = 4 # Manual input: number of workers to spin-up
# FREE_SOCKET = get_free_port() # Get a free port
# cluster = SLURMCluster(
# name="dask-worker", # Name of the Slurm job
# queue="normal", # Name of the node partition on your SLURM system
# cores=4, # Number of cores per worker
# memory="30 GB", # Total amount of memory per worker
# memory="32 GB", # Total amount of memory per worker
# processes=1, # Number of Python processes per worker
# walltime="3:00:00", # Reserve each worker for X hour
# scheduler_options={"dashboard_address": f":{FREE_SOCKET}"}, # Host Dashboard in a free socket
Expand Down
22 changes: 11 additions & 11 deletions pydepsi/classification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Functions for scatter selection related operations."""
"""Functions for scatterer selection related operations."""

from typing import Literal

Expand All @@ -13,7 +13,7 @@ def ps_selection(
output_chunks: int = 10000,
mem_persist: bool = False,
) -> xr.Dataset:
"""Select Persistent Scatterers (PS) from a SLC stack, and return a Space-Time Matrix.
"""Select Persistent Scatterers (PS) from an SLC 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.
Expand All @@ -32,7 +32,7 @@ def ps_selection(
method : Literal["nad", "nmad"], optional
Method of selection, by default "nad".
- "nad": Normalized Amplitude Dispersion
- "nmad": Normalized Median Amplitude Deviation
- "nmad": Normalized median absolute deviation
output_chunks : int, optional
Chunk size in the `space` dimension, by default 10000
mem_persist : bool, optional
Expand All @@ -42,14 +42,14 @@ def ps_selection(
Returns
-------
xr.Dataset
Selected PS, in form of an xarray.Dataset with two dimensions: (space, time).
Selected STM, in form of an xarray.Dataset with two dimensions: (space, time).
Raises
------
NotImplementedError
Raised when an unsupported method is provided.
"""
# Make sure there is not temporal chunk
# Make sure there is no temporal chunk
# since later a block function assumes all temporal data is available in a spatial block
slcs = slcs.chunk({"time": -1})

Expand Down Expand Up @@ -133,14 +133,14 @@ def _nad_block(amp: xr.DataArray) -> xr.DataArray:
----------
amp : xr.DataArray
Amplitude data, with dimensions ("azimuth", "range", "time").
This can be extracted from a SLC xr.Dataset.
This can be extracted from an SLC xr.Dataset.
Returns
-------
xr.DataArray
Normalized Amplitude Dispersion (NAD) data, with dimensions ("azimuth", "range").
"""
# Compoute amplitude dispersion
# Compute amplitude dispersion
# By defalut, the mean and std function from Xarray will skip NaN values
# However, if there is NaN value in time series, we want to discard the pixel
# Therefore, we set skipna=False
Expand All @@ -151,13 +151,13 @@ def _nad_block(amp: xr.DataArray) -> xr.DataArray:


def _nmad_block(amp: xr.DataArray) -> xr.DataArray:
"""Compute Normalized Median Absolute Dispersion (NMAD) for a block of amplitude data.
"""Compute Normalized Median Absolute Deviation(NMAD) for a block of amplitude data.
Parameters
----------
amp : xr.DataArray
Amplitude data, with dimensions ("azimuth", "range", "time").
This can be extracted from a SLC xr.Dataset.
This can be extracted from an SLC xr.Dataset.
Returns
-------
Expand All @@ -166,7 +166,7 @@ def _nmad_block(amp: xr.DataArray) -> xr.DataArray:
"""
# Compoute NMAD
median_amplitude = amp.median(dim="time", skipna=False)
mad = (np.abs(amp - median_amplitude)).median(dim="time") # Median Absolute Dispersion
nmad = mad / (median_amplitude + np.finfo(amp.dtype).eps) # Normalized Median Absolute Dispersion
mad = (np.abs(amp - median_amplitude)).median(dim="time") # Median Absolute Deviation
nmad = mad / (median_amplitude + np.finfo(amp.dtype).eps) # Normalized Median Absolute Deviation

return nmad

0 comments on commit 934c4f3

Please sign in to comment.