Exemplo n.º 1
0
 def download(self, scene_id, output_dir):
     """Download a Landsat scene given its identifier and an output
     directory.
     """
     dataset = guess_dataset(scene_id)
     url = EE_DOWNLOAD_URL.format(folder=EE_FOLDER[dataset], sid=scene_id)
     self._download(url, output_dir, file_size=SIZES[dataset])
Exemplo n.º 2
0
    def query_metadata_srcid(self, platform, srcid):
        """Queries metadata from data source by srcid.

        :param platform: Image platform (<enum 'Platform'>).
        :param srcid: Srcid of a specific product (String).
        :generates: Metadata of product that matches srcid (PySTAC item).
        """
        if self.src == Datahub.STAC_local:
            # query Spatio Temporal Asset Catalog for metadata by srcid
            for item in self.api.get_all_items():
                if item.id == srcid:
                    yield item

        elif self.src == Datahub.STAC_API:
            raise NotImplementedError(
                f"Do this directly with our StacApi functionalities, see "
                f"https://ukis-pysat.readthedocs.io/en/latest/api/stacapi.html."
            )

        elif self.src == Datahub.EarthExplorer:
            from landsatxplore.util import guess_dataset

            dataset = guess_dataset(srcid)
            metadata = self.api.metadata(
                self.api.get_entity_id(srcid, dataset), dataset)
            yield self.construct_metadata(meta=metadata, platform=platform)

        else:  # query Scihub for metadata by srcid
            for meta in self.api.to_geojson(
                    self.api.query(identifier=srcid))["features"]:
                yield self.construct_metadata(meta=meta, platform=platform)
Exemplo n.º 3
0
def test_api_metadata(ee_api):

    PRODUCTS = [
        "LT05_L1GS_173058_20111028_20161005_01_T2",
        "LE07_L1TP_173058_20200926_20201022_01_T1",
        "LC08_L1TP_173058_20201004_20201015_01_T1",
        "LT05_L1TP_173058_20111028_20200820_02_T1",
        "LT05_L2SP_173058_20111028_20200820_02_T1",
        "LE07_L1TP_173058_20200926_20201022_02_T1",
        "LE07_L2SP_173058_20200926_20201022_02_T1",
        "LC08_L1TP_173058_20201004_20201015_02_T1",
        "LC08_L2SP_173058_20201004_20201016_02_T1",
        "L1C_T30QXG_A027990_20201031T103908",
    ]

    for display_id in PRODUCTS:
        dataset = util.guess_dataset(display_id)
        entity_id = ee_api.get_entity_id(display_id, dataset)
        metadata = ee_api.metadata(entity_id, dataset)
        assert isinstance(metadata["cloud_cover"], float)
        assert isinstance(metadata["acquisition_date"], datetime)
        if dataset.startswith("landsat"):
            assert util._is_landsat_product_id(metadata["landsat_product_id"])
            assert util._is_landsat_scene_id(metadata["landsat_scene_id"])
        elif dataset.startswith("sentinel"):
            assert util._is_sentinel_display_id(metadata["display_id"])
            assert util._is_sentinel_entity_id(metadata["entity_id"])
Exemplo n.º 4
0
 def download(self, scene_id, output_dir):
     """Download a Landsat scene given its identifier and an output
     directory.
     """
     dataset = guess_dataset(scene_id)
     if is_product_id(scene_id):
         scene_id = self.api.lookup(dataset, [scene_id], inverse=True)[0]
     url = EE_DOWNLOAD_URL.format(folder=EE_FOLDER[dataset], sid=scene_id)
     filename = self._download(url, output_dir, file_size=SIZES[dataset])
     return filename
Exemplo n.º 5
0
 def download(self, scene_id, output_dir):
     """Download a Landsat scene given its identifier and an output
     directory.
     """
     os.makedirs(output_dir, exist_ok=True)
     dataset = guess_dataset(scene_id)
     if is_product_id(scene_id):
         scene_id = self.api.lookup(dataset, [scene_id], inverse=True)[0]
     url = EE_DOWNLOAD_URL.format(dataset_id=DATASETS[dataset],
                                  scene_id=scene_id)
     filename = self._download(url, output_dir)
     return filename
Exemplo n.º 6
0
    def download_file(self, uuid, output_dir):
        from landsatxplore.util import guess_dataset
        from landsatxplore.earthexplorer import EE_DOWNLOAD_URL, DATASETS

        self.api.download(
            uuid, output_dir
        )

        # pseudo-checksum control
        dataset = guess_dataset(uuid)
        url = EE_DOWNLOAD_URL.format(dataset_id=DATASETS[dataset], scene_id=uuid)
        with self.api.session.get(url, stream=True, allow_redirects=True) as r:
            expected_filesize = int(r.headers['Content-Length'])

        return expected_filesize
    def download(self, scene_id, output_dir, data_set=False):
        """Download a Landsat scene given its identifier and an output
        directory.

        override to adjust for donwloading datasets other than landsat
        """
        if not data_set:
            dataset = guess_dataset(scene_id)
            if is_product_id(scene_id):
                scene_id = self.api.lookup(dataset, [scene_id],
                                           inverse=True)[0]
        else:
            dataset = data_set
            scene_id = self.api.lookup(data_set, [scene_id], inverse=True)[0]

        url = EE_DOWNLOAD_URL.format(folder=EE_FOLDER[dataset], sid=scene_id)
        filename = self._download(url, output_dir, dataset)
        return filename
Exemplo n.º 8
0
    def download(
        self,
        identifier,
        output_dir,
        dataset=None,
        timeout=300,
        skip=False,
        overwrite=False,
    ):
        """Download a Landsat scene.

        Parameters
        ----------
        identifier : str
            Scene Entity ID or Display ID.
        output_dir : str
            Output directory. Automatically created if it does not exist.
        dataset : str, optional
            Dataset name. If not provided, automatically guessed from scene id.
        timeout : int, optional
            Connection timeout in seconds.
        skip : bool, optional
            Skip download, only returns the remote filename.

        Returns
        -------
        filename : str
            Path to downloaded file.
        """
        os.makedirs(output_dir, exist_ok=True)
        if not dataset:
            dataset = guess_dataset(identifier)
        if is_display_id(identifier):
            entity_id = self.api.get_entity_id(identifier, dataset)
        else:
            entity_id = identifier
        url = EE_DOWNLOAD_URL.format(data_product_id=DATA_PRODUCTS[dataset],
                                     entity_id=entity_id)
        filename = self._download(url,
                                  output_dir,
                                  timeout=timeout,
                                  skip=skip,
                                  overwrite=overwrite)
        return filename