Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.1]

### Added
- Added check for valid pixels on the downloaded pairs, if it does not find any it removes the pair.

## [1.2.0]

### Added
Expand Down
4 changes: 2 additions & 2 deletions requirements-static.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ruff==0.15.2
mypy==1.19.1
ruff==0.15.11
mypy==1.20.1
opensarlab_lib
6 changes: 6 additions & 0 deletions src/hyp3_mintpy/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def download_job_pairs(
for z in file_list:
if check_product(z.name, start, end):
shutil.unpack_archive(str(z), folder)
wphase = list(Path(folder).glob('**/*_wrapped_phase.tif'))[0]
if not util.check_valid_pixels(wphase):
shutil.rmtree('/'.join(str(wphase).split('/')[0:-1]))
z.unlink()

rename_products(folder)
Expand Down Expand Up @@ -123,6 +126,9 @@ def download_bucket_pairs(
buck.download_file(s3_object.key, f'{folder}/{filename}')
z = Path(f'{folder}/{filename}')
shutil.unpack_archive(str(z), folder)
wphase = list(Path(folder).glob('**/*_wrapped_phase.tif'))[0]
if not util.check_valid_pixels(wphase):
shutil.rmtree('/'.join(str(wphase).split('/')[0:-1]))
z.unlink()
rename_products(folder)

Expand Down
20 changes: 20 additions & 0 deletions src/hyp3_mintpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,26 @@ def nullable_string(argument_string: str) -> str | None:
return argument_string if argument_string else None


def check_valid_pixels(image_path: Path) -> bool:
"""Check if the image has valid pixels.

Takes:
image: Local image path

Returns: True if there's at least one valid pixel, False otherwise
"""
has_valid = False
with rasterio.open(str(image_path)) as src:
data = src.read(1)
nodata = src.nodata
valid_mask = ~np.isnan(data) & ~np.isinf(data)
if nodata is not None:
valid = data != nodata
valid_mask &= valid
has_valid = bool(np.any(valid_mask))
return has_valid


def upload_file_to_s3_with_publish_access_keys(
path_to_file: Path, bucket: str, prefix: str = '', s3_name: str | None = None
) -> None:
Expand Down
Loading