def test_strds_info(self):
        iface = ActiniaInterface(self.gconf)
        status, info = iface.layer_info(
            layer_name="latlong_wgs84.modis_ndvi_global.strds.ndvi_16_5600m")
        pprint(info)

        self.assertEqual(status, 200)
        self.assertTrue("temporal_type" in info)
        self.assertTrue("aggregation_type" in info)
        self.assertTrue("creation_time" in info)
        self.assertTrue("creator" in info)
        self.assertTrue("granularity" in info)
        self.assertTrue("modification_time" in info)
        self.assertTrue("number_of_maps" in info)
Exemple #2
0
def create_process_chain_entry(data_object: DataObject,
                               output_object: DataObject):
    """Create a Actinia process description that uses t.rast.series
       and r.mapcalc to create a multilayer mask.

    :param data_object: The input time series object
    :param output_object: The name of the output raster map
    :return: A Actinia process chain description
    """

    output_temp_object = DataObject(name=f"{output_object.name}_temp",
                                    datatype=GrassDataType.RASTER)

    # get number of maps in input_time_series
    iface = ActiniaInterface()
    # this is not working because the input object might not yet exist
    status_code, layer_data = iface.layer_info(
        layer_name=data_object.grass_name())
    if status_code != 200:
        return make_response(
            jsonify(
                {
                    "description":
                    "An internal error occurred "
                    "while catching GRASS GIS layer information "
                    "for layer <%s>!\n Error: %s"
                    "" % (data_object, str(layer_data))
                }, 400))
    nmaps = layer_data['number_of_maps']

    rn = randint(0, 1000000)

    pc = [{
        "id":
        "t_rast_series_%i" % rn,
        "module":
        "t.rast.series",
        "inputs": [{
            "param": "input",
            "value": data_object.grass_name()
        }, {
            "param": "method",
            "value": "count"
        }, {
            "param": "output",
            "value": output_temp_object.grass_name()
        }],
        "flags":
        "t"
    }, {
        "id":
        "r_mapcalc_%i" % rn,
        "module":
        "r.mapcalc",
        "inputs": [{
            "param": "expression",
            "value": "%(result)s = int(if(%(raw)s < %(nmaps)s, 1, 0))" % {
                "result": output_object.grass_name(),
                "raw": output_temp_object.grass_name(),
                "nmaps": str(nmaps)
            }
        }],
    }]
    # g.remove raster name=output_name_tmp -f ?

    return pc
Exemple #3
0
class CollectionInformationResource(Resource):

    def __init__(self):
        self.iface = ActiniaInterface()

    def get(self, name):

        # List strds maps from the GRASS location
        location, mapset, datatype, layer = self.iface.layer_def_to_components(
            name)

        if location == "stac":
            status_code, collection = self.iface.get_stac_collection(name=name)
            if status_code != 200:
                return make_response(
                    jsonify(
                        {
                            "id": "12345678",
                            "code": "Internal",
                            "message": "Server error: %s" %
                            (name),
                            "links": {}}),
                    500)

            # Not using CollectionInformation model here for now
            # as valid STAC collections comply.
            # Using it here might omit some properties
            # which are not modelled in this backend (e.g. assets)
            return make_response(collection, 200)

        status_code, layer_data = self.iface.layer_info(layer_name=name)
        if status_code != 200:
            return make_response(
                jsonify(
                    {
                        "id": "12345678",
                        "code": "CollectionNotFound",
                        "message": "Collection '%s' does not exist." %
                        (name),
                        "links": {}}),
                404)

        # Get the projection from the GRASS mapset
        status_code, mapset_info = self.iface.mapset_info(
            location=location, mapset=mapset)
        if status_code != 200:
            return make_response(
                jsonify(
                    {
                        "id": "12345678",
                        "code": "Internal",
                        "message": "Server error: %s" %
                        (mapset_info),
                        "links": {}}),
                500)

        extent = CollectionExtent(
            spatial=(
                float(
                    layer_data["west"]), float(
                    layer_data["south"]), float(
                    layer_data["east"]), float(
                        layer_data["north"])), temporal=(
                            "1900-01-01T00:00:00", "2100-01-01T00:00:00"))

        title = "Raster dataset"
        bands = []
        dimensions = {"x": {
            "type": "spatial",
            "axis": "x",
            "extent": [layer_data["west"], layer_data["east"]],
            "reference_system": mapset_info["projection"]
        },
            "y": {
            "type": "spatial",
            "axis": "y",
            "extent": [layer_data["south"], layer_data["north"]],
            "reference_system": mapset_info["projection"]
        },
        }
        platform = "unknown"
        instrument = "unknown"
        if datatype.lower() == "strds":
            title = "Space time raster dataset"

            start_time = layer_data["start_time"]
            end_time = layer_data["end_time"]

            if start_time:
                start_time = start_time.replace(
                    " ",
                    "T").replace(
                    "'",
                    "").replace(
                    '"',
                    '')

            if end_time:
                end_time = end_time.replace(
                    " ",
                    "T").replace(
                    "'",
                    "").replace(
                    '"',
                    '')

            dimensions['t'] = {"type": "temporal",
                               "extent": [start_time, end_time]
                               }

            extent = CollectionExtent(
                spatial=(
                    float(
                        layer_data["west"]), float(
                        layer_data["south"]), float(
                        layer_data["east"]), float(
                        layer_data["north"])), temporal=(
                            start_time, end_time))

            if "semantic_labels" in layer_data:
                bandlist = layer_data["semantic_labels"].split(',')
                dimensions['bands'] = {"type": "bands",
                                       "values": bandlist
                                       }
                for bandname in bandlist:
                    # not so nice, better use different name and common_name
                    # waiting for GRASS GIS
                    bands.append(EOBands(name=bandname, common_name=bandname))

                # get platform and sensor
                # see
                # https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md#platform
                # https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md#instruments
                if "_" in bandlist[0]:
                    sensor_abbr = bandlist[0].split('_')[0]
                    if sensor_abbr == "L5":
                        platform = "landsat-5"
                        instrument = "tm, mss"
                    elif sensor_abbr == "L7":
                        platform = "landsat-7"
                        instrument = "etm+"
                    elif sensor_abbr == "L8":
                        platform = "landsat-8"
                        instrument = "oli, trs"
                    elif sensor_abbr == "S1":
                        platform = "sentinel-1"
                        instrument = "c-sar"
                    elif sensor_abbr == "S2":
                        platform = "sentinel-2"
                        instrument = "msi"

        if datatype.lower() == "vector":
            title = "Vector dataset"

        description = "GRASS GIS location/mapset path: /%s/%s" % (
            location, mapset)
        crs = mapset_info["projection"]

        coordinate_transform_extent_to_EPSG_4326(crs=crs, extent=extent)

        # GRASS / actinia do not yet report platform and instrument
        properties = (CollectionProperties(eo_platform=platform,
                                           eo_instrument=instrument,
                                           eo_bands=bands))

        ci = CollectionInformation(id=name, title=title,
                                   description=description,
                                   extent=extent,
                                   properties=properties,
                                   dimensions=dimensions)

        return ci.as_response(http_status=200)
Exemple #4
0
class CollectionInformationResource(Resource):
    def __init__(self):
        self.iface = ActiniaInterface()

    def get(self, name):

        # List strds maps from the GRASS location
        location, mapset, datatype, layer = self.iface.layer_def_to_components(
            name)

        status_code, layer_data = self.iface.layer_info(layer_name=name)
        if status_code != 200:
            return make_response(
                jsonify(
                    {
                        "description":
                        "An internal error occurred "
                        "while catching GRASS GIS layer information "
                        "for layer <%s>!\n Error: %s"
                        "" % (name, str(layer_data))
                    }, 400))

        # Get the projection from the GRASS mapset
        status_code, mapset_info = self.iface.mapset_info(location=location,
                                                          mapset=mapset)
        if status_code != 200:
            return make_response(
                jsonify(
                    {
                        "description":
                        "An internal error occurred "
                        "while catching mapset info "
                        "for mapset <%s>!" % mapset
                    }, 400))

        extent = Extent(spatial=(float(layer_data["west"]),
                                 float(layer_data["south"]),
                                 float(layer_data["east"]),
                                 float(layer_data["north"])))

        title = "Raster dataset"
        if datatype.lower() == "strds":
            title = "Space time raster dataset"
            extent = Extent(spatial=(float(layer_data["west"]),
                                     float(layer_data["south"]),
                                     float(layer_data["east"]),
                                     float(layer_data["north"])),
                            temporal=(layer_data["start_time"],
                                      layer_data["end_time"]))
        if datatype.lower() == "vector":
            title = "Vector dataset"

        description = "GRASS GIS location/mapset path: /%s/%s" % (location,
                                                                  mapset)
        crs = mapset_info["projection"]

        coorindate_transform_extent_to_EPSG_4326(crs=crs, extent=extent)

        ci = CollectionInformation(name=name,
                                   title=title,
                                   description=description,
                                   extent=extent)

        return make_response(ci.to_json(), 200)