Ejemplo n.º 1
0
def parsemtl(mtl):
    """Converts a Landsat 8 text MTL
    to JSON
    """
    try:
        mtl = str(click.open_file(mtl).read())
    except IOError:
        mtl = str('\n'.join([inputtiles]))

    click.echo(json.dumps(_parse_mtl_txt(mtl)))
Ejemplo n.º 2
0
def parsemtl(mtl):
    """Converts a Landsat 8 text MTL
    to JSON
    """
    try:
        mtl = str(click.open_file(mtl).read())
    except IOError:
        mtl = str('\n'.join([inputtiles]))

    click.echo(json.dumps(_parse_mtl_txt(mtl)))
Ejemplo n.º 3
0
 def __enter__(self):
     """Support using with Context Managers."""
     self.scene_params = sceneid_parser(self.sceneid)
     prefix = self._prefix.format(**self.scene_params)
     basename = f"{self.sceneid}_MTL.txt"
     self.mtl_metadata = toa_utils._parse_mtl_txt(
         get_object(self._hostname, f"{prefix}/{basename}").decode())
     self.bounds = tuple(
         toa_utils._get_bounds_from_metadata(
             self.mtl_metadata["L1_METADATA_FILE"]["PRODUCT_METADATA"]))
     return self
Ejemplo n.º 4
0
def landsat_get_mtl(sceneid):
    """
    Get Landsat-8 MTL metadata.

    Attributes
    ----------
    sceneid : str
        Landsat sceneid. For scenes after May 2017,
        sceneid have to be LANDSAT_PRODUCT_ID.

    Returns
    -------
    out : dict
        returns a JSON like object with the metadata.

    """
    scene_params = landsat_parse_scene_id(sceneid)
    meta_file = "http://landsat-pds.s3.amazonaws.com/{}_MTL.txt".format(
        scene_params["key"])
    metadata = str(urlopen(meta_file).read().decode())
    return toa_utils._parse_mtl_txt(metadata)
Ejemplo n.º 5
0
def _landsat_get_mtl(sceneid: str) -> Dict:
    """
    Get Landsat-8 MTL metadata.

    Attributes
    ----------
        sceneid : str
            Landsat sceneid. For scenes after May 2017,
            sceneid have to be LANDSAT_PRODUCT_ID.

    Returns
    -------
        out : dict
            returns a JSON like object with the metadata.

    """
    scene_params = landsat_parser(sceneid)
    meta_file = "http://{bucket}.s3.amazonaws.com/{prefix}/{scene}_MTL.txt".format(
        **scene_params
    )
    metadata = str(urlopen(meta_file).read().decode())
    return toa_utils._parse_mtl_txt(metadata)
Ejemplo n.º 6
0
def landsat_get_mtl(sceneid):
    """Get Landsat-8 MTL metadata

    Attributes
    ----------

    sceneid : str
        Landsat sceneid. For scenes after May 2017,
        sceneid have to be LANDSAT_PRODUCT_ID.

    Returns
    -------
    out : dict
        returns a JSON like object with the metadata.
    """

    try:
        scene_params = landsat_parse_scene_id(sceneid)
        meta_file = 'http://landsat-pds.s3.amazonaws.com/{}_MTL.txt'.format(scene_params['key'])
        metadata = str(urlopen(meta_file).read().decode())
        return toa_utils._parse_mtl_txt(metadata)
    except:
        raise Exception('Could not retrieve {} metadata'.format(sceneid))
Ejemplo n.º 7
0
import pytest

from mock import patch

from rio_toa import toa_utils
from remotepixel import l8_ovr

landsat_scene_c1 = "LC08_L1TP_016037_20170813_20170814_01_RT"
landsat_bucket = os.path.join(os.path.dirname(__file__), "fixtures",
                              "landsat-pds")

landsat_path = os.path.join(landsat_bucket, "c1", "L8", "016", "037",
                            landsat_scene_c1, landsat_scene_c1)
with open("{}_MTL.txt".format(landsat_path), "r") as f:
    landsat_meta = toa_utils._parse_mtl_txt(f.read())


def test_worker_valid():
    """Should work as expected (read data, proccess to TOA and rescale to int)."""
    assert l8_ovr.worker(4, landsat_path, landsat_meta.get("L1_METADATA_FILE"),
                         512).shape == (1, 512, 512)


