diff --git a/examples/examples.md b/examples/examples.md index aa7d432..2e07cd4 100644 --- a/examples/examples.md +++ b/examples/examples.md @@ -34,6 +34,16 @@ Sampling STRDS by area curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/modis_lst/strds/LST_Day_monthly/timestamp/2016-01-01T00:00:00/area_stats_sync -d @area.geojson ``` +area_stats_univar for STRDS +``` +# async +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/modis_lst/strds/LST_Day_monthly/timestamp/2016-01-01T00:00:00/area_stats_univar_async -d @area.geojson + +# sync +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/modis_lst/strds/LST_Day_monthly/timestamp/2016-01-01T00:00:00/area_stats_univar_sync -d @area.geojson +``` + + ## Raster sampling Raster statistics of area ``` @@ -44,9 +54,17 @@ Univar raster statistics of area ``` curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/elevation/area_stats_univar_sync -d @area2.geojson ``` +``` +# async +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/landuse96_28m/sampling_async -d @points2.json +# sync +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/landuse96_28m/sampling_sync -d @points2.json +# note: sync doesn't run successfully (even though test_raste_sample.py passed all tests) +``` ## Vector sampling ``` curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/PERMANENT/vector_layers/nc_state/sampling_async -d @points2.json ``` + diff --git a/tests/test_raster_sample.py b/tests/test_raster_sample.py index f63d02d..e4d0134 100644 --- a/tests/test_raster_sample.py +++ b/tests/test_raster_sample.py @@ -80,7 +80,7 @@ def test_async_sampling(self): break time.sleep(0.2) - self.assertEquals(resp["status"], "finished", "Process not finished.") + self.assertEqual(resp["status"], "finished", "Process not finished.") self.assertEqual( rv.status_code, 200, @@ -101,7 +101,6 @@ def test_async_sampling(self): time.sleep(1) - """ def test_sync_sampling(self): # PROBLEM: Not yet returned! @@ -133,31 +132,6 @@ def test_sync_sampling(self): time.sleep(1) - def test_sync_sampling_geojson(self): - - rv = self.server.post( - f"{URL_PREFIX}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/" - "landuse96_28m/sampling_sync_geojson", - headers=self.user_auth_header, - data=json_dump(JSON), - content_type="application/json") - - self.assertEqual( - rv.status_code, 200, "HTML status code is wrong %i" - % rv.status_code) - self.assertEqual( - rv.mimetype, "application/json", "Wrong mimetype %s" % rv.mimetype) - - value_list = json_load(rv.data)["process_results"] - - self.assertEqual(value_list[0][0], "easting") - self.assertEqual(value_list[0][1], "northing") - self.assertEqual(value_list[0][2], "site_name") - self.assertEqual(value_list[0][3], "landuse96_28m") - self.assertEqual(value_list[0][4], "landuse96_28m_label") - self.assertEqual(value_list[0][5], "landuse96_28m_color") - """ - if __name__ == "__main__": unittest.main() diff --git a/tests/test_strds_area_stats_univar.py b/tests/test_strds_area_stats_univar.py index 1fbaa32..6224af9 100644 --- a/tests/test_strds_area_stats_univar.py +++ b/tests/test_strds_area_stats_univar.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- import unittest # import time -# from flask.json import loads as json_load -# from flask.json import dumps as json_dump +from flask.json import loads as json_load +from flask.json import dumps as json_dump -# try: -# from .test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX -# except Exception: -# from test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX +try: + from .test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX +except Exception: + from test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX __license__ = "GPLv3" __author__ = "Sören Gebbert" @@ -19,13 +19,14 @@ LOCATION = "nc_spm_08" MAPSET = "modis_lst" STRDS = "LST_Day_monthly" +TIMESTAMP = "2016-01-01T00:00:00" # TODO change coordinates JSON = { "type": "FeatureCollection", "crs": { "type": "name", - "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}, + "properties": {"name": "urn:x-ogc:def:crs:EPSG:3358"}, }, "features": [ { @@ -35,11 +36,11 @@ "type": "Polygon", "coordinates": [ [ - [7.756, 52.298157894736846], - [11.986947368421044, 51.657105263157924], - [9.550947368421047, 48.580052631578958], - [6.345684210526304, 48.836473684210539], - [7.756, 52.298157894736846], + [330000.0, 65000.0], + [331000.0, 65000.0], + [331000.0, 649000.0], + [330000.0, 649000.0], + [330000.0, 65000.0], ] ], }, @@ -47,13 +48,12 @@ ], } -""" + class STRDSAreaStatsUnivarTestCase(ActiniaResourceTestCaseBase): def test_async_raster_area_stats_json(self): rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2001-01-01T00:00:00/" + URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/" + f"{STRDS}/timestamp/{TIMESTAMP}/" "area_stats_univar_async", headers=self.admin_auth_header, data=json_dump(JSON), @@ -65,6 +65,7 @@ def test_async_raster_area_stats_json(self): 200, "HTML status code is wrong %i" % rv.status_code, ) + self.assertEqual( rv.mimetype, "application/json", "Wrong mimetype %s" % rv.mimetype ) @@ -73,13 +74,13 @@ def test_async_raster_area_stats_json(self): rv, headers=self.admin_auth_header )["process_results"] self.assertEqual(value_list[0]["cat"], "1") - self.assertEqual(value_list[0]["raster_number"], 209) + self.assertEqual(value_list[0]["raster_maximum"], 13781.) + self.assertEqual(value_list[0]["raster_number"], 1.0) def test_sync_raster_area_stats_1(self): rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2001-01-01T00:00:00/" + URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/" + f"{STRDS}/timestamp/{TIMESTAMP}/" "area_stats_univar_sync", headers=self.admin_auth_header, data=json_dump(JSON), @@ -97,13 +98,13 @@ def test_sync_raster_area_stats_1(self): value_list = json_load(rv.data)["process_results"] self.assertEqual(value_list[0]["cat"], "1") - self.assertEqual(value_list[0]["raster_number"], 209) + self.assertEqual(value_list[0]["raster_maximum"], 13781.) + self.assertEqual(value_list[0]["raster_number"], 1.0) def test_sync_raster_area_stats_2(self): rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2001-01-01T00:00:00/" + URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/" + f"{STRDS}/timestamp/{TIMESTAMP}/" "area_stats_univar_sync", headers=self.admin_auth_header, data=json_dump(JSON), @@ -121,13 +122,13 @@ def test_sync_raster_area_stats_2(self): value_list = json_load(rv.data)["process_results"] self.assertEqual(value_list[0]["cat"], "1") - self.assertEqual(value_list[0]["raster_number"], 209) + self.assertEqual(value_list[0]["raster_maximum"], 13781.) + self.assertEqual(value_list[0]["raster_number"], 1.0) def test_sync_raster_area_stats_error_no_map_found(self): rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2021-01-01T00:00:00/" + URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/" + f"{STRDS}/timestamp/{TIMESTAMP}/" "area_stats_univar_sync", headers=self.admin_auth_header, data=None, @@ -145,9 +146,8 @@ def test_sync_raster_area_stats_error_no_map_found(self): def test_sync_raster_area_stats_module_error(self): rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2001-01-01T00:00:00/" + URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/" + f"{STRDS}/timestamp/{TIMESTAMP}/" "area_stats_univar_sync", headers=self.admin_auth_header, data=json_dump({}), @@ -165,9 +165,8 @@ def test_sync_raster_area_stats_module_error(self): def test_sync_raster_area_stats_error_nodata(self): rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2001-01-01T00:00:00/" + URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/" + f"{STRDS}/timestamp/{TIMESTAMP}/" "area_stats_univar_sync", headers=self.admin_auth_header, data=None, @@ -185,9 +184,8 @@ def test_sync_raster_area_stats_error_nodata(self): def test_sync_raster_area_stats_error_wrong_timestamp(self): rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2001-01-01T00.00.00/" + URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/" + f"{STRDS}/timestamp/2001-01-01T00.00.00/" "area_stats_univar_sync", headers=self.admin_auth_header, data=json_dump(JSON), @@ -202,7 +200,6 @@ def test_sync_raster_area_stats_error_wrong_timestamp(self): self.assertEqual( rv.mimetype, "application/json", "Wrong mimetype %s" % rv.mimetype ) -""" if __name__ == "__main__":