Skip to content

Commit

Permalink
test_intersect passing now
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmaurer committed Jul 18, 2023
1 parent be23ace commit 9b06df3
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 39 deletions.
13 changes: 13 additions & 0 deletions test/scenario_6/lon.rdr.aux.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
<Metadata domain="IMAGE_STRUCTURE">
<MDI key="INTERLEAVE">BAND</MDI>
</Metadata>
<Metadata>
<MDI key="Band_1">Band 1</MDI>
</Metadata>
<Metadata domain="ENVI">
<MDI key="bands">1</MDI>
<MDI key="band_names">{Band 1}</MDI>
<MDI key="byte_order">0</MDI>
<MDI key="data_ignore_value">-9999</MDI>
<MDI key="data_type">4</MDI>
<MDI key="description">{lon.rdr}</MDI>
<MDI key="file_type">ENVI Standard</MDI>
<MDI key="header_offset">0</MDI>
<MDI key="interleave">bsq</MDI>
Expand All @@ -14,5 +20,12 @@
</Metadata>
<PAMRasterBand band="1">
<NoDataValue>-9.99900000000000E+03</NoDataValue>
<Metadata>
<MDI key="STATISTICS_MAXIMUM">-100.44786071777</MDI>
<MDI key="STATISTICS_MEAN">-100.56314943275</MDI>
<MDI key="STATISTICS_MINIMUM">-100.67877960205</MDI>
<MDI key="STATISTICS_STDDEV">0.057789502319966</MDI>
<MDI key="STATISTICS_VALID_PERCENT">100</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>
2 changes: 2 additions & 0 deletions test/test_GUNW.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def compute_transform(lats, lons):
return (a, b, c, d, e, f)


@pytest.mark.long
@pytest.mark.isce3
@pytest.mark.parametrize('weather_model_name', ['GMAO', 'HRRR'])
def test_GUNW_update(test_dir_path, test_gunw_path, weather_model_name):
Expand Down Expand Up @@ -66,6 +67,7 @@ def test_GUNW_update(test_dir_path, test_gunw_path, weather_model_name):
[os.remove(f) for f in glob.glob(f'{weather_model_name}*')]


@pytest.mark.long
def test_GUNW_metadata_update(test_gunw_json_path, test_gunw_json_schema_path, tmp_path, mocker):
"""This test performs the GUNW entrypoint with bucket/prefix provided and only updates the json.
Monkey patches the upload/download to/from s3 and the actual computation.
Expand Down
1 change: 0 additions & 1 deletion test/test_datelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test_datelist():
def test_datestep():
SCENARIO_DIR = os.path.join(TEST_DIR, 'scenario_5')
st, en, step = '20200124', '20200130', 3
n_dates = 3
true_dates = [datetime.datetime(2020,1,24), datetime.datetime(2020,1,27), datetime.datetime(2020,1,30)]

dct_group = {
Expand Down
78 changes: 40 additions & 38 deletions test/test_intersect.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import glob
import shutil

import pandas as pd
import rioxarray as xrr
import rasterio

from scipy.interpolate import griddata

from test import *


@pytest.mark.parametrize('wm', 'ERA5'.split())
def test_cube_intersect(wm):
""" Test the intersection of lat/lon files with the DEM (model height levels?) """
SCENARIO_DIR = os.path.join(TEST_DIR, "INTERSECT")
os.makedirs(SCENARIO_DIR, exist_ok=True)

## make the lat lon grid
S, N, W, E = 33, 34.5, -118.0, -117.0
SCENARIO_DIR = os.path.join(TEST_DIR, 'scenario_6')
WM_DIR = os.path.join(SCENARIO_DIR, 'weather_files')
date = 20200130
time ='13:52:45'
f_lat, f_lon = makeLatLonGrid([S, N, W, E], 'LA', SCENARIO_DIR, 0.5)

## make the template file
grp = {
'date_group': {'date_start': date},
'time_group': {'time': time, 'interpolate_time': False},
'weather_model': wm,
'aoi_group': {'lat_file': f_lat, 'lon_file': f_lon},
'runtime_group': {'output_directory': SCENARIO_DIR,
'weather_model_directory': WM_DIR,
},
'aoi_group': {
'lat_file': os.path.join(SCENARIO_DIR, 'lat.rdr'),
'lon_file': os.path.join(SCENARIO_DIR, 'lon.rdr')
},
'runtime_group': {
'output_directory': SCENARIO_DIR,
'weather_model_directory': WM_DIR,
},
'verbose': False,
}

## generate the default template file and overwrite it with new parms
Expand All @@ -39,26 +39,31 @@ def test_cube_intersect(wm):
assert proc.returncode == 0, 'RAiDER Failed.'

## hard code what it should be and check it matches
gold = {'ERA5': 2.2906463, 'GMAO': np.nan, 'HRRR': np.nan}
gold = {'ERA5': 2.2787, 'GMAO': np.nan, 'HRRR': np.nan}

path_delays = os.path.join(SCENARIO_DIR, f'{wm}_hydro_{date}T{time.replace(":", "")}_ztd.tiff')
da = xrr.open_rasterio(path_delays, band_as_variable=True)['band_1']
hyd = da.sel(x=-117.8, y=33.4, method='nearest').item()
np.testing.assert_almost_equal(gold[wm], hyd, decimal=4)
latf = os.path.join(SCENARIO_DIR, 'lat.rdr')
lonf = os.path.join(SCENARIO_DIR, 'lon.rdr')

# Clean up files
shutil.rmtree(SCENARIO_DIR)
[os.remove(f) for f in glob.glob(f'{wm}*')]
os.remove('temp.yaml')
hyd = rasterio.open(path_delays).read(1)
lats = rasterio.open(latf).read(1)
lons = rasterio.open(lonf).read(1)
hyd = griddata(np.stack([lons.flatten(), lats.flatten()], axis=-1), hyd.flatten(), (-100.6, 16.15), method='nearest')

# test for equality with golden data
np.testing.assert_almost_equal(hyd, gold[wm], decimal=4)

return


@pytest.mark.parametrize('wm', 'ERA5'.split())
def test_gnss_intersect(wm):
SCENARIO_DIR = os.path.join(TEST_DIR, "INTERSECT")
os.makedirs(SCENARIO_DIR, exist_ok=True)
gnss_file = os.path.join(TEST_DIR, 'scenario_2', 'stations2.csv')
SCENARIO_DIR = os.path.join(TEST_DIR, 'scenario_6')
WM_DIR = os.path.join(SCENARIO_DIR, 'weather_files')

gnss_file = os.path.join(SCENARIO_DIR, 'stations.csv')
id = 'TORP'

date = 20200130
time ='13:52:45'

Expand All @@ -68,9 +73,11 @@ def test_gnss_intersect(wm):
'time_group': {'time': time, 'interpolate_time': False},
'weather_model': wm,
'aoi_group': {'station_file': gnss_file},
'runtime_group': {'output_directory': SCENARIO_DIR,
'weather_model_directory': WM_DIR,
}
'runtime_group': {
'output_directory': SCENARIO_DIR,
'weather_model_directory': WM_DIR,
},
'verbose': False,
}

## generate the default template file and overwrite it with new parms
Expand All @@ -81,16 +88,11 @@ def test_gnss_intersect(wm):
proc = subprocess.run(cmd.split(), stdout=subprocess.PIPE, universal_newlines=True)
assert proc.returncode == 0, 'RAiDER Failed.'

gold = {'ERA5': 2.3451457, 'GMAO': np.nan, 'HRRR': np.nan}

df = pd.read_csv(os.path.join(SCENARIO_DIR, f'{wm}_Delay_{date}T{time.replace(":", "")}_ztd.csv'))

id = 'TORP'
td = df.set_index('ID').loc[id, 'totalDelay']
np.testing.assert_almost_equal(gold[wm], td.item(), decimal=4)
gold = {'ERA5': 2.3466, 'GMAO': np.nan, 'HRRR': np.nan}
df = pd.read_csv(os.path.join(SCENARIO_DIR, f'{wm}_Delay_{date}T{time.replace(":", "")}.csv'))
td = df['totalDelay'][df['ID']==id].values

shutil.rmtree(SCENARIO_DIR)
[os.remove(f) for f in glob.glob(f'{wm}*')]
os.remove('temp.yaml')
# test for equality with golden data
np.testing.assert_almost_equal(td.item(), gold[wm], decimal=4)

return
Binary file removed test/weather_files/ERA-5_2019_11_17_T20_51_58.nc
Binary file not shown.
Binary file not shown.
Binary file removed test/weather_files/ERA-5_2020_01_30_T13_52_45.nc
Binary file not shown.
Binary file not shown.
Binary file removed test/weather_files/ERA-5_2022_08_29_T17_00_01.nc
Binary file not shown.
Binary file not shown.

0 comments on commit 9b06df3

Please sign in to comment.