Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tighter control flow logic for calcDelays #585

Merged
merged 12 commits into from
Sep 29, 2023
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* Return xarray.Dataset types for RAiDER.calcGUNW.tropo_gunw_slc and RAiDER.raider.calcDelayGUNW for easier inspection and testing

## [0.4.4]

## Fixes
* For s1-azimuth-time interpolation, overlapping orbits when one orbit does not cover entire GUNW product errors out. We now ensure state-vectors are both unique and in order before creating a orbit object in ISCE3.

## [0.4.3]
+ Bug fixes, unit tests, docstrings
+ Prevent ray tracing integration from occuring at exactly top of weather model
+ Properly expose z_ref (max integration height) parameter, and dont allow higher than weather model
+ Min version for sentineleof for obtaining restituted orbits.
Expand Down
6 changes: 3 additions & 3 deletions test/test_GUNW.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import os
import shutil
import subprocess
import unittest
from pathlib import Path

Expand All @@ -23,6 +22,7 @@
check_weather_model_availability
)
from RAiDER.cli.raider import calcDelaysGUNW
from RAiDER.models.customExceptions import *


def compute_transform(lats, lons):
Expand Down Expand Up @@ -515,7 +515,7 @@ def test_GUNW_workflow_fails_if_a_download_fails(gunw_azimuth_test, orbit_dict_f
'-interp', 'azimuth_time_grid'
]

with pytest.raises(ValueError):
with pytest.raises(RuntimeError):
calcDelaysGUNW(iargs_1)
RAiDER.s1_azimuth_timing.get_s1_azimuth_time_grid.assert_not_called()

Expand All @@ -534,6 +534,6 @@ def test_value_error_for_file_inputs_when_no_data_available(mocker):
'-interp', 'azimuth_time_grid'
]

with pytest.raises(ValueError):
with pytest.raises(NoWeatherModelData):
calcDelaysGUNW(iargs)
RAiDER.aria.prepFromGUNW.main.assert_not_called()
37 changes: 37 additions & 0 deletions test/test_llreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pandas as pd

from test import GEOM_DIR, TEST_DIR
from pyproj import CRS

from RAiDER.cli.raider import calcDelays

Expand Down Expand Up @@ -41,6 +42,31 @@ def test_latlon_reader_2():
RasterRDR(lat_file='doesnotexist.rdr', lon_file='doesnotexist.rdr')


def test_aoi_epsg():
bbox = [20, 27, -115, -104]
r = BoundingBox(bbox)
r.set_output_spacing(ll_res=0.05)
test = r.get_output_spacing(4978)
assert test == 0.05 * 1e5


def test_set_output_dir():
bbox = [20, 27, -115, -104]
r = BoundingBox(bbox)
r.set_output_directory('dummy_directory')
assert r._output_directory == 'dummy_directory'


def test_set_xygrid():
bbox = [20, 27, -115, -104]
crs = CRS.from_epsg(4326)
r = BoundingBox(bbox)
r.set_output_spacing(ll_res=0.1)
r.set_output_xygrid(dst_crs=4978)
r.set_output_xygrid(dst_crs=crs)
assert True


def test_latlon_reader():
latfile = os.path.join(GEOM_DIR, 'lat.rdr')
lonfile = os.path.join(GEOM_DIR, 'lon.rdr')
Expand All @@ -60,6 +86,17 @@ def test_latlon_reader():
assert all([np.allclose(b, t, rtol=1e-4) for b, t in zip(query.bounds(), bounds_true)])


def test_badllfiles(station_file):
latfile = os.path.join(GEOM_DIR, 'lat.rdr')
lonfile = os.path.join(GEOM_DIR, 'lon_dummy.rdr')
station_file = station_file
with pytest.raises(ValueError):
RasterRDR(lat_file=latfile, lon_file=lonfile)
with pytest.raises(ValueError):
RasterRDR(lat_file=latfile, lon_file=station_file)
with pytest.raises(ValueError):
RasterRDR(lat_file=station_file, lon_file=lonfile)

