Esempio n. 1
0
def test_metadata_load_collection_040(session040, requests_mock):
    requests_mock.get(API_URL + "/collections/SENTINEL2",
                      json={
                          "properties": {
                              "cube:dimensions": {
                                  "bands": {
                                      "type": "bands",
                                      "values": ["B2", "B3"]
                                  }
                              },
                              "eo:bands": [
                                  {
                                      "name": "B2",
                                      "common_name": "blue"
                                  },
                                  {
                                      "name": "B3",
                                      "common_name": "green"
                                  },
                              ]
                          }
                      })
    im = ImageCollectionClient.load_collection('SENTINEL2', session=session040)
    assert im.metadata.bands == [
        openeo.metadata.Band("B2", "blue", None),
        openeo.metadata.Band("B3", "green", None)
    ]
Esempio n. 2
0
    def load_collection(
        self,
        collection_id: str,
        spatial_extent: Optional[Dict[str, float]] = None,
        temporal_extent: Optional[List[Union[str, datetime.datetime,
                                             datetime.date]]] = None,
        bands: Optional[List[str]] = None,
        properties: Optional[Dict[str, Union[str, PGNode, Callable]]] = None
    ) -> DataCube:
        """
        Load a DataCube by collection id.

        :param collection_id: image collection identifier
        :param spatial_extent: limit data to specified bounding box or polygons
        :param temporal_extent: limit data to specified temporal interval
        :param bands: only add the specified bands
        :param properties: limit data by metadata property predicates
        :return: a datacube containing the requested data
        """
        if self._api_version.at_least("1.0.0"):
            return DataCube.load_collection(collection_id=collection_id,
                                            connection=self,
                                            spatial_extent=spatial_extent,
                                            temporal_extent=temporal_extent,
                                            bands=bands,
                                            properties=properties)
        else:
            return ImageCollectionClient.load_collection(
                collection_id=collection_id,
                session=self,
                spatial_extent=spatial_extent,
                temporal_extent=temporal_extent,
                bands=bands)
Esempio n. 3
0
def eodc_script(output_filename):
    """
    
    """

    backend_url = 'https://openeo.eodc.eu'

    session = openeo.connect(backend_url,
                             auth_type='basic',
                             auth_options={
                                 "username": os.environ["EODC_USERNAME"],
                                 "password": os.environ["EODC_PASSWORD"]
                             })
    minx = 11.279182434082033
    maxx = 11.406898498535158
    maxy = 46.522729291844286
    miny = 46.464349400461145
    epsg = "EPSG:4326"
    spatial_extent = {
        'west': minx,
        'east': maxx,
        'north': maxy,
        'south': miny,
        'crs': epsg
    }

    temporal_extent = ["2018-06-04T00:00:00.000Z", "2018-06-23T00:00:00.000Z"]

    spectral_extent = [8, 4, 2]

    s2a = ImageCollectionClient.load_collection(
        session=session,
        collection_id='s2a_prd_msil1c',
        temporal_extent=temporal_extent,
        spatial_extent=spatial_extent,
        bands=spectral_extent)
    s2b = s2a.load_collection(session=session,
                              collection_id='s2b_prd_msil1c',
                              temporal_extent=temporal_extent,
                              spatial_extent=spatial_extent,
                              bands=spectral_extent)
    s2_radiometry = s2a.merge(s2b)

    #s2_radiometry =
    B02 = s2_radiometry.band(2)
    B04 = s2_radiometry.band(1)
    B08 = s2_radiometry.band(0)

    evi_cube = (2.5 * (B08 - B04)) / ((B08 + 6.0 * B04 - 7.5 * B02) + 10000)

    min_evi = evi_cube.min_time()

    output = min_evi.download(output_filename, format="GTiff")
Esempio n. 4
0
    def load_collection(self, collection_id: str,
                        **kwargs) -> ImageCollectionClient:
        """
        Load an image collection by collection id

        see :py:meth:`openeo.rest.imagecollectionclient.ImageCollectionClient.load_collection`
        for available arguments.

        :param collection_id: image collection identifier (string)
        :return: ImageCollectionClient
        """
        return ImageCollectionClient.load_collection(
            collection_id=collection_id, session=self, **kwargs)
Esempio n. 5
0
    def load_collection(self, collection_id: str, **kwargs) -> Union[ImageCollectionClient, DataCube]:
        """
        Load an image collection by collection id

        see :py:meth:`openeo.rest.imagecollectionclient.ImageCollectionClient.load_collection`
        for available arguments.

        :param collection_id: image collection identifier (string)
        :return: ImageCollectionClient
        """
        if self._api_version.at_least("1.0.0"):
            return DataCube.load_collection(collection_id=collection_id, connection=self, **kwargs)
        else:
            return ImageCollectionClient.load_collection(collection_id=collection_id, session=self, **kwargs)
Esempio n. 6
0
def eurac_script(input_data, output_filename):
    """
    
    """

    backend_url = 'https://openeo.eurac.edu'

    if input_data == 'L1C':
        collection_id = 'openEO_S2_32632_10m_L1C_D22'
    elif input_data == 'L2A':
        collection_id = 'openEO_S2_32632_10m_L2A_D22'

    session = openeo.connect(backend_url,
                             auth_type='basic',
                             auth_options={
                                 "username": os.environ["EURAC_USERNAME"],
                                 "password": os.environ["EURAC_PASSWORD"]
                             })

    minx = 11.279182434082033
    maxx = 11.406898498535158
    maxy = 46.522729291844286
    miny = 46.464349400461145
    epsg = "EPSG:4326"

    s2_radiometry = ImageCollectionClient.load_collection(
        session=session,
        collection_id=collection_id,
        temporal_extent=[
            "2018-06-04T00:00:00.000Z", "2018-06-23T00:00:00.000Z"
        ],
        spatial_extent={
            'west': minx,
            'east': maxx,
            'north': maxy,
            'south': miny,
            'crs': epsg
        },
        bands=["B08", "B04", "B02"])
    B02 = s2_radiometry.band(2)
    B04 = s2_radiometry.band(1)
    B08 = s2_radiometry.band(0)

    evi_cube = (2.5 * (B08 - B04)) / ((B08 + 6.0 * B04 - 7.5 * B02) + 10000)

    min_evi = evi_cube.min_time()

    output = min_evi.download(output_filename, format="GTiff")
Esempio n. 7
0
def vito_script(input_data, output_filename):
    """
    
    """

    backend_url = 'https://openeo.vito.be/openeo/0.4.2'

    if input_data == 'L1C':
        collection_id = 'SENTINEL2_L1C_SENTINELHUB'
    elif input_data == 'L2A':
        collection_id = 'SENTINEL2_L2A_SENTINELHUB'

    session = openeo.connect(backend_url)

    minx = 11.279182434082033
    maxx = 11.406898498535158
    maxy = 46.522729291844286
    miny = 46.464349400461145
    epsg = "EPSG:4326"
    spatial_extent = {
        'west': minx,
        'east': maxx,
        'north': maxy,
        'south': miny,
        'crs': epsg
    }

    temporal_extent = ["2018-06-04T00:00:00.000Z", "2018-06-22T00:00:00.000Z"]

    spectral_extent = ["B08", "B04", "B02"]

    s2_radiometry = ImageCollectionClient.load_collection(
        session=session,
        collection_id=collection_id,
        temporal_extent=temporal_extent,
        spatial_extent=spatial_extent)

    B02 = s2_radiometry.band(spectral_extent[2])
    B04 = s2_radiometry.band(spectral_extent[1])
    B08 = s2_radiometry.band(spectral_extent[0])

    evi_cube = (2.5 * (B08 - B04)) / ((B08 + 6.0 * B04 - 7.5 * B02) + 1.0)

    min_evi = evi_cube.min_time()

    output = min_evi.download(output_filename, format="GeoTiff")
Esempio n. 8
0
def sinergise_script(output_filename):
    """
    
    """

    backend_url = 'https://e3oind87n9.execute-api.eu-central-1.amazonaws.com/production/'
    #'https://openeo.sentinel-hub.com/production'
    collection_id = 'S2L1C'

    session = openeo.connect(backend_url)

    minx = 11.279182434082033
    maxx = 11.406898498535158
    maxy = 46.522729291844286
    miny = 46.464349400461145
    epsg = "EPSG:4326"
    spatial_extent = {
        'west': minx,
        'east': maxx,
        'north': maxy,
        'south': miny,
        'crs': epsg
    }

    temporal_extent = ["2018-06-04T00:00:00.000Z", "2018-06-23T00:00:00.000Z"]

    spectral_extent = ["B08", "B04", "B02"]

    s2_radiometry = ImageCollectionClient.load_collection(
        session=session,
        collection_id=collection_id,
        temporal_extent=temporal_extent,
        spatial_extent=spatial_extent)

    B02 = s2_radiometry.band(spectral_extent[2])
    B04 = s2_radiometry.band(spectral_extent[1])
    B08 = s2_radiometry.band(spectral_extent[0])

    evi_cube = (2.5 * (B08 - B04)) / ((B08 + 6.0 * B04 - 7.5 * B02) + 1.0)

    min_evi = evi_cube.min_time()

    min_evi.download(output_filename,
                     format="GTiff",
                     options={"datatype": "float32"})
Esempio n. 9
0
def mundialis_script(output_filename):
    """
    
    """

    backend_url = 'https://openeo.mundialis.de'

    collection_id = 'utm32n.openeo_bolzano.strds.openeo_bolzano_S2'

    session = openeo.connect(backend_url,
                             auth_type='basic',
                             auth_options={
                                 "username": os.environ["MUNDIALIS_USERNAME"],
                                 "password": os.environ["MUNDIALIS_PASSWORD"]
                             })

    minx = 11.279182434082033
    maxx = 11.406898498535158
    maxy = 46.522729291844286
    miny = 46.464349400461145
    epsg = "EPSG:4326"

    s2_radiometry = ImageCollectionClient.load_collection(
        session=session,
        collection_id=collection_id,
        temporal_extent=[
            "2018-06-04T00:00:00.000Z", "2018-06-23T00:00:00.000Z"
        ],
        spatial_extent={
            'west': minx,
            'east': maxx,
            'north': maxy,
            'south': miny,
            'crs': epsg
        })
    B02 = s2_radiometry.band("S2_2")
    B04 = s2_radiometry.band("S2_4")
    B08 = s2_radiometry.band("S2_8")

    evi_cube = (2.5 * (B08 - B04)) / ((B08 + 6.0 * B04 - 7.5 * B02) + 10000)

    min_evi = evi_cube.min_time()

    output = min_evi.download(output_filename, format="GTiff")
Esempio n. 10
0
maxx = 10.62927246093749
maxy = 46.84516443029275
miny = 46.72574176193996
epsg = "EPSG:4326"
spatial_extent = {'west':minx,'east':maxx,'north':maxy,'south':miny,'crs':epsg}
temporal_extent=["2018-05-01T00:00:00.000Z","2018-10-01T00:00:00.000Z"]

# To find the band names in GRASS GIS: `g.bands pattern="S2"`
spectral_extent = ["S2_8", "S2_4", "S2_2"]

# connect to mundialis backend
session = openeo.connect(backend_url).authenticate_basic(auth_id, password = auth_pwd)

# TODO change to s2_radiometry = session.load_collection( ...)
s2_radiometry = ImageCollectionClient.load_collection(
                    session=session,
                    collection_id=collection_id,
                    temporal_extent=temporal_extent,
                    spatial_extent=spatial_extent
                    )            
# g.bands pattern="S2"
B02 = s2_radiometry.band("S2_2")
B04 = s2_radiometry.band("S2_4")
B08 = s2_radiometry.band("S2_8")

evi_cube = (2.5 * (B08 - B04)) / ((B08 + 6.0 * B04 - 7.5 * B02) + 10000)

min_evi = evi_cube.min_time()

