|
1 |
| -import numpy as np |
2 | 1 | import pytest
|
3 | 2 | import xarray as xr
|
4 | 3 |
|
5 |
| -from tests.fixtures import generate_dataset |
6 |
| -from xcdat.utils import ( |
7 |
| - _validate_min_weight, |
8 |
| - compare_datasets, |
9 |
| - mask_var_with_weight_threshold, |
10 |
| - str_to_bool, |
11 |
| -) |
| 4 | +from xcdat.utils import _validate_min_weight, compare_datasets, str_to_bool |
12 | 5 |
|
13 | 6 |
|
14 | 7 | class TestCompareDatasets:
|
@@ -112,132 +105,6 @@ def test_raises_error_if_str_is_not_a_python_bool(self):
|
112 | 105 | str_to_bool("1")
|
113 | 106 |
|
114 | 107 |
|
115 |
| -class TestMaskVarWithWeightThreshold: |
116 |
| - @pytest.fixture(autouse=True) |
117 |
| - def setup(self): |
118 |
| - self.ds = generate_dataset( |
119 |
| - decode_times=True, cf_compliant=False, has_bounds=True |
120 |
| - ) |
121 |
| - |
122 |
| - def test_returns_mask_var_with_spatial_min_weight_of_100(self): |
123 |
| - ds = self.ds.copy() |
124 |
| - ds = ds.isel({"time": slice(0, 3), "lat": slice(0, 3), "lon": slice(0, 3)}) |
125 |
| - ds["ts"][0, :, 2] = np.nan |
126 |
| - |
127 |
| - # Function arguments. |
128 |
| - dv = ds["ts"].copy() |
129 |
| - weights = ds.spatial.get_weights( |
130 |
| - axis=["X", "Y"], |
131 |
| - lat_bounds=(-5.0, 5), |
132 |
| - lon_bounds=(-170, -120.1), |
133 |
| - data_var="ts", |
134 |
| - ) |
135 |
| - |
136 |
| - result = mask_var_with_weight_threshold(dv, weights, min_weight=1.0) |
137 |
| - expected = xr.DataArray( |
138 |
| - data=np.array( |
139 |
| - [ |
140 |
| - [ |
141 |
| - [np.nan, np.nan, np.nan], |
142 |
| - [np.nan, np.nan, np.nan], |
143 |
| - [np.nan, np.nan, np.nan], |
144 |
| - ], |
145 |
| - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], |
146 |
| - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], |
147 |
| - ] |
148 |
| - ), |
149 |
| - coords={"time": ds.time, "lat": ds.lat, "lon": ds.lon}, |
150 |
| - dims=["time", "lat", "lon"], |
151 |
| - ) |
152 |
| - |
153 |
| - xr.testing.assert_allclose(result, expected) |
154 |
| - |
155 |
| - def test_returns_mask_var_with_spatial_min_weight_of_0(self): |
156 |
| - ds = self.ds.copy() |
157 |
| - ds = ds.isel({"time": slice(0, 3), "lat": slice(0, 3), "lon": slice(0, 3)}) |
158 |
| - |
159 |
| - # Function arguments. |
160 |
| - dv = ds["ts"].copy() |
161 |
| - weights = ds.spatial.get_weights( |
162 |
| - axis=["X", "Y"], |
163 |
| - lat_bounds=(-5.0, 5), |
164 |
| - lon_bounds=(-170, -120.1), |
165 |
| - data_var="ts", |
166 |
| - ) |
167 |
| - |
168 |
| - result = mask_var_with_weight_threshold(dv, weights, min_weight=0) |
169 |
| - expected = xr.DataArray( |
170 |
| - data=np.array( |
171 |
| - [ |
172 |
| - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], |
173 |
| - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], |
174 |
| - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], |
175 |
| - ] |
176 |
| - ), |
177 |
| - coords={"time": ds.time, "lat": ds.lat, "lon": ds.lon}, |
178 |
| - dims=["time", "lat", "lon"], |
179 |
| - ) |
180 |
| - |
181 |
| - xr.testing.assert_allclose(result, expected) |
182 |
| - |
183 |
| - def test_returns_mask_var_with_temporal_min_weight_of_100(self): |
184 |
| - ds = self.ds.copy() |
185 |
| - ds = ds.isel({"time": slice(0, 3), "lat": slice(0, 3), "lon": slice(0, 3)}) |
186 |
| - ds["ts"][0, :, 2] = np.nan |
187 |
| - |
188 |
| - # Function arguments. |
189 |
| - dv = ds["ts"].copy() |
190 |
| - weights = xr.DataArray( |
191 |
| - name="time_wts", |
192 |
| - data=np.array([1.0, 1.0, 1.0]), |
193 |
| - dims="time", |
194 |
| - coords={"time": ds.time}, |
195 |
| - ) |
196 |
| - |
197 |
| - result = mask_var_with_weight_threshold(dv, weights, min_weight=0) |
198 |
| - expected = xr.DataArray( |
199 |
| - data=np.array( |
200 |
| - [ |
201 |
| - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [np.nan, 1.0, 1.0]], |
202 |
| - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [np.nan, 1.0, 1.0]], |
203 |
| - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [np.nan, 1.0, 1.0]], |
204 |
| - ] |
205 |
| - ), |
206 |
| - coords={"lat": ds.lat, "lon": ds.lon, "time": ds.time}, |
207 |
| - dims=["lat", "lon", "time"], |
208 |
| - ) |
209 |
| - |
210 |
| - xr.testing.assert_allclose(result, expected) |
211 |
| - |
212 |
| - def test_returns_mask_var_with_temporal_min_weight_of_0(self): |
213 |
| - ds = self.ds.copy() |
214 |
| - ds = ds.isel({"time": slice(0, 3), "lat": slice(0, 3), "lon": slice(0, 3)}) |
215 |
| - |
216 |
| - # Function arguments. |
217 |
| - dv = ds["ts"].copy() |
218 |
| - weights = xr.DataArray( |
219 |
| - name="time_wts", |
220 |
| - data=np.array([1.0, 1.0, 1.0]), |
221 |
| - dims="time", |
222 |
| - coords={"time": ds.time}, |
223 |
| - ) |
224 |
| - |
225 |
| - result = mask_var_with_weight_threshold(dv, weights, min_weight=0) |
226 |
| - expected = xr.DataArray( |
227 |
| - data=np.array( |
228 |
| - [ |
229 |
| - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], |
230 |
| - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], |
231 |
| - [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], |
232 |
| - ] |
233 |
| - ), |
234 |
| - coords={"lat": ds.lat, "lon": ds.lon, "time": ds.time}, |
235 |
| - dims=["lat", "lon", "time"], |
236 |
| - ) |
237 |
| - |
238 |
| - xr.testing.assert_allclose(result, expected) |
239 |
| - |
240 |
| - |
241 | 108 | class TestValidateMinWeight:
|
242 | 109 | def test_pass_None_returns_0(self):
|
243 | 110 | result = _validate_min_weight(None)
|
|
0 commit comments