Last active
October 13, 2017 09:01
-
-
Save jdries/33d9945de676f9c793c5e349cdcaaf3d to your computer and use it in GitHub Desktop.
Client API examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some examples of existing API's. | |
https://nbviewer.jupyter.org/urls/bitbucket.org/vitotap/notebooks/raw/master/QuickstartExample.ipynb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compute the Normalized Difference Vegetation Index (NDVI). | |
var nir = image.select('B5'); | |
var red = image.select('B4'); | |
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI'); | |
////ZONAL STATS | |
// Load input imagery: Landsat 7 5-year composite. | |
var image = ee.Image('LE7_TOA_5YEAR/2008_2012'); | |
// Load a FeatureCollection of counties in Maine. | |
var maineCounties = ee.FeatureCollection('ft:1S4EB6319wWW2sWQDPhDvmSBIVrD3iEmCLYB7nMM') | |
.filter(ee.Filter.eq('StateName', 'Maine')); | |
// Add reducer output to the Features in the collection. | |
var maineMeansFeatures = image.reduceRegions({ | |
collection: maineCounties, | |
reducer: ee.Reducer.mean(), | |
scale: 30, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for( key <- temporalKeys ) { | |
val spatialRDD = timeseriesRDD.toSpatial(key.instant ) | |
val histogram: Map[Int, Histogram[Int]] = spatialRDD.zonalHistogram(zonesRDD) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# simple example for pyGRASS usage: raster processing via modules approach | |
from grass.pygrass.modules.shortcuts import general as g | |
from grass.pygrass.modules.shortcuts import raster as r | |
g.message("Filter elevation map by a threshold...") | |
# set computational region | |
input = 'elevation' | |
g.region(rast=input) | |
# hardcoded: | |
# r.mapcalc('elev_100m = if(elevation > 100, elevation, null())', overwrite = True) | |
# with variables | |
output = 'elev_100m' | |
thresh = 100.0 | |
r.mapcalc("%s = if(%s > %d, %s, null())" % (output, input, thresh, input), overwrite = True) | |
#Zonal stats on timeseries | |
# Install v.strds.stats add-on | |
gmod.Module("g.extension", extension="v.strds.stats") | |
# Extract mean, max and min LST for municipalities | |
gmod.Module("v.strds.stats", input="geology", output="geology_aggr_lst", | |
strds="LST_Day_monthly_celsius", method="average,minimum,maximum") | |
# Save the attribute table of the new vector into a csv file | |
gmod.Module("v.db.select", map="geology_aggr_lst", file="ts_polygons.csv") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Compute NDVI (Dask) | |
red = RioArray('../data/LC81160482016300LGN00_B3.TIF', 1) | |
nir = RioArray('../data/LC81160482016300LGN00_B4.TIF', 1) | |
ndvi = (nir - red) / (nir + red) | |
# store the resultant/intermediate arrays onto disk | |
da.to_hdf5('ndvi_result.hdf5', '/ndvi', ndvi) | |
#ZONAL STATS | |
from rasterstats import zonal_stats | |
zonal_stats("polygons.shp", "elevation.tif", | |
stats="count min mean max median") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment