The purpose of this code is to demonstrate the potential of Earth Engine for building maps driven by python code structures and visualized inline in an iPython notebook.
Initialize the Earth Engine object using the authentication credentials. These two lines of code below require a special environment and authentication procedure to work. To read more about how to set up the authentication process, please visit: https://github.com/catherinekuhn/ee-python/ee-python/ and select the "Python API Instructions" notebook for detailed instructions. Once you have followed the set-up directions, you should be ready to access the Google Earth Engine Python API.
Before we actually initialize, always make sure you are in the correct environment. You can do this by typing the following command into the terminal.
conda info --envs
If you aren't in the ee-python environments switch to it by using the following (exclude source if using Windows)
source activate ee-python
If you have followed the installation instructions and are in the correct environment, you are now ready to use the following code.
In [16]:
# Call into the web API and authenticate your user credentials
% run 'ee_utils.ipynb'
initialize_api()
In [17]:
test_api()
Out[17]:
Run Google Developer Tyler Erickson's ever-useful interactive widget to enable map interactive zoomable map visualization of our data.
In [18]:
%run 'define_google_maps_interactive_widget.ipynb'
Now, we will call in three different images from our Earth Engine assets. These assets are images with a single band that stores the value of a single chemical parameter for each pixel. While we will use CO2, CH4 and FDOM for our demo, users could generate these images for any field-collected chemical variable.
In [19]:
missco2= ee.Image('users/kuhniculous/missco2')
missch4 = ee.Image('users/kuhniculous/missch4')
missfdom = ee.Image('users/kuhniculous/missfdom')
This function from ee_utils will isolate pixels classified as open water by the National Land Cover Dataset
In [20]:
NLCD2011 = ee.Image("NLCD2011");
water_features_ = NLCD2011.select('landcover').eq(11);
water_features = water_features_.mask(water_features_)
Get the percent imperviousness for each pixel from the 2011 National Land Cover Dataset.
In [21]:
impervious = NLCD2011.select('impervious')
Call elevation (10 m) from the USGS National Elevation Dataset.
In [22]:
elevation = ee.Image("USGS/NED");
Filter the NLCD to visualize just cultivated cropland
In [23]:
crops = NLCD2011.select('landcover').eq(82);
crops = crops.mask(crops)
Define palettes to display imagery
In [24]:
print('UPPER MISSISSIPPI RIVER BASIN')
# Call the map widget and center the map
map = GoogleMapsWidget(lat=43.7219, lng=-91.2482, zoom=10)
display(map)
# Define visualization parameters for chemical variables
co2pal = {'min': 0, 'max': 40, 'palette': ','.join(['0000FF','00FF00','00FFFF','FF0000'])}
ch4pal = {'min': 0, 'max': 0.6, 'palette': ','.join(['0000FF','00FF00','00FFFF','FF0000'])}
fdompal = {'min': 0, 'max': 90, 'palette': ','.join(['0000FF', '00FF00', '00FFFF', 'FF0000'])}
# Display chemical variables
map.addLayer(image=missco2, vis_params=co2pal, name='CO2')
map.addLayer(image=missch4, vis_params=ch4pal, name = 'CH4')
map.addLayer(image=missfdom, vis_params=fdompal, name = 'FDOM')
# Define palettes for landscape characteristics
h20pal = {'min': 0, 'max': 1, 'palette': ','.join(["000000","0000FF"])}
imppal = {'min': 0, 'max': 100, 'palette': ','.
join(["66ffff","00ff00", "ffff00", "ff3300", "ff0000"])}
elpal = {'min': 0, 'max': 600, 'palette': ','.join(['000000','ffffff'])}
croppal = {'min': 0, 'max': 1, 'palette': ','.join(["000000","76EE00"])}
# Display landscape characteristics
map.addLayer(image = water_features, vis_params=h20pal, name = 'Permanent Water' )
map.addLayer(image = impervious, vis_params=imppal, name ='Impervious Surface (%)')
map.addLayer(image = elevation, vis_params = elpal, name = 'Elevation (m)')
map.addLayer( image = crops, vis_params = croppal, name = 'Cultivated Crops')
This data was collected by the UW River Systems Research Group.
In [25]:
amzco2 = ee.Image("users/kuhniculous/amzco2")
amzch4 = ee.Image("users/kuhniculous/amzch4")
amzfdom = ee.Image("users/kuhniculous/amzfdom")
In [26]:
# Elevation
elevation = ee.Image('srtm90_v4')
# Water Features
GlobCover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3");
waterf = GlobCover.select('landcover').eq(210)
waterfeatures = waterf.mask(waterf)
In [27]:
print('AMAZON RIVER BASIN')
map = GoogleMapsWidget(lat=-2.068641999489608, lng=-53.470458984375, zoom=8)
display(map)
co2pal = {'min': 0, 'max': 100, 'palette': ','.join(['0000FF','00FF00','00FFFF','FF0000'])}
ch4pal = {'min': 0, 'max': 0.2, 'palette': ','.join(['0000FF','00FF00','00FFFF','FF0000'])}
fdompal = {'min': 0, 'max': 50, 'palette': ','.join(['0000FF', '00FF00', '00FFFF', 'FF0000'])}
map.addLayer(image=amzco2, vis_params=co2pal, name='CO2')
map.addLayer(image=amzch4, vis_params=ch4pal, name = 'CH4')
map.addLayer(image=amzfdom, vis_params=fdompal, name = 'FDOM')
# Define palettes for landscape characteristics
h20pal = {'min': 0, 'max': 1, 'palette': ','.join(["000000","0000FF"])}
elpal = {'min': 0, 'max': 1000, 'palette': ','.join(['000000','ffffff'])}
# Display landscape characteristics
map.addLayer(image = waterfeatures, vis_params=h20pal, name = 'Permanent Water' )
map.addLayer(image = elevation, vis_params = elpal, name = 'Elevation (m)')
Export image metadata as a text file for use later.
In [35]:
co2_metadata = missco2.getInfo()
In [36]:
%store co2_metadata >> missco2_metadata.txt
Run a unit test to make sure the file saved.
In [ ]:
% run ee_debug.ipynb