diff --git a/sarwind/sarwind.py b/sarwind/sarwind.py index 33ff8b1..935f613 100755 --- a/sarwind/sarwind.py +++ b/sarwind/sarwind.py @@ -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) diff --git a/tests/test_sarwind.py b/tests/test_sarwind.py index 36e8b82..edb41c1 100644 --- a/tests/test_sarwind.py +++ b/tests/test_sarwind.py @@ -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] ] @@ -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):