Skip to content

Commit b9dc4e9

Browse files
committed
fixing bug with snap_to_grid on cpc lat lon input
added test using cpc_global-daily data
1 parent efbde14 commit b9dc4e9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

dweather_client/tests/test_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ def test_snap_to_grid_prism():
1313
prism_metadata = http_client.get_metadata(heads['prism_precip-daily'])
1414
lat, lon = utils.snap_to_grid(39.8398, -104.193, prism_metadata)
1515
assert lat == 39.833
16-
assert lon == -104.208
16+
assert lon == -104.208
17+
18+
def test_snap_to_grid_cpc_global_daily():
19+
# tests snap_to_grid with ideosyncratic cpc lat/lon format
20+
heads = http_client.get_heads()
21+
prism_metadata = http_client.get_metadata(heads['cpc_global-daily'])
22+
lat, lon = utils.snap_to_grid(69.754, 330.759, prism_metadata)
23+
assert lat == 69.750
24+
assert lon == 330.750

dweather_client/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ def snap_to_grid(lat, lon, metadata):
2121
category = metadata['climate category']
2222

2323
if 'cpc' in metadata['source data url']:
24-
start[0], start[1] = conventional_lat_lon_to_cpc(start[0], start[1])
25-
end[0], end[1] = conventional_lat_lon_to_cpc(end[0], end[1])
24+
min_lat, min_lon = conventional_lat_lon_to_cpc(min_lat, min_lon)
25+
2626
# check that the lat lon is in the bounding box
2727

2828
if category != 'rainfall':
2929
raise Exception('snap_to_grid() called on non rainfall dataset.')
3030

3131
snap_lat = round(round((lat - min_lat)/resolution) * resolution + min_lat, 3)
3232
snap_lon = round(round((lon - min_lon)/resolution) * resolution + min_lon, 3)
33-
return snap_lat, snap_lon
33+
return snap_lat, snap_lon
3434

3535
def cpc_lat_lon_to_conventional(lat, lon):
3636
"""

0 commit comments

Comments
 (0)