def test_read_bbox():
bbox = [20, 27, -115, -104]
query = BoundingBox(bbox)
Expand Down
2 changes: 1 addition & 1 deletion test/test_losreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_get_sv_3(svs):
def test_get_sv_4(svs):
true_svs = svs
filename = os.path.join(ORB_DIR, 'no_exist.txt')
with pytest.raises(FileNotFoundError):
with pytest.raises(ValueError):
get_sv(filename, true_svs[0][0], pad=3*60)


Expand Down
11 changes: 5 additions & 6 deletions test/test_weather_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from RAiDER.models.gmao import GMAO
from RAiDER.models.merra2 import MERRA2
from RAiDER.models.ncmr import NCMR
from RAiDER.models.customExceptions import *


_LON0 = 0
Expand Down Expand Up @@ -156,12 +157,12 @@ def test_weatherModel_basic1(model: MockWeatherModel):
wm.setTime('19720229', fmt='%Y%m%d') # test a leap year
assert wm._time == datetime.datetime(1972, 2, 29, 0, 0, 0)

with pytest.raises(RuntimeError):
with pytest.raises(DatetimeOutsideRange):
wm.checkTime(datetime.datetime(1950, 1, 1))

wm.checkTime(datetime.datetime(2000, 1, 1))

with pytest.raises(RuntimeError):
with pytest.raises(DatetimeOutsideRange):
wm.checkTime(datetime.datetime.now())


Expand Down Expand Up @@ -309,7 +310,7 @@ def test_hrrr(hrrr: HRRR):
assert wm._Name == 'HRRR'
assert wm._valid_range[0] == datetime.datetime(2016, 7, 15)
assert wm._proj.to_epsg() is None
with pytest.raises(RuntimeError):
with pytest.raises(DatetimeOutsideRange):
wm.checkTime(datetime.datetime(2010, 7, 15))
wm.checkTime(datetime.datetime(2018, 7, 12))

Expand All @@ -329,7 +330,7 @@ def test_hrrrak(hrrrak: HRRRAK):
with pytest.raises(ValueError):
wm.checkValidBounds([15, 20, 265, 270])

with pytest.raises(RuntimeError):
with pytest.raises(DatetimeOutsideRange):
wm.checkTime(datetime.datetime(2018, 7, 12))

wm.checkTime(datetime.datetime(2018, 7, 15))
Expand Down Expand Up @@ -431,7 +432,6 @@ def test_hrrr_badloc(wm:hrrr=HRRR):
with pytest.raises(ValueError):
wm._fetch('dummy_filename')


def test_hrrrak_dl(tmp_path: Path, wm:hrrrak=HRRRAK):
wm = wm()
d = tmp_path / "files"
Expand All @@ -443,7 +443,6 @@ def test_hrrrak_dl(tmp_path: Path, wm:hrrrak=HRRRAK):
wm._fetch(fname)
assert True


def test_hrrrak_dl2(tmp_path: Path, wm:hrrrak=HRRRAK):
# test the international date line crossing
wm = wm()
Expand Down
9 changes: 8 additions & 1 deletion tools/RAiDER/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ def main():

sys.argv = [args.process, *unknowns]

from RAiDER.cli.raider import calcDelays, downloadGNSS, calcDelaysGUNW
if args.process == 'calcDelays':
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This control flow reduces the total import load

from RAiDER.cli.raider import calcDelays
elif args.process == 'downloadGNSS':
from RAiDER.cli.raider import downloadGNSS
elif args.process == 'calcDelaysGUNW':
from RAiDER.cli.raider import calcDelaysGUNW
else:
raise NotImplementedError(f'Process {args.process} has not been fully implemented')

try:
# python >=3.10 interface
Expand Down
Loading
Loading