Skip to content

Commit

Permalink
added subsetting pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
jpswinski committed Nov 14, 2023
1 parent 2dc051e commit b19aa28
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
71 changes: 71 additions & 0 deletions clients/python/tests/test_subsetting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Tests for sliderule subsetting code."""

import pytest
from sliderule import icesat2, sliderule
from pathlib import Path
import os.path

TESTDIR = Path(__file__).parent

@pytest.mark.network
class TestSubsetting:

def test_rasterize(self, init):
resource = "ATL03_20181017222812_02950102_005_01.h5"
region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson"))
parms = {
"poly": region['poly'],
"raster": region['raster'],
"srt": icesat2.SRT_LAND,
"cnf": icesat2.CNF_SURFACE_LOW,
"ats": 20.0,
"cnt": 10,
"len": 40.0,
"res": 20.0 }
gdf = icesat2.atl06p(parms, resources=[resource])
assert init
assert len(gdf) == 953
assert abs(gdf["h_mean"].describe()["mean"] - 1749.8456579488566) < 0.00001
assert abs(gdf["y_atc"].describe()["mean"] - -5516.94775390625) < 0.00001

def test_180_edge(self, init):
resource = "ATL03_20221012073759_03291712_005_01.h5"
poly = [ { "lat": -73.0, "lon": 155.00 },
{ "lat": -74.0, "lon": 155.00 },
{ "lat": -74.0, "lon": 180.00 },
{ "lat": -73.0, "lon": 180.00 },
{ "lat": -73.0, "lon": 155.00 } ]
parms = {
"poly": poly,
"srt": icesat2.SRT_LAND,
"cnf": icesat2.CNF_SURFACE_LOW,
"ats": 20.0,
"cnt": 10,
"len": 40.0,
"res": 20.0 }
gdf = icesat2.atl06p(parms, resources=[resource])
assert init
assert len(gdf) == 33998
assert abs(gdf["h_mean"].describe()["mean"] - 1963.3552883770715) < 0.00001
assert abs(gdf["y_atc"].describe()["mean"] - 1.4383291006088257) < 0.00001

def test_150_translation(self, init):
resource = "ATL03_20221009072040_02831712_005_01.h5"
poly = [ { "lat": -73.0, "lon": 160.00 },
{ "lat": -74.0, "lon": 160.00 },
{ "lat": -74.0, "lon": 170.00 },
{ "lat": -73.0, "lon": 170.00 },
{ "lat": -73.0, "lon": 160.00 } ]
parms = {
"poly": poly,
"srt": icesat2.SRT_LAND,
"cnf": icesat2.CNF_SURFACE_LOW,
"ats": 20.0,
"cnt": 10,
"len": 40.0,
"res": 20.0 }
gdf = icesat2.atl06p(parms, resources=[resource])
assert init
assert len(gdf) == 26663
assert abs(gdf["h_mean"].describe()["mean"] - 95.01489210986797) < 0.00001
assert abs(gdf["y_atc"].describe()["mean"] - 77.65708923339844) < 0.00001
2 changes: 1 addition & 1 deletion clients/python/utils/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def atl06_no_sample_arcticdem():
def atl03_rasterized_subset():
parms = {
"poly": region['poly'],
"raster": region['raster'], # TODO: this is very slow!
"raster": region['raster'],
"srt": icesat2.SRT_LAND,
"cnf": icesat2.CNF_SURFACE_LOW,
"ats": 20.0,
Expand Down

0 comments on commit b19aa28

Please sign in to comment.