Skip to content

Toggle zero mask and apply to unw phase field#262

Merged
mirzaees merged 20 commits into
isce-framework:mainfrom
sssangha:sss_zeromsk
Mar 18, 2024
Merged

Toggle zero mask and apply to unw phase field#262
mirzaees merged 20 commits into
isce-framework:mainfrom
sssangha:sss_zeromsk

Conversation

@sssangha
Copy link
Copy Markdown
Contributor

When passing a mask for unwrapping, it seems to be ignored even though an INT mask was clearly generated (see screenshot below):
Screenshot 2024-03-12 at 3 10 16 PM

After digging a bit, I realized that this was because by default the zero_where_masked parameter is set to False, which according to this conditional downstream must be set to true in addition to providing a mask.

In this PR, I've exposed this zero_where_masked parameter so it can be toggled. It seems to work now as here is the resulting UNW phase field:
Screenshot 2024-03-12 at 10 39 41 AM

That said, clearly snaphu-related artifacts appear to persist in the masked region, so I made some additions to the code to apply the mask to the final unw phase field which now looks as I would expect:
Screenshot 2024-03-12 at 11 02 06 AM

@scottstanie
Copy link
Copy Markdown
Member

So I turned off the zero_where_masked option in this PR, as we're passing the mask to snaphu here:

