diff --git a/test/test_scenario_4.py b/test/test_scenario_4.py index b979b4003..2a99c8ffe 100644 --- a/test/test_scenario_4.py +++ b/test/test_scenario_4.py @@ -1,10 +1,12 @@ import datetime import os import pytest +import xarray import numpy as np +from pyproj import CRS -from RAiDER.delay import tropo_delay +from RAiDER.delay import tropo_delay, _get_delays_on_cube from RAiDER.llreader import RasterRDR from RAiDER.losreader import Zenith from RAiDER.processWM import prepareWeatherModel @@ -36,4 +38,31 @@ def test_aoi_without_xpts(): assert np.nanmean(zen_hydro) > 0 +def test_get_delays_on_cube(): + los = Zenith() + latfile = os.path.join(SCENARIO_DIR, 'lat.rdr') + lonfile = os.path.join(SCENARIO_DIR, 'lon.rdr') + hgtfile = os.path.join(SCENARIO_DIR, 'hgt.rdr') + aoi = RasterRDR(latfile, lonfile, hgtfile) + dt = datetime.datetime(2020,1,1) + + wm = ERA5() + wm.set_latlon_bounds(aoi.bounds()) + wm.setTime(dt) + f = prepareWeatherModel(wm, dt, aoi.bounds()) + + with xarray.load_dataset(f) as ds: + wm_levels = ds.z.values + wm_proj = CRS.from_wkt(ds['proj'].attrs['crs_wkt']) + + zref = 10000 + + with pytest.raises(AttributeError): + aoi.xpts + + ds = _get_delays_on_cube(dt, f, wm_proj, aoi, wm_levels, los, wm_proj, zref) + + assert len(ds.x) > 0 + assert ds.hydro.mean() > 0 + diff --git a/tools/RAiDER/delay.py b/tools/RAiDER/delay.py index e3175eb8d..4895abf23 100755 --- a/tools/RAiDER/delay.py +++ b/tools/RAiDER/delay.py @@ -86,8 +86,9 @@ def tropo_delay( #TODO: expose this as library function - ds = _get_delays_on_cube(dt, weather_model_file, wm_proj, aoi, height_levels, - los, crs, zref) + ds = _get_delays_on_cube( + dt, weather_model_file, wm_proj, aoi, height_levels, los, crs, zref + ) if (aoi.type() == 'bounding_box') or (aoi.type() == 'Geocube'): return ds, None