Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
spatialthoughts committed Sep 1, 2023
1 parent be887ed commit 2196878
Show file tree
Hide file tree
Showing 20 changed files with 310 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,9 @@ Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '201
// The pyramidingPolicy parameter should a dictionary specifying
// the policy for each band. A simpler way to specify it for all
// bands is to use {'.default': 'mode'}

// assetId should be specified as a string
// Lookup your asset root name from the 'Assets' tab
// If it is 'users/username', you can specify the id as
// 'users/username/classified_image'

Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ var after = s2
.select('B.*')
.median();

Map.addLayer(after, rgbVis, 'after');
Map.addLayer(after.clip(geometry), rgbVis, 'after');

// Classify the image.
var afterClassified= after.classify(classifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var after = s2
.select('B.*')
.median();

Map.addLayer(after, rgbVis, 'after');
Map.addLayer(after.clip(geometry), rgbVis, 'after');

// Classify the image.
var afterClassified= after.classify(classifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function maskS2clouds(image) {
}


var s2 = ee.ImageCollection('COPERNICUS/S2')
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
.filter(ee.Filter.bounds(geometry))
.map(maskS2clouds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function maskS2clouds(image) {
}


var s2 = ee.ImageCollection("COPERNICUS/S2")
var s2 = ee.ImageCollection("COPERNICUS/S2_HARMONIZED")
.filter(ee.Filter.bounds(geometry))
.map(maskS2clouds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// We create a NDVI time-series and export each
// image as a separate GeoTiff file
var s2 = ee.ImageCollection("COPERNICUS/S2");
var s2 = ee.ImageCollection("COPERNICUS/S2_HARMONIZED/");
var geometry = ee.Geometry.Polygon([[
[82.60642647743225, 27.16350437805251],
[82.60984897613525, 27.1618529901377],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ var imageId = '20190703T050701_20190703T052312_T43PGP';

// S2 Cloudless Algorithm
// This algorithm requires different bands from 3 different datasets
var s2Bands = ee.Image('COPERNICUS/S2/'+ imageId)
var s2Bands = ee.Image('COPERNICUS/S2_HARMONIZED/'+ imageId)
.select(['B7', 'B8', 'B8A', 'B10']);
var s2SrBands = ee.Image('COPERNICUS/S2_SR/' + imageId)
var s2SrBands = ee.Image('COPERNICUS/S2_SR_HARMONIZED/' + imageId)
.select(['B2', 'B3', 'B4', 'B5']);
var s2CloudBands = ee.Image('COPERNICUS/S2_CLOUD_PROBABILITY/'+ imageId)
.select(['probability'])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var s2 = ee.ImageCollection("COPERNICUS/S2");
var admin2 = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level2");
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var admin2 = ee.FeatureCollection('FAO/GAUL_SIMPLIFIED_500m/2015/level2');

var bangalore = admin2.filter(ee.Filter.eq('ADM2_NAME', 'Bangalore Urban'))
var geometry = bangalore.geometry()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var geometry = ee.Geometry.Point([77.5979, 13.00896]);
Map.centerObject(geometry, 10)

var s2 = ee.ImageCollection("COPERNICUS/S2")
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
var rgbVis = {
min: 0.0,
max: 0.3,
Expand All @@ -24,8 +24,8 @@ function maskS2clouds(image) {
var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
qa.bitwiseAnd(cirrusBitMask).eq(0))
return image.updateMask(mask).divide(10000)
.select("B.*")
.copyProperties(image, ["system:time_start"])
.select('B.*')
.copyProperties(image, ['system:time_start'])
}


Expand Down Expand Up @@ -60,6 +60,7 @@ var chartPanel = ui.Panel();
var selectionPanel = ui.Panel({
layout: ui.Panel.Layout.flow('horizontal'),
});
var downloadPanel = ui.Panel();

resultsPanel.style().set({
width: '400px',
Expand All @@ -69,15 +70,17 @@ resultsPanel.style().set({
var resetPanel = ui.Panel();


resultsPanel.add(selectionPanel)
resultsPanel.add(chartPanel)
resultsPanel.add(resetPanel)
resultsPanel.add(selectionPanel);
resultsPanel.add(chartPanel);
resultsPanel.add(downloadPanel);
resultsPanel.add(resetPanel);

// Function to reset the app to initial state
var resetEverything = function() {
chartPanel.clear()
selectionPanel.clear()
resetPanel.clear()
chartPanel.clear();
selectionPanel.clear();
downloadPanel.clear();
resetPanel.clear();

Map.clear()

Expand All @@ -104,7 +107,7 @@ var displayChart = function(point) {

var filtered = s2
.filter(ee.Filter.date('2019-01-01', '2019-12-31'))
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 50))
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
.map(maskS2clouds)
.map(addNDVI)
.filter(ee.Filter.bounds(geometry))
Expand All @@ -116,35 +119,79 @@ var displayChart = function(point) {
scale: 20}).setOptions({
title: 'NDVI Time Series',
vAxis: {title: 'NDVI'},
hAxis: {title: 'Date', gridlines: {count: 12}}
hAxis: {title: 'Date', gridlines: {count: 12}},
interpolateNulls: true,
pointSize: 2,
lineWidth: 1
})

chartPanel.clear()
selectionPanel.clear()
selectionPanel.add(ui.Label('Choose an image to display:'))
chartPanel.add(chart)

// S2 collection has overlapping granules for same dates
// Add a 'date' property so we can merge data for the same date
var filtered = filtered.map(function(image) {
var dateString = ee.Date(image.date()).format('YYYY-MM-dd')
return image.set('date', dateString);
});

var addNdviLayer = function(dateString) {
var date = ee.Date.parse('YYYY-MM-dd', dateString)
var image = ee.Image(filtered.filter(ee.Filter.date(date, date.advance(1, 'day'))).mosaic())
var image = filtered
.filter(ee.Filter.date(date, date.advance(1, 'day')))
.mosaic();
Map.addLayer(image.select('ndvi'), ndviVis, 'NDVI Image -' + dateString)
}


filtered.aggregate_array('system:time_start').evaluate(function(ids) {
var dates = ee.List(ids).distinct().map(function(timestamp) {
return ee.Date(timestamp).format('YYYY-MM-dd')
})
dates.evaluate(function(dateList){
var dates = filtered.aggregate_array('date').distinct();

// Add dates to a dropdown selector
dates.evaluate(function(dateList){
selectionPanel.add(ui.Select({
items: dateList,
onChange: addNdviLayer,
placeholder: 'Select a date'
}))
})

// Extract the NDVI values as a FeatureCollection
var ndviFc = ee.FeatureCollection(dates.map(function(dateString) {
var date = ee.Date.parse('YYYY-MM-dd', dateString)
var image = filtered
.filter(ee.Filter.date(date, date.advance(1, 'day')))
.mosaic();

var ndviImage = image.select('ndvi');
var stats = ndviImage.reduceRegion({
reducer: ee.Reducer.mean().setOutputs(['ndvi']),
geometry: geometry,
scale: 20
});
// Add date as wel as lat/lon columns
var properties = stats.combine({
'date': dateString,
'longitude': point['lon'],
'latitude': point['lat']
})
return ee.Feature(null, properties);
}));

// Prepare the collection to download
var downloadReady = function(url) {
var label = ui.Label({
value: 'Download CSV',
targetUrl: url})
downloadPanel.add(label);
}
ndviFc.getDownloadURL({
format: 'CSV',
selectors: ['date', 'latitude', 'longitude', 'ndvi'],
filename: 'ndvi_time_series',
callback: downloadReady})

});
//});

}
// Call the function to build the initial UI state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,9 @@ Map.addLayer(classified.clip(geometry), {min: 0, max: 3, palette: palette}, '201
// The pyramidingPolicy parameter should a dictionary specifying
// the policy for each band. A simpler way to specify it for all
// bands is to use {'.default': 'mode'}

// assetId should be specified as a string
// Lookup your asset root name from the 'Assets' tab
// If it is 'users/username', you can specify the id as
// 'users/username/classified_image'

Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ var after = s2
.select('B.*')
.median();

Map.addLayer(after, rgbVis, 'after');
Map.addLayer(after.clip(geometry), rgbVis, 'after');

// Classify the image.
var afterClassified= after.classify(classifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var after = s2
.select('B.*')
.median();

Map.addLayer(after, rgbVis, 'after');
Map.addLayer(after.clip(geometry), rgbVis, 'after');

// Classify the image.
var afterClassified= after.classify(classifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function maskS2clouds(image) {
}


var s2 = ee.ImageCollection('COPERNICUS/S2')
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
.filter(ee.Filter.bounds(geometry))
.map(maskS2clouds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function maskS2clouds(image) {
}


var s2 = ee.ImageCollection("COPERNICUS/S2")
var s2 = ee.ImageCollection("COPERNICUS/S2_HARMONIZED")
.filter(ee.Filter.bounds(geometry))
.map(maskS2clouds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// We create a NDVI time-series and export each
// image as a separate GeoTiff file
var s2 = ee.ImageCollection("COPERNICUS/S2");
var s2 = ee.ImageCollection("COPERNICUS/S2_HARMONIZED/");
var geometry = ee.Geometry.Polygon([[
[82.60642647743225, 27.16350437805251],
[82.60984897613525, 27.1618529901377],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ var imageId = '20190703T050701_20190703T052312_T43PGP';

// S2 Cloudless Algorithm
// This algorithm requires different bands from 3 different datasets
var s2Bands = ee.Image('COPERNICUS/S2/'+ imageId)
var s2Bands = ee.Image('COPERNICUS/S2_HARMONIZED/'+ imageId)
.select(['B7', 'B8', 'B8A', 'B10']);
var s2SrBands = ee.Image('COPERNICUS/S2_SR/' + imageId)
var s2SrBands = ee.Image('COPERNICUS/S2_SR_HARMONIZED/' + imageId)
.select(['B2', 'B3', 'B4', 'B5']);
var s2CloudBands = ee.Image('COPERNICUS/S2_CLOUD_PROBABILITY/'+ imageId)
.select(['probability'])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var s2 = ee.ImageCollection("COPERNICUS/S2");
var admin2 = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level2");
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var admin2 = ee.FeatureCollection('FAO/GAUL_SIMPLIFIED_500m/2015/level2');

var bangalore = admin2.filter(ee.Filter.eq('ADM2_NAME', 'Bangalore Urban'))
var geometry = bangalore.geometry()
Expand Down
Loading

0 comments on commit 2196878

Please sign in to comment.