Snaphu does ignore the values in the mask (it sets the amplitudes to 0 while it's running).

I can't tell if the mask is getting ignored from your first image actually- the unwrapping in the island looks okay.. what does the connected component label file look like? If it's 0 around the water, that's what we'd want.
I don't think we want to set the output phase from an unwrapped interferogram to 0 everywhere that a water mask says... there's too many people who would object to certain water masks, so our plan was to reset the phase back to the wrapped phase, and have the output mask (i.e. the 0 connected component label) say "dont trust the phase here".

If we set the water to 0, there is no chance of somebody later re-wrapping and doing a better job unwrapping if they disagree with the mask

@sssangha
Copy link
Copy Markdown
Contributor Author

So I turned off the zero_where_masked option in this PR, as we're passing the mask to snaphu here:

Snaphu does ignore the values in the mask (it sets the amplitudes to 0 while it's running).

I can't tell if the mask is getting ignored from your first image actually- the unwrapping in the island looks okay.. what does the connected component label file look like? If it's 0 around the water, that's what we'd want. I don't think we want to set the output phase from an unwrapped interferogram to 0 everywhere that a water mask says... there's too many people who would object to certain water masks, so our plan was to reset the phase back to the wrapped phase, and have the output mask (i.e. the 0 connected component label) say "dont trust the phase here".

If we set the water to 0, there is no chance of somebody later re-wrapping and doing a better job unwrapping if they disagree with the mask

Yeah the conncomp mask does seem to capture this.

But I should clarify that the original unw field 20221005_20221029.unw.tif isn't overwritten, but rather a separate new 20221005_20221029.unw.zeroed.tif file is generated so whoever wants to use that can, which mirrors the convention we see for the INT fields (i.e. 20221005_20221029.int.tif vs 20221005_20221029.int.zeroed.tif). So do you think that this is something we can support and appropriate as I've proposed?

@scottstanie
Copy link
Copy Markdown
Member

Oh sorry, i didn't see you also made it configurable now.

Yeah this does seem like a better way to do it rather than me decided for everyone haha.

Copy link
Copy Markdown
Member

@scottstanie scottstanie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending the stitching reverts

Comment thread src/dolphin/stitching.py Outdated
Comment thread src/dolphin/workflows/config/_common.py Outdated
@sssangha
Copy link
Copy Markdown
Contributor Author

Thanks @scottstanie !

Ok I made the requested edits, but I notice one of the checks is failing. I'm having a hard time to reconcile this:

src/dolphin/unwrap/_snaphu_py.py:149: error: Incompatible types in assignment (expression has type "Path", variable has type "str")  [assignment]
src/dolphin/unwrap/_tophu.py:187: error: Incompatible types in assignment (expression has type "Path", variable has type "str")  [assignment]
src/dolphin/unwrap/_isce3.py:150: error: Incompatible types in assignment (expression has type "Path", variable has type "str")  [assignment]

I thought I had called _zero_from_mask as intended, and it's working on my end. So I'm not sure what's the problem. Could you perhaps advise? Thanks

@scottstanie
Copy link
Copy Markdown
Member

Thanks @scottstanie !

Ok I made the requested edits, but I notice one of the checks is failing. I'm having a hard time to reconcile this:

src/dolphin/unwrap/_snaphu_py.py:149: error: Incompatible types in assignment (expression has type "Path", variable has type "str")  [assignment]
src/dolphin/unwrap/_tophu.py:187: error: Incompatible types in assignment (expression has type "Path", variable has type "str")  [assignment]
src/dolphin/unwrap/_isce3.py:150: error: Incompatible types in assignment (expression has type "Path", variable has type "str")  [assignment]

I thought I had called _zero_from_mask as intended, and it's working on my end. So I'm not sure what's the problem. Could you perhaps advise? Thanks

mypy usually doesn't like when you overwrite/redefine a variable with a different type.
One possible fix would be something like
(at the end of snaphu-py)

        if zero_where_masked and mask_file is not None:
            logger.info("Zeroing unw/conncomp of pixels masked in " f"{mask_file}")
            return _zero_from_mask(unw_filename, cc_filename, mask_file)

    return Path(unw_filename), Path(cc_filename)

since the return type would be the same (also note that you dont need to coerce the unw_filename to a string to input it into _zero_from_mask)

@sssangha
Copy link
Copy Markdown
Contributor Author

sssangha commented Mar 14, 2024

@scottstanie ok, I finally resolved the cli-related issues!

I also had to make some tweaks to _unwrap.py to return the masked unw phase fields if they were generated. Before, the masked fields were just generated, but then the unmasked unw phase fields were passed anyways.

Again though, I ensured this is only done if the two conditionals (zero_where_masked=True and a valid mask file is specified) are met.

@mirzaees mirzaees merged commit a3b0dd6 into isce-framework:main Mar 18, 2024
scottstanie pushed a commit to scottstanie/dolphin that referenced this pull request May 17, 2024
* Add option to toggle zeromsk for unw

* Add unwrapping mask

* snaphu ci string fix

* tophu ci str fix

* remove typo from common

* Pass zero unw files if applicable

* Fix snaphu cli error

---------

Co-authored-by: Simran S Sangha <ssangha@trappist.jpl.nasa.gov>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
scottstanie added a commit that referenced this pull request Jun 21, 2024
* start paper folder

* add skele

* fix names

* add fig placeholder, new ref

* fix makefile

* fix paper instructions

* add ref

* more refs

* refs

* draft to end

* add paper action

* missing space

* no need to run full test for this branch

* typo

* fix ref

* +

* Enforce consistency between jax and jaxlib (#252)

Consistency between jax and jaxlib can be enforced by installing the most recent versions via pip, which is currently not possible through conda where the two packages are out of sync.

This is necessary as dolphin would crash early on in processing if the two packages are not in sync.

* Disable corrections part of pytest, add one for timeseries (#254)

* dont exit before unwrapping for full test

* make test data have mostly signal, not pure noise

* fix the failing test due to len 1 stack losing dimension

* raise an error if the reference point selection fails

* fix 3d writing, pytest gets farther

* `max_bandwidth` can be 1: fix `gt` pydantic restriction

* try more

* disable corrections pytest

This is very annoying to get working with fake data.
The current error is:
RuntimeError: The -tr option was used, but there's no geotransform or it is
rotated.  This configuration is not supported.

The geometdata for statis layers is wrong

* fix jax warning

* [skip ci] fix changelog date

* Add option to toggle off inversion (#255)

* Add option to toggle off inversion

Add option to toggle inversion in the config function. By default set to true, like for unwrapping.

This allows for more flexibility when running especially large-scale processing.

* Make downstream updates to displacement.py

* Revert outdated disp changes

* Revert another vestigial change to displacement

* Add `similarity` module (#256)

* add similarity module and `median_similarity` funciton

* extract `process_blocks` to an io module

* add basic tests

* add max sim, add process blocks function

* fix argument ordering for `invert`

* fix block proc ordering and protocol definitions

* fix process check, zip self similarity check

* make strictly less

* remove `-tap` option from `gdal_merge.py` call (#257)

* Goldstein filtering step for unwrapping workflow (#247)

* Implement goldstein filtering step for unwrapping workflow

* Fix linter checks, reformat

* Default goldstein filtering to false

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

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

* Fix mypy/ruff issues, add type annotations

* Fix numpy typing annotation

* Add goldstein pytest

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#263)

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](astral-sh/ruff-pre-commit@v0.2.2...v0.3.2)
- [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](pre-commit/mirrors-mypy@v1.8.0...v1.9.0)

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

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

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Create dependabot.yml (#266)

* Bump the actions group with 7 updates (#267)

* Bump the actions group with 7 updates

Bumps the actions group with 7 updates:

| Package | From | To |
| --- | --- | --- |
| [actions/checkout](https://github.com/actions/checkout) | `3` | `4` |
| [actions/cache](https://github.com/actions/cache) | `3` | `4` |
| [actions/upload-artifact](https://github.com/actions/upload-artifact) | `3` | `4` |
| [actions/setup-python](https://github.com/actions/setup-python) | `4` | `5` |
| [docker/login-action](https://github.com/docker/login-action) | `2` | `3` |
| [docker/build-push-action](https://github.com/docker/build-push-action) | `4` | `5` |
| [akhilerm/tag-push-action](https://github.com/akhilerm/tag-push-action) | `2.1.0` | `2.2.0` |


Updates `actions/checkout` from 3 to 4
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v3...v4)

Updates `actions/cache` from 3 to 4
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](actions/cache@v3...v4)

Updates `actions/upload-artifact` from 3 to 4
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@v3...v4)

Updates `actions/setup-python` from 4 to 5
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](actions/setup-python@v4...v5)

Updates `docker/login-action` from 2 to 3
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](docker/login-action@v2...v3)

Updates `docker/build-push-action` from 4 to 5
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](docker/build-push-action@v4...v5)

Updates `akhilerm/tag-push-action` from 2.1.0 to 2.2.0
- [Release notes](https://github.com/akhilerm/tag-push-action/releases)
- [Commits](akhilerm/tag-push-action@v2.1.0...v2.2.0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/cache
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: docker/login-action
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: akhilerm/tag-push-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>

* add write package permission

see https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages

also https://stackoverflow.com/questions/76607955/error-denied-installation-not-allowed-to-create-organization-package

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Scott Staniewicz <scott.j.staniewicz@jpl.nasa.gov>

* Toggle zero mask and apply to unw phase field (#262)

* Add option to toggle zeromsk for unw

* Add unwrapping mask

* snaphu ci string fix

* tophu ci str fix

* remove typo from common

* Pass zero unw files if applicable

* Fix snaphu cli error

---------

Co-authored-by: Simran S Sangha <ssangha@trappist.jpl.nasa.gov>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#270)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.3.2 → v0.3.3](astral-sh/ruff-pre-commit@v0.3.2...v0.3.3)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Add interpolation option for unwrapping (#264)

* add interpolation option for unwrapping

* add reference, convert float weights once

* remove the extra all check

* Remove pymp reference

* remove todo

* Pass through the correlation threshold for interpolation

The last implementation had a default of 0.0
Since every weight was >=0, no pixels were interpolated.

* support to have both interpolation and filtering

* change the values of all zero sample interferogram

* add test for interpolation loop

* change docstring to match datatype

---------

Co-authored-by: mirzaees <smirzaee@aurora.jpl.nasa.gov>
Co-authored-by: Scott Staniewicz <scott.j.staniewicz@jpl.nasa.gov>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#271)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.3.3 → v0.3.4](astral-sh/ruff-pre-commit@v0.3.3...v0.3.4)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Grow conncomp (#272)

* add grow conncomp

* change typing

* select reference point with a general condition file

* Update src/dolphin/timeseries.py

* use a more generic form of Callable

* use with to open files

---------

Co-authored-by: mirzaees <smirzaee@aurora.jpl.nasa.gov>
Co-authored-by: Geoffrey Gunter <12984092+gmgunter@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#273)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.3.4 → v0.3.5](astral-sh/ruff-pre-commit@v0.3.4...v0.3.5)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#275)

updates:
- [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v4.6.0](pre-commit/pre-commit-hooks@v4.5.0...v4.6.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Compressed slc naming (#274)

* change compressed slc naming in unit tests
* change default for tilecostthreshold

---------

Co-authored-by: mirzaees <smirzaee@aurora.jpl.nasa.gov>
Co-authored-by: Scott Staniewicz <scott.j.staniewicz@jpl.nasa.gov>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Docs cleanup (#268)

* use `pymdownx.snippets` to cut repeated docs from readme. add `CONTRIBUTING.MD`

* remove the extra gpu env file since Jax needs separate installs

* Revert #252

* update contrib, setup, tutorial map

* add JAX GPU setup notes

* typos

* update the change log (#276)

* update the change log

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

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

---------

Co-authored-by: mirzaees <smirzaee@aurora.jpl.nasa.gov>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#278)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.3.5 → v0.3.7](astral-sh/ruff-pre-commit@v0.3.5...v0.3.7)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Cli timeseries (#279)

* add timeseries step to cli

* pre-commit fix

---------

Co-authored-by: mirzaees <smirzaee@aurora.jpl.nasa.gov>

* [pre-commit.ci] pre-commit autoupdate (#280)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.3.7 → v0.4.1](astral-sh/ruff-pre-commit@v0.3.7...v0.4.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* correct reference point typing (#281)

* correct reference point typing

* correct coherence threshold typing

* correct raising error

---------

Co-authored-by: mirzaees <smirzaee@aurora.jpl.nasa.gov>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#283)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.1 → v0.4.2](astral-sh/ruff-pre-commit@v0.4.1...v0.4.2)
- [github.com/pre-commit/mirrors-mypy: v1.9.0 → v1.10.0](pre-commit/mirrors-mypy@v1.9.0...v1.10.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* fix bug for get dates (#284)

* fix bug for get dates

* add comments to clarify

---------

Co-authored-by: mirzaees <smirzaee@aurora.jpl.nasa.gov>

* temporary fix for compressed SLC metadata (#287)

* temporary fix for compressed slc metadata

Co-authored-by: mirzaees <smirzaee@aurora.jpl.nasa.gov>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#286)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.2 → v0.4.3](astral-sh/ruff-pre-commit@v0.4.2...v0.4.3)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Enforce convention for conncomp files to be consistent with unw files (#288)

* Do not add COR suffix, in case CONCOMP file

* Update constants for conncomp

* fix names

* add fig placeholder, new ref

fix makefile

fix paper instructions

add ref

more refs

refs

draft to end

add paper action

missing space

no need to run full test for this branch

typo

fix ref

+

refs, typos

* reword example

* This is a combination of 2 commits.

reword example

frontmatter yaml

* edits for draft

* add image for figure plot

* add SNWG ack.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Simran S Sangha <sssangha@ucla.edu>
Co-authored-by: Ryan Burns <rtburns@jpl.nasa.gov>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Simran S Sangha <ssangha@trappist.jpl.nasa.gov>
Co-authored-by: Sara Mirzaee <37273875+mirzaees@users.noreply.github.com>
Co-authored-by: mirzaees <smirzaee@aurora.jpl.nasa.gov>
Co-authored-by: Geoffrey Gunter <12984092+gmgunter@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants