コード例 #1
0
    def test_viewing_service(self, m):

        collection_org = COLLECTIONS[2]
        collection_id = collection_org["product_id"]
        collection_url = "{}/data/{}".format(self.endpoint, collection_id)

        def match_graph(request):
            self.assertDictEqual(
                {
                    "custom_param": 45,
                    "process_graph": {
                        'product_id': 'COPERNICUS/S2'
                    },
                    "type": 'WMTS',
                    "title": "My Service",
                    "description": "Service description"
                }, request.json())
            return True

        m.get(collection_url, json=collection_org)
        m.post("http://localhost:8000/api/services",
               json={},
               additional_matcher=match_graph)

        session = openeo.session(self.user_id, endpoint=self.endpoint)

        resp = session.image(collection_id)
        resp.tiled_viewing_service(type="WMTS",
                                   title="My Service",
                                   description="Service description",
                                   custom_param=45)
コード例 #2
0
    def test_timeseries_fusion(self):
        #configuration phase: define username, endpoint, parameters?
        session = openeo.session("driesj")

        s2_radio = session.imagecollection("SENTINEL2_RADIOMETRY_10M")
        probav_radio = session.imagecollection("PROBA_V_RADIOMETRY_100M")

        #we want to get data at fixed days of month, in roughly 10-daily periods,
        s2_radio.temporal_composite(method="day_of_month",
                                    resampling="nearest",
                                    days=[1, 11, 21])
        probav_radio.temporal_composite(method="day_of_month",
                                        resampling="nearest",
                                        days=[1, 11, 21])

        #how do pixels get aligned?
        #option 1: resample PROBA-V to S2
        probav_radio.resample(s2_radio.layout)

        #option 2: create lookup table/transformation that maps S2 pixel coordinate to corresponding PROBA-V pixel?
        #this does add a bunch of complexity, resampling is easier, but maybe requires more resources?

        #combine timeseries, assumes pixels are aligned?
        fused_timeseries = openeo.timeseries_combination(
            [s2_radio, probav_radio])

        fused_timeseries.timeseries(4, 51)
コード例 #3
0
 def test_user_delete_file(self, m):
     delete_url = "{}/users/{}/files/{}".format(self.endpoint, self.user_id,
                                                self.upload_remote_fname)
     m.register_uri('DELETE', delete_url)
     session = openeo.session(self.user_id, endpoint=self.endpoint)
     session.auth(self.auth_id, self.auth_pwd)
     status = session.user_delete_file(self.upload_remote_fname)
     assert status
コード例 #4
0
    def user_jobs(self, m):

        collection_url = "{}/users/{}/jobs".format(self.endpoint, self.user_id)
        m.register_uri('GET', collection_url, json=PROCESSES)

        session = openeo.session(self.user_id, endpoint=self.endpoint)

        resp = session.user_jobs()

        assert resp == PROCESSES
コード例 #5
0
    def test_job_creation(self, m):
        m.get("http://localhost:8000/api/auth/login", json={"token": "blabla"})
        m.post("http://localhost:8000/api/jobs?evaluate=lazy",
               json={"job_id": "748df7caa8c84a7ff6e"})

        session = openeo.session(self.uiser_id, endpoint=self.endpoint)
        session.auth(self.auth_id, self.auth_pwd)

        job_id = session.create_job(POST_DATA)
        self.assertIsNotNone(job_id)
コード例 #6
0
 def test_user_upload_file(self, m):
     upload_url = "{}/files/{}/{}".format(self.endpoint, self.user_id,
                                          self.upload_remote_fname)
     m.register_uri('PUT',
                    upload_url,
                    additional_matcher=self.match_uploaded_file)
     session = openeo.session(self.user_id, endpoint=self.endpoint)
     session.auth(self.auth_id, self.auth_pwd)
     status = session.user_upload_file(self.upload_local_fname,
                                       remote_path=self.upload_remote_fname)
     assert status
コード例 #7
0
    def test_viewing_userjobs(self, m):
        m.get("http://localhost:8000/api/auth/login", json={"token": "blabla"})
        m.get("http://localhost:8000/api/users/%s/jobs" % self.uiser_id,
              json=[{
                  "job_id": "748df7caa8c84a7ff6e"
              }])

        session = openeo.session(self.uiser_id, endpoint=self.endpoint)
        session.auth(self.auth_id, self.auth_pwd)
        userjobs = session.user_jobs()

        self.assertGreater(len(userjobs), 0)
コード例 #8
0
    def test_monthly_aggregation(self):
        from openeo.temporal import MONTH_OF_YEAR
        session = openeo.session("driesj")
        s2_radio = session.imagecollection("SENTINEL2_RADIOMETRY_10M")

        #how to find out which bands I need?
        #are band id's supposed to be consistent across endpoints? Is that possible?

        #define a computation to perform
        #combinebands to REST: udf_type:apply_pixel, lang: Python
        bandFunction = lambda timeseries: {
            #timeseries is an xarray dataarray
        }
        ndvi_coverage = s2_radio.aggregate_time(MONTH_OF_YEAR, bandFunction)
コード例 #9
0
 def test_user_download_file(self, m):
     download_url = "http://localhost:8000/api/users/{}/files/{}".format(
         self.user_id, self.upload_remote_fname)
     with open(self.upload_local_fname, 'rb') as response_file:
         content = response_file.read()
     m.get(download_url, content=content)
     session = openeo.session(self.user_id, endpoint=self.endpoint)
     session.auth(self.auth_id, self.auth_pwd)
     local_output_fname = tempfile.NamedTemporaryFile()
     status = session.user_download_file(self.upload_remote_fname,
                                         local_output_fname.name)
     assert status
     with open(local_output_fname.name, 'rb') as downloaded_file:
         downloaded_content = downloaded_file.read()
     assert content == downloaded_content
コード例 #10
0
    def test_viewing_processes(self, m):
        m.get("http://localhost:8000/api/processes",
              json=[{
                  "process_id": "calculate_ndvi"
              }])
        m.get("http://localhost:8000/api/processes/calculate_ndvi",
              json={"process_id": "calculate_ndvi"})

        session = openeo.session(self.uiser_id, endpoint=self.endpoint)
        processes = session.get_all_processes()

        self.assertGreater(str(processes).find(self.process_id), -1)

        process_info = session.get_process(self.process_id)

        self.assertEqual(process_info["process_id"], self.process_id)
コード例 #11
0
    def test_viewing_data(self, m):
        m.get("http://localhost:8000/api/data",
              json=[{
                  "product_id": "sentinel2_subset"
              }])
        m.get("http://localhost:8000/api/data/sentinel2_subset",
              json={"product_id": "sentinel2_subset"})

        session = openeo.session(self.uiser_id, endpoint=self.endpoint)
        data = session.list_collections()

        self.assertGreater(str(data).find(self.data_id), -1)

        data_info = session.get_collection(self.data_id)

        self.assertEqual(data_info["product_id"], self.data_id)
コード例 #12
0
import openeo
import logging

#enable logging in requests library
logging.basicConfig(level=logging.DEBUG)

#connect with EURAC backend
session = openeo.session("nobody", "http://saocompute.eurac.edu/openEO_WCPS_Driver/openeo")

#retrieve the list of available collections
collections = session.list_collections()
print(collections)

#create image collection
s2_fapar = session.image("S2_L2A_T32TPS_20M")

#specify process graph
download = s2_fapar \
    .date_range_filter("2016-01-01","2016-03-10") \
    .bbox_filter(left=652000,right=672000,top=5161000,bottom=5181000,srs="EPSG:32632") \
    .max_time() \
    .download("/tmp/openeo-wcps.geotiff",format="netcdf")
print(download)
コード例 #13
0
from openeo import ImageCollection

import openeo
import logging
import os
from pathlib import Path
import pandas as pd

#enable logging in requests library
from openeo.rest.imagecollectionclient import ImageCollectionClient

logging.basicConfig(level=logging.DEBUG)

#connect with EURAC backend
session = openeo.session("nobody", "http://openeo.vgt.vito.be/openeo/0.4.0")
#session = openeo.session("nobody", "http://localhost:5000/openeo/0.4.0")

#retrieve the list of available collections
collections = session.list_collections()
print(collections)

#create image collection

#specify process graph
#compute cloud mask
"""
cloud_mask = session.image("S2_SCENECLASSIFICATION") \
    .filter_temporal("2017-03-01","2017-02-20") \
    .filter_bbox(west=652000,east=672000,north=5161000,south=5181000,crs="EPSG:32632") \
    .apply_pixel(map_classification_to_binary)
コード例 #14
0
    def test_ndvi_udf(self, m):
        #configuration phase: define username, endpoint, parameters?
        session = openeo.session("driesj",
                                 endpoint="http://localhost:8000/api")
        session.post = MagicMock()
        session.download = MagicMock()

        m.get("http://localhost:8000/api/data",
              json=[{
                  "product_id": "sentinel2_subset"
              }])
        m.get("http://localhost:8000/api/data/SENTINEL2_RADIOMETRY_10M",
              json={
                  "product_id":
                  "sentinel2_subset",
                  "bands": [{
                      'band_id': 'B0'
                  }, {
                      'band_id': 'B1'
                  }, {
                      'band_id': 'B2'
                  }, {
                      'band_id': 'B3'
                  }],
                  'time': {
                      'from': '2015-06-23',
                      'to': '2018-06-18'
                  }
              })

        #discovery phase: find available data
        #basically user needs to find available data on a website anyway?
        #like the imagecollection ID on: https://earthengine.google.com/datasets/

        #access multiband 4D (x/y/time/band) coverage
        s2_radio = session.imagecollection("SENTINEL2_RADIOMETRY_10M")

        #dir = os.path.dirname(openeo_udf.functions.__file__)
        #file_name = os.path.join(dir, "raster_collections_ndvi.py")
        #udf_code = UdfCode(language="python", source=open(file_name, "r").read())

        ndvi_coverage = s2_radio.apply_tiles(
            "def myfunction(tile): print(tile)")

        #materialize result in the shape of a geotiff
        #REST: WCS call
        ndvi_coverage.download("out.geotiff",
                               bbox="",
                               time=s2_radio.dates['to'])

        #get result as timeseries for a single point
        #How to define a point? Ideally it should also have the CRS?
        ndvi_coverage.timeseries(4, 51)

        expected_graph = {
            'process_graph': {
                'process_id': 'apply_tiles',
                'args': {
                    'imagery': {
                        'collection_id': 'SENTINEL2_RADIOMETRY_10M'
                    },
                    'code': {
                        'language': 'python',
                        'source': 'def myfunction(tile): print(tile)'
                    }
                }
            }
        }
        session.post.assert_called_once_with(
            "/timeseries/point?x=4&y=51&srs=EPSG:4326", expected_graph)
        session.download.assert_called_once()
コード例 #15
0
    def test_ndvi(self, m):
        #configuration phase: define username, endpoint, parameters?
        session = openeo.session("driesj",
                                 endpoint="http://localhost:8000/api")
        session.post = MagicMock()
        session.download = MagicMock()

        m.get("http://localhost:8000/api/data",
              json=[{
                  "product_id": "sentinel2_subset"
              }])
        m.get("http://localhost:8000/api/data/SENTINEL2_RADIOMETRY_10M",
              json={
                  "product_id":
                  "sentinel2_subset",
                  "bands": [{
                      'band_id': 'B0'
                  }, {
                      'band_id': 'B1'
                  }, {
                      'band_id': 'B2'
                  }, {
                      'band_id': 'B3'
                  }],
                  'time': {
                      'from': '2015-06-23',
                      'to': '2018-06-18'
                  }
              })

        #discovery phase: find available data
        #basically user needs to find available data on a website anyway?
        #like the imagecollection ID on: https://earthengine.google.com/datasets/

        #access multiband 4D (x/y/time/band) coverage
        s2_radio = session.imagecollection("SENTINEL2_RADIOMETRY_10M")

        #how to find out which bands I need?
        #are band id's supposed to be consistent across endpoints? Is that possible?

        #define a computation to perform
        #combinebands to REST: udf_type:apply_pixel, lang: Python
        bandFunction = lambda band1, band2, band3: band1 + band2
        ndvi_coverage = s2_radio.apply_pixel(
            [s2_radio.bands[0], s2_radio.bands[1], s2_radio.bands[2]],
            bandFunction)

        #materialize result in the shape of a geotiff
        #REST: WCS call
        ndvi_coverage.download("out.geotiff",
                               bbox="",
                               time=s2_radio.dates['to'])

        #get result as timeseries for a single point
        #How to define a point? Ideally it should also have the CRS?
        ndvi_coverage.timeseries(4, 51)

        import base64
        import cloudpickle
        expected_function = str(
            base64.b64encode(cloudpickle.dumps(bandFunction)), "UTF-8")
        expected_graph = {
            'process_graph': {
                'process_id': 'apply_pixel',
                'args': {
                    'imagery': {
                        'collection_id': 'SENTINEL2_RADIOMETRY_10M'
                    },
                    'bands': ['B0', 'B1', 'B2'],
                    'function': expected_function
                }
            }
        }
        session.post.assert_called_once_with(
            "/timeseries/point?x=4&y=51&srs=EPSG:4326", expected_graph)
        session.download.assert_called_once()
コード例 #16
0
import openeo
import logging
import time

logging.basicConfig(level=logging.DEBUG)

GEE_DRIVER_URL = "http://127.0.0.1:8080"

OUTPUT_FILE = "/tmp/openeo_gee_output.png"

#connect with GEE backend
session = openeo.session("nobody", GEE_DRIVER_URL)

#retrieve the list of available collections
coperincus_s2_image = session.image("COPERNICUS/S2")
logging.debug(coperincus_s2_image.graph)

timeseries = coperincus_s2_image.bbox_filter(left=9.0,
                                             right=9.1,
                                             top=12.1,
                                             bottom=12.0,
                                             srs="EPSG:4326")
logging.debug(timeseries.graph)
timeseries = timeseries.date_range_filter("2017-01-01", "2017-01-31")
logging.debug(timeseries.graph)
timeseries = timeseries.ndvi("B4", "B8")
logging.debug(timeseries.graph)
timeseries = timeseries.min_time()
logging.debug(timeseries.graph)
timeseries = timeseries.stretch_colors(-1, 1)
logging.debug(timeseries.graph)
コード例 #17
0
from openeo import ImageCollection

import openeo
import logging
import os
from pathlib import Path

#enable logging in requests library
from openeo.rest.imagecollectionclient import ImageCollectionClient

logging.basicConfig(level=logging.DEBUG)

#connect with EURAC backend
#session = openeo.session("nobody", "http://openeo.vgt.vito.be/openeo/0.4.0")
session = openeo.session("nobody", "http://localhost:5000/openeo/0.4.0")

#retrieve the list of available collections
collections = session.list_collections()
print(collections)

#create image collection


#specify process graph
#compute cloud mask

"""
cloud_mask = session.image("S2_SCENECLASSIFICATION") \
    .date_range_filter("2017-03-01","2017-02-20") \
    .bbox_filter(left=652000,right=672000,top=5161000,bottom=5181000,srs="EPSG:32632") \
コード例 #18
0
    def test_user_login(self, m):
        m.get("http://localhost:8000/api/auth/login", json={"token": "blabla"})

        session = openeo.session(self.uiser_id, endpoint=self.endpoint)
        token = session.auth(self.auth_id, self.auth_pwd)
        self.assertNotEqual(token, None)