Skip to content

Commit d029e9a

Browse files
update
1 parent b9b8b02 commit d029e9a

File tree

39 files changed

+4623
-3339
lines changed

39 files changed

+4623
-3339
lines changed
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var date = '2020-01-01' // This is client-side
2-
print(typeof(date))
1+
var date = '2020-01-01'; // This is client-side
2+
print(typeof(date));
33

4-
var eedate = ee.Date('2020-01-01').format() // This is server-side
5-
print(typeof(eedate))
4+
var eedate = ee.Date('2020-01-01').format(); // This is server-side
5+
print(typeof(eedate));
66

77
// To bring server-side objects to client-side, you can call .getInfo()
88

@@ -13,8 +13,8 @@ print(typeof(eedate))
1313
// getInfo() blocks the execution of your code till the value is fetched
1414
// If the value takes time to compute, your code editor will freeze
1515
// This is not a good user experience
16-
var s2 = ee.ImageCollection("COPERNICUS/S2_SR")
17-
var filtered = s2.filter(ee.Filter.date('2020-01-01', '2020-02-01'))
16+
var s2 = ee.ImageCollection('COPERNICUS/S2_SR');
17+
var filtered = s2.filter(ee.Filter.date('2020-01-01', '2020-02-01'));
1818

1919
//var numImages = filtered.size().getInfo()
2020
//print(numImages)
@@ -25,7 +25,7 @@ var filtered = s2.filter(ee.Filter.date('2020-01-01', '2020-02-01'))
2525
// value has been computed and ready to be used.
2626

2727
var myCallback = function(object) {
28-
print(object)
29-
}
30-
print('Computing the size of the collection')
31-
var numImages = filtered.size().evaluate(myCallback)
28+
print(object);
29+
};
30+
print('Computing the size of the collection');
31+
var numImages = filtered.size().evaluate(myCallback);

code/end_to_end_gee/05-Earth-Engine-Apps/01c_Client_vs_Server_(exercise)

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
var date = ee.Date.fromYMD(2019, 1, 1)
2-
print(date)
1+
var date = ee.Date.fromYMD(2019, 1, 1);
2+
print(date);
33

44
// We can use the format() function to create
55
// a string from a date object
6-
var dateString = date.format('dd MMM, YYYY')
7-
print(dateString)
6+
var dateString = date.format('dd MMM, YYYY');
7+
print(dateString);
88

99
// Exercise
1010
// The print statement below combines a client-side string
1111
// with a server-side string - resulting in an error.
1212

1313
// Fix the code so that the following message is printed
1414
// 'The date is 01 Jan, 2019'
15-
var message = 'The date is ' + dateString
16-
print(message)
15+
var message = 'The date is ' + dateString;
16+
print(message);
1717

1818
// Hint:
1919
// Convert the client-side string to a server-side string

code/end_to_end_gee/05-Earth-Engine-Apps/02b_Using_UI_Elements_(complete)

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var yearSelector = ui.Select({
66
items: years,
77
value: '2014',
88
placeholder: 'Select a year',
9-
})
9+
});
1010
Map.add(yearSelector);
1111

1212
var loadImage = function() {

code/end_to_end_gee/05-Earth-Engine-Apps/02c_Using_UI_Elements_(exercise)

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Instead of manually creating a list of years like before
22
// we can create a list of years using ee.List.sequence()
3-
var years = ee.List.sequence(2014, 2020)
3+
var years = ee.List.sequence(2014, 2020);
44

55
// Convert them to strings using format() function
66
var yearStrings = years.map(function(year){
7-
return ee.Number(year).format('%04d')
8-
})
7+
return ee.Number(year).format('%04d');
8+
});
99
print(yearStrings);
1010

1111
// Convert the server-side object to client-side using
@@ -15,8 +15,8 @@ yearStrings.evaluate(function(yearList) {
1515
items: yearList,
1616
value: '2014',
1717
placeholder: 'Select a year',
18-
})
19-
Map.add(yearSelector)
18+
});
19+
Map.add(yearSelector);
2020
});
2121

2222
// Exercise

code/end_to_end_gee/05-Earth-Engine-Apps/03a_Building_an_App_with_UI_Widgets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var title = ui.Label({
99
style: {'fontSize': '24px'}
1010
});
1111
// You can add widgets to the panel
12-
mainPanel.add(title)
12+
mainPanel.add(title);
1313

14-
Map.setCenter(76.43, 12.41, 8)
14+
Map.setCenter(76.43, 12.41, 8);
1515
ui.root.add(mainPanel);

