Ejemplo n.º 1
0
def sentinel1_parser(sceneid: str) -> Dict:
    """
    Parse Sentinel-1 scene id.

    Attributes
    ----------
        sceneid : str
            Sentinel-1 sceneid.

    Returns
    -------
        out : dict
            dictionary with metadata constructed from the sceneid.

    """
    if not re.match(
            "^S1[AB]_(IW)|(EW)_[A-Z]{3}[FHM]_[0-9][SA][A-Z]{2}_[0-9]{8}T[0-9]{6}_[0-9]{8}T[0-9]{6}_[0-9A-Z]{6}_[0-9A-Z]{6}_[0-9A-Z]{4}$",
            sceneid,
    ):
        raise InvalidSentinelSceneId("Could not match {}".format(sceneid))

    sentinel_pattern = (
        r"^S"
        r"(?P<sensor>\w{1})"
        r"(?P<satellite>[AB]{1})"
        r"_"
        r"(?P<beam>[A-Z]{2})"
        r"_"
        r"(?P<product>[A-Z]{3})"
        r"(?P<resolution>[FHM])"
        r"_"
        r"(?P<processing_level>[0-9])"
        r"(?P<product_class>[SA])"
        r"(?P<polarisation>(SH)|(SV)|(DH)|(DV)|(HH)|(HV)|(VV)|(VH))"
        r"_"
        r"(?P<startDateTime>[0-9]{8}T[0-9]{6})"
        r"_"
        r"(?P<stopDateTime>[0-9]{8}T[0-9]{6})"
        r"_"
        r"(?P<absolute_orbit>[0-9]{6})"
        r"_"
        r"(?P<mission_task>[0-9A-Z]{6})"
        r"_"
        r"(?P<product_id>[0-9A-Z]{4})$")

    meta: Dict[str, Any] = re.match(sentinel_pattern, sceneid,
                                    re.IGNORECASE).groupdict()

    meta["scene"] = sceneid
    year = meta["startDateTime"][0:4]
    month = meta["startDateTime"][4:6].strip("0")
    day = meta["startDateTime"][6:8].strip("0")

    meta["scheme"] = "s3"
    meta["bucket"] = "sentinel-s1-l1c"
    meta["prefix"] = os.path.join(meta["product"], year, month, day,
                                  meta["beam"], meta["polarisation"], sceneid)

    return meta
Ejemplo n.º 2
0
def sentinel_parse_scene_id(sceneid):
    """Parse Sentinel-2 scene id"""

    if not re.match('^S2[AB]_tile_[0-9]{8}_[0-9]{2}[A-Z]{3}_[0-9]$', sceneid):
        raise InvalidSentinelSceneId('Could not match {}'.format(sceneid))

    sentinel_pattern = (r'^S'
                        r'(?P<sensor>\w{1})'
                        r'(?P<satellite>[AB]{1})'
                        r'_tile_'
                        r'(?P<acquisitionYear>[0-9]{4})'
                        r'(?P<acquisitionMonth>[0-9]{2})'
                        r'(?P<acquisitionDay>[0-9]{2})'
                        r'_'
                        r'(?P<utm>[0-9]{2})'
                        r'(?P<lat>\w{1})'
                        r'(?P<sq>\w{2})'
                        r'_'
                        r'(?P<num>[0-9]{1})$')

    meta = None
    match = re.match(sentinel_pattern, sceneid, re.IGNORECASE)
    if match:
        meta = match.groupdict()

    utm_zone = meta['utm'].lstrip("0")
    grid_square = meta['sq']
    latitude_band = meta['lat']
    year = meta['acquisitionYear']
    month = meta['acquisitionMonth'].lstrip("0")
    day = meta['acquisitionDay'].lstrip("0")
    img_num = meta['num']

    meta['key'] = 'tiles/{}/{}/{}/{}/{}/{}/{}'.format(utm_zone, latitude_band,
                                                      grid_square, year, month,
                                                      day, img_num)

    meta['scene'] = sceneid

    return meta
Ejemplo n.º 3
0
def sentinel_parse_scene_id(sceneid):
    """Parse Sentinel-2 scene id."""
    if not re.match("^S2[AB]_tile_[0-9]{8}_[0-9]{2}[A-Z]{3}_[0-9]$", sceneid):
        raise InvalidSentinelSceneId("Could not match {}".format(sceneid))

    sentinel_pattern = (r"^S"
                        r"(?P<sensor>\w{1})"
                        r"(?P<satellite>[AB]{1})"
                        r"_tile_"
                        r"(?P<acquisitionYear>[0-9]{4})"
                        r"(?P<acquisitionMonth>[0-9]{2})"
                        r"(?P<acquisitionDay>[0-9]{2})"
                        r"_"
                        r"(?P<utm>[0-9]{2})"
                        r"(?P<lat>\w{1})"
                        r"(?P<sq>\w{2})"
                        r"_"
                        r"(?P<num>[0-9]{1})$")

    meta = None
    match = re.match(sentinel_pattern, sceneid, re.IGNORECASE)
    if match:
        meta = match.groupdict()

    utm_zone = meta["utm"].lstrip("0")
    grid_square = meta["sq"]
    latitude_band = meta["lat"]
    year = meta["acquisitionYear"]
    month = meta["acquisitionMonth"].lstrip("0")
    day = meta["acquisitionDay"].lstrip("0")
    img_num = meta["num"]

    meta["key"] = "tiles/{}/{}/{}/{}/{}/{}/{}".format(utm_zone, latitude_band,
                                                      grid_square, year, month,
                                                      day, img_num)

    meta["scene"] = sceneid

    return meta
Ejemplo n.º 4
0
def _sentinel_parse_scene_id(sceneid):
    """Parse Sentinel-2 scene id.

    Attributes
    ----------
    sceneid : str
        Sentinel-2 sceneid.

    Returns
    -------
    out : dict
        dictionary with metadata constructed from the sceneid.

        e.g:
        _sentinel_parse_scene_id('S2A_tile_20170323_07SNC_0')
        {
            "acquisitionDay": "23",
            "acquisitionMonth": "03",
            "acquisitionYear": "2017",
            "key": "tiles/7/S/NC/2017/3/23/0",
            "lat": "S",
            "num": "0",
            "satellite": "A",
            "scene": "S2A_tile_20170323_07SNC_0",
            "sensor": "2",
            "sq": "NC",
            "utm": "07",
        }

    """

    if not re.match("^S2[AB]_tile_[0-9]{8}_[0-9]{2}[A-Z]{3}_[0-9]$", sceneid):
        raise InvalidSentinelSceneId("Could not match {}".format(sceneid))

    sentinel_pattern = (
        r"^S"
        r"(?P<sensor>\w{1})"
        r"(?P<satellite>[AB]{1})"
        r"_tile_"
        r"(?P<acquisitionYear>[0-9]{4})"
        r"(?P<acquisitionMonth>[0-9]{2})"
        r"(?P<acquisitionDay>[0-9]{2})"
        r"_"
        r"(?P<utm>[0-9]{2})"
        r"(?P<lat>\w{1})"
        r"(?P<sq>\w{2})"
        r"_"
        r"(?P<num>[0-9]{1})$"
    )

    meta = None
    match = re.match(sentinel_pattern, sceneid, re.IGNORECASE)
    if match:
        meta = match.groupdict()

    utm_zone = meta["utm"].lstrip("0")
    grid_square = meta["sq"]
    latitude_band = meta["lat"]
    year = meta["acquisitionYear"]
    month = meta["acquisitionMonth"].lstrip("0")
    day = meta["acquisitionDay"].lstrip("0")
    img_num = meta["num"]

    meta["key"] = "tiles/{}/{}/{}/{}/{}/{}/{}".format(
        utm_zone, latitude_band, grid_square, year, month, day, img_num
    )

    meta["scene"] = sceneid

    return meta
Ejemplo n.º 5
0
def sentinel2_parser(sceneid: str) -> Dict:
    """
    Parse Sentinel-2 scene id.

    Attributes
    ----------
        sceneid : str
            Sentinel-2 sceneid.

    Returns
    -------
        out : dict
            dictionary with metadata constructed from the sceneid.

    """

    if not re.match("^S2[AB]_L[0-2][A-C]_[0-9]{8}_[0-9]{2}[A-Z]{3}_[0-9]$",
                    sceneid):
        raise InvalidSentinelSceneId("Could not match {}".format(sceneid))

    sentinel_pattern = (r"^S"
                        r"(?P<sensor>\w{1})"
                        r"(?P<satellite>[AB]{1})"
                        r"_"
                        r"(?P<processingLevel>L[0-2][ABC])"
                        r"_"
                        r"(?P<acquisitionYear>[0-9]{4})"
                        r"(?P<acquisitionMonth>[0-9]{2})"
                        r"(?P<acquisitionDay>[0-9]{2})"
                        r"_"
                        r"(?P<utm>[0-9]{2})"
                        r"(?P<lat>\w{1})"
                        r"(?P<sq>\w{2})"
                        r"_"
                        r"(?P<num>[0-9]{1})$")

    meta: Dict[str, Any] = re.match(sentinel_pattern, sceneid,
                                    re.IGNORECASE).groupdict()
    meta["scene"] = sceneid

    utm_zone = meta["utm"].lstrip("0")
    grid_square = meta["sq"]
    latitude_band = meta["lat"]
    year = meta["acquisitionYear"]
    month = meta["acquisitionMonth"].lstrip("0")
    day = meta["acquisitionDay"].lstrip("0")
    img_num = meta["num"]

    meta["scheme"] = "s3"
    meta["bucket"] = "sentinel-s2-" + meta["processingLevel"].lower()
    meta["prefix"] = os.path.join("tiles", utm_zone, latitude_band,
                                  grid_square, year, month, day, img_num)

    if meta["processingLevel"] == "L1C":
        meta["preview_file"] = "preview.jp2"
        meta["preview_prefix"] = ""
        meta["bands"] = list(
            itertools.chain.from_iterable(
                [bands for _, bands in SENTINEL_L1_BANDS.items()]))
        meta["valid_bands"] = meta["bands"]
    else:
        meta["preview_file"] = "R60m/TCI.jp2"
        meta["preview_prefix"] = "R60m"
        meta["bands"] = SENTINEL_L2_BANDS["60"]
        meta["valid_bands"] = meta["bands"] + SENTINEL_L2_PRODUCTS["60"]

    return meta
Ejemplo n.º 6
0
def _sentinel_parse_scene_id(sceneid):
    """Parse Sentinel-1 scene id.

    Attributes
    ----------
    sceneid : str
        Sentinel-1 sceneid.

    Returns
    -------
    out : dict
        dictionary with metadata constructed from the sceneid.

        e.g:
        _sentinel_parse_scene_id('S1A_IW_GRDH_1SDV_20180716T004042_20180716T004107_022812_02792A_FD5B')
        {
            "sensor": "1",
            "satellite": "A",
            "beam": "IW",
            "product": "GRD",
            "resolution": "H",
            "processing_level": "1",
            "product_class": "S",
            "polarisation": "DV",
            "startDateTime": "20180716T004042",
            "stopDateTime": "20180716T004107",
            "absolute_orbit": "022812",
            "mission_task": "02792A",
            "product_id": "FD5B",
            "key": "GRD/2018/7/16/IW/DV/S1A_IW_GRDH_1SDV_20180716T004042_20180716T004107_022812_02792A_FD5B",
            "scene": "S1A_IW_GRDH_1SDV_20180716T004042_20180716T004107_022812_02792A_FD5B",
        }

    """
    if not re.match(
            "^S1[AB]_(IW)|(EW)_[A-Z]{3}[FHM]_[0-9][SA][A-Z]{2}_[0-9]{8}T[0-9]{6}_[0-9]{8}T[0-9]{6}_[0-9A-Z]{6}_[0-9A-Z]{6}_[0-9A-Z]{4}$",
            sceneid,
    ):
        raise InvalidSentinelSceneId("Could not match {}".format(sceneid))

    sentinel_pattern = (
        r"^S"
        r"(?P<sensor>\w{1})"
        r"(?P<satellite>[AB]{1})"
        r"_"
        r"(?P<beam>[A-Z]{2})"
        r"_"
        r"(?P<product>[A-Z]{3})"
        r"(?P<resolution>[FHM])"
        r"_"
        r"(?P<processing_level>[0-9])"
        r"(?P<product_class>[SA])"
        r"(?P<polarisation>(SH)|(SV)|(DH)|(DV)|(HH)|(HV)|(VV)|(VH))"
        r"_"
        r"(?P<startDateTime>[0-9]{8}T[0-9]{6})"
        r"_"
        r"(?P<stopDateTime>[0-9]{8}T[0-9]{6})"
        r"_"
        r"(?P<absolute_orbit>[0-9]{6})"
        r"_"
        r"(?P<mission_task>[0-9A-Z]{6})"
        r"_"
        r"(?P<product_id>[0-9A-Z]{4})$")

    meta = re.match(sentinel_pattern, sceneid, re.IGNORECASE).groupdict()
    year = meta["startDateTime"][0:4]
    month = meta["startDateTime"][4:6].strip("0")
    day = meta["startDateTime"][6:8].strip("0")
    meta["key"] = "{}/{}/{}/{}/{}/{}/{}".format(meta["product"], year, month,
                                                day, meta["beam"],
                                                meta["polarisation"], sceneid)

    meta["scene"] = sceneid

    return meta
Ejemplo n.º 7
0
def _sentinel_parse_scene_id(sceneid):
    """
    Parse Sentinel-2 scene id.

    Attributes
    ----------
        sceneid : str
            Sentinel-2 sceneid.

    Returns
    -------
        out : dict
            dictionary with metadata constructed from the sceneid.

            e.g:
            _sentinel_parse_scene_id('S2A_tile_20170323_07SNC_0')
            {
                "acquisitionDay": "23",
                "acquisitionMonth": "03",
                "acquisitionYear": "2017",
                "key": "tiles/7/S/NC/2017/3/23/0",
                "lat": "S",
                "num": "0",
                "satellite": "A",
                "scene": "S2A_tile_20170323_07SNC_0",
                "sensor": "2",
                "sq": "NC",
                "utm": "07",
            }

    """
    old_sceneid = "S2[AB]_tile_[0-9]{8}_[0-9]{2}[A-Z]{3}_[0-9]"
    new_sceneid = "S2[AB]_L[0-2][A-C]_[0-9]{8}_[0-9]{2}[A-Z]{3}_[0-9]"
    if not re.match("^{}|{}$".format(old_sceneid, new_sceneid), sceneid):
        raise InvalidSentinelSceneId("Could not match {}".format(sceneid))

    if re.match(old_sceneid, sceneid):
        warnings.warn(
            "Old Sentinel-2 scene id will be deprecated starting in rio-tiler v2.0.0"
            "Processing level is set to L1A.",
            DeprecationWarning,
        )

    sentinel_pattern_old = (r"^S"
                            r"(?P<sensor>\w{1})"
                            r"(?P<satellite>[AB]{1})"
                            r"_tile_"
                            r"(?P<acquisitionYear>[0-9]{4})"
                            r"(?P<acquisitionMonth>[0-9]{2})"
                            r"(?P<acquisitionDay>[0-9]{2})"
                            r"_"
                            r"(?P<utm>[0-9]{2})"
                            r"(?P<lat>\w{1})"
                            r"(?P<sq>\w{2})"
                            r"_"
                            r"(?P<num>[0-9]{1})$")

    sentinel_pattern_new = (r"^S"
                            r"(?P<sensor>\w{1})"
                            r"(?P<satellite>[AB]{1})"
                            r"_"
                            r"(?P<processingLevel>L[0-2][ABC])"
                            r"_"
                            r"(?P<acquisitionYear>[0-9]{4})"
                            r"(?P<acquisitionMonth>[0-9]{2})"
                            r"(?P<acquisitionDay>[0-9]{2})"
                            r"_"
                            r"(?P<utm>[0-9]{2})"
                            r"(?P<lat>\w{1})"
                            r"(?P<sq>\w{2})"
                            r"_"
                            r"(?P<num>[0-9]{1})$")

    meta = None
    for pattern in [sentinel_pattern_old, sentinel_pattern_new]:
        match = re.match(pattern, sceneid, re.IGNORECASE)
        if match:
            meta = match.groupdict()
            break

    if not meta.get("processingLevel"):
        meta["processingLevel"] = "L1C"

    utm_zone = meta["utm"].lstrip("0")
    grid_square = meta["sq"]
    latitude_band = meta["lat"]
    year = meta["acquisitionYear"]
    month = meta["acquisitionMonth"].lstrip("0")
    day = meta["acquisitionDay"].lstrip("0")
    img_num = meta["num"]

    meta["scene"] = sceneid
    meta["aws_bucket"] = AWS_SENTINEL_BUCKET + meta["processingLevel"].lower()
    meta["aws_prefix"] = "tiles/{}/{}/{}/{}/{}/{}/{}".format(
        utm_zone, latitude_band, grid_square, year, month, day, img_num)
    meta["key"] = meta["aws_prefix"]  # Will be deprecated in rio-tiler v2.0.0

    if meta["processingLevel"] == "L1C":
        meta["preview_file"] = "preview.jp2"
        meta["preview_prefix"] = "preview"
        meta["bands"] = list(
            itertools.chain.from_iterable(
                [bands for _, bands in SENTINEL_L1_BANDS.items()]))
        meta["valid_bands"] = meta["bands"]
    else:
        meta["preview_file"] = "R60m/TCI.jp2"
        meta["preview_prefix"] = "R60m"
        meta["bands"] = SENTINEL_L2_BANDS["60m"]
        meta["valid_bands"] = meta["bands"] + SENTINEL_L2_PRODUCTS["60m"]

    return meta