diff --git a/clients/python/sliderule/sliderule.py b/clients/python/sliderule/sliderule.py index 1b722f47c..0e081c099 100644 --- a/clients/python/sliderule/sliderule.py +++ b/clients/python/sliderule/sliderule.py @@ -658,6 +658,11 @@ def init (url=PUBLIC_URL, verbose=False, loglevel=logging.INFO, organization=0, plugins: list names of the plugins that need to be available on the server + Returns + ------- + bool + Status of version check + Examples -------- >>> import sliderule @@ -670,7 +675,7 @@ def init (url=PUBLIC_URL, verbose=False, loglevel=logging.INFO, organization=0, organization = PUBLIC_ORG authenticate(organization) # configure credentials (if any) for organization scaleout(desired_nodes, time_to_live, bypass_dns) # set cluster to desired number of nodes (if permitted based on credentials) - check_version(plugins=plugins) # verify compatibility between client and server versions + return check_version(plugins=plugins) # verify compatibility between client and server versions # # source diff --git a/clients/python/tests/conftest.py b/clients/python/tests/conftest.py index 3415ee3db..1ba8b966c 100644 --- a/clients/python/tests/conftest.py +++ b/clients/python/tests/conftest.py @@ -1,4 +1,8 @@ import pytest +import logging +import sliderule + +logging.basicConfig(level=logging.DEBUG) def pytest_addoption(parser): parser.addoption("--domain", action="store", default="slideruleearth.io") @@ -12,13 +16,6 @@ def domain(request): pytest.skip() return value -@pytest.fixture(scope='session') -def asset(request): - value = request.config.option.asset - if value is None: - pytest.skip() - return value - @pytest.fixture(scope='session') def organization(request): value = request.config.option.organization @@ -35,3 +32,7 @@ def desired_nodes(request): else: value = int(value) return value + +@pytest.fixture(scope='function') +def init(domain, organization, desired_nodes): + return sliderule.init(domain, verbose=True, loglevel=logging.DEBUG, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) diff --git a/clients/python/tests/test_3dcrs.py b/clients/python/tests/test_3dcrs.py index 832f61ac3..6cb589ca9 100644 --- a/clients/python/tests/test_3dcrs.py +++ b/clients/python/tests/test_3dcrs.py @@ -5,8 +5,7 @@ @pytest.mark.network class Test3dCRS: - def test_atl06p(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl06p(self, init): resource = "ATL03_20181019065445_03150111_005_01.h5" parms = { "cnf": "atl03_high", "ats": 20.0, @@ -15,12 +14,12 @@ def test_atl06p(self, domain, organization, desired_nodes): "res": 20.0, "maxi": 1 } gdf = icesat2.atl06p(parms, resources=[resource], height_key='h_mean') + assert init assert min(gdf["rgt"]) == 315 assert min(gdf["cycle"]) == 1 assert len(gdf["h_mean"]) == 622419 - def test_atl03sp(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl03sp(self, init): resource = "ATL03_20181019065445_03150111_005_01.h5" region = [ { "lat": -80.75, "lon": -70.00 }, { "lat": -81.00, "lon": -70.00 }, @@ -39,12 +38,12 @@ def test_atl03sp(self, domain, organization, desired_nodes): "res": 20.0, "maxi": 1 } gdf = icesat2.atl03sp(parms, resources=[resource], height_key='height') + assert init assert min(gdf["rgt"]) == 315 assert min(gdf["cycle"]) == 1 assert len(gdf["height"]) == 488690 - def test_atl08p(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl08p(self, init): resource = "ATL03_20181213075606_11560106_005_01.h5" region = [ {"lon": -108.3435200747503, "lat": 38.89102961045247}, {"lon": -107.7677425431139, "lat": 38.90611184543033}, @@ -61,5 +60,6 @@ def test_atl08p(self, domain, organization, desired_nodes): "phoreal": {"binsize": 1.0, "geoloc": "center", "use_abs_h": False, "send_waveform": True} } gdf = icesat2.atl08p(parms, resources=[resource], height_key='h_te_median') + assert init assert len(gdf) > 0 diff --git a/clients/python/tests/test_3dep.py b/clients/python/tests/test_3dep.py index ca27601a5..a7257e41e 100644 --- a/clients/python/tests/test_3dep.py +++ b/clients/python/tests/test_3dep.py @@ -13,14 +13,13 @@ @pytest.mark.network class Test3DEP: - def test_sample(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_sample(self, init): geojson = earthdata.tnm(short_name='Digital Elevation Model (DEM) 1 meter', polygon=region) gdf = raster.sample("usgs3dep-1meter-dem", [[-108.0,39.0]], {"catalog": geojson}) + assert init assert len(gdf) >= 4 - def test_as_numpy_array(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_as_numpy_array(self, init): parms = { "poly": region, "degrade_flag": 0, @@ -29,14 +28,14 @@ def test_as_numpy_array(self, domain, organization, desired_nodes): "samples": {"3dep": {"asset": "usgs3dep-1meter-dem"}} } gdf = gedi.gedi04ap(parms, resources=['GEDI04_A_2019123154305_O02202_03_T00174_02_002_02_V002.h5'], as_numpy_array=True) + assert init assert len(gdf) > 0 for key in gdf.keys(): if '3dep' in key: for entry in gdf[key]: assert (type(entry) == numpy.ndarray) or math.isnan(entry) - def test_as_variable(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_as_variable(self, init): parms = { "poly": region, "degrade_flag": 0, @@ -45,6 +44,7 @@ def test_as_variable(self, domain, organization, desired_nodes): "samples": {"3dep": {"asset": "usgs3dep-1meter-dem"}} } gdf = gedi.gedi04ap(parms, resources=['GEDI04_A_2019123154305_O02202_03_T00174_02_002_02_V002.h5'], as_numpy_array=False) + assert init non_array_count = 0 for key in gdf.keys(): if '3dep' in key: diff --git a/clients/python/tests/test_ancillary.py b/clients/python/tests/test_ancillary.py index fe3d063c8..b66a7c2f3 100644 --- a/clients/python/tests/test_ancillary.py +++ b/clients/python/tests/test_ancillary.py @@ -1,7 +1,6 @@ """Tests for sliderule icesat2 api.""" import pytest -from requests.exceptions import ConnectTimeout, ConnectionError import sliderule from sliderule import icesat2 from pathlib import Path @@ -11,8 +10,7 @@ @pytest.mark.network class TestAncillary: - def test_geo(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_geo(self, init): region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson")) parms = { "poly": region["poly"], @@ -20,11 +18,11 @@ def test_geo(self, domain, organization, desired_nodes): "atl03_geo_fields": ["solar_elevation"] } gdf = icesat2.atl06p(parms, resources=["ATL03_20181017222812_02950102_005_01.h5"]) + assert init assert len(gdf["solar_elevation"]) == 1180 assert gdf['solar_elevation'].describe()["min"] - 20.803468704223633 < 0.0000001 - def test_ph(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_ph(self, init): region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson")) parms = { "poly": region["poly"], @@ -32,5 +30,6 @@ def test_ph(self, domain, organization, desired_nodes): "atl03_ph_fields": ["ph_id_count"] } gdf = icesat2.atl03s(parms, "ATL03_20181017222812_02950102_005_01.h5") + assert init assert sum(gdf["ph_id_count"]) == 626032 assert len(gdf["ph_id_count"]) == 403462 diff --git a/clients/python/tests/test_apis.py b/clients/python/tests/test_apis.py index 40e301dfc..08a19250c 100644 --- a/clients/python/tests/test_apis.py +++ b/clients/python/tests/test_apis.py @@ -17,8 +17,7 @@ # @pytest.mark.network class TestTime: - def test_time(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_time(self, init): rqst = { "time": "NOW", "input": "NOW", @@ -34,11 +33,12 @@ def test_time(self, domain, organization, desired_nodes): rqst["output"] = "GPS" d = sliderule.source("time", rqst) again = d["time"] + assert init assert now == again - def test_gps2utc(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_gps2utc(self, init): utc = sliderule.gps2utc(1235331234) + assert init assert utc == '2019-02-27T19:33:36Z' # @@ -46,12 +46,12 @@ def test_gps2utc(self, domain, organization, desired_nodes): # @pytest.mark.network class TestDefinition: - def test_definition(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_definition(self, init): rqst = { "rectype": "atl06rec.elevation", } d = sliderule.source("definition", rqst) + assert init assert d["time"]["offset"] == 192 # @@ -59,9 +59,9 @@ def test_definition(self, domain, organization, desired_nodes): # @pytest.mark.network class TestVersion: - def test_version_endpoint(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_version_endpoint(self, init): rsps = sliderule.source("version", {}) + assert init assert 'server' in rsps assert 'version' in rsps['server'] assert 'commit' in rsps['server'] @@ -78,9 +78,9 @@ def test_version_endpoint(self, domain, organization, desired_nodes): assert '.' in rsps['icesat2']['version'] assert len(rsps['icesat2']['commit']) - def test_get_version_api(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_get_version_api(self, init): version = sliderule.get_version() + assert init assert isinstance(version, dict) assert {'icesat2', 'server', 'client'} <= version.keys() @@ -92,7 +92,7 @@ def test_check_version(self, domain, organization, desired_nodes): sliderule.set_url(domain) sliderule.authenticate(organization) sliderule.scaleout(desired_nodes, 15, True) - sliderule.check_version(plugins=['icesat2']) + assert sliderule.check_version(plugins=['icesat2']) # # Initialization APIs @@ -103,10 +103,11 @@ def test_loop_init(self, domain, organization, desired_nodes): for _ in range(10): icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) - def test_loop_versions(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_loop_versions(self, init): + assert init for _ in range(10): - sliderule.source("version", {}) + rsps = sliderule.source("version", {}) + assert len(rsps) > 0 def test_init_badurl(self): with pytest.raises( (sliderule.FatalError) ): diff --git a/clients/python/tests/test_arcticdem.py b/clients/python/tests/test_arcticdem.py index f5738627c..f8ee7dcc0 100644 --- a/clients/python/tests/test_arcticdem.py +++ b/clients/python/tests/test_arcticdem.py @@ -18,37 +18,36 @@ @pytest.mark.network class TestMosaic: - def test_vrt(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_vrt(self, init): rqst = {"samples": {"asset": "arcticdem-mosaic"}, "coordinates": [[vrtLon,vrtLat]]} rsps = sliderule.source("samples", rqst) + assert init assert abs(rsps["samples"][0][0]["value"] - vrtElevation) < sigma assert rsps["samples"][0][0]["file"] == vrtFile assert rsps["samples"][0][0]["time"] == vrtFileTime - def test_vrt_with_aoi(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_vrt_with_aoi(self, init): bbox = [-179, 50, -177, 52] rqst = {"samples": {"asset": "arcticdem-mosaic", "aoi_bbox" : bbox}, "coordinates": [[vrtLon,vrtLat]]} rsps = sliderule.source("samples", rqst) + assert init assert abs(rsps["samples"][0][0]["value"] - vrtElevation) < sigma assert rsps["samples"][0][0]["file"] == vrtFile assert rsps["samples"][0][0]["time"] == vrtFileTime - def test_vrt_with_proj_pipeline(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_vrt_with_proj_pipeline(self, init): # Output from: projinfo -s EPSG:4326 -t EPSG:3413 -o proj pipeline = "+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +x_0=0 +y_0=0 +ellps=WGS84" rqst = {"samples": {"asset": "arcticdem-mosaic", "proj_pipeline" : pipeline}, "coordinates": [[vrtLon,vrtLat]]} rsps = sliderule.source("samples", rqst) + assert init assert abs(rsps["samples"][0][0]["value"] - vrtElevation) < sigma assert rsps["samples"][0][0]["file"] == vrtFile assert rsps["samples"][0][0]["time"] == vrtFileTime - def test_nearestneighbour(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_nearestneighbour(self, init): resource = "ATL03_20190314093716_11600203_005_01.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/dicksonfjord.geojson")) parms = { "poly": region['poly'], @@ -60,6 +59,7 @@ def test_nearestneighbour(self, domain, organization, desired_nodes): "maxi": 1, "samples": {"mosaic": {"asset": "arcticdem-mosaic"}} } gdf = icesat2.atl06p(parms, resources=[resource]) + assert init assert len(gdf) == 957 assert len(gdf.keys()) == 19 assert gdf["rgt"][0] == 1160 @@ -68,8 +68,7 @@ def test_nearestneighbour(self, domain, organization, desired_nodes): assert gdf['segment_id'].describe()["max"] == 405902 assert abs(gdf["mosaic.value"].describe()["min"] - 600.4140625) < sigma - def test_zonal_stats(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_zonal_stats(self, init): resource = "ATL03_20190314093716_11600203_005_01.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/dicksonfjord.geojson")) parms = { "poly": region['poly'], @@ -81,6 +80,7 @@ def test_zonal_stats(self, domain, organization, desired_nodes): "maxi": 1, "samples": {"mosaic": {"asset": "arcticdem-mosaic", "radius": 10.0, "zonal_stats": True}} } gdf = icesat2.atl06p(parms, resources=[resource]) + assert init assert len(gdf) == 957 assert len(gdf.keys()) == 26 assert gdf["rgt"][0] == 1160 @@ -94,8 +94,7 @@ def test_zonal_stats(self, domain, organization, desired_nodes): @pytest.mark.network class TestStrips: - def test_indexed_raster(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_indexed_raster(self, init): region_of_interest = [ {'lon': -46.76533411521963, 'lat': 65.4938164756588}, {'lon': -46.34013213284274, 'lat': 65.49860245693627}, {'lon': -46.35015561146599, 'lat': 65.67523503534576}, @@ -113,7 +112,7 @@ def test_indexed_raster(self, domain, organization, desired_nodes): "time_end":'2021-01-01', "samples": {"strips": {"asset": "arcticdem-strips", "with_flags": True}} } gdf = icesat2.atl06p(parms, resources=['ATL03_20191108234307_06580503_005_01.h5']) - print(gdf.attrs['file_directory']) + assert init assert len(gdf.attrs['file_directory']) == 32 for file_id in range(16): assert file_id in gdf.attrs['file_directory'].keys() diff --git a/clients/python/tests/test_earthdata.py b/clients/python/tests/test_earthdata.py index 6ff21d63b..c4c8f673f 100644 --- a/clients/python/tests/test_earthdata.py +++ b/clients/python/tests/test_earthdata.py @@ -27,21 +27,21 @@ # @pytest.mark.network class TestCMR: - def test_grandmesa_time_range(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_grandmesa_time_range(self, init): granules = earthdata.cmr(short_name='ATL03', polygon=grandmesa, time_start='2018-10-01', time_end='2018-12-01') + assert init assert isinstance(granules, list) assert 'ATL03_20181017222812_02950102_006_02.h5' in granules - def test_collection(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_collection(self, init): entries = cmr_collection_query('NSIDC_ECS', 'ATL03') + assert init assert isinstance(entries, list) assert entries[0]['short_name'] == 'ATL03' - def test_max_version(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_max_version(self, init): max_version = cmr_max_version('NSIDC_ECS', 'ATL03') + assert init assert isinstance(max_version, str) assert int(max_version) >= 6 @@ -50,21 +50,18 @@ def test_max_version(self, domain, organization, desired_nodes): # @pytest.mark.network class TestSTAC: - def test_asdict(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_asdict(self): region = sliderule.toregion(os.path.join(TESTDIR, 'data/polygon.geojson')) catalog = earthdata.stac(short_name="HLS", polygon=region["poly"], time_start="2022-01-01T00:00:00Z", time_end="2022-03-01T00:00:00Z", as_str=False) assert catalog["features"][0]['properties']['eo:cloud_cover'] == 99 - def test_asstr(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_asstr(self): region = sliderule.toregion(os.path.join(TESTDIR, 'data/polygon.geojson')) response = earthdata.stac(short_name="HLS", polygon=region["poly"], time_start="2022-01-01T00:00:00Z", time_end="2022-03-01T00:00:00Z", as_str=True) catalog = json.loads(response) assert catalog["features"][0]['properties']['eo:cloud_cover'] == 99 - def test_bad_short_name(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_bad_short_name(self): region = sliderule.toregion(os.path.join(TESTDIR, 'data/polygon.geojson')) with pytest.raises(sliderule.FatalError): earthdata.stac(short_name="DOES_NOT_EXIST", polygon=region["poly"], time_start="2022-01-01T00:00:00Z", time_end="2022-03-01T00:00:00Z") @@ -74,21 +71,18 @@ def test_bad_short_name(self, domain, organization, desired_nodes): # @pytest.mark.network class TestTNM: - def test_asdict(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_asdict(self): region = sliderule.toregion(os.path.join(TESTDIR, 'data/polygon.geojson')) geojson = earthdata.tnm(short_name='Digital Elevation Model (DEM) 1 meter', polygon=region["poly"], as_str=False) assert 'https://prd-tnm.s3.amazonaws.com/StagedProducts/Elevation/1m' in geojson["features"][0]['properties']['url'] - def test_asstr(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_asstr(self): region = sliderule.toregion(os.path.join(TESTDIR, 'data/polygon.geojson')) response = earthdata.tnm(short_name='Digital Elevation Model (DEM) 1 meter', polygon=region["poly"], as_str=True) geojson = json.loads(response) assert 'https://prd-tnm.s3.amazonaws.com/StagedProducts/Elevation/1m' in geojson["features"][0]['properties']['url'] - def test_bad_short_name(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_bad_short_name(self): region = sliderule.toregion(os.path.join(TESTDIR, 'data/polygon.geojson')) geojson = earthdata.tnm(short_name='DOES_NOT_EXIST', polygon=region["poly"], as_str=False) assert len(geojson['features']) == 0 \ No newline at end of file diff --git a/clients/python/tests/test_gedi.py b/clients/python/tests/test_gedi.py index 03824de5f..e3f286ea4 100644 --- a/clients/python/tests/test_gedi.py +++ b/clients/python/tests/test_gedi.py @@ -9,8 +9,7 @@ @pytest.mark.network class TestL1B: - def test_gedi(self, domain, organization, desired_nodes): - gedi.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_gedi(self, init): resource = "GEDI01_B_2019109210809_O01988_03_T02056_02_005_01_V002.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson")) parms = { @@ -20,6 +19,7 @@ def test_gedi(self, domain, organization, desired_nodes): "beam": 0 } gdf = gedi.gedi01bp(parms, resources=[resource]) + assert init assert gdf.describe()["beam"]["mean"] == 0.0 assert gdf.describe()["flags"]["mean"] == 0.0 assert gdf.describe()["tx_size"]["mean"] == 128.0 @@ -36,8 +36,7 @@ def test_cmr(self): @pytest.mark.network class TestL2A: - def test_gedi(self, domain, organization, desired_nodes): - gedi.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_gedi(self, init): resource = "GEDI02_A_2022288203631_O21758_03_T00021_02_003_02_V002.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson")) parms = { @@ -47,6 +46,7 @@ def test_gedi(self, domain, organization, desired_nodes): "beam": 0 } gdf = gedi.gedi02ap(parms, resources=[resource]) + assert init assert gdf.describe()["beam"]["mean"] == 0.0 assert gdf.describe()["flags"]["max"] == 130.0 assert abs(gdf.describe()["elevation_lm"]["min"] - 667.862000) < 0.001 @@ -62,8 +62,7 @@ def test_cmr(self): @pytest.mark.network class TestL3: - def test_gedi(self, domain, organization, desired_nodes): - gedi.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_gedi(self, init): resource = "ATL03_20220105023009_02111406_005_01.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson")) parms = { @@ -78,6 +77,7 @@ def test_gedi(self, domain, organization, desired_nodes): "samples": {"gedi": {"asset": "gedil3-elevation"}} } gdf = icesat2.atl06p(parms, resources=[resource]) + assert init assert gdf.describe()["gedi.time"]["std"] == 0.0 assert abs(gdf.describe()["gedi.value"]["mean"] - 3142.8526604140434) < 0.001 assert gdf.describe()["gedi.file_id"]["max"] == 0.0 @@ -85,8 +85,7 @@ def test_gedi(self, domain, organization, desired_nodes): @pytest.mark.network class TestL4A: - def test_gedi(self, domain, organization, desired_nodes): - gedi.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_gedi(self, init): resource = "GEDI04_A_2019123154305_O02202_03_T00174_02_002_02_V002.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson")) parms = { @@ -96,6 +95,7 @@ def test_gedi(self, domain, organization, desired_nodes): "beam": 0 } gdf = gedi.gedi04ap(parms, resources=[resource]) + assert init assert gdf.describe()["beam"]["mean"] == 0.0 assert gdf.describe()["flags"]["max"] == 134.0 assert abs(gdf.describe()["elevation"]["min"] - 1499.137329) < 0.001 @@ -111,8 +111,7 @@ def test_cmr(self): @pytest.mark.network class TestL4B: - def test_gedi(self, domain, organization, desired_nodes): - gedi.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_gedi(self, init): resource = "ATL03_20220105023009_02111406_005_01.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson")) parms = { @@ -127,6 +126,7 @@ def test_gedi(self, domain, organization, desired_nodes): "samples": {"gedi": {"asset": "gedil4b"}} } gdf = icesat2.atl08p(parms, resources=[resource], keep_id=True) + assert init exp_keys = ['snowcover', 'h_max_canopy', 'canopy_h_metrics', 'solar_elevation', 'h_canopy', 'spot', 'segment_id', 'rgt', 'gnd_ph_count', 'h_te_median', 'cycle', 'ph_count', 'h_mean_canopy', 'x_atc', 'landcover', diff --git a/clients/python/tests/test_geo.py b/clients/python/tests/test_geo.py index b0db6be8b..9f70d9b2e 100644 --- a/clients/python/tests/test_geo.py +++ b/clients/python/tests/test_geo.py @@ -9,8 +9,7 @@ @pytest.mark.network class TestGeo: - def test_geospatial1(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_geospatial1(self, init): test = { "asset": "icesat2", "pole": "north", @@ -38,6 +37,7 @@ def test_geospatial1(self, domain, organization, desired_nodes): } } d = sliderule.source("geo", test) + assert init assert d["intersect"] == True assert abs(d["combine"]["lat0"] - 44.4015) < 0.001 assert abs(d["combine"]["lon0"] - 108.6949) < 0.001 @@ -54,8 +54,7 @@ def test_geospatial1(self, domain, organization, desired_nodes): assert d["lat"] == 40.0 and d["lon"] == 60.0 assert d["x"] == 0.466307658155 and d["y"] == 0.80766855588292 - def test_geospatial2(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_geospatial2(self, init): test = { "asset": "icesat2", "pole": "north", @@ -65,10 +64,10 @@ def test_geospatial2(self, domain, organization, desired_nodes): "y": 1.1371580426033, } d = sliderule.source("geo", test) + assert init assert abs(d["lat"] - 30.0) < 0.0001 and d["lon"] == 100.0 - def test_geospatial3(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_geospatial3(self, init): test = { "asset": "icesat2", "pole": "north", @@ -78,10 +77,10 @@ def test_geospatial3(self, domain, organization, desired_nodes): "y": -1.1371580426033, } d = sliderule.source("geo", test) + assert init assert abs(d["lat"] - 30.0) < 0.0001 and d["lon"] == -100.0 - def test_geospatial4(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_geospatial4(self, init): test = { "asset": "icesat2", "pole": "north", @@ -91,4 +90,5 @@ def test_geospatial4(self, domain, organization, desired_nodes): "y": -1.1371580426033, } d = sliderule.source("geo", test) + assert init assert abs(d["lat"] - 30.0) < 0.0001 and d["lon"] == -80.0 diff --git a/clients/python/tests/test_geojson.py b/clients/python/tests/test_geojson.py index a4f74a45a..e83e00c32 100644 --- a/clients/python/tests/test_geojson.py +++ b/clients/python/tests/test_geojson.py @@ -10,8 +10,7 @@ @pytest.mark.network class TestGeoJson: - def test_atl03(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl03(self, init): for testfile in ["data/grandmesa.geojson", "data/grandmesa.shp"]: region = sliderule.toregion(os.path.join(TESTDIR, testfile)) parms = { @@ -25,6 +24,7 @@ def test_atl03(self, domain, organization, desired_nodes): "res": 20.0, } gdf = icesat2.atl03s(parms, "ATL03_20181017222812_02950102_005_01.h5") + assert init assert gdf["rgt"].unique()[0] == 295 assert gdf["cycle"].unique()[0] == 1 assert len(gdf) == 21006 diff --git a/clients/python/tests/test_h5.py b/clients/python/tests/test_h5.py index 0293898fa..228626316 100644 --- a/clients/python/tests/test_h5.py +++ b/clients/python/tests/test_h5.py @@ -12,38 +12,38 @@ @pytest.mark.network class TestApi: - def test_happy_case(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_happy_case(self, init): epoch_offset = h5coro.h5("ancillary_data/atlas_sdp_gps_epoch", ATL03_FILE1, "icesat2")[0] + assert init assert epoch_offset == 1198800018.0 - def test_h5_types(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_h5_types(self, init): heights_64 = h5coro.h5("/gt1l/land_ice_segments/h_li", ATL06_FILE1, "icesat2") expected_64 = [45.95665, 45.999374, 46.017857, 46.015575, 46.067562, 46.099796, 46.14037, 46.105526, 46.096024, 46.12297] heights_32 = h5coro.h5("/gt1l/land_ice_segments/h_li", ATL06_FILE2, "icesat2") expected_32 = [350.46988, 352.08688, 352.43243, 353.19345, 353.69543, 352.25998, 350.15366, 346.37888, 342.47903, 341.51] bckgrd_32nf = h5coro.h5("/gt1l/bckgrd_atlas/bckgrd_rate", ATL03_FILE2, "icesat2") expected_32nf = [29311.428, 6385.937, 6380.8413, 28678.951, 55349.168, 38201.082, 19083.434, 38045.67, 34942.434, 38096.266] + assert init for c in zip(heights_64, expected_64, heights_32, expected_32, bckgrd_32nf, expected_32nf): assert (round(c[0]) == round(c[1])) and (round(c[2]) == round(c[3])) and (round(c[4]) == round(c[5])) - def test_variable_length(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_variable_length(self, init): v = h5coro.h5("/gt1r/geolocation/segment_ph_cnt", ATL03_FILE1, "icesat2") + assert init assert v[0] == 258 and v[1] == 256 and v[2] == 273 - def test_invalid_file(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_invalid_file(self, init): v = h5coro.h5("/gt1r/geolocation/segment_ph_cnt", INVALID_FILE, "icesat2") + assert init assert len(v) == 0 - def test_invalid_asset(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_invalid_asset(self, init): v = h5coro.h5("/gt1r/geolocation/segment_ph_cnt", ATL03_FILE1, "invalid-asset") + assert init assert len(v) == 0 - def test_invalid_path(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_invalid_path(self, init): v = h5coro.h5("/gt1r/invalid-path", ATL03_FILE1, "icesat2") + assert init assert len(v) == 0 diff --git a/clients/python/tests/test_h5p.py b/clients/python/tests/test_h5p.py index 6fbf7d073..be277d5fe 100644 --- a/clients/python/tests/test_h5p.py +++ b/clients/python/tests/test_h5p.py @@ -8,8 +8,7 @@ @pytest.mark.network class TestApi: - def test_happy_case(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_happy_case(self, init): datasets = [ {"dataset": "/gt1l/land_ice_segments/h_li", "numrows": 5}, {"dataset": "/gt1r/land_ice_segments/h_li", "numrows": 5}, @@ -18,6 +17,7 @@ def test_happy_case(self, domain, organization, desired_nodes): {"dataset": "/gt3l/land_ice_segments/h_li", "numrows": 5}, {"dataset": "/gt3r/land_ice_segments/h_li", "numrows": 5} ] rsps = h5.h5p(datasets, ATL06_FILE1, "icesat2") + assert init expected = {'/gt1l/land_ice_segments/h_li': [45.95665, 45.999374, 46.017857, 46.015575, 46.067562], '/gt1r/land_ice_segments/h_li': [45.980865, 46.02602, 46.02262, 46.03137, 46.073578], '/gt2l/land_ice_segments/h_li': [45.611526, 45.588196, 45.53242, 45.48105, 45.443752], @@ -28,20 +28,20 @@ def test_happy_case(self, domain, organization, desired_nodes): for index in range(len(expected[dataset])): assert round(rsps[dataset][index]) == round(expected[dataset][index]) - def test_invalid_file(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_invalid_file(self, init): datasets = [ {"dataset": "/gt3r/land_ice_segments/h_li", "numrows": 5} ] rsps = h5.h5p(datasets, "invalid_file.h5", "icesat2") + assert init assert len(rsps) == 0 - def test_invalid_asset(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_invalid_asset(self, init): datasets = [ {"dataset": "/gt3r/land_ice_segments/h_li", "numrows": 5} ] rsps = h5.h5p(datasets, ATL06_FILE1, "invalid-asset") + assert init assert len(rsps) == 0 - def test_invalid_dataset(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_invalid_dataset(self, init): datasets = [ {"dataset": "/gt3r/invalid", "numrows": 5} ] rsps = h5.h5p(datasets, ATL06_FILE1, "icesat2") + assert init assert len(rsps) == 0 \ No newline at end of file diff --git a/clients/python/tests/test_icesat2.py b/clients/python/tests/test_icesat2.py index 5eaa757ff..f77bd1ca0 100644 --- a/clients/python/tests/test_icesat2.py +++ b/clients/python/tests/test_icesat2.py @@ -9,8 +9,7 @@ @pytest.mark.network class TestAlgorithm: - def test_atl06(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl06(self, init): resource = "ATL03_20181019065445_03150111_005_01.h5" parms = { "cnf": "atl03_high", "ats": 20.0, @@ -20,13 +19,13 @@ def test_atl06(self, domain, organization, desired_nodes): "maxi": 1 } perf_start = time.perf_counter() gdf = icesat2.atl06(parms, resource) + assert init assert (time.perf_counter() - perf_start) < 50 assert min(gdf["rgt"]) == 315 assert min(gdf["cycle"]) == 1 assert len(gdf["h_mean"]) == 622419 - def test_atl06p(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl06p(self, init): resource = "ATL03_20181019065445_03150111_005_01.h5" parms = { "cnf": "atl03_high", "ats": 20.0, @@ -36,13 +35,13 @@ def test_atl06p(self, domain, organization, desired_nodes): "maxi": 1 } perf_start = time.perf_counter() gdf = icesat2.atl06p(parms, resources=[resource]) + assert init assert (time.perf_counter() - perf_start) < 50 assert min(gdf["rgt"]) == 315 assert min(gdf["cycle"]) == 1 assert len(gdf["h_mean"]) == 622419 - def test_atl03s(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl03s(self, init): resource = "ATL03_20181019065445_03150111_005_01.h5" region = [ { "lat": -80.75, "lon": -70.00 }, { "lat": -81.00, "lon": -70.00 }, @@ -62,13 +61,13 @@ def test_atl03s(self, domain, organization, desired_nodes): "maxi": 1 } perf_start = time.perf_counter() gdf = icesat2.atl03s(parms, resource) + assert init assert (time.perf_counter() - perf_start) < 40 assert min(gdf["rgt"]) == 315 assert min(gdf["cycle"]) == 1 assert len(gdf["height"]) == 488690 - def test_atl03sp(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl03sp(self, init): resource = "ATL03_20181019065445_03150111_005_01.h5" region = [ { "lat": -80.75, "lon": -70.00 }, { "lat": -81.00, "lon": -70.00 }, @@ -88,13 +87,13 @@ def test_atl03sp(self, domain, organization, desired_nodes): "maxi": 1 } perf_start = time.perf_counter() gdf = icesat2.atl03sp(parms, resources=[resource]) + assert init assert (time.perf_counter() - perf_start) < 40 assert min(gdf["rgt"]) == 315 assert min(gdf["cycle"]) == 1 assert len(gdf["height"]) == 488690 - def test_atl08(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl08(self, init): resource = "ATL03_20181213075606_11560106_005_01.h5" track = 1 region = [ {"lon": -108.3435200747503, "lat": 38.89102961045247}, @@ -114,6 +113,7 @@ def test_atl08(self, domain, organization, desired_nodes): "maxi": 1 } perf_start = time.perf_counter() gdf = icesat2.atl03s(parms, resource) + assert init assert (time.perf_counter() - perf_start) < 30 assert min(gdf["rgt"]) == 1156 assert min(gdf["cycle"]) == 1 @@ -124,8 +124,7 @@ def test_atl08(self, domain, organization, desired_nodes): assert len(gdf[gdf["atl08_class"] == 3]) == 18285 assert len(gdf[gdf["atl08_class"] == 4]) == 15978 - def test_gs(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_gs(self, init): resource_prefix = "20210114170723_03311012_005_01.h5" region = [ {"lon": 126.54560629670780, "lat": -70.28232209449946}, {"lon": 114.29798416287946, "lat": -70.08880029415151}, @@ -253,6 +252,7 @@ def test_gs(self, domain, organization, desired_nodes): total_error[element] += abs(error) # Asserts + assert init assert min(sliderule["rgt"]) == 331 assert min(sliderule["cycle"]) == 10 assert len(sliderule) == 55367 diff --git a/clients/python/tests/test_landsat.py b/clients/python/tests/test_landsat.py index b4aa4644c..3cff2acfb 100644 --- a/clients/python/tests/test_landsat.py +++ b/clients/python/tests/test_landsat.py @@ -9,8 +9,7 @@ @pytest.mark.network class TestHLS: - def test_samples(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_samples(self, init): time_start = "2021-01-01T00:00:00Z" time_end = "2021-02-01T23:59:59Z" polygon = [ {"lon": -177.0000000001, "lat": 51.0000000001}, @@ -21,9 +20,10 @@ def test_samples(self, domain, organization, desired_nodes): catalog = earthdata.stac(short_name="HLS", polygon=polygon, time_start=time_start, time_end=time_end, as_str=True) rqst = {"samples": {"asset": "landsat-hls", "catalog": catalog, "bands": ["B02"]}, "coordinates": [[-178.0, 50.7]]} rsps = sliderule.source("samples", rqst) + assert init + assert len(rsps) > 0 - def test_subset1(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_subset1(self, init): time_start = "2021-01-01T00:00:00Z" time_end = "2021-02-01T23:59:59Z" polygon = [ {"lon": -177.0000000001, "lat": 51.0000000001}, @@ -34,6 +34,7 @@ def test_subset1(self, domain, organization, desired_nodes): catalog = earthdata.stac(short_name="HLS", polygon=polygon, time_start=time_start, time_end=time_end, as_str=True) rqst = {"samples": {"asset": "landsat-hls", "catalog": catalog, "bands": ["B02"]}, "extents": [[-179.87, 50.45, -178.77, 50.75]]} rsps = sliderule.source("subsets", rqst) + assert init assert len(rsps) > 0 assert len(rsps['subsets'][0][0]['data']) > 0 assert rsps['subsets'][0][0]['rows'] == 1030 @@ -46,8 +47,7 @@ def test_subset1(self, domain, organization, desired_nodes): assert rsps['subsets'][0][0]['wkt'] != "" - def test_subset167(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_subset167(self, init): time_start = "2021-01-01T00:00:00Z" time_end = "2021-02-01T23:59:59Z" polygon = [ {"lon": -177.0000000001, "lat": 51.0000000001}, @@ -59,6 +59,7 @@ def test_subset167(self, domain, organization, desired_nodes): rqst = {"samples": {"asset": "landsat-hls", "catalog": catalog, "bands": ["VAA", "VZA", "Fmask","SAA", "SZA", "NDSI", "NDVI", "NDWI","B01", "B02", "B03", "B04", "B05", "B06","B07", "B08", "B09", "B10", "B11", "B12", "B8A"]}, "extents": [[-179.87, 50.45, -178.27, 51.44]]} rsps = sliderule.source("subsets", rqst) subsets = rsps['subsets'][0] + assert init assert len(subsets) == 167 for subset in subsets: @@ -74,8 +75,7 @@ def test_subset167(self, domain, organization, desired_nodes): assert subset['wkt'] != "" - def test_ndvi(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_ndvi(self, init): region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson")) resource = "ATL03_20181017222812_02950102_005_01.h5" parms = { "poly": region['poly'], @@ -88,5 +88,6 @@ def test_ndvi(self, domain, organization, desired_nodes): "maxi": 1, "samples": {"ndvi": {"asset": "landsat-hls", "t0": "2021-01-01T00:00:00Z", "t1": "2021-02-01T23:59:59Z", "bands": ["NDVI"]}} } gdf = icesat2.atl06p(parms, resources=[resource]) + assert init assert len(gdf) > 0 assert len(gdf["ndvi.value"]) > 0 diff --git a/clients/python/tests/test_luaerr.py b/clients/python/tests/test_luaerr.py index 760f6430f..39f8e118a 100644 --- a/clients/python/tests/test_luaerr.py +++ b/clients/python/tests/test_luaerr.py @@ -17,37 +17,37 @@ def catchexceptions(rec): @pytest.mark.network class TestAtl03s: - def test_badasset(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_badasset(self, init): invalid_asset = "invalid-asset" rqst = { "resource": [], "parms": {"asset" : "invalid-asset"} } rsps = sliderule.source("atl03s", rqst, stream=True, callbacks=GLOBAL_callbacks) + assert init assert(len(rsps) == 0) assert("invalid asset specified: {}".format(invalid_asset) == GLOBAL_message) @pytest.mark.network class TestAtl06: - def test_badasset(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_badasset(self, init): invalid_asset = "invalid-asset" rqst = { "resource": [], "parms": {"asset" : "invalid-asset"} } rsps = sliderule.source("atl06", rqst, stream=True, callbacks=GLOBAL_callbacks) + assert init assert(len(rsps) == 0) assert("invalid asset specified: {}".format(invalid_asset) == GLOBAL_message) - def test_timeout(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_timeout(self, init): resource = "ATL03_20220208000041_07291401_005_01.h5" rqst = { "resource": resource, "parms": {"track": 0, "srt": 0, "pass_invalid":True, "yapc": {"score":0}, "timeout": 1}, } rsps = sliderule.source("atl06", rqst, stream=True, callbacks=GLOBAL_callbacks) + assert init assert(len(rsps) == 0) # assert("{} timed-out after 10 seconds".format(resource) in GLOBAL_message) # non-deterministic diff --git a/clients/python/tests/test_meritdem.py b/clients/python/tests/test_meritdem.py index a67bacb6b..fba336458 100644 --- a/clients/python/tests/test_meritdem.py +++ b/clients/python/tests/test_meritdem.py @@ -7,8 +7,8 @@ @pytest.mark.network class TestMerit: - def test_sample(self, domain, organization, desired_nodes): - sliderule.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_sample(self, init): gdf = raster.sample("merit-dem", [[-172, 51.7], [-172, 51.71], [-172, 51.72], [-172, 51.73], [-172, 51.74]]) + assert init assert gdf["value"][0] == -99990000 assert len(gdf) == 5 diff --git a/clients/python/tests/test_parquet.py b/clients/python/tests/test_parquet.py index c734c670d..e1b7ea67d 100644 --- a/clients/python/tests/test_parquet.py +++ b/clients/python/tests/test_parquet.py @@ -12,8 +12,7 @@ @pytest.mark.network class TestParquet: - def test_atl06(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl06(self, init): resource = "ATL03_20190314093716_11600203_005_01.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/dicksonfjord.geojson")) parms = { "poly": region['poly'], @@ -26,6 +25,7 @@ def test_atl06(self, domain, organization, desired_nodes): "output": { "path": "testfile1.parquet", "format": "parquet", "open_on_complete": True } } gdf = icesat2.atl06p(parms, resources=[resource]) os.remove("testfile1.parquet") + assert init assert len(gdf) == 957 assert len(gdf.keys()) == 16 assert gdf["rgt"][0] == 1160 @@ -33,8 +33,7 @@ def test_atl06(self, domain, organization, desired_nodes): assert gdf['segment_id'].describe()["min"] == 405231 assert gdf['segment_id'].describe()["max"] == 405902 - def test_atl06_non_geo(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl06_non_geo(self, init): resource = "ATL03_20190314093716_11600203_005_01.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/dicksonfjord.geojson")) parms = { "poly": region['poly'], @@ -47,6 +46,7 @@ def test_atl06_non_geo(self, domain, organization, desired_nodes): "output": { "path": "testfile5.parquet", "format": "parquet", "open_on_complete": True, "as_geo": False } } gdf = icesat2.atl06p(parms, resources=[resource]) os.remove("testfile5.parquet") + assert init assert len(gdf) == 957 assert len(gdf.keys()) == 17 assert gdf["rgt"][0] == 1160 @@ -54,8 +54,7 @@ def test_atl06_non_geo(self, domain, organization, desired_nodes): assert gdf['segment_id'].describe()["min"] == 405231 assert gdf['segment_id'].describe()["max"] == 405902 - def test_atl03(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl03(self, init): resource = "ATL03_20190314093716_11600203_005_01.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/dicksonfjord.geojson")) parms = { "poly": region['poly'], @@ -68,6 +67,7 @@ def test_atl03(self, domain, organization, desired_nodes): "output": { "path": "testfile2.parquet", "format": "parquet", "open_on_complete": True } } gdf = icesat2.atl03sp(parms, resources=[resource]) os.remove("testfile2.parquet") + assert init assert len(gdf) == 190491 assert len(gdf.keys()) == 23 assert gdf["rgt"][0] == 1160 @@ -75,8 +75,7 @@ def test_atl03(self, domain, organization, desired_nodes): assert gdf['segment_id'].describe()["min"] == 405231 assert gdf['segment_id'].describe()["max"] == 405902 - def test_atl06_index(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl06_index(self, init): resource = "ATL03_20181017222812_02950102_005_01.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson")) parms = { @@ -90,12 +89,12 @@ def test_atl06_index(self, domain, organization, desired_nodes): "output": { "path": "testfile3.parquet", "format": "parquet", "open_on_complete": True } } gdf = icesat2.atl06p(parms, resources=[resource]) os.remove("testfile3.parquet") + assert init assert len(gdf) == 265 assert gdf.index.values.min() == numpy.datetime64('2018-10-17T22:31:17.350047744') assert gdf.index.values.max() == numpy.datetime64('2018-10-17T22:31:19.582527744') - def test_atl03_index(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_atl03_index(self, init): resource = "ATL03_20181017222812_02950102_005_01.h5" region = sliderule.toregion(os.path.join(TESTDIR, "data/grandmesa.geojson")) parms = { @@ -109,6 +108,7 @@ def test_atl03_index(self, domain, organization, desired_nodes): "output": { "path": "testfile4.parquet", "format": "parquet", "open_on_complete": True } } gdf = icesat2.atl03sp(parms, resources=[resource]) os.remove("testfile4.parquet") + assert init assert len(gdf) == 20642 assert gdf.index.values.min() == numpy.datetime64('2018-10-17T22:31:17.349347328') assert gdf.index.values.max() == numpy.datetime64('2018-10-17T22:31:19.582347520') diff --git a/clients/python/tests/test_rema.py b/clients/python/tests/test_rema.py index b78530931..3a9c2a6d8 100644 --- a/clients/python/tests/test_rema.py +++ b/clients/python/tests/test_rema.py @@ -19,29 +19,29 @@ @pytest.mark.network class TestMosaic: - def test_vrt(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_vrt(self, init): rqst = {"samples": {"asset": "rema-mosaic"}, "coordinates": [[vrtLon,vrtLat]]} rsps = sliderule.source("samples", rqst) + assert init assert abs(rsps["samples"][0][0]["value"] - vrtElevation) < sigma assert rsps["samples"][0][0]["file"] == vrtFile assert rsps["samples"][0][0]["time"] == vrtFileTime - def test_vrt_with_aoi(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_vrt_with_aoi(self, init): bbox = [-81, -81, -79, -79] rqst = {"samples": {"asset": "rema-mosaic", "aoi_bbox" : bbox}, "coordinates": [[vrtLon,vrtLat]]} rsps = sliderule.source("samples", rqst) + assert init assert abs(rsps["samples"][0][0]["value"] - vrtElevation) < sigma assert rsps["samples"][0][0]["file"] == vrtFile assert rsps["samples"][0][0]["time"] == vrtFileTime - def test_vrt_with_proj_pipeline(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_vrt_with_proj_pipeline(self, init): # Output from: projinfo -s EPSG:4326 -t EPSG:3031 -o proj pipeline = "+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84" rqst = {"samples": {"asset": "rema-mosaic", "proj_pipeline" : pipeline}, "coordinates": [[vrtLon,vrtLat]]} rsps = sliderule.source("samples", rqst) + assert init assert abs(rsps["samples"][0][0]["value"] - vrtElevation) < sigma assert rsps["samples"][0][0]["file"] == vrtFile assert rsps["samples"][0][0]["time"] == vrtFileTime \ No newline at end of file diff --git a/clients/python/tests/test_worldcover.py b/clients/python/tests/test_worldcover.py index 3ad8d9817..dd86a239f 100644 --- a/clients/python/tests/test_worldcover.py +++ b/clients/python/tests/test_worldcover.py @@ -2,9 +2,7 @@ import pytest from pathlib import Path -import os.path import sliderule -from sliderule import icesat2 TESTDIR = Path(__file__).parent @@ -19,10 +17,10 @@ @pytest.mark.network class TestMosaic: - def test_vrt(self, domain, organization, desired_nodes): - icesat2.init(domain, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + def test_vrt(self, init): rqst = {"samples": {"asset": "esa-worldcover-10meter"}, "coordinates": [[vrtLon,vrtLat]]} rsps = sliderule.source("samples", rqst) + assert init assert abs(rsps["samples"][0][0]["value"] - vrtValue) < sigma assert rsps["samples"][0][0]["file"] == vrtFile assert rsps["samples"][0][0]["time"] == vrtFileTime