@patch("remotepixel.l8_ovr.landsat_get_mtl")
def test_create_valid(landsat_get_mtl, monkeypatch):
    """Should work as expected (read r,g,b bands and create JPEG image)."""
    monkeypatch.setattr(l8_ovr, "LANDSAT_BUCKET", landsat_bucket)
    landsat_get_mtl.return_value = landsat_meta
    assert l8_ovr.create(landsat_scene_c1, bands=[4, 3, 2])
Ejemplo n.º 8
0
                               'sentinel-s2-l1c')
SENTINEL_PATH = os.path.join(SENTINEL_BUCKET, 'tiles/19/U/DP/2017/7/29/0/')

LANDSAT_SCENE_C1 = 'LC08_L1TP_016037_20170813_20170814_01_RT'
LANDSAT_BUCKET = os.path.join(os.path.dirname(__file__), 'fixtures',
                              'landsat-pds')
LANDSAT_PATH = os.path.join(LANDSAT_BUCKET, 'c1', 'L8', '016', '037',
                            LANDSAT_SCENE_C1, LANDSAT_SCENE_C1)

S3_KEY = 'hro_sources/colorado/201404_13SED190110_201404_0x1500m_CL_1.tif'
S3_LOCAL = PREFIX = os.path.join(os.path.dirname(__file__), 'fixtures',
                                 'my-bucket')
S3_PATH = os.path.join(S3_LOCAL, S3_KEY)

with open('{}_MTL.txt'.format(LANDSAT_PATH), 'r') as f:
    LANDSAT_METADATA = toa_utils._parse_mtl_txt(f.read())

with open('{}_MTL.txt'.format(LANDSAT_PATH), 'r') as f:
    LANDSAT_METADATA_RAW = f.read().encode('utf-8')


def test_landsat_min_max_worker():
    """
    Should work as expected (read data and return histogram cuts)
    """

    assert utils.landsat_min_max_worker('2', LANDSAT_PATH,
                                        LANDSAT_METADATA['L1_METADATA_FILE'],
                                        2, 98) == [939, 7025]

Ejemplo n.º 9
0
"""Test remotepixel.utils ."""

import os

import pytest

from rio_toa import toa_utils

from remotepixel import utils

mtl_file = os.path.join(os.path.dirname(__file__), "fixtures",
                        "LC80140352017115LGN00_MTL.txt")
with open(mtl_file, "r") as f:
    meta_data = toa_utils._parse_mtl_txt(f.read())

with open(mtl_file, "r") as f:
    meta_data_raw = f.read().encode("utf-8")


def test_get_overview_validLandsat():
    """Valid Landsat."""
    landsat_scene_c1 = "LC08_L1TP_016037_20170813_20170814_01_RT"
    landsat_bucket = os.path.join(os.path.dirname(__file__), "fixtures",
                                  "landsat-pds")
    landsat_path = os.path.join(landsat_bucket, "c1", "L8", "016", "037",
                                landsat_scene_c1, landsat_scene_c1)
    address = f"{landsat_path}_B4.TIF"
    assert utils.get_overview(address, 512).shape == (1, 512, 512)


def test_get_overview_validSentinel():
Ejemplo n.º 10
0
from landsat_footprint.utils import _parse_ang_txt
from landsat_footprint.scripts import cli
from landsat_footprint.scripts.cli import l8

LANDSAT_SCENE_C1 = "LC08_L1GT_020036_20190103_20190103_01_RT"
LANDSAT_BUCKET = os.path.join(os.path.dirname(__file__), "fixtures",
                              "landsat-pds")

LANDSAT_PATH = os.path.join(LANDSAT_BUCKET, "c1", "L8", "020", "036",
                            LANDSAT_SCENE_C1, LANDSAT_SCENE_C1)

with open("{}_ANG.txt".format(LANDSAT_PATH), "r") as f:
    LANDSAT_ANG_METADATA = _parse_ang_txt(f.read())

with open("{}_MTL.txt".format(LANDSAT_PATH), "r") as f:
    LANDSAT_METADATA = _parse_mtl_txt(f.read())


@pytest.fixture(autouse=True)
def testing_env_var(monkeypatch):
    monkeypatch.setenv("AWS_ACCESS_KEY_ID", "jqt")
    monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "rde")
    monkeypatch.delenv("AWS_PROFILE", raising=False)
    monkeypatch.setenv("AWS_CONFIG_FILE", "/tmp/noconfigheere")
    monkeypatch.setenv("AWS_SHARED_CREDENTIALS_FILE",
                       "/tmp/noconfighereeither")


def test_l8_valid():
    """Should work as expected."""
    runner = CliRunner()