Example #1
0
    def addToMap(self, eeobj, center=False, **vis_params):
        """Example of `palettable <https://jiffyclub.github.io/palettable/>`_ palette use::

            from palettable.cartocolors.sequential import SunsetDark_6

            GEE.addToMap(image, {'bands': ['HH], 'min':-20, 'max':0, 'palette': SunsetDark_6.hex_colors})

        Note that palettes can only be used with single-band visualiztion.

        """
        try:
            assert(mapclient.map_instance.is_alive())
            center = True
        except:
            mapclient.map_instance = None
        if 'palette' not in vis_params and hasattr(self, 'palette'):
            vis_params['palette'] = self.palette.hex_colors
        mapclient.addToMap(eeobj, vis_params)
        mapclient.centerMap(*self.map_center)
Example #2
0
in Earth Engine using image.neighborhoodToBands(). Using the image from the previous example:
"""

# Create a list of weights for a 9x9 kernel.
lst = [1 for _ in range(9)]
# The center of the kernel is zero.
centerList = [1 for _ in range(9)]
centerList[4] = 0
# Assemble a list of lists: the 9x9 kernel weights as a 2-D matrix
lists = [lst for _ in range(9)]
lists[4] = centerList
# Create the kernel from the weights.
# Non-zero weights represent the spatial neighborhood
kernel = ee.Kernel.fixed(9, 9, lists, -4, -4, False)

# Convert the neighborhood into multiple bands.
neighs = nir.neighborhoodToBands(kernel)

# Compute local Geary's C, a measure of spatial association
gearys = nir.subtract(neighs)\
    .pow(2)\
    .reduce(ee.Reducer.sum())\
    .divide(81)


mapclient.centerMap(-122.44829, 37.76664, 17)
mapclient.addToMap(gearys,
                   {'min': 20,
                    'max': 2500,
                    'palette': ['0000CC', 'CC0000']},
                    "Geary's C")
Specifically, when an image has distinct patches identified by unique pixel values,
use image.connectedPixelCount() to compute the number of pixels in each patch
and image.connectedComponents() to label each patch with a unique identifier.
The unique identifiers can then be used to enumerate the patches
and analyze the distribution of size or some other quality of interest.
The following computes the size and unique identifiers of hot patches in a surface temperature image:
"""

# Load a Landsat 8 image and display the thermal band.
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')

# Threshold the thermal band to find "hot" objects.
hotspots = image.select('B10').gt(303)

# Mask 'cold' pixels.
hotspots = hotspots.updateMask(hotspots)

# Compute the number of pixels in each patch
patchsize = hotspots.connectedPixelCount(256, False)

# Uniquely label the patches and visualize
patchid = hotspots.connectedComponents(ee.Kernel.plus(1), 256)
mapclient.centerMap(-122.1899, 37.5010, 13)
mapclient.addToMap(patchid.randomVisualizer(), {}, 'patches')
"""
In the previous example, note that the maximum patch size is set to 256 pixels by the arguments to the connectedPixelCount()
and connectedComponents() methods. The connectivity is also specified by the arguments,
in the former method by a boolean and in the latter method by an ee.Kernel. In this example,
only four neighbors are considered for each pixel.
"""
Example #4
0
# Perform Hough transform of the Canny result and display.
hough = ee.Algorithms.HoughTransform(image=canny,
                                     inputThreshold=100,
                                     lineThreshold=100,
                                     smooth=True)

#mapclient.centerMap(-122.054, 37.7295, 10)
#mapclient.addToMap(hough, {}, 'hough')

# `zeroCrossing() method`

# Define a "fat" Gaussian kernel
fat = ee.Kernel.gaussian(radius=3,
                         sigma=3,
                         units="pixels",
                         normalize=True,
                         magnitude=-1)

# Define a "skinny" Gaussian kernel
skinny = ee.Kernel.gaussian(radius=3, sigma=1, units="pixels", normalize=True)

# Compute a difference-of-Gaussian (DOG) kernel
dog = fat.add(skinny)

# Compute the zero corossing of second derivative, display

zeroXings = image.convolve(dog).zeroCrossing()
mapclient.centerMap(-122.054, 37.7295, 10)
mapclient.addToMap(zeroXings.updateMask(zeroXings), {'palette': 'FF0000'},
                   'zero crossings')
Example #5
0
# Display the threshold image as three district zone near Paris
palette = ['000000', '0000FF', '00FF00', 'FF0000']

# Create zones using an expression
zonesExp = nl2012.expression("(b('stable_lights')>62) ? 3" +\
                             ": (b('stable_lights')>55) ? 2" +\
                             ": (b('stable_lights')>30) ? 1" +\
                             ": 0")

#mapclient.centerMap(2.373, 48.8683, 8)
#mapclient.addToMap(zonesExp, {'min': 0, 'max': 3, 'palette': palette}, 'development zones')

# Load a cloudy Landsat 8 image
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20130603')

# Load another image to relace the cloudy pixels
replacement = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20130416')

# Compute a cloud score band
cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud')

# Set cloudy pixels to the other image
replaced = image.where(cloud.gt(10), replacement)

mapclient.centerMap(-122.151, 37.451, 9)
mapclient.addToMap(replaced, {
    'bands': ['B5', 'B4', 'B3'],
    'min': 0,
    'max': 0.5
}, 'clouds replaced')
# Compute the multi-band difference image
diff = landsat2008.subtract(landsat1999)
print('#####diff#####')
pprint(diff.getInfo())
print('#####diff.pow(2)#####')
pprint(diff.pow(2).getInfo())

# Expressions

# Load a Landsat 8 image
image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')

# Compute the EVI using an expression
evi = image.expression(
    expression='2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))',
    opt_map={
        'NIR': image.select('B5'),
        'RED': image.select('B4'),
        'BLUE': image.select('B2')
    })
vizParam = {'min': -1, 'max': 1, 'palette': ['FF0000', '00FF00']}
mapclient.centerMap(-122.1225, 37.5217, 10)
mapclient.addToMap(evi, vizParam, 'evi')
print('#####evi#####')
pprint(evi.getInfo())

# Another way to apply a expression, using 'b(index)' to refer a band
evi = image.expression(
    '2.5 * ((b(5) - b(4)) / (b(5) + 6 * 1.0 * b(4) - 7.5 * b(2) + 1.0))')
#mapclient.centerMap(-122.1225, 37.5217, 10)
#mapclient.addToMap(evi, vizParam, 'evi')