output = min_evi.download_results("min-evi_mundialis.tiff",format="GTiff")
Esempio n. 11
0
def execute(
    out_dir,
    user,
    password,
    provider,
    driver_url,
    image_collection,
    all_bands,
    bands,
    band_format,
    bbox_string,
    temporal_extent,
):
    """
    Identification:
    Name -- OpenEO PoC
    Description -- Retrieve Sentinel 2 bands in GeoTIFF
    Version -- 1-hbo
    Author -- Alexander Jacob, Eurac Research, openEO
    Mission -- hackathon
    
    Inputs:
    user -- User -- 45/User String -- openeo
    password -- Password -- 45/User String -- XXXXXXXXX
    provider -- Provider -- 45/User String -- mundialis
    driver_url -- Driver URL -- 45/User String -- https://openeo.mundialis.de
    image_collection -- Image Collection -- 45/User String -- utm32n.openeo_bolzano.strds.openeo_bolzano_S2
    all_bands -- Bands -- 45/User String -- B02 B03 B04 B05 B06 B07 B8A B11 B12
    bands -- Bands -- 45/User String -- B03 B11
    band_format -- Band Format -- 45/User String -- GTiff
    bbox_string -- BBox -- 45/User String -- 10.446624755859375, 46.72574176193996, 10.629272460937498, 46.845164430292755
    temporal_extent -- Temporal Extent -- 44/DateRange -- 2018-05-01T00:00:00.000Z/2018-10-01T00:00:00.000Z
    
    Outputs:
    band_dir -- Band Directory -- 45/User String
    band_files -- Band Files -- 45/User String
    out_dir -- directory to store output
    
    Main Dependency:
    python-3

    Software Dependencies:
    openeo-0.4
    
    Processing Resources:
    ram -- 1
    disk -- 10
    cpu -- 1
    """
    all_bands = all_bands.split()
    bands = bands.split()
    temporal_extent = temporal_extent.split("/")
    west, south, east, north = list(
        map(lambda value: value.strip(), bbox_string.split(",")))
    bbox = {"west": west, "east": east, "south": south, "north": north}
    logger.info("Demo user: %s", user)
    logger.info("Provider: %s with driver URL %s", provider, driver_url)
    logger.info("Image Collection: %s", image_collection)
    logger.info("Bands: %s", bands)
    logger.info(
        "Using BBox in str format - raw input (west, south, east, north): %s",
        bbox_string)
    logger.info("BBox: %s", bbox)
    logger.info("Temporal extent in string format start/end: %s",
                temporal_extent)
    connection = openeo.connect(driver_url)
    connection.authenticate_basic(user, password)

    logger.info(
        "describe_collection('%s'):\n %s\n",
        image_collection,
        json.dumps(connection.describe_collection(image_collection), indent=2),
    )
    # TODO: change to con.load_collection()
    cube = ImageCollectionClient.load_collection(
        session=connection, collection_id=image_collection, bands=all_bands)
    cube = cube.filter_bbox(**bbox)
    cube = cube.filter_temporal(extent=temporal_extent)

    logger.info("cube.to_json: \n%s\n", cube.to_json())

    logger.info("File Format: %s", band_format)
    logger.info(
        "File Name Format: {provider}.{image_collection}.{west}.{south}.{east}.{north}."
        "{temporal_extent[0]}.{temporal_extent[1]}.B{band.zfill(2)}.{band_format}"
    )
    band_dir = out_dir
    logger.info("Downloading bands in %s", out_dir)
    band_files = []
    for band in bands:
        cube_band = cube.band(band)
        band_file = (
            f"{provider}.{image_collection}.{west}.{south}.{east}.{north}."
            f"{temporal_extent[0]}.{temporal_extent[1]}.B{band.zfill(2)}.{band_format.lower()}"
        )
        logger.info("Downloading band %s: %s", band, band_file)
        band_path = f"{out_dir}/{band_file}"
        band_files.append(band_file)
        logger.info("Starting download at %s", datetime.now())
        cube_band.download(band_path, format=band_format)
        logger.info("Download finished for band %s at %s", band,
                    datetime.now())

    logger.info("Downloads finished at %s", datetime.now())

    return {"band_dir": band_dir, "band_files": band_files}