forked from shilosh/ContinuousLST
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Explore TFA graphs
202 lines (170 loc) · 7.54 KB
/
Explore TFA graphs
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// This code allows the reader to investigate the effects of topography
// and vegetation on the anomalies and LSTcont.
var CFSV2_TFA = ee.Image("users/shilosh/CFSv2_Daily_LST_TFA"),
MODIS_TFA = ee.Image("users/shilosh/MODIS_Daily_LST_TFA"),
LST_Cont = ee.Image("users/shilosh/MODIS_Continuous_LST_Daily_2018");
var firstDay = '2018-01-01';
var lastDay = '2019-01-01';
var Temperature_Band = 'LST_Daily_Mean';
var Day_Temperature_Band = 'LST_Day_1km';
var Night_Temperature_Band = 'LST_Night_1km';
var collection = 'MODIS/006/MYD11A1';
var geometry = ee.Geometry.Rectangle([33.2,29.0,36.6,34.0]);
var geometry_json = geometry.toGeoJSON();
// Zoom to a location.
Map.setCenter(34.80, 31.25, 9); // Center on Beer-Sheva
// Reverse the images into imageCollections
var MODIS_TFA_ic = ee.ImageCollection(MODIS_TFA.bandNames().map(function(name) {
return MODIS_TFA.select([ee.Algorithms.String(name)],['mod']).set('system:DOY', ee.Number.parse(ee.Algorithms.String(name).replace('TFA','0').replace('_','')).add(1)) }))
var CFSV2_TFA_ic = ee.ImageCollection(CFSV2_TFA.bandNames().map(function(name) {
return CFSV2_TFA.select([ee.Algorithms.String(name)],['cfs']).set('system:DOY', ee.Number.parse(ee.Algorithms.String(name).replace('TFA','0').replace('_','')).add(1)) }))
var Cont_LST = ee.ImageCollection(LST_Cont.bandNames().map(function(name) {
return LST_Cont.select([ee.Algorithms.String(name)],['contLst']).set('system:time_start', ee.Date(ee.Algorithms.String(name).replace('day_',''))) }))
print('Cont_LST = ', Cont_LST)
//convert Kelvin to Celsius
var MODIS_k2celsius = function(image) {
return image.updateMask(image.select(Day_Temperature_Band))
.updateMask(image.select(Night_Temperature_Band))
.reduce( ee.Reducer.mean()).rename(Temperature_Band)
.multiply(ee.Image(0.02))
.subtract(ee.Image(273.15)) //convert Kelvin to Celsius
.set('system:time_start', image.get('system:time_start'));
};
var CFSV2_k2celsius = function(image) {
return image.subtract(ee.Image(273.15))
.set('system:time_start', image.get('system:time_start'));
};
// Add a property with doy to the colection.
function createDoyProperty(img) {
var d = ee.Date(img.get('system:time_start'))
.getRelative('day', 'year')
.add(1);
return img.set('system:DOY', d);
}
// var MODIS_Daily = ee.ImageCollection(ee.List.sequence(1, 365).map(function (doy){
// return ee.ImageCollection(collection)
// .select(Day_Temperature_Band, Night_Temperature_Band)
// .filter(ee.Filter.calendarRange(doy, doy, 'day_of_year'))
// .map(MODIS_k2celsius)
// .mean()
// .set('system:DOY',doy)
// }))
var MODIS_Daily = ee.ImageCollection(collection)
.filterDate(firstDay, lastDay)
.select('LST_Day_1km', 'LST_Night_1km')
// .map(function (image){return image.reduce(ee.Reducer.mean())
// .set('system:time_start', image.get('system:time_start'))})
// .map(addTimeStampToMODIS)
.map(MODIS_k2celsius)
.map(createDoyProperty)
print('MODIS_Daily = ', MODIS_Daily)
var CFSV2_Daily = ee.ImageCollection(ee.List.sequence(1, 365).map(function (doy){
return ee.ImageCollection('NOAA/CFSV2/FOR6H')
.filterDate(firstDay, lastDay)
.select('Maximum_temperature_height_above_ground_6_Hour_Interval')
.filter(ee.Filter.calendarRange(doy, doy, 'day_of_year'))
.map(CFSV2_k2celsius)
.mean()
.set('system:DOY',doy)
}))
print('CFSV2_Daily = ', CFSV2_Daily)
// Use an equals filter to specify how the collections match.
var Filter = ee.Filter.equals({
leftField: 'system:DOY',
rightField: 'system:DOY'
});
// Define the join.
var innerJoin = ee.Join.inner('primary', 'secondary');
// Join CFSV2 with CFSV2_TFA_ic by DOY
// Apply the join.
var CFSV2_JoinInner = innerJoin.apply(CFSV2_Daily, CFSV2_TFA_ic, Filter);
// Calculate CFSv2 anomalies
CFSV2_Daily = CFSV2_JoinInner.map(function(f) {
var CFSv2_TFA = ee.Image(f.get('secondary'));
var CFSv2_Daily_mean = ee.Image(f.get('primary'));
return CFSv2_Daily_mean.addBands(CFSv2_TFA.rename('CFSv2_TFA'));
})
// Join CFSV2 with MODIS_TFA_ic by DOY
// Apply the join.
var CFSV2_JoinInner = innerJoin.apply(CFSV2_Daily, MODIS_TFA_ic, Filter);
// Calculate CFSv2 anomalies
CFSV2_Daily = CFSV2_JoinInner.map(function(f) {
var Modis_TFA = ee.Image(f.get('secondary'));
var CFSv2 = ee.Image(f.get('primary'));
return CFSv2.addBands(Modis_TFA.rename('MODIS_TFA'));
})
// Join all with MODIS_Daily by DOY
// Apply the join.
var CFSV2_JoinInner = innerJoin.apply(CFSV2_Daily, MODIS_Daily, Filter);
// Calculate CFSv2 anomalies
CFSV2_Daily = CFSV2_JoinInner.map(function(f) {
var Modis_daily_mean = ee.Image(f.get('secondary'));
var CFSv2 = ee.Image(f.get('primary'));
return CFSv2.addBands(Modis_daily_mean.rename('MODIS_Daily'));
})
var timeFromDOY_LST = function(image) {
var days = ee.Number(image.get('system:DOY'))
// var d = ee.Date('2010-01-01')
var d = ee.Date(firstDay)
return image
.set('system:time_start', d.advance(days.subtract(1), 'day'));
};
CFSV2_Daily = CFSV2_Daily.map(timeFromDOY_LST)
print('CFSV2_Daily = ', CFSV2_Daily)
// Use an equals filter to specify how the collections match.
var Filter = ee.Filter.equals({
leftField: 'system:time_start',
rightField: 'system:time_start'
});
// Join all with Cont_LST by system:time_start
// Apply the join.
var CFSV2_JoinInner = innerJoin.apply(CFSV2_Daily, Cont_LST, Filter);
// Calculate CFSv2 anomalies
CFSV2_Daily = CFSV2_JoinInner.map(function(f) {
var cont_lst = ee.Image(f.get('secondary'));
var CFSv2 = ee.Image(f.get('primary'));
return CFSv2.addBands(cont_lst);
})
print('CFSV2_Daily = ', CFSV2_Daily)
var scale = ee.Image('MODIS/006/MYD11A1/2018_01_01').projection().nominalScale().getInfo();
// Map.addLayer(ee.Image(MaskedValues.first()).select('con'))
// Map.addLayer(rmse_val)
var panel = ui.Panel();
panel.style().set('width', '300px');
// Create an intro panel with labels.
var intro = ui.Panel([
ui.Label({
value: 'LSTcont Chart Inspector',
style: {fontSize: '20px', fontWeight: 'bold'}
}),
ui.Label('Click a point on the map to inspect 2018 data.')
]);
panel.add(intro);
// Create panels to hold lon/lat values.
var lon = ui.Label();
var lat = ui.Label();
panel.add(ui.Panel([lon, lat], ui.Panel.Layout.flow('horizontal')));
// Register a callback on the default map to be invoked when the map is clicked.
Map.onClick(function(coords) {
// Update the lon/lat panel with values from the click event.
lon.setValue('lon: ' + coords.lon.toFixed(2)),
lat.setValue('lat: ' + coords.lat.toFixed(2));
// Add a red dot for the point clicked on.
var point = ee.Geometry.Point(coords.lon, coords.lat);
var dot = ui.Map.Layer(point, {color: 'FF0000'});
Map.layers().set(1, dot);
// Create an LST TFA chart.
// var series = ui.Chart.image.doySeriesByYear(
// LST, Temperature_Band, geometry, ee.Reducer.mean(), 500);
var series = ui.Chart.image.series(
CFSV2_Daily, point, ee.Reducer.mean(), 500);
series.setOptions({
title: 'LST & ContinuousLST',
vAxis: {title: 'Celsius'},
hAxis: {title: 'Day of year', gridlines: {count: 7}},
});
panel.widgets().set(2, series);
});
Map.style().set('cursor', 'crosshair');
// Add the panel to the ui.root.
ui.root.insert(0, panel);