Exemple #1
0
class ApiTest(unittest.TestCase):
    """Tests ConfigManager and local/remote config access."""
    def setUp(self):
        self.api = Api()  # url='http://api.eoss.cloud'

    def testCreateConfig(self):
        """
        Create simple config object from string
        """

        ds = self.api.get_dataset('LC81920272016240LGN00')
        self.assertEqual(len(ds), 1)

        ds = self.api.get_dataset('LE71010172003151EDC00')
        self.assertEqual(len(ds), 1)

        ds = self.api.get_dataset(
            'S2A_OPER_PRD_MSIL1C_PDMC_20160806T202847_R142_V20160805T192909_20160805T192909'
        )
        self.assertEqual(len(ds), 21)

    def testCatalogSearch(self):
        aoi_nw = (-91.5175095, 16.8333384)
        aoi_se = (-91.3617268, 16.8135385)
        aoi_ne = (aoi_se[0], aoi_nw[1])
        aoi_sw = (aoi_nw[0], aoi_se[1])
        aoi = [aoi_nw, aoi_ne, aoi_se, aoi_sw, aoi_nw]

        # Object representation
        results = self.api.search_dataset(aoi,
                                          100,
                                          parse('2015-01-01'),
                                          parse('2015-03-01'),
                                          'landsat8',
                                          full_objects=True)
        self.assertEqual(len(results), 3)
        for item in results:
            self.assertTrue(type(item).__name__ == 'Catalog_Dataset')

        results = self.api.search_dataset(aoi,
                                          100,
                                          parse('2015-01-01'),
                                          parse('2015-03-01'),
                                          'landsat8',
                                          full_objects=False)
        # JSON representation
        self.assertEqual(len(results), 3)
        for item in results:
            self.assertTrue(type(item) == dict)
Exemple #2
0
def import_from_sentinel_catalog(sensor, start_date, api_url):
    import numpy
    api = Api(api_url)

    max_cloud_ratio = 1.0
    ag_season_start = dateutil.parser.parse(start_date)
    ag_season_end = ag_season_start + datetime.timedelta(days=1)

    for lon in numpy.arange(-180, 180, 9):
        for lat in numpy.arange(-90, 90, 9):
            lon_end = lon + 9
            lat_end = lat + 9

            aoi_se = (lon_end, lat)
            aoi_nw = (lon, lat_end)
            aoi_ne = (aoi_se[0], aoi_nw[1])
            aoi_sw = (aoi_nw[0], aoi_se[1])
            aoi = [aoi_nw, aoi_ne, aoi_se, aoi_sw, aoi_nw]

            cat = SentinelCatalog()
            datasets = cat.find(sensor, aoi, ag_season_start, ag_season_end,
                                max_cloud_ratio)

            if datasets != None:
                ds_found = list()
                ds_missing = list()
                for counter, ds in enumerate(datasets):
                    catalog_ds = api.get_dataset(ds.entity_id)
                    if catalog_ds is None or len(catalog_ds) == 0:
                        ds_missing.append(ds)
                    elif len(catalog_ds) == 1:
                        ds_found.append(catalog_ds)
                    else:
                        print 'More in catalog found: %s (%d)' % (
                            ds.entity_id, len(catalog_ds))
                    if (counter % 25) == 0:
                        print counter, len(datasets)
                print 'already registered: ', len(ds_found), len(datasets)
                print 'missing: ', len(ds_missing), len(datasets)

                for counter, ds_obj in enumerate(ds_missing):
                    new_ds = api.create_dataset(ds_obj)
                    if not new_ds is None:
                        print new_ds
                    if (counter % 25) == 0:
                        print counter, len(ds_missing)
            else:
                print 'No data found in catalog for %s from %s to %s' % (
                    sensor, ag_season_start.strftime("%Y-%m-%d"),
                    ag_season_end.strftime("%Y-%m-%d"))
def import_from_landsat_catalog(sensor, start_date, api_url):
    api = Api(api_url)

    max_cloud_ratio = 1.0
    ag_season_start = dateutil.parser.parse(start_date)
    ag_season_end = ag_season_start + datetime.timedelta(days=1)
    aoi_se = (180, -90)
    aoi_nw = (-180, 90)
    aoi_ne = (aoi_se[0], aoi_nw[1])
    aoi_sw = (aoi_nw[0], aoi_se[1])
    aoi = [aoi_nw, aoi_ne, aoi_se, aoi_sw, aoi_nw]

    cat = USGSCatalog()
    # "LANDSAT_8", "LANDSAT_ETM_SLC_OFF", "LANDSAT_ETM"
    datasets = cat.find(sensor, aoi, ag_season_start, ag_season_end,
                        max_cloud_ratio)

    if datasets != None:
        ds_found = list()
        ds_missing = list()
        for counter, ds in enumerate(datasets):
            catalog_ds = api.get_dataset(ds.entity_id)
            if catalog_ds is None or len(catalog_ds) == 0:
                ds_missing.append(ds)
            elif len(catalog_ds) == 1:
                ds_found.append(catalog_ds)
            else:
                print 'More in catalog found: %s (%d)' % (ds.entity_id,
                                                          len(catalog_ds))
            if (counter % 25) == 0:
                print counter, len(datasets)
        print 'already registered: ', len(ds_found), len(datasets)
        print 'missing: ', len(ds_missing), len(datasets)

        for counter, ds_obj in enumerate(ds_missing):
            new_ds = api.create_dataset(ds_obj)
            if not new_ds is None:
                print new_ds
            if (counter % 25) == 0:
                print counter, len(ds_missing)
    else:
        print 'No data found in catalog for sentinel from %s to %s' % (
            ag_season_start.strftime("%Y-%m-%d"),
            ag_season_end.strftime("%Y-%m-%d"))