Skip to content

Commit

Permalink
Merge pull request #592 from ASFHyP3/develop
Browse files Browse the repository at this point in the history
Release v9.0.1
  • Loading branch information
AndrewPlayer3 authored Dec 17, 2024
2 parents 3ff18b5 + 3067b97 commit 029e960
Show file tree
Hide file tree
Showing 37 changed files with 1,484 additions and 756 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ on:

jobs:
call-changelog-check-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-changelog-check.yml@v0.11.2
uses: ASFHyP3/actions/.github/workflows/reusable-changelog-check.yml@v0.12.0
2 changes: 1 addition & 1 deletion .github/workflows/create-jira-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
call-create-jira-issue-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-create-jira-issue.yml@v0.11.2
uses: ASFHyP3/actions/.github/workflows/reusable-create-jira-issue.yml@v0.12.0
secrets:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/labeled-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ on:

jobs:
call-labeled-pr-check-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-labeled-pr-check.yml@v0.11.2
uses: ASFHyP3/actions/.github/workflows/reusable-labeled-pr-check.yml@v0.12.0
2 changes: 1 addition & 1 deletion .github/workflows/release-template-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ on:

jobs:
call-release-checklist-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-release-checklist-comment.yml@v0.11.2
uses: ASFHyP3/actions/.github/workflows/reusable-release-checklist-comment.yml@v0.12.0
secrets:
USER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
call-release-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-release.yml@v0.11.2
uses: ASFHyP3/actions/.github/workflows/reusable-release.yml@v0.12.0
with:
release_prefix: HyP3 GAMMA
secrets:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Static analysis
on: push

jobs:
call-flake8-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-flake8.yml@v0.11.2
with:
local_package_names: hyp3_gamma

call-secrets-analysis-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-secrets-analysis.yml@v0.11.2
# Docs: https://github.com/ASFHyP3/actions
uses: ASFHyP3/actions/.github/workflows/reusable-secrets-analysis.yml@v0.12.0

call-ruff-workflow:
# Docs: https://github.com/ASFHyP3/actions
uses: ASFHyP3/actions/.github/workflows/reusable-ruff.yml@v0.12.0
2 changes: 1 addition & 1 deletion .github/workflows/tag-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ on:

jobs:
call-bump-version-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-bump-version.yml@v0.11.2
uses: ASFHyP3/actions/.github/workflows/reusable-bump-version.yml@v0.12.0
secrets:
USER_TOKEN: ${{ secrets.TOOLS_BOT_PAK }}
4 changes: 2 additions & 2 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ env:

jobs:
call-pytest-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-pytest.yml@v0.11.2
uses: ASFHyP3/actions/.github/workflows/reusable-pytest.yml@v0.12.0
with:
local_package_name: hyp3_gamma
python_versions: >-
["3.10"]
call-version-info-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-version-info.yml@v0.11.2
uses: ASFHyP3/actions/.github/workflows/reusable-version-info.yml@v0.12.0
with:
python_version: '3.10'

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ 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).

## [9.0.1]
### Changed
- The [`static-analysis`](.github/workflows/static-analysis.yml) Github Actions workflow now uses `ruff` rather than `flake8` for linting.

## [9.0.0]
### Changed
- Orbit files are now retrieved using the [s1-orbits](https://github.com/ASFHyP3/sentinel1-orbits-py) library.
Expand Down
12 changes: 7 additions & 5 deletions hyp3_gamma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
try:
__version__ = version(__name__)
except PackageNotFoundError:
print(f'{__name__} package is not installed!\n'
f'Install in editable/develop mode via (from the top of this repo):\n'
f' python -m pip install -e .[develop]\n'
f'Or, to just get the version number use:\n'
f' python setup.py --version')
print(
f'{__name__} package is not installed!\n'
f'Install in editable/develop mode via (from the top of this repo):\n'
f' python -m pip install -e .[develop]\n'
f'Or, to just get the version number use:\n'
f' python setup.py --version'
)

__all__ = ['__version__']
37 changes: 23 additions & 14 deletions hyp3_gamma/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
rtc_gamma and insar_gamma processing for HyP3
"""
"""rtc_gamma and insar_gamma processing for HyP3"""

import concurrent.futures
import logging
import os
Expand All @@ -23,20 +22,24 @@
def main():
parser = ArgumentParser(prefix_chars='+', formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument(
'++process', choices=['rtc', 'insar'], default='rtc',
help='Select the HyP3 entrypoint version to use'
'++process',
choices=['rtc', 'insar'],
default='rtc',
help='Select the HyP3 entrypoint version to use',
)
parser.add_argument(
'++omp-num-threads',
type=int,
help='The number of OpenMP threads to use for parallel regions',
)
parser.add_argument('++omp-num-threads', type=int, help='The number of OpenMP threads to use for parallel regions')
args, unknowns = parser.parse_known_args()
(process_entry_point,) = entry_points(group='console_scripts', name=args.process)

if args.omp_num_threads:
os.environ['OMP_NUM_THREADS'] = str(args.omp_num_threads)

sys.argv = [args.process, *unknowns]
sys.exit(
process_entry_point.load()()
)
sys.exit(process_entry_point.load()())


def check_earthdata_credentials(username, password):
Expand Down Expand Up @@ -80,8 +83,11 @@ def rtc():

username, password = check_earthdata_credentials(args.username, args.password)

logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO)
logging.basicConfig(
format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p',
level=logging.INFO,
)

write_credentials_to_netrc_file(username, password)

Expand Down Expand Up @@ -147,8 +153,11 @@ def insar():
if len(args.granules) != 2:
parser.error('Must provide exactly two granules')

logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO)
logging.basicConfig(
format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p',
level=logging.INFO,
)

write_credentials_to_netrc_file(username, password)

Expand All @@ -169,7 +178,7 @@ def insar():
include_wrapped_phase=args.include_wrapped_phase,
include_inc_map=args.include_inc_map,
apply_water_mask=args.apply_water_mask,
phase_filter_parameter=args.phase_filter_parameter
phase_filter_parameter=args.phase_filter_parameter,
)

output_zip = make_archive(base_name=product_name, format='zip', base_dir=product_name)
Expand Down
35 changes: 27 additions & 8 deletions hyp3_gamma/dem.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
import json
from collections.abc import Generator
from pathlib import Path
from subprocess import PIPE, run
from tempfile import TemporaryDirectory
from typing import Generator, List

from hyp3lib import DemError
from osgeo import gdal, ogr

from hyp3_gamma.util import GDALConfigManager


DEM_GEOJSON = '/vsicurl/https://asf-dem-west.s3.amazonaws.com/v2/cop30-2021-with-cop90-us-west-2-mirror.geojson'

gdal.UseExceptions()
ogr.UseExceptions()


def get_geometry_from_kml(kml_file: str) -> ogr.Geometry:
cmd = ['ogr2ogr', '-wrapdateline', '-datelineoffset', '20', '-f', 'GeoJSON', '-mapfieldtype', 'DateTime=String',
'/vsistdout', kml_file]
cmd = [
'ogr2ogr',
'-wrapdateline',
'-datelineoffset',
'20',
'-f',
'GeoJSON',
'-mapfieldtype',
'DateTime=String',
'/vsistdout',
kml_file,
]
geojson_str = run(cmd, stdout=PIPE, check=True).stdout
geometry = json.loads(geojson_str)['features'][0]['geometry']
return ogr.CreateGeometryFromJson(json.dumps(geometry))
Expand All @@ -37,7 +48,7 @@ def intersects_dem(geometry: ogr.Geometry) -> bool:
return True


def get_dem_file_paths(geometry: ogr.Geometry) -> List[str]:
def get_dem_file_paths(geometry: ogr.Geometry) -> list[str]:
file_paths = []
for feature in get_dem_features():
if feature.GetGeometryRef().Intersects(geometry):
Expand All @@ -61,7 +72,7 @@ def get_centroid_crossing_antimeridian(geometry: ogr.Geometry) -> ogr.Geometry:
return shifted_geometry.Centroid()


def shift_for_antimeridian(dem_file_paths: List[str], directory: Path) -> List[str]:
def shift_for_antimeridian(dem_file_paths: list[str], directory: Path) -> list[str]:
shifted_file_paths = []
for file_path in dem_file_paths:
if '_W' in file_path:
Expand All @@ -71,7 +82,7 @@ def shift_for_antimeridian(dem_file_paths: List[str], directory: Path) -> List[s
corners['upperLeft'][0] + 360,
corners['upperLeft'][1],
corners['lowerRight'][0] + 360,
corners['lowerRight'][1]
corners['lowerRight'][1],
]
gdal.Translate(shifted_file_path, file_path, format='VRT', outputBounds=output_bounds)
shifted_file_paths.append(shifted_file_path)
Expand Down Expand Up @@ -110,5 +121,13 @@ def prepare_dem_geotiff(output_name: str, geometry: ogr.Geometry, pixel_size: fl
gdal.BuildVRT(str(dem_vrt), dem_file_paths)

epsg_code = utm_from_lon_lat(centroid.GetX(), centroid.GetY())
gdal.Warp(output_name, str(dem_vrt), dstSRS=f'EPSG:{epsg_code}', xRes=pixel_size, yRes=pixel_size,
targetAlignedPixels=True, resampleAlg='cubic', multithread=True)
gdal.Warp(
output_name,
str(dem_vrt),
dstSRS=f'EPSG:{epsg_code}',
xRes=pixel_size,
yRes=pixel_size,
targetAlignedPixels=True,
resampleAlg='cubic',
multithread=True,
)
7 changes: 5 additions & 2 deletions hyp3_gamma/insar/getDemFileGamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ def get_dem_file_gamma(dem_image: str, dem_par: str, safe_dir: str, pixel_size:
geometry = get_geometry_from_kml(f'{safe_dir}/preview/map-overlay.kml')
with NamedTemporaryFile() as dem_tif:
prepare_dem_geotiff(dem_tif.name, geometry, pixel_size)
execute(f'dem_import {dem_tif.name} {dem_image} {dem_par} - - $DIFF_HOME/scripts/egm2008-5.dem '
f'$DIFF_HOME/scripts/egm2008-5.dem_par - - - 1', uselogging=True)
execute(
f'dem_import {dem_tif.name} {dem_image} {dem_par} - - $DIFF_HOME/scripts/egm2008-5.dem '
f'$DIFF_HOME/scripts/egm2008-5.dem_par - - - 1',
uselogging=True,
)
Loading

0 comments on commit 029e960

Please sign in to comment.