I calculated the NBR for a Landsat 8 imagecollection and mapped it over. I now want to calculate daily difference of the index as NBR[i] - NBR[i-1] for each day ,for each pixel in the image collection anything I have tried so far has failed.
var landsat8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterDate("2015-01-1","2017-12-31").filterBounds(geometry);
var NBR=function(image){
var nbr=image.normalizedDifference(["B5","B7"]);
return image.addBands(nbr.rename("nbr"));
}
var imNBR=landsat8.map(NBR);
print(imNBR);
Related
As a newbie to the google earth engine, I have been trying something (https://code.earthengine.google.com/6f45059a59b75757c88ce2d3869fc9fd) following a NASA tutorial (https://www.youtube.com/watch?v=JFvxudueT_k&ab_channel=NASAVideo). My last line (line 60) shows image.filter is not a function, while the one in the tutorial (line 34) is working. I am not sure what happened and how to sort this out?
//creating a new variable 'image' from the L8 collection data imported
var image = ee.Image (L8_tier1 //the details in the data will represent that the band resolution is 30m
//the details in the data will represent that the band resolution is 30m
//.filterDate ("2019-07-01","2021-10-03") //for a specific date range. maybe good to remove it for the function.
//the details in the data will represent that the band resolution is 30m
//the details in the data will represent that the band resolution is 30m
//.filterDate ("2019-07-01","2021-10-03") //for a specific date range. maybe good to remove it for the function.
.filterBounds (ROI) //for the region of interest we are interested in
//.sort ("COLUD_COVER") //for sorting the data between the range with a cloud cover, the metadata property we are interested in. Other way to do this is using the function below.
//.first() //this will make the image choose the first image with the least amount of cloud cover for the area. Other way to do this is using the function below.
);
//print ("Hague and Rotterdam", image); //printing the image in the console
//console on the right hand side will explain everything from the data
//id will show the image deatils and date of the image, for this case 29th July 2019
//under the properties tab cloud cover can be found, this is the least we can get for this area during this period
// //vizualisation of the data in the map with true color rendering
// var trueColour = {
// bands:["SR_B4","SR_B3","SR_B2"],
// min: 5000,
// max: 12000
// };
// Map.centerObject (ROI, 12); //for the centering the area in the center of the map with required zoom level
// Map.addLayer (image, trueColour, "Hague and Rotterdam"); //for adding the image with the variable of bands we made and naming the image
//Alternate way
//Function to cloud mask from the qa_pixel band of Landsat 8 SR data. In this case bits 3 and 4 are clouds and cloud shadow respectively. This can be different for different image sets.
function maskL8sr(image) {
var cloudsBitMask = 1 << 3; //remember to check this with the source
var cloudshadowBitMask = 1 << 4; //remember to check this with the source
var qa = image.select ('qa_pixel'); //creating the new variable from the band of the source image
var mask = qa.bitwiseAnd(cloudsBitMask).eq(0) //making the cloud equal to zero to mask them out
.and(qa.bitwiseAnd(cloudshadowBitMask).eq(0)); //making the cloud shadow equal to zero to mask them out
return image.updateMask(mask).divide(10000)
.select("SR_B[0-9]*")
.copyProperties(image, ["system:time_start"]);
}
// print ("Hague and Rotterdam", image);// look into the console now. How many images the code have downloaded!!!
//filtering imagery for 2015 to 2021 summer date ranges
//creating joint filter and applying to image collection
var sum21 = ee.Filter.date ('2021-06-01','2021-09-30');
var sum20 = ee.Filter.date ('2020-06-01','2020-09-30');
var sum19 = ee.Filter.date ('2019-06-01','2019-09-30');
var sum18 = ee.Filter.date ('2018-06-01','2018-09-30');
var sum17 = ee.Filter.date ('2017-06-01','2017-09-30');
var sum16 = ee.Filter.date ('2016-06-01','2016-09-30');
var sum15 = ee.Filter.date ('2015-06-01','2015-09-30');
var SumFilter = ee.Filter.or(sum21, sum20, sum19, sum18, sum17, sum16, sum15);
var allsum = image.filter(SumFilter);
Filtering is an operation you can do on ImageCollections, not individual Images, because all filtering does is choose a subset of the images. Then, in your script, you have (with the comments removed):
var image = ee.Image (L8_tier1
.filterBounds (ROI)
);
The result of l8_tier1.filterBounds(ROI) is indeed an ImageCollection. But in this case, you have told the Earth Engine client that it should be treated as an Image, and it believed you. So, then, the last line
var allsum = image.filter(SumFilter);
fails with the error you saw because there is no filter() on ee.Image.
The script will successfully run if you change ee.Image(...) to ee.ImageCollection(...), or even better, remove the cast because it's not necessary — that is,
var image = L8_tier1.filterBounds(ROI);
You should probably also change the name of var image too, since it is confusing to call an ImageCollection by the name image. Naming things accurately helps avoid mistakes, while you are working on the code and also when others try to read it or build on it.
This is the code i have so far.
var roi = ee.FeatureCollection(polygon);
Map.addLayer(roi, {}, 'Turkey');
//Load Sentinel data
var image = ee.ImageCollection("COPERNICUS/S2_SR")
filterDate('2019-04-01', '2019-04-10')
//Remove cloud contamination
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.filterBounds(roi)
//Visualise data
var visParamsTrue = {bands: ['B4', 'B3', 'B2'], min:0, max:2500 ,gamma:1.1};
Map.addLayer(image.clip(roi), visParamsTrue, 'Sentinel 2019');
Map.centerObject(roi, 20);
I want to import sentinel - 2 data within the study region using Google Earth Engine.
This is just an example of the expected result -
Sentinel data is imported within the vector points
This is what i get -
Sentinel data is not imported
How do i fix this?
The code above is taken from the youtube video : https://www.youtube.com/watch?v=N_yJDMgRfik
I want to filter time series in the google earth engine which requires two for loops over time-series of a single pixel. I searched around and not found any example related to this. I know about .map function and I am using it for the generation of RVI on the earth engine. I found about .toArray function but not found any example related to my problem.
I will appreciate any help in this regard. Also, I am new to the earth engine so this may be a trivial question for others.
This is the code that I have. I took it from a blog and modified it according to my need. I am stuck after this.
var sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD_FLOAT');
// Filter VH, IW
var vh = sentinel1
// Filter to get images with VV and VH dual polarization.
//.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
// Filter to get images collected in interferometric wide swath mode.
.filter(ee.Filter.eq('instrumentMode', 'IW'))
// reduce to VH polarization
//.select('VH')
// filter 10m resolution
.filter(ee.Filter.eq('resolution_meters', 10));
// Filter to orbitdirection Descending
var vhDescending = vh.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'));
// Filter time 2015
var vhDesc2015 = vhDescending.filterDate(ee.Date('2021-01-01'), ee.Date('2021-04-30'));
// Filter to MKD roi
var s1_mkd = vhDesc2015.filterBounds(roi);
print('All metadata:', s1_mkd);
var count = s1_mkd.size();
print('Count: ', count);
//var dates = s1_mkd.aggregate_array("system:time_start")
//print('dates: ', dates);
var dates = s1_mkd
.map(function(image) {
return ee.Feature(null, {'date': image.date().format('YYYY-MM-dd')})
})
.distinct('date')
.aggregate_array('date')
print('dates: ', dates);
var featureCollection = ee.FeatureCollection(dates
.map(function(element){
return ee.Feature(null,{prop:element})}))
//Export a .csv table of date, mean NDVI for watershed
Export.table.toDrive({
collection: featureCollection,
description: 'Timeseries',
folder: 'WC_raw',
fileFormat: 'CSV',
});
var rvi4s1 = function(img){
var vh = img.select('VH');
var vv = img.select('VV');
var col = vv.divide(vv.add(vh)).sqrt().rename('dop');
var dop = col.select('dop')
var value = dop.multiply(vh.multiply(4).divide(vv.add(vh))).rename('rvi4s1');
return value;
};
var rvi = s1_mkd.map(rvi4s1);
print(rvi);
I'm working on a google earth engine app. In order to let it run without code changing, i need to specify a date range to filter an ImageCollection. The inicial date should be an arbitrary one, but the last date should be the "latest" available.
It would be nice also if anybody knows how to open a dialogue to let the user specify the inicial date.
var app = function (image)
{
//NDVI
var ndvi = image.normalizedDifference(['B8', 'B4']);
image = image.addBands(ndvi.rename('NDVI'));
return image;
}
var OLI = ee.ImageCollection("COPERNICUS/S2")
.filterDate('2016-10-01','2019-01-29')
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE','less_than',10)
//.map aplica la funcion "app" definida previamente a la ImageCollection
.filterBounds(table)
.map(app);
I want to plot the count of burn pixels for modis burned area product within my geometry regions called "table" for only agricultural pixels (obtained from 'lc' image collection). I couldn't find anything in the docs to indicate you can do such a query between 2 image collections. Anyone have any suggestions?
I have tried using a mask, but it seems that this might only work on individual ee.Image not between different image collections. The code is shown below:
var modba = ee.ImageCollection('MODIS/006/MCD64A1').filterDate('2017-01-
01', '2017-12-31').select('BurnDate')
var modbaN = ee.ImageCollection('MODIS/006/MCD64A1').filterDate('2017-01-
01', '2017-12-31').select('Uncertainty')
var lc = ee.ImageCollection('MODIS/006/MCD12Q1').filterDate('2017-01-01',
'2017-12-31').select('LC_Type1')
var AgOnly = lc.map(function(img) {
var ag = img.select('LC_Type1');
return ag.eq(12);
//Would also like to maybe have 2 or 3 LC types to select here
});
var mask_ba = modba.map(function(img){
return img.updateMask(AgOnly);
});
var bats =
//ui.Chart.image.seriesByRegion(modba, table, ee.Reducer.count());
ui.Chart.image.seriesByRegion(mask_ba, table, ee.Reducer.count());
print(bats);
var unts =
ui.Chart.image.seriesByRegion(modbaN, table, ee.Reducer.mean());
print(unts);
It's still doable with a wider date range and several land cover types.
In that case, just keep your old code that calculates AgOnly, and modify the code that calculates mask_ba as below:
var mask_ba = modba.map(function(img){
var img_year = img.date().format('YYYY');
var start_date = ee.Date(img_year.cat('-01-01'));
var end_date = start_day.advance(1, 'year');
var Agri_this_year = AgOnly.filterDate(start_date, end_date).max();
return img.updateMask(Agri_this_year);
});
Basically, the above code just extracts the year of the current img, then use filterDate method to select the land type cover of that year from AgOnly image collection, and finally apply updateMask.
The same idea could be applied to other land cover types.
Hope this helps.
As I understand, what you're trying to do is to mask each image in modba image collection (which has 12 images or one per month) by the corresponding image in AgOnly image collection (which has only 1 image for the whole year). That's totally doable.
In your provided code, you're updateMask using AgOnly (an image collection) which is not allowed by GEE.
All you need to do is just make AgOnly an image before using it for updateMask.
Try this:
var AgOnly = lc.map(function(img) {
var ag = img.select('LC_Type1');
return ag.eq(12);
//Would also like to maybe have 2 or 3 LC types to select here
}).max();
The max() method will convert your image collection into an image. You can also use min() or mean() if you like, which will all give the same result as there's only one image in AgOnl anyway.