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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,7 @@ tags

# Data
src/multirtc/multimetric/*/

# pixi environments
.pixi/*
!.pixi/config.toml
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ 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.5.4]

### Fixed
* Copernicus DEM for NISAR URLs to fix 404 errors.
* Support for EARTHDATA credentials passed as env vars.

## [0.5.3]

### Changed
Expand Down
7 changes: 7 additions & 0 deletions src/multirtc/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import argparse
import os

from multirtc import dem, geocode, multirtc
from multirtc.fetch import write_credentials_to_netrc_file
from multirtc.multimetric import ale, point_target, rle


def main():
username = os.getenv('EARTHDATA_USERNAME')
password = os.getenv('EARTHDATA_PASSWORD')
if username and password:
write_credentials_to_netrc_file(username, password, append=False)

global_parser = argparse.ArgumentParser(
prog='multirtc',
description='ISCE3-based multi-sensor RTC and cal/val tool',
Expand Down
2 changes: 1 addition & 1 deletion src/multirtc/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def get_dem_granule_url(lat: int, lon: int) -> str:
lon_cardinal = 'W' if lon_tens < 0 else 'E'

prefix = f'{lat_cardinal}{np.abs(lat_tens):02d}/{lat_cardinal}{np.abs(lat_tens):02d}_{lon_cardinal}{np.abs(lon_tens):03d}'
filename = f'DEM{lat_cardinal}{np.abs(lat):02d}_00_{lon_cardinal}{np.abs(lon):03d}_00_C01.tif'
filename = f'DEM_{lat_cardinal}{np.abs(lat):02d}_00_{lon_cardinal}{np.abs(lon):03d}_00_C01.tif'
file_url = f'{URL}/{prefix}/{filename}'
return file_url

Expand Down
15 changes: 15 additions & 0 deletions src/multirtc/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
from urllib3.util.retry import Retry


EARTHDATA_LOGIN_DOMAIN = 'urs.earthdata.nasa.gov'


def write_credentials_to_netrc_file(
username: str, password: str, domain: str = EARTHDATA_LOGIN_DOMAIN, append: bool = False
):
"""Write credentials to .netrc file"""
netrc_file = Path.home() / '.netrc'
if netrc_file.exists() and not append:
logging.warning(f'Using existing .netrc file: {netrc_file}')
else:
with open(netrc_file, 'a') as f:
f.write(f'machine {domain} login {username} password {password}\n')


def _get_download_path(url: str, content_disposition: str | None = None, directory: Path | str = '.'):
filename = None
if content_disposition is not None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def test_get_granule_url():
test_url = (
'https://nisar.asf.earthdatacloud.nasa.gov/NISAR/DEM/v1.2/EPSG4326/S10/S10_W020/DEMS01_00_W001_00_C01.tif'
'https://nisar.asf.earthdatacloud.nasa.gov/NISAR/DEM/v1.2/EPSG4326/S10/S10_W020/DEM_S01_00_W001_00_C01.tif'
)
url = dem.get_dem_granule_url(-1, -1)
assert url == test_url
Expand Down