Esempio n. 1
0
    def test_getRegion(self):
        expected = [[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0],
                    [0.0, 0.0]]
        pol = ee.Geometry.Polygon(expected)
        feat = ee.Feature(pol)

        region_geom = tools.getRegion(pol)
        region_feat = tools.getRegion(feat)

        self.assertEqual(region_geom, [expected])
        self.assertEqual(region_feat, [expected])
Esempio n. 2
0
    def test_bap2016_0(self):
        pmulti = scores.MultiYear(2016, self.temporada)
        objbap = bap.Bap(year=2016,
                         # colgroup=self.coleccion,
                         season=self.temporada,
                         scores=(self.pindice, self.pmascpor, self.psat,
                                 self.pout, self.pop, self.pdoy, pmulti),
                         masks=(self.nubes,),
                         filters=(self.filtro,),
                         )

        # objbap.debug = True
        sitio = self.sitio

        unpix = objbap.bestpixel(sitio, indices=("ndvi",))
        img = unpix.image
        col = unpix.col

        self.assertIsInstance(img, ee.Image)
        self.assertIsInstance(col, ee.ImageCollection)

        idict = img.getInfo()
        cdict = col.getInfo()
        self.assertIsInstance(idict, dict)
        self.assertIsInstance(cdict, dict)

        value = tools.get_value(img, self.centroid, 30, 'client')
        print(value)

        self.assertIsInstance(value, dict)

        visual = img.visualize(bands=['NIR','SWIR','RED'], min=0, max=0.5)
        url = visual.getThumbUrl({'region':tools.getRegion(img)})
        print('Result:', url)
Esempio n. 3
0
def export(image, folder, score, scale=30):
    user = ee.data.getAssetRoots()[0]['id']
    task = ee.batch.Export.image.toAsset(image,
                                         assetId='{}/{}/{}'.format(
                                             user, folder, score),
                                         scale=30,
                                         region=tools.getRegion(image))
    task.start()
Esempio n. 4
0
    def test_generate_mask(self):
        band = 'B1'
        mask = cloud_mask.sentinel2(cloud_S2)
        cld_score = self.score.generate_score(mask, band)
        vis = cld_score.visualize(
            min=0, max=1, palette=['b9936c', 'dac292', 'e6e2d3', 'c4b7a6'])

        region = cloud_S2.geometry().centroid().buffer(5000)
        url = vis.getThumbUrl({'region': tools.getRegion(region)})

        print('\nCloud Distance Score: {}\n'.format(url))
        self.assertEqual(cld_score.getInfo()['type'], 'Image')
Esempio n. 5
0
    def __init__(self,
                 timeseries,
                 fit_band,
                 area=None,
                 date_measure='year',
                 **kwargs):

        self.timeSeries = timeseries
        self.fit_band = fit_band
        self.date_measure = date_measure

        self.maxSegments = kwargs.get("maxSegments", 4)
        self.spikeThreshold = kwargs.get("spikeThreshold", 0.9)
        self.vertexCountOvershoot = kwargs.get("vertexCountOvershoot", 3)
        self.preventOneYearRecovery = kwargs.get("preventOneYearRecovery",
                                                 False)
        self.recoveryThreshold = kwargs.get("recoveryThreshold", 0.25)
        self.pvalThreshold = kwargs.get("pvalThreshold", 0.1)
        self.bestModelProportion = kwargs.get("bestModelProportion", 1.25)
        self.minObservationsNeeded = kwargs.get("minObservationsNeeded", 6)

        # Axes
        self.year_axis = 1
        self.band_axis = 0

        if area:
            self.area = area
        else:
            self.area = ee.Image(self.timeSeries.first()).geometry()

        self.region = tools.getRegion(self.area)

        self._core = None
        self._breakdown = None
        self._slope = None
        self._statistics = None
        self._date_range = None
        self._date_range_bitreader = None
Esempio n. 6
0
def col2gcs(col,
            bucket,
            fileNamePrefix=None,
            scale=30,
            dataType="float",
            region=None,
            **kwargs):
    """ Upload all images from one collection to Google Drive. You can use the
    same arguments as the original function ee.batch.export.image.toDrive
    :param col: Collection to upload
    :type col: ee.ImageCollection
    :param region: area to upload. Defualt to the footprint of the first
        image in the collection
    :type region: ee.Geometry.Rectangle or ee.Feature
    :param scale: scale of the image (side of one pixel). Defults to 30
        (Landsat resolution)
    :type scale: int
    :param maxImgs: maximum number of images inside the collection
    :type maxImgs: int
    :param dataType: as downloaded images **must** have the same data type in all
        bands, you have to set it here. Can be one of: "float", "double", "int",
        "Uint8", "Int8" or a casting function like *ee.Image.toFloat*
    :type dataType: str
    :return: list of tasks
    :rtype: list
    """
    TYPES = {
        'float': ee.Image.toFloat,
        'int': ee.Image.toInt,
        'Uint8': ee.Image.toUint8,
        'int8': ee.Image.toInt8,
        'double': ee.Image.toDouble
    }

    size = col.size().getInfo()
    alist = col.toList(size)
    tasklist = []

    #region = ee.Image(alist.get(0)).geometry().getInfo()["coordinates"]
    region = tools.getRegion(region)

    for idx in range(0, size):
        img = alist.get(idx)
        img = ee.Image(img)
        name = img.id().getInfo().split("/")[-1] + "_" + str(scale) + "m"

        if dataType in TYPES:
            typefunc = TYPES[dataType]
            img = typefunc(img)
        elif dataType in dir(ee.Image):
            img = dataType(img)
        else:
            raise ValueError("specified data type is not found")

        if fileNamePrefix is None:
            fileNamePrefix = name

        task = ee.batch.Export.image.toCloudStorage(
            image=img,
            description=name,
            bucket=bucket,
            fileNamePrefix=fileNamePrefix + name,
            region=region,
            scale=scale)

        print("starting task {}/{} of {}".format(idx, size, name))
        task.start()
        tasklist.append(task)

    return tasklist
Esempio n. 7
0
def output(image, name, vis_params):

    visimage = image.visualize(**vis_params)
    url = visimage.getThumbUrl({'region': tools.getRegion(cloud_S2)})

    print(name, url)