Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
258 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import ee | ||
from ee_plugin import Map | ||
|
||
# Make a date filter to get images in this date range. | ||
dateFilter = ee.Filter.date('2014-01-01', '2014-02-01') | ||
|
||
# Load a MODIS collection with EVI data. | ||
mcd43a4 = ee.ImageCollection('MODIS/MCD43A4_006_EVI') \ | ||
.filter(dateFilter) | ||
|
||
# Load a MODIS collection with quality data. | ||
mcd43a2 = ee.ImageCollection('MODIS/006/MCD43A2') \ | ||
.filter(dateFilter) | ||
|
||
# Define an inner join. | ||
innerJoin = ee.Join.inner() | ||
|
||
# Specify an equals filter for image timestamps. | ||
filterTimeEq = ee.Filter.equals(**{ | ||
'leftField': 'system:time_start', | ||
'rightField': 'system:time_start' | ||
}) | ||
|
||
# Apply the join. | ||
innerJoinedMODIS = innerJoin.apply(mcd43a4, mcd43a2, filterTimeEq) | ||
|
||
# Display the join result: a FeatureCollection. | ||
print('Inner join output:', innerJoinedMODIS) | ||
|
||
# Map a function to merge the results in the output FeatureCollection. | ||
joinedMODIS = innerJoinedMODIS.map(lambda feature: ee.Image.cat(feature.get('primary'), feature.get('secondary'))) | ||
|
||
# Print the result of merging. | ||
print('Inner join, merged bands:', joinedMODIS.getInfo()) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import ee | ||
from ee_plugin import Map | ||
|
||
def intersect(state): | ||
nPowerPlants = ee.List(state.get('power_plants')).size() | ||
# Return the state feature with a new property: power plant count. | ||
return state.set('n_power_plants', nPowerPlants) | ||
|
||
# Load the primary 'collection': US state boundaries. | ||
states = ee.FeatureCollection('TIGER/2018/States') | ||
|
||
# Load the secondary 'collection': power plants. | ||
powerPlants = ee.FeatureCollection('WRI/GPPD/power_plants') | ||
|
||
# Define a spatial filter as geometries that intersect. | ||
spatialFilter = ee.Filter.intersects(**{ | ||
'leftField': '.geo', | ||
'rightField': '.geo', | ||
'maxError': 10 | ||
}) | ||
|
||
# Define a save all join. | ||
saveAllJoin = ee.Join.saveAll(**{ | ||
'matchesKey': 'power_plants', | ||
}) | ||
|
||
# Apply the join. | ||
intersectJoined = saveAllJoin.apply(states, powerPlants, spatialFilter) | ||
|
||
# Add power plant count per state as a property. | ||
intersectJoined = intersectJoined.map(intersect) | ||
# intersectJoined = intersectJoined.map(function(state) { | ||
# # Get "power_plant" intersection list, count how many intersected this state. | ||
# nPowerPlants = ee.List(state.get('power_plants')).size() | ||
# # Return the state feature with a new property: power plant count. | ||
# return state.set('n_power_plants', nPowerPlants) | ||
# }) | ||
|
||
print(intersectJoined.getInfo()) | ||
|
||
# # Make a bar chart for the number of power plants per state. | ||
# chart = ui.Chart.feature.byFeature(intersectJoined, 'NAME', 'n_power_plants') \ | ||
# .setChartType('ColumnChart') \ | ||
# .setSeriesNames({n_power_plants: 'Power plants'}) \ | ||
# .setOptions({ | ||
# title: 'Power plants per state', | ||
# hAxis: {title: 'State'}, | ||
# vAxis: {title: 'Frequency'}}) | ||
|
||
# # Print the chart to the console. | ||
# print(chart) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import ee | ||
from ee_plugin import Map | ||
|
||
# Load a Landsat 8 image collection at a point of interest. | ||
collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') \ | ||
.filterBounds(ee.Geometry.Point(-122.09, 37.42)) | ||
|
||
# Define start and end dates with which to filter the collections. | ||
april = '2014-04-01' | ||
may = '2014-05-01' | ||
june = '2014-06-01' | ||
july = '2014-07-01' | ||
|
||
# The primary collection is Landsat images from April to June. | ||
primary = collection.filterDate(april, june) | ||
|
||
# The secondary collection is Landsat images from May to July. | ||
secondary = collection.filterDate(may, july) | ||
|
||
# Use an equals filter to define how the collections match. | ||
filter = ee.Filter.equals(**{ | ||
'leftField': 'system:index', | ||
'rightField': 'system:index' | ||
}) | ||
|
||
# Define the join. | ||
invertedJoin = ee.Join.inverted() | ||
|
||
# Apply the join. | ||
invertedJoined = invertedJoin.apply(primary, secondary, filter) | ||
|
||
# Display the result. | ||
print('Inverted join: ', invertedJoined.getInfo()) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import ee | ||
from ee_plugin import Map | ||
|
||
# Load a primary 'collection': Landsat imagery. | ||
primary = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') \ | ||
.filterDate('2014-04-01', '2014-06-01') \ | ||
.filterBounds(ee.Geometry.Point(-122.092, 37.42)) | ||
|
||
# Load a secondary 'collection': MODIS imagery. | ||
modSecondary = ee.ImageCollection('MODIS/006/MOD09GA') \ | ||
.filterDate('2014-03-01', '2014-07-01') | ||
|
||
# Define an allowable time difference: two days in milliseconds. | ||
twoDaysMillis = 2 * 24 * 60 * 60 * 1000 | ||
|
||
# Create a time filter to define a match as overlapping timestamps. | ||
timeFilter = ee.Filter.Or( | ||
ee.Filter.maxDifference(**{ | ||
'difference': twoDaysMillis, | ||
'leftField': 'system:time_start', | ||
'rightField': 'system:time_end' | ||
}), | ||
ee.Filter.maxDifference(**{ | ||
'difference': twoDaysMillis, | ||
'leftField': 'system:time_end', | ||
'rightField': 'system:time_start' | ||
}) | ||
) | ||
|
||
# Define the join. | ||
saveAllJoin = ee.Join.saveAll(**{ | ||
'matchesKey': 'terra', | ||
'ordering': 'system:time_start', | ||
'ascending': True | ||
}) | ||
|
||
# Apply the join. | ||
landsatModis = saveAllJoin.apply(primary, modSecondary, timeFilter) | ||
|
||
# Display the result. | ||
print('Join.saveAll:', landsatModis.getInfo()) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import ee | ||
from ee_plugin import Map | ||
|
||
# Load a primary 'collection': Landsat imagery. | ||
primary = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') \ | ||
.filterDate('2014-04-01', '2014-06-01') \ | ||
.filterBounds(ee.Geometry.Point(-122.092, 37.42)) | ||
|
||
# Load a secondary 'collection': GRIDMET meteorological data | ||
gridmet = ee.ImageCollection('IDAHO_EPSCOR/GRIDMET') | ||
|
||
# Define a max difference filter to compare timestamps. | ||
maxDiffFilter = ee.Filter.maxDifference(**{ | ||
'difference': 2 * 24 * 60 * 60 * 1000, | ||
'leftField': 'system:time_start', | ||
'rightField': 'system:time_start' | ||
}) | ||
|
||
# Define the join. | ||
saveBestJoin = ee.Join.saveBest(**{ | ||
'matchKey': 'bestImage', | ||
'measureKey': 'timeDiff' | ||
}) | ||
|
||
# Apply the join. | ||
landsatMet = saveBestJoin.apply(primary, gridmet, maxDiffFilter) | ||
|
||
# Print the result. | ||
print(landsatMet.getInfo()) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import ee | ||
from ee_plugin import Map | ||
|
||
# Load a Landsat 8 image collection at a point of interest. | ||
collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') \ | ||
.filterBounds(ee.Geometry.Point(-122.09, 37.42)) | ||
|
||
# Define start and end dates with which to filter the collections. | ||
april = '2014-04-01' | ||
may = '2014-05-01' | ||
june = '2014-06-01' | ||
july = '2014-07-01' | ||
|
||
# The primary collection is Landsat images from April to June. | ||
primary = collection.filterDate(april, june) | ||
|
||
# The secondary collection is Landsat images from May to July. | ||
secondary = collection.filterDate(may, july) | ||
|
||
# Use an equals filter to define how the collections match. | ||
filter = ee.Filter.equals(**{ | ||
'leftField': 'system:index', | ||
'rightField': 'system:index' | ||
}) | ||
|
||
# Create the join. | ||
simpleJoin = ee.Join.simple() | ||
|
||
# Apply the join. | ||
simpleJoined = simpleJoin.apply(primary, secondary, filter) | ||
|
||
# Display the result. | ||
print('Simple join: ', simpleJoined.getInfo()) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import ee | ||
from ee_plugin import Map | ||
|
||
# Load a primary 'collection': protected areas (Yosemite National Park). | ||
primary = ee.FeatureCollection("WCMC/WDPA/current/polygons") \ | ||
.filter(ee.Filter.eq('NAME', 'Yosemite National Park')) | ||
|
||
# Load a secondary 'collection': power plants. | ||
powerPlants = ee.FeatureCollection('WRI/GPPD/power_plants') | ||
|
||
# Define a spatial filter, with distance 100 km. | ||
distFilter = ee.Filter.withinDistance(**{ | ||
'distance': 100000, | ||
'leftField': '.geo', | ||
'rightField': '.geo', | ||
'maxError': 10 | ||
}) | ||
|
||
# Define a saveAll join. | ||
distSaveAll = ee.Join.saveAll(**{ | ||
'matchesKey': 'points', | ||
'measureKey': 'distance' | ||
}) | ||
|
||
# Apply the join. | ||
spatialJoined = distSaveAll.apply(primary, powerPlants, distFilter) | ||
|
||
# Print the result. | ||
# print(spatialJoined.getInfo()) | ||
Map.centerObject(spatialJoined, 10) | ||
Map.addLayer(ee.Image().paint(spatialJoined, 1, 3), {}, 'Spatial Joined') |
This file contains 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