Skip to content

Commit

Permalink
Raise error if SAR data is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenwh committed Jun 25, 2024
1 parent f5ead3a commit 7074674
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sarwind/sarwind.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def __init__(self, sar_image, wind, pixelsize=500, resample_alg=1, max_diff_minu
"polarization": "VV",
"dataType": "6"
})
# Check that there is data
s0vv = self[self.sigma0_bandNo]
if s0vv[~np.isnan(s0vv)].shape[0] == 0:
raise ValueError("Erroneous SAR product - all NRCS values are NaN.")

logging.debug("Resize SAR..")
# Resize to given pixel size (default 500 m)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_sarwind.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def testSARWind_using_s1EWnc_arome_filenames(mock_nansat, sarEW_NBS, arome, monk
with monkeypatch.context() as mp:
smock = SelectMock()
smock.side_effect = [
np.array([1, 1]), # self[self.sigma0_bandNo]
np.array([0, 0]), # topo[1]
1, # self[self.sigma0_bandNo]
]
Expand All @@ -82,6 +83,25 @@ def testSARWind_using_s1EWnc_arome_filenames(mock_nansat, sarEW_NBS, arome, monk
SARWind(sarEW_NBS, arome)
assert str(ee.value) == "The SAR and wind datasets do not intersect."

# Test that sarwind raises exception if the NRCS is NaN
with monkeypatch.context() as mp:
smock = SelectMock()
smock.side_effect = [
np.array([np.nan, np.nan]) # self[self.sigma0_bandNo]
]
mp.setattr("sarwind.sarwind.Nansat.__getitem__", smock)
smock2 = SelectMock()
smock2.side_effect = [
"VV",
"2024-04-04T23:28:31+00:00",
"2024-04-04T23:28:51+00:00",
"2024-04-04T23:28:31+00:00",
]
mp.setattr("sarwind.sarwind.Nansat.get_metadata", smock2)
with pytest.raises(ValueError) as ee:
SARWind(sarEW_NBS, arome)
assert str(ee.value) == "Erroneous SAR product - all NRCS values are NaN."


@pytest.mark.without_nansat
def testSARWind_get_model_wind_field(mock_nansat, arome, monkeypatch):
Expand Down

0 comments on commit 7074674

Please sign in to comment.