1 |
ddd9a810
|
Adam M. Wilson
|
import ee
|
2 |
|
|
from ee import mapclient
|
3 |
|
|
|
4 |
|
|
import logging
|
5 |
|
|
logging.basicConfig()
|
6 |
|
|
|
7 |
|
|
MY_SERVICE_ACCOUNT = '511722844190@developer.gserviceaccount.com' # replace with your service account
|
8 |
|
|
MY_PRIVATE_KEY_FILE = '/Users/adamw/EarthEngine-privatekey.p12' # replace with you private key file path
|
9 |
|
|
|
10 |
|
|
ee.Initialize(ee.ServiceAccountCredentials(MY_SERVICE_ACCOUNT, MY_PRIVATE_KEY_FILE))
|
11 |
|
|
|
12 |
|
|
#// EVI_Cloud_month
|
13 |
|
|
|
14 |
|
|
#// Make land mask
|
15 |
|
|
#// Select the forest classes from the MODIS land cover image and intersect them
|
16 |
|
|
#// with elevations above 1000m.
|
17 |
|
|
elev = ee.Image('srtm90_v4');
|
18 |
|
|
cover = ee.Image('MCD12Q1/MCD12Q1_005_2001_01_01').select('Land_Cover_Type_1');
|
19 |
|
|
blank = ee.Image(0);
|
20 |
|
|
#// Where (cover == 0) and (elev > 0), set the output to 1.
|
21 |
|
|
land = blank.where(
|
22 |
|
|
cover.neq(0).and(cover.neq(15)),//.and(elev.gt(0)),
|
23 |
|
|
1);
|
24 |
|
|
|
25 |
|
|
palette = ["aec3d4", // water
|
26 |
|
|
"152106", "225129", "369b47", "30eb5b", "387242", // forest
|
27 |
|
|
"6a2325", "c3aa69", "b76031", "d9903d", "91af40", // shrub, grass, savanah
|
28 |
|
|
"111149", // wetlands
|
29 |
|
|
"cdb33b", // croplands
|
30 |
|
|
"cc0013", // urban
|
31 |
|
|
"33280d", // crop mosaic
|
32 |
|
|
"d7cdcc", // snow and ice
|
33 |
|
|
"f7e084", // barren
|
34 |
|
|
"6f6f6f"].join(',');// tundra
|
35 |
|
|
|
36 |
|
|
#// make binary map for forest/nonforest
|
37 |
|
|
forest = blank.where(cover.gte(1).and(cover.lte(5)),1);
|
38 |
|
|
|
39 |
|
|
#//addToMap(forest, {min: 0, max: 1});
|
40 |
|
|
#//addToMap(cover, {min: 0, max: 17, palette:palette});
|
41 |
|
|
|
42 |
|
|
#// MODIS EVI Collection
|
43 |
|
|
collection = ee.ImageCollection("MCD43A4_EVI");
|
44 |
|
|
|
45 |
|
|
#//define reducers and filters
|
46 |
|
|
COUNT = ee.call("Reducer.count");
|
47 |
|
|
#// Loop through months and get monthly % cloudiness
|
48 |
|
|
#//for (var month = 1; month < 2; month += 1) {
|
49 |
|
|
#//month=1;
|
50 |
|
|
FilterMonth = ee.Filter(ee.call("Filter.calendarRange",
|
51 |
|
|
start=month,end=month,field="month"));
|
52 |
|
|
tmonth=collection.filter(FilterMonth)
|
53 |
|
|
|
54 |
|
|
n=tmonth.getInfo().features.length; #// Get total number of images
|
55 |
|
|
print(n+" Layers in the collection for month "+month)
|
56 |
|
|
tcloud=tmonth.reduce(COUNT).float()
|
57 |
|
|
c=ee.Image(n); #// make raster with constant value of n
|
58 |
|
|
c1=ee.Image(-1); #// make raster with constant value of -1 to convert to % cloudy
|
59 |
|
|
|
60 |
|
|
#/////////////////////////////////////////////////
|
61 |
|
|
#// Generate the cloud frequency surface:
|
62 |
|
|
#// 1 Calculate the number of days with measurements
|
63 |
|
|
#// 2 divide by the total number of layers
|
64 |
|
|
#// 3 Add -1 and multiply by -1 to invert to % cloudy
|
65 |
|
|
#// 4 Rename to "PCloudy_month"
|
66 |
|
|
tcloud = tcloud.divide(c).add(c1).multiply(c1).expression("b()*100").int8().select_([0],["PCloudy_"+month]);
|
67 |
|
|
#//if(month==1) {var cloud=tcloud} // if first year, make new object
|
68 |
|
|
#//if(month>1) {var cloud=cloud.addBands(tcloud)} // if not first year, append to first year
|
69 |
|
|
#//} //end loop over months
|
70 |
|
|
# // end loop over years
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
#//print(evi_miss.stats())
|
74 |
|
|
#//addToMap(tcloud,{min:0,max:100,palette:"000000,00FF00,FF0000"});
|
75 |
|
|
#//addToMap(elev,{min:0,max:2500,palette:"000000,00FF00,FF0000"});
|
76 |
|
|
|
77 |
|
|
#//centerMap(-122.418, 37.72, 10);
|
78 |
|
|
path = tcloud.getDownloadURL({
|
79 |
|
|
'scale': 1000,
|
80 |
|
|
'crs': 'EPSG:4326',
|
81 |
|
|
'region': '[[-90, 0], [-90, 20], [-50, 0], [-50, 20]]' //h11v08
|
82 |
|
|
#// 'region': '[[-180, -90], [-180, 90], [180, -90], [180, 90]]'
|
83 |
|
|
});
|
84 |
|
|
print('https://earthengine.googleapis.com' + path);
|