Skip to content

Commit

Permalink
Merge pull request #289 from ASFHyP3/new-orbits
Browse files Browse the repository at this point in the history
Switch to s1_orbits for Orbit Download
  • Loading branch information
AndrewPlayer3 authored Aug 9, 2024
2 parents f819a1e + 9d7c9e8 commit 4637e1b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 99 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ 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).

## [0.19.0]
### Changed
* Orbits are now downloaded using `s1_orbits` rather than `hyp3lib`.

### Removed
* Removed support for the `--esa-username` and `--esa-password` command-line options and the `ESA_USERNAME` and `ESA_PASSWORD` environment variables.

## [0.18.1]
### Changed
* The conversion matrices netCDF file created bt the S1 correction workflow is now called `conversion_matricies.nc` and no longer includes the scene name per feedback from JPL.
Expand Down
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,19 @@ export AWS_SESSION_TOKEN=your-token # optional; for when using temporary creden

For more information, please see: <https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html>

#### NASA Earthdata Login and ESA Copernicus Data Space Ecosystem (CDSE)
#### NASA Earthdata Login

To process Sentinel-1 images, you must provide Earthdata Login credentials and ESA Copernicus Data Space Ecosystem (CDSE) credentials in order to download input data.
To process Sentinel-1 images, you must provide Earthdata Login credentials in order to download input data.
* If you do not already have an Earthdata account, you can sign up [here](https://urs.earthdata.nasa.gov/home).
* If you do not already have a CDSE account, you can sign up [here](https://dataspace.copernicus.eu).

For Earthdata login and CDSE, you can provide credentials by exporting environment variables:
For Earthdata login, you can provide credentials by exporting environment variables:
```
export EARTHDATA_USERNAME=your-edl-username
export EARTHDATA_PASSWORD=your-edl-password
export ESA_USERNAME=your-esa-username
export ESA_PASSWORD=your-esa-password
```
or via your [`~/.netrc` file](https://everything.curl.dev/usingcurl/netrc) which should contain lines like these two:
```
machine urs.earthdata.nasa.gov login your-edl-username password your-edl-password
machine dataspace.copernicus.eu login your-esa-username password your-esa-password
```

> [!TIP]
Expand All @@ -119,8 +115,6 @@ docker run -it --rm \
-e AWS_SECRET_ACCESS_KEY=[YOUR_SECRET] \
-e EARTHDATA_USERNAME=[YOUR_USERNAME_HERE] \
-e EARTHDATA_PASSWORD=[YOUR_PASSWORD_HERE] \
-e ESA_USERNAME=[YOUR_USERNAME_HERE] \
-e ESA_PASSWORD=[YOUR_PASSWORD_HERE] \
ghcr.io/asfhyp3/hyp3-autorift:latest \
++process hyp3_autorift \
[WORKFLOW_ARGS]
Expand Down Expand Up @@ -148,8 +142,6 @@ To retain hyp3_autorift output files running via Docker there are two recommende
-e AWS_SESSION_TOKEN=[YOUR_TOKEN] \ # Optional
-e EARTHDATA_USERNAME=[YOUR_USERNAME_HERE] \
-e EARTHDATA_PASSWORD=[YOUR_PASSWORD_HERE] \
-e ESA_USERNAME=[YOUR_USERNAME_HERE] \
-e ESA_PASSWORD=[YOUR_PASSWORD_HERE] \
ghcr.io/asfhyp3/hyp3-autorift:latest \
++process hyp3_autorift \
[WORKFLOW_ARGS] \
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ dependencies:
- requests
- scipy
- xarray
- s1_orbits
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies = [
'scipy',
'xarray',
'hyp3lib>=3,<4',
's1_orbits',
]
dynamic = ["version"]

Expand Down
25 changes: 7 additions & 18 deletions src/hyp3_autorift/s1_isce2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
import numpy as np
from autoRIFT import __version__ as version
from hyp3lib.fetch import download_file
from hyp3lib.get_orb import downloadSentinelOrbitFile
from hyp3lib.scene import get_download_url
from netCDF4 import Dataset
from osgeo import gdal, osr
from s1_orbits import fetch_for_scene

from hyp3_autorift import geometry, utils
from hyp3_autorift.process import DEFAULT_PARAMETER_FILE
from hyp3_autorift.utils import get_esa_credentials

log = logging.getLogger(__name__)

Expand All @@ -44,17 +43,11 @@ def process_sentinel1_with_isce2(reference, secondary, parameter_file):
orbits = Path('Orbits').resolve()
orbits.mkdir(parents=True, exist_ok=True)

esa_username, esa_password = utils.get_esa_credentials()
reference_state_vec = fetch_for_scene(reference, dir=orbits)
log.info(f'Downloaded orbit file {reference_state_vec} from s1-orbits')

reference_state_vec, reference_provider = downloadSentinelOrbitFile(
reference, directory=str(orbits), esa_credentials=(esa_username, esa_password)
)
log.info(f'Downloaded orbit file {reference_state_vec} from {reference_provider}')

secondary_state_vec, secondary_provider = downloadSentinelOrbitFile(
secondary, directory=str(orbits), esa_credentials=(esa_username, esa_password)
)
log.info(f'Downloaded orbit file {secondary_state_vec} from {secondary_provider}')
secondary_state_vec = fetch_for_scene(secondary, dir=orbits)
log.info(f'Downloaded orbit file {secondary_state_vec} from s1-orbits')

polarization = get_s1_primary_polarization(reference)
lat_limits, lon_limits = bounding_box(f'{reference}.zip', polarization=polarization, orbits=str(orbits))
Expand Down Expand Up @@ -297,12 +290,8 @@ def generate_correction_data(
orbits = Path('Orbits').resolve()
orbits.mkdir(parents=True, exist_ok=True)

esa_username, esa_password = get_esa_credentials()

state_vec, oribit_provider = downloadSentinelOrbitFile(
scene, directory=str(orbits), esa_credentials=(esa_username, esa_password)
)
log.info(f'Downloaded orbit file {state_vec} from {oribit_provider}')
state_vec = fetch_for_scene(scene, dir=orbits)
log.info(f'Downloaded orbit file {state_vec} from s1-orbits')

polarization = get_s1_primary_polarization(scene)
lat_limits, lon_limits = bounding_box(f'{scene}.zip', polarization=polarization, orbits=str(orbits))
Expand Down
26 changes: 0 additions & 26 deletions src/hyp3_autorift/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""Helper utilities for autoRIFT"""

import logging
import netrc
import os
from pathlib import Path
from platform import system
from typing import Tuple, Union

import boto3
Expand All @@ -15,33 +13,9 @@
from hyp3_autorift.geometry import fix_point_for_antimeridian, flip_point_coordinates


ESA_HOST = 'dataspace.copernicus.eu'

log = logging.getLogger(__name__)


def get_esa_credentials() -> Tuple[str, str]:
netrc_name = '_netrc' if system().lower() == 'windows' else '.netrc'
netrc_file = Path.home() / netrc_name

if "ESA_USERNAME" in os.environ and "ESA_PASSWORD" in os.environ:
username = os.environ["ESA_USERNAME"]
password = os.environ["ESA_PASSWORD"]
return username, password

if netrc_file.exists():
netrc_credentials = netrc.netrc(netrc_file)
if ESA_HOST in netrc_credentials.hosts:
username = netrc_credentials.hosts[ESA_HOST][0]
password = netrc_credentials.hosts[ESA_HOST][2]
return username, password

raise ValueError(
"Please provide Copernicus Data Space Ecosystem (CDSE) credentials via the "
"ESA_USERNAME and ESA_PASSWORD environment variables, or your netrc file."
)


def upload_file_to_s3_with_publish_access_keys(path_to_file: Path, bucket: str, prefix: str = ''):
try:
access_key_id = os.environ['PUBLISH_ACCESS_KEY_ID']
Expand Down
44 changes: 0 additions & 44 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,6 @@
from hyp3_autorift.process import DEFAULT_PARAMETER_FILE


def test_get_esa_credentials_env(tmp_path, monkeypatch):
with monkeypatch.context() as m:
m.setenv('ESA_USERNAME', 'foo')
m.setenv('ESA_PASSWORD', 'bar')
m.setenv('HOME', str(tmp_path))
(tmp_path / '.netrc').write_text(f'machine {utils.ESA_HOST} login netrc_username password netrc_password')

username, password = utils.get_esa_credentials()
assert username == 'foo'
assert password == 'bar'


def test_get_esa_credentials_netrc(tmp_path, monkeypatch):
with monkeypatch.context() as m:
m.delenv('ESA_USERNAME', raising=False)
m.delenv('ESA_PASSWORD', raising=False)
m.setenv('HOME', str(tmp_path))
(tmp_path / '.netrc').write_text(f'machine {utils.ESA_HOST} login foo password bar')

username, password = utils.get_esa_credentials()
assert username == 'foo'
assert password == 'bar'


def test_get_esa_credentials_missing(tmp_path, monkeypatch):
with monkeypatch.context() as m:
m.delenv('ESA_USERNAME', raising=False)
m.setenv('ESA_PASSWORD', 'env_password')
m.setenv('HOME', str(tmp_path))
(tmp_path / '.netrc').write_text('')
msg = 'Please provide.*'
with pytest.raises(ValueError, match=msg):
utils.get_esa_credentials()

with monkeypatch.context() as m:
m.setenv('ESA_USERNAME', 'env_username')
m.delenv('ESA_PASSWORD', raising=False)
m.setenv('HOME', str(tmp_path))
(tmp_path / '.netrc').write_text('')
msg = 'Please provide.*'
with pytest.raises(ValueError, match=msg):
utils.get_esa_credentials()


def test_upload_file_to_s3_credentials_missing(tmp_path, monkeypatch):
with monkeypatch.context() as m:
m.delenv('PUBLISH_ACCESS_KEY_ID', raising=False)
Expand Down

0 comments on commit 4637e1b

Please sign in to comment.