-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnowProba.js
86 lines (69 loc) · 2.24 KB
/
snowProba.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Script to add MOD10A1 snow probability statistics to GMBA polygons
// IACS joint body on mountain snow cover, working group 2
// config
var config = {
name:'snowProba',
ymin:2000,
ymax:2022
};
// input datasets
var gmba = ee.FeatureCollection("users/sgascoin/GMBA_lite");
var dem250 = ee.Image("USGS/GMTED2010_FULL");
// collection of interest
var coi = ee.ImageCollection("MODIS/061/MOD10A1").select('NDSI_Snow_Cover');
// function to convert mod10a1 to snow/no snow (clouds are masked)
var binarize = function(img){return img.gt(0)};
// masking water improves the output
var waterMask = ee.Image('MODIS/MOD44W/MOD44W_005_2000_02_24')
.select('water_mask')
.not();
// dem mask
var dem = dem250.select('mea').resample();
/*
// smaller domain for debugging
gmba = gmba.filterBounds(debug);
*/
// function to get the variable of interest
// annual snow probability in days/year
var getVoi = function(y1,hem){
// select first month of water year according to hemisphere
var m0 = ee.Algorithms.If(hem.equals('N'),9,3);
// filter one water year
var t1 = ee.Date.fromYMD(y1,m0,1);
var t2 = t1.advance(1,'year');
var filteredCol = coi.filterDate(t1,t2);
// count cloud-free snow days
var snow = filteredCol.map(binarize).sum();
// count cloud-free days
var clear = filteredCol.count();
// compute snow probability
var snowProba = snow.divide(clear)
.multiply(t2.difference(t1,'day'))
// mask water
.updateMask(waterMask)
// mask non-valid elevations
.updateMask(demMask);
return snowProba;
};
// load function to fill gmba
var addToGmba = require('users/sgascoin/iacs_jb_wg2:addToGmba.js');
// min elevation of the lower bound
var low0 = 0;
// max elevation of the lower bound
var low1 = 9000;
// output filename prefix
var name0 = config.name;
// elevation band loop (client-side)
while (low0 < low1) {
// define elevation range
var elevParam = {low:low0, up:low0 + 500};
// adjust output filename
config.name = name0+'_'+elevParam.low+elevParam.up+'_';
// create DEM mask
var demMask = dem.gte(elevParam.low).and(dem.lt(elevParam.up));
// run computations
addToGmba.addToGmba(config,coi,gmba,getVoi);
// increment lower elevation
low0 = low0 + 500;
}