Skip to content

Commit

Permalink
compare means with GUNW cubes/rasters representing similar items
Browse files Browse the repository at this point in the history
  • Loading branch information
cmarshak committed Feb 1, 2024
1 parent ff122b2 commit 288fcdc
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions tests/test_packaging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
from pathlib import Path

import numpy as np
import rasterio
from numpy.testing import assert_almost_equal

from isce2_topsapp.packaging import (
Expand Down Expand Up @@ -59,11 +61,41 @@ def test_mean_of_geocoded_isce_outputs():
merged_dir="https://gunw-development-testing.s3.us-west-2.amazonaws.com/sample_merged_data"
)
expected_out = {
"mean_filtered_coherence_without_water_mask": 0.3126283,
"mean_filtered_coherence_with_water_mask": 0.32342613,
"mean_incidence_angle": 28.281992,
"mean_azimuth_angle": -99.18769836425781,
"mean_filtered_coherence_without_water_mask": 0.4395995,
"mean_filtered_coherence_with_water_mask": 0.4649538,
"mean_unfiltered_coherence_without_water_mask": 0.33125195,
"mean_unfiltered_coherence_with_water_mask": 0.33531728,
"mean_incidence_angle": 38.845047,
"mean_azimuth_angle": -169.84756469726562,
}

for key in expected_out:
assert_almost_equal(expected_out[key], out[key], decimal=5)

# Use output GUNW and compare means
gunw_s3_path = (
"/vsis3/gunw-development-testing/sample_merged_data"
"/S1-GUNW-A-R-164-tops-20220212_20220131-222829-00071W_00047N-PP-3d6c-v3_0_0.nc"
)

vars_data_0 = {var: f"//science/grids/data/{var}" for var in ["unfilteredCoherence", "coherence"]}
vars_data_1 = {var: f"//science/grids/imagingGeometry/{var}" for var in ["azimuthAngle", "incidenceAngle"]}
vars_data = {**vars_data_0, **vars_data_1}

gunw_mean_data = {}
for var, var_path in vars_data.items():
with rasterio.open(f"HDF5:{gunw_s3_path}:{var_path}") as ds:
X = ds.read()
# 0 is the nodata for all the variables we consider
gunw_mean_data[var] = np.mean(X[X != 0])

# Ensure the GUNW cubes and rasters (with lower resolution than geocoded ISCE2 data) are within a reasonable range
# of the geocoded rasters that ICE2 produces
assert np.abs(out['mean_filtered_coherence_without_water_mask'] - gunw_mean_data['coherence']) < .01
assert np.abs(out['mean_unfiltered_coherence_without_water_mask'] - gunw_mean_data['unfilteredCoherence']) < .01
assert np.abs(out['mean_azimuth_angle'] - gunw_mean_data['azimuthAngle']) < 1
assert np.abs(out['mean_incidence_angle'] - gunw_mean_data['incidenceAngle']) < 1

# Sanity checks - make sure that applying a water mask *increases* the coherence as water has low coherence
assert out['mean_filtered_coherence_without_water_mask'] < out['mean_filtered_coherence_with_water_mask']
assert out['mean_unfiltered_coherence_without_water_mask'] < out['mean_unfiltered_coherence_with_water_mask']

0 comments on commit 288fcdc

Please sign in to comment.