Skip to content

Commit 6a1906f

Browse files
committed
add spatial resolution tests and import error handling
1 parent 3c975fc commit 6a1906f

File tree

4 files changed

+145
-8
lines changed

4 files changed

+145
-8
lines changed

scripts/ej/create_ej_dump.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88
from cmr_processing import CmrDataset
99
from threshold_processing import ThresholdProcessor
1010

11-
from config import (
12-
CMR_FILENAME,
13-
INFERENCE_FILENAME,
14-
OUTPUT_FILENAME_TEMPLATE,
15-
TIMESTAMP_FORMAT,
16-
)
11+
try:
12+
from config import (
13+
CMR_FILENAME,
14+
INFERENCE_FILENAME,
15+
OUTPUT_FILENAME_TEMPLATE,
16+
TIMESTAMP_FORMAT,
17+
)
18+
except ImportError:
19+
from scripts.ej.config import (
20+
CMR_FILENAME,
21+
INFERENCE_FILENAME,
22+
OUTPUT_FILENAME_TEMPLATE,
23+
TIMESTAMP_FORMAT,
24+
)
1725

1826

1927
def load_json_file(file_path: str) -> dict:

scripts/ej/test_cmr_processing.py

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_full_dataset_processing(self, cmr_dataset):
2626
assert cmr_dataset.limitations == "None"
2727
assert cmr_dataset.format == "application/vnd.nasa.cmr.umm+json"
2828
assert cmr_dataset.temporal_extent == "" # No SingleDateTimes in example
29-
assert cmr_dataset.intended_use == "exploration" # ProcessingLevel is 4
29+
assert cmr_dataset.intended_use == "Path A" # ProcessingLevel is 4
3030
assert cmr_dataset.source_link == "https://doi.org/10.7927/H4NK3BZJ"
3131
assert "Long temporal extent" in cmr_dataset.strengths
3232
assert "No recent data available" in cmr_dataset.weaknesses
@@ -180,6 +180,130 @@ def test_non_global_coverage(self):
180180
dataset = CmrDataset(data)
181181
assert dataset.geographic_coverage == ""
182182

183+
def test_spatial_resolution_varies(self):
184+
"""Test spatial resolution when it varies."""
185+
data = {
186+
"umm": {
187+
"SpatialExtent": {
188+
"HorizontalSpatialDomain": {
189+
"ResolutionAndCoordinateSystem": {"HorizontalDataResolution": {"VariesResolution": "Varies"}}
190+
}
191+
}
192+
}
193+
}
194+
dataset = CmrDataset(data)
195+
assert dataset.spatial_resolution == "Varies"
196+
197+
def test_spatial_resolution_gridded_range(self):
198+
"""Test spatial resolution with gridded range resolutions."""
199+
data = {
200+
"umm": {
201+
"SpatialExtent": {
202+
"HorizontalSpatialDomain": {
203+
"ResolutionAndCoordinateSystem": {
204+
"HorizontalDataResolution": {
205+
"GriddedRangeResolutions": [
206+
{
207+
"MinimumXDimension": 5.0,
208+
"MinimumYDimension": 5.0,
209+
"MaximumXDimension": 50.0,
210+
"MaximumYDimension": 40.0,
211+
"Unit": "Kilometers",
212+
}
213+
]
214+
}
215+
}
216+
}
217+
}
218+
}
219+
}
220+
dataset = CmrDataset(data)
221+
assert dataset.spatial_resolution == "50.0 kilometers"
222+
223+
def test_spatial_resolution_gridded(self):
224+
"""Test spatial resolution with gridded resolutions."""
225+
data = {
226+
"umm": {
227+
"SpatialExtent": {
228+
"HorizontalSpatialDomain": {
229+
"ResolutionAndCoordinateSystem": {
230+
"HorizontalDataResolution": {
231+
"GriddedResolutions": [{"XDimension": 30.0, "YDimension": 30.0, "Unit": "Meters"}]
232+
}
233+
}
234+
}
235+
}
236+
}
237+
}
238+
dataset = CmrDataset(data)
239+
assert dataset.spatial_resolution == "30.0 meters"
240+
241+
def test_spatial_resolution_generic(self):
242+
"""Test spatial resolution with generic resolutions."""
243+
data = {
244+
"umm": {
245+
"SpatialExtent": {
246+
"HorizontalSpatialDomain": {
247+
"ResolutionAndCoordinateSystem": {
248+
"HorizontalDataResolution": {
249+
"GenericResolutions": [{"XDimension": 10.0, "YDimension": 10.0, "Unit": "Kilometers"}]
250+
}
251+
}
252+
}
253+
}
254+
}
255+
}
256+
dataset = CmrDataset(data)
257+
assert dataset.spatial_resolution == "10.0 kilometers"
258+
259+
def test_spatial_resolution_missing(self):
260+
"""Test spatial resolution when resolution data is missing."""
261+
data = {"umm": {"SpatialExtent": {"HorizontalSpatialDomain": {"ResolutionAndCoordinateSystem": {}}}}}
262+
dataset = CmrDataset(data)
263+
assert dataset.spatial_resolution == ""
264+
265+
def test_spatial_resolution_different_dimensions(self):
266+
"""Test spatial resolution when X and Y dimensions differ."""
267+
data = {
268+
"umm": {
269+
"SpatialExtent": {
270+
"HorizontalSpatialDomain": {
271+
"ResolutionAndCoordinateSystem": {
272+
"HorizontalDataResolution": {
273+
"GriddedResolutions": [{"XDimension": 30.0, "YDimension": 40.0, "Unit": "Meters"}]
274+
}
275+
}
276+
}
277+
}
278+
}
279+
}
280+
dataset = CmrDataset(data)
281+
assert dataset.spatial_resolution == "40.0 meters"
282+
283+
def test_spatial_resolution_incomplete_data(self):
284+
"""Test spatial resolution with incomplete resolution data."""
285+
data = {
286+
"umm": {
287+
"SpatialExtent": {
288+
"HorizontalSpatialDomain": {
289+
"ResolutionAndCoordinateSystem": {
290+
"HorizontalDataResolution": {
291+
"GriddedResolutions": [
292+
{
293+
"XDimension": 30.0,
294+
# Missing YDimension
295+
"Unit": "Meters",
296+
}
297+
]
298+
}
299+
}
300+
}
301+
}
302+
}
303+
}
304+
dataset = CmrDataset(data)
305+
assert dataset.spatial_resolution == ""
306+
183307

184308
class TestDownloadProcessing:
185309
"""Unit tests for download information processing"""

scripts/ej/test_threshold_processing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Unit tests for threshold processing functionality."""
22

3+
# docker-compose -f local.yml run --rm django pytest scripts/ej/test_threshold_processing.py
4+
35
import pytest
46
from threshold_processing import ThresholdProcessor
57

scripts/ej/threshold_processing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""Module for processing classification predictions with thresholds."""
22

3-
from config import AUTHORIZED_CLASSIFICATIONS, INDICATOR_THRESHOLDS
3+
try:
4+
from config import AUTHORIZED_CLASSIFICATIONS, INDICATOR_THRESHOLDS
5+
except ImportError:
6+
from scripts.ej.config import AUTHORIZED_CLASSIFICATIONS, INDICATOR_THRESHOLDS
47

58

69
class ThresholdProcessor:

0 commit comments

Comments
 (0)