code/end_to_end_gee/05-Earth-Engine-Apps/03b_Building_an_App_with_UI_Widgets_(complete)

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ mainPanel.add(dropdownPanel);
1919

2020
var yearSelector = ui.Select({
2121
placeholder: 'please wait..',
22-
})
22+
});
2323

2424
var monthSelector = ui.Select({
2525
placeholder: 'please wait..',
26-
})
26+
});
2727

28-
var button = ui.Button('Load')
29-
dropdownPanel.add(yearSelector)
30-
dropdownPanel.add(monthSelector)
31-
dropdownPanel.add(button)
28+
var button = ui.Button('Load');
29+
dropdownPanel.add(yearSelector);
30+
dropdownPanel.add(monthSelector);
31+
dropdownPanel.add(button);
3232

3333

3434
// Let's add a dropdown with the years
35-
var years = ee.List.sequence(2014, 2020)
36-
var months = ee.List.sequence(1, 12)
35+
var years = ee.List.sequence(2014, 2020);
36+
var months = ee.List.sequence(1, 12);
3737

3838
// Dropdown items need to be strings
3939
var yearStrings = years.map(function(year){

code/end_to_end_gee/05-Earth-Engine-Apps/03c_Building_an_App_with_UI_Widgets_(exercise)

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var title = ui.Label({
99
style: {'fontSize': '24px'}
1010
});
1111
// You can add widgets to the panel
12-
mainPanel.add(title)
12+
mainPanel.add(title);
1313

1414
// You can even add panels to other panels
1515
var dropdownPanel = ui.Panel({
@@ -19,60 +19,59 @@ mainPanel.add(dropdownPanel);
1919

2020
var yearSelector = ui.Select({
2121
placeholder: 'please wait..',
22-
})
22+
});
2323

2424
var monthSelector = ui.Select({
2525
placeholder: 'please wait..',
26-
})
26+
});
2727

28-
var button = ui.Button('Load')
29-
dropdownPanel.add(yearSelector)
30-
dropdownPanel.add(monthSelector)
31-
dropdownPanel.add(button)
28+
var button = ui.Button('Load');
29+
dropdownPanel.add(yearSelector);
30+
dropdownPanel.add(monthSelector);
31+
dropdownPanel.add(button);
3232

3333

3434
// Let's add a dropdown with the years
35-
var years = ee.List.sequence(2014, 2020)
36-
var months = ee.List.sequence(1, 12)
35+
var years = ee.List.sequence(2014, 2020);
36+
var months = ee.List.sequence(1, 12);
3737

3838
// Dropdown items need to be strings
3939
var yearStrings = years.map(function(year){
40-
return ee.Number(year).format('%04d')
41-
})
40+
return ee.Number(year).format('%04d');
41+
});
4242
var monthStrings = months.map(function(month){
43-
return ee.Number(month).format('%02d')
44-
})
43+
return ee.Number(month).format('%02d');
44+
});
4545

4646
// Evaluate the results and populate the dropdown
4747
yearStrings.evaluate(function(yearList) {
48-
yearSelector.items().reset(yearList)
49-
yearSelector.setPlaceholder('select a year')
50-
})
48+
yearSelector.items().reset(yearList);
49+
yearSelector.setPlaceholder('select a year');
50+
});
5151

5252
monthStrings.evaluate(function(monthList) {
53-
monthSelector.items().reset(monthList)
54-
monthSelector.setPlaceholder('select a month')
55-
56-
})
53+
monthSelector.items().reset(monthList);
54+
monthSelector.setPlaceholder('select a month');
55+
});
5756

5857
// Define a function that triggers when any value is changed
5958
var loadComposite = function() {
6059
var col = ee.ImageCollection("NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG");
61-
var year = yearSelector.getValue()
62-
var month = monthSelector.getValue()
60+
var year = yearSelector.getValue();
61+
var month = monthSelector.getValue();
6362
var startDate = ee.Date.fromYMD(
64-
ee.Number.parse(year), ee.Number.parse(month), 1)
65-
var endDate = startDate.advance(1, 'month')
66-
var filtered = col.filter(ee.Filter.date(startDate, endDate))
67-
68-
var image = ee.Image(filtered.first()).select('avg_rad')
69-
var nighttimeVis = {min: 0.0, max: 60.0}
70-
var layerName = 'Night Lights ' + year + '-' + month
71-
Map.addLayer(image, nighttimeVis, layerName)
72-
}
73-
button.onClick(loadComposite)
74-
75-
Map.setCenter(76.43, 12.41, 8)
63+
ee.Number.parse(year), ee.Number.parse(month), 1);
64+
var endDate = startDate.advance(1, 'month');
65+
var filtered = col.filter(ee.Filter.date(startDate, endDate));
66+
67+
var image = ee.Image(filtered.first()).select('avg_rad');
68+
var nighttimeVis = {min: 0.0, max: 60.0};
69+
var layerName = 'Night Lights ' + year + '-' + month;
70+
Map.addLayer(image, nighttimeVis, layerName);
71+
};
72+
button.onClick(loadComposite);
73+
74+
Map.setCenter(76.43, 12.41, 8);
7675
ui.root.add(mainPanel);
7776

7877
// Exercise

code/end_to_end_gee/05-Earth-Engine-Apps/04a_Publishing_the_App

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var title = ui.Label({
99
style: {'fontSize': '24px'}
1010
});
1111
// You can add widgets to the panel
12-
mainPanel.add(title)
12+
mainPanel.add(title);
1313

1414
// You can even add panels to other panels
1515
var dropdownPanel = ui.Panel({
@@ -19,59 +19,58 @@ mainPanel.add(dropdownPanel);
1919

2020
var yearSelector = ui.Select({
2121
placeholder: 'please wait..',
22-
})
22+
});
2323

2424
var monthSelector = ui.Select({
2525
placeholder: 'please wait..',
26-
})
26+
});
2727

28-
var button = ui.Button('Load')
29-
dropdownPanel.add(yearSelector)
30-
dropdownPanel.add(monthSelector)
31-
dropdownPanel.add(button)
28+
var button = ui.Button('Load');
29+
dropdownPanel.add(yearSelector);
30+
dropdownPanel.add(monthSelector);
31+
dropdownPanel.add(button);
3232

3333

3434
// Let's add a dropdown with the years
35-
var years = ee.List.sequence(2014, 2020)
36-
var months = ee.List.sequence(1, 12)
35+
var years = ee.List.sequence(2014, 2020);
36+
var months = ee.List.sequence(1, 12);
3737

3838
// Dropdown items need to be strings
3939
var yearStrings = years.map(function(year){
40-
return ee.Number(year).format('%04d')
41-
})
40+
return ee.Number(year).format('%04d');
41+
});
4242
var monthStrings = months.map(function(month){
43-
return ee.Number(month).format('%02d')
44-
})
43+
return ee.Number(month).format('%02d');
44+
});
4545

4646
// Evaluate the results and populate the dropdown
4747
yearStrings.evaluate(function(yearList) {
48-
yearSelector.items().reset(yearList)
49-
yearSelector.setPlaceholder('select a year')
50-
})
48+
yearSelector.items().reset(yearList);
49+
yearSelector.setPlaceholder('select a year');
50+
});
5151

5252
monthStrings.evaluate(function(monthList) {
53-
monthSelector.items().reset(monthList)
54-
monthSelector.setPlaceholder('select a month')
55-
56-
})
53+
monthSelector.items().reset(monthList);
54+
monthSelector.setPlaceholder('select a month');
55+
});
5756

5857
// Define a function that triggers when any value is changed
5958
var loadComposite = function() {
6059
var col = ee.ImageCollection("NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG");
61-
var year = yearSelector.getValue()
62-
var month = monthSelector.getValue()
60+
var year = yearSelector.getValue();
61+
var month = monthSelector.getValue();
6362
var startDate = ee.Date.fromYMD(
64-
ee.Number.parse(year), ee.Number.parse(month), 1)
65-
var endDate = startDate.advance(1, 'month')
66-
var filtered = col.filter(ee.Filter.date(startDate, endDate))
67-
68-
var image = ee.Image(filtered.first()).select('avg_rad')
69-
var nighttimeVis = {min: 0.0, max: 60.0}
70-
var layerName = 'Night Lights ' + year + '-' + month
71-
Map.addLayer(image, nighttimeVis, layerName)
72-
}
73-
button.onClick(loadComposite)
74-
75-
Map.setCenter(76.43, 12.41, 8)
63+
ee.Number.parse(year), ee.Number.parse(month), 1);
64+
var endDate = startDate.advance(1, 'month');
65+
var filtered = col.filter(ee.Filter.date(startDate, endDate));
66+
67+
var image = ee.Image(filtered.first()).select('avg_rad');
68+
var nighttimeVis = {min: 0.0, max: 60.0};
69+
var layerName = 'Night Lights ' + year + '-' + month;
70+
Map.addLayer(image, nighttimeVis, layerName);
71+
};
72+
button.onClick(loadComposite);
73+
74+
Map.setCenter(76.43, 12.41, 8);
7675

7776
ui.root.add(mainPanel);

0 commit comments

Comments
 (0)