Skip to content

Commit

Permalink
Add basic time series module for unwrapping network inversion (#191)
Browse files Browse the repository at this point in the history
* start timeseries module

* skip B for now, make vmapped versions

* start ts tests

* remove unused

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* move shapely to a test req

* start making test for ts

* make first pass at temporal avg/blockwise processor

* better test

* get basic `solve` test, add velo function

* more comments, add network invert func

* revert back tophu to not install from conda

* get test working for est velo

* revamp writers/protocols

* start setup for weighted least squares loading

* fix shapes, add weight to velo

* add spatial ref point to unw invert

* rename, more tests

* get file stack working

* [skip ci] update CHANGELOG for past releases

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
scottstanie and pre-commit-ci[bot] authored Mar 2, 2024
1 parent 5478a89 commit 39ea994
Show file tree
Hide file tree
Showing 13 changed files with 1,020 additions and 57 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
- name: Install test dependencies
run: |
micromamba install -f tests/requirements.txt -c conda-forge
pip install --no-deps git+https://github.com/isce-framework/tophu@main
- name: Enable numba boundscheck for better error catching
run: |
echo "NUMBA_BOUNDSCHECK=1" >> $GITHUB_ENV
Expand Down
34 changes: 32 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
# [Unreleased](https://github.com/isce-framework/dolphin/compare/v0.15.0...main)
# [Unreleased](https://github.com/isce-framework/dolphin/compare/v0.15.3...main)

**Added**
- Added `dolphin.timeseries` module with basic functionality:
- Invert a stack of unwrapped interferograms to a timeseries (using correlation weighting optionally)
- Estimate a (weighted) linear velocity from a timeseries
- Create `DatasetStackWriter` protocol, with `BackgroundStackWriter` implementation

**Changed**
- Rename `GdalWriter` to `BackgroundBlockWriter`

**Fixed**
- `BackgroundRasterWriter` was not creating the files necessary before writing

# [0.15.3](https://github.com/isce-framework/dolphin/compare/v0.15.2...0.15.3) - 2024-02-27

**Changed**
- Return the output paths created by the ionosphere/troposphere modules to make it easier to use afterward

# [0.15.2](https://github.com/isce-framework/dolphin/compare/v0.15.1...0.15.2) - 2024-02-27

**Fixed**

- Fixes to ionosphere/troposphere correction in for `DisplacementWorkflow` and `PsWorkflow`
- Correct the nodata value passed through to snaphu-py

# [0.15.1](https://github.com/isce-framework/dolphin/compare/v0.15.0...0.15.1) - 2024-02-26

**Fixed**

- PHASS now uses the Tophu wrapper to avoid isce3 inconsistencies between argument order

# [0.15.0](https://github.com/isce-framework/dolphin/compare/v0.14.1...0.15.0) - 2024-02-16

Expand All @@ -10,7 +40,7 @@

**Fixed**

- Intersection of nodata regions for SLC stack are now all set to `nan` during phase linking
- Intersection of nodata regions for SLC stack are now all set to `nan` during phase linking, avoiding 0 gaps between bursts

# [0.14.1](https://github.com/isce-framework/dolphin/compare/v0.14.0...0.14.1) - 2024-02-15

Expand Down
1 change: 0 additions & 1 deletion conda-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dependencies:
- rasterio>=1.3
- ruamel.yaml>=0.15
- scipy>=1.9 # "scipy 0.16+ is required for linear algebra", numba. 1.9 is the oldest version working with jax=0.4.19
- shapely>=1.8
- threadpoolctl>=3.0
- tqdm>=4.60
- typing_extensions>=3.10
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ pyproj>=3.3
rasterio>=1.3
ruamel_yaml>=0.15
scipy>=1.9
shapely>=1.8
threadpoolctl>=3.0
tqdm>=4.60
33 changes: 4 additions & 29 deletions src/dolphin/io/_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from dolphin.io._blocks import iter_blocks

from ._background import _DEFAULT_TIMEOUT, BackgroundReader
from ._utils import _ensure_slices, _unpack_3d_slices

logger = logging.getLogger(__name__)

Expand All @@ -44,10 +45,9 @@
"EagerLoader",
]

if TYPE_CHECKING:
from builtins import ellipsis

Index = ellipsis | slice | int
if TYPE_CHECKING:
from dolphin._types import Index


@runtime_checkable
Expand Down Expand Up @@ -276,18 +276,6 @@ def __getitem__(self, key: tuple[Index, ...], /) -> np.ndarray:
return _mask_array(data, self.nodata) if self.nodata is not None else data


def _ensure_slices(rows: Index, cols: Index) -> tuple[slice, slice]:
def _parse(key: Index):
if isinstance(key, int):
return slice(key, key + 1)
elif key is ...:
return slice(None)
else:
return key

return _parse(rows), _parse(cols)


@dataclass
class RasterReader(DatasetReader):
"""A single raster band of a GDAL-compatible dataset.
Expand Down Expand Up @@ -414,20 +402,7 @@ def __getitem__(self, key: tuple[Index, ...], /) -> np.ndarray:
def _read_3d(
key: tuple[Index, ...], readers: Sequence[DatasetReader], num_threads: int = 1
):
# Check that it's a tuple of slices
if not isinstance(key, tuple):
msg = "Index must be a tuple of slices."
raise TypeError(msg)
if len(key) not in (1, 3):
msg = "Index must be a tuple of 1 or 3 slices."
raise TypeError(msg)
# If only the band is passed (e.g. stack[0]), convert to (0, :, :)
if len(key) == 1:
key = (key[0], slice(None), slice(None))
# unpack the slices
bands, rows, cols = key
# convert the rows/cols to slices
r_slice, c_slice = _ensure_slices(rows, cols)
bands, r_slice, c_slice = _unpack_3d_slices(key)

if isinstance(bands, slice):
# convert the bands to -1-indexed list
Expand Down
36 changes: 36 additions & 0 deletions src/dolphin/io/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from dolphin._types import Index


def _ensure_slices(rows: Index, cols: Index) -> tuple[slice, slice]:
def _parse(key: Index):
if isinstance(key, int):
return slice(key, key + 1)
elif key is ...:
return slice(None)
else:
return key

return _parse(rows), _parse(cols)


def _unpack_3d_slices(key: tuple[Index, ...]) -> tuple[Index, slice, slice]:
# Check that it's a tuple of slices
if not isinstance(key, tuple):
msg = "Index must be a tuple of slices."
raise TypeError(msg)
if len(key) not in (1, 3):
msg = "Index must be a tuple of 1 or 3 slices."
raise TypeError(msg)
# If only the band is passed (e.g. stack[0]), convert to (0, :, :)
if len(key) == 1:
key = (key[0], slice(None), slice(None))
# unpack the slices
bands, rows, cols = key
# convert the rows/cols to slices
r_slice, c_slice = _ensure_slices(rows, cols)
return bands, r_slice, c_slice
Loading

0 comments on commit 39ea994

Please sign in to comment.