Skip to content

Commit

Permalink
Merge pull request #584 from ASFHyP3/new-orbits
Browse files Browse the repository at this point in the history
Switch from hyp3lib to s1-orbits for Orbit Fetching
  • Loading branch information
jtherrmann authored Aug 8, 2024
2 parents d7afc31 + 51391bc commit 9b95101
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 37 deletions.
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).

## [9.0.0]
### Changed
- Orbit files are now retrieved using the [s1-orbits](https://github.com/ASFHyP3/sentinel1-orbits-py) library.
### Removed
- Removed support for the `--esa-username` and `--esa-password` command-line options and the `ESA_USERNAME` and `ESA_PASSWORD` environment variables.

## [8.2.0]
### Changed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rtc_sentinel.py S1A_IW_SLC__1SSV_20150621T120220_20150621T120232_006471_008934_7
To run the RTC process through the HyP3 interface:
```
hyp3_gamma ++process rtc --help
hyp3_gamma ++process rtc --username ${EDL_USERNAME} --password ${EDL_PASSWORD} --esa-username ${ESA_USERNAME} --esa-password ${ESA_PASSWORD} \
hyp3_gamma ++process rtc --username ${EDL_USERNAME} --password ${EDL_PASSWORD} \
S1A_IW_SLC__1SSV_20150621T120220_20150621T120232_006471_008934_72D8
```

Expand All @@ -59,7 +59,7 @@ ifm_sentinel.py \
To run the InSAR process through the HyP3 interface:
```
hyp3_gamma ++process insar --help
hyp3_gamma ++process insar --username ${EDL_USERNAME} --password ${EDL_PASSWORD} --esa-username ${ESA_USERNAME} --esa-password ${ESA_PASSWORD} \
hyp3_gamma ++process insar --username ${EDL_USERNAME} --password ${EDL_PASSWORD} \
S1A_IW_SLC__1SDV_20200203T172103_20200203T172122_031091_03929B_3048 \
S1A_IW_SLC__1SDV_20200110T172104_20200110T172123_030741_03864E_A996
```
Expand Down
25 changes: 0 additions & 25 deletions hyp3_gamma/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from importlib.metadata import entry_points
from pathlib import Path
from shutil import make_archive
from typing import Optional

from hyp3lib.aws import upload_file_to_s3
from hyp3lib.fetch import write_credentials_to_netrc_file
Expand Down Expand Up @@ -60,30 +59,10 @@ def check_earthdata_credentials(username, password):
return username, password


def check_esa_credentials(username: Optional[str], password: Optional[str]) -> None:
if username is not None:
os.environ['ESA_USERNAME'] = username
elif 'ESA_USERNAME' not in os.environ:
raise ValueError(
'Please provide Copernicus Data Space Ecosystem (CDSE) username via the --esa-username option '
'or the ESA_USERNAME environment variable.'
)

if password is not None:
os.environ['ESA_PASSWORD'] = password
elif 'ESA_PASSWORD' not in os.environ:
raise ValueError(
'Please provide Copernicus Data Space Ecosystem (CDSE) password via the --esa-password option '
'or the ESA_PASSWORD environment variable.'
)


def rtc():
parser = ArgumentParser()
parser.add_argument('--username')
parser.add_argument('--password')
parser.add_argument('--esa-username')
parser.add_argument('--esa-password')
parser.add_argument('--bucket')
parser.add_argument('--bucket-prefix', default='')
parser.add_argument('--resolution', type=float, choices=[10.0, 20.0, 30.0], default=30.0)
Expand All @@ -100,7 +79,6 @@ def rtc():
args = parser.parse_args()

username, password = check_earthdata_credentials(args.username, args.password)
check_esa_credentials(args.esa_username, args.esa_password)

logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO)
Expand Down Expand Up @@ -146,8 +124,6 @@ def insar():
parser = ArgumentParser()
parser.add_argument('--username')
parser.add_argument('--password')
parser.add_argument('--esa-username')
parser.add_argument('--esa-password')
parser.add_argument('--bucket')
parser.add_argument('--bucket-prefix', default='')
parser.add_argument('--include-dem', type=string_is_true, default=False)
Expand All @@ -163,7 +139,6 @@ def insar():
args = parser.parse_args()

username, password = check_earthdata_credentials(args.username, args.password)
check_esa_credentials(args.esa_username, args.esa_password)

# TODO: Remove `--include-los-displacement` and this logic once it's no longer supported by the HyP3 API
args.include_displacement_maps = args.include_displacement_maps | args.include_los_displacement
Expand Down
7 changes: 3 additions & 4 deletions hyp3_gamma/insar/ifm_sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
from hyp3lib.SLC_copy_S1_fullSW import SLC_copy_S1_fullSW
from hyp3lib.execute import execute
from hyp3lib.getParameter import getParameter
from hyp3lib.get_orb import downloadSentinelOrbitFile
from hyp3lib.makeAsfBrowse import makeAsfBrowse
from hyp3lib.par_s1_slc_single import par_s1_slc_single
from hyp3lib.system import gamma_version
from lxml import etree, objectify
from s1_orbits import fetch_for_scene

import hyp3_gamma
from hyp3_gamma.insar.getDemFileGamma import get_dem_file_gamma
Expand Down Expand Up @@ -342,7 +342,6 @@ def insar_sentinel_gamma(reference_file, secondary_file, rlooks=20, alooks=4, in
include_dem=False, apply_water_mask=False, phase_filter_parameter=0.6):
log.info("\n\nSentinel-1 differential interferogram creation program\n")

esa_credentials = (os.environ['ESA_USERNAME'], os.environ['ESA_PASSWORD'])
wrk = os.getcwd()
reference_date = reference_file[17:32]
reference = reference_file[17:25]
Expand All @@ -363,8 +362,8 @@ def insar_sentinel_gamma(reference_file, secondary_file, rlooks=20, alooks=4, in
orbit_files = []
for granule in (reference_file, secondary_file):
log.info(f'Downloading orbit file for {granule}')
orbit_file, provider = downloadSentinelOrbitFile(granule, esa_credentials=esa_credentials)
log.info(f'Got orbit file {orbit_file} from provider {provider}')
orbit_file = str(fetch_for_scene(granule))
log.info(f'Got orbit file {orbit_file} from s1_orbits')
par_s1_slc_single(granule, pol, os.path.abspath(orbit_file))
orbit_files.append(orbit_file)

Expand Down
11 changes: 5 additions & 6 deletions hyp3_gamma/rtc/rtc_sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
from typing import List

import numpy as np
from hyp3lib import DemError, ExecuteError, GranuleError, OrbitDownloadError
from hyp3lib import DemError, ExecuteError, GranuleError
from hyp3lib import saa_func_lib as saa
from hyp3lib.byteSigmaScale import byteSigmaScale
from hyp3lib.createAmp import createAmp
from hyp3lib.execute import execute
from hyp3lib.getParameter import getParameter
from hyp3lib.get_orb import downloadSentinelOrbitFile
from hyp3lib.makeAsfBrowse import makeAsfBrowse
from hyp3lib.make_cogs import cogify_dir
from hyp3lib.raster_boundary2shape import raster_boundary2shape
from hyp3lib.rtc2color import rtc2color
from hyp3lib.system import gamma_version
from osgeo import gdal, gdalconst, ogr
from s1_orbits import OrbitNotFoundError, fetch_for_scene

import hyp3_gamma
from hyp3_gamma.dem import get_geometry_from_kml, prepare_dem_geotiff
Expand Down Expand Up @@ -308,17 +308,16 @@ def rtc_sentinel_gamma(safe_dir: str, resolution: float = 30.0, radiometry: str
product_name: Name of the output product directory
"""

esa_credentials = (os.environ['ESA_USERNAME'], os.environ['ESA_PASSWORD'])
safe_dir = safe_dir.rstrip('/')
granule = os.path.splitext(os.path.basename(safe_dir))[0]
granule_type = get_granule_type(granule)
polarizations = get_polarizations(granule, skip_cross_pol)

try:
log.info(f'Downloading orbit file for {granule}')
orbit_file, provider = downloadSentinelOrbitFile(granule, esa_credentials=esa_credentials)
log.info(f'Got orbit file {orbit_file} from provider {provider}')
except OrbitDownloadError as e:
orbit_file = str(fetch_for_scene(granule))
log.info(f'Got orbit file {orbit_file} from s1-orbits.')
except OrbitNotFoundError as e:
log.warning(e)
log.warning(f'Proceeding using original predicted orbit data included with {granule}')
orbit_file = None
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ pillow==10.4.0
pyproj==3.6.1
python-dateutil==2.9.0.post0
rtree==1.3.0
s1_orbits==0.1.1

0 comments on commit 9b95101

Please sign in to comment.