Creating a Rule in NOAA/CDR/AVHRR/NDVI/V5 TO Only display ndvi for dense vegetation google earth engine - google-earth-engine

I'm trying to apply a rule to NOOA NDVI the already classified region to only display dense vegetation areas but it's saying ndvi is not a function, any help will be much appreciated.
Here is the code:
//collecting data using ndvi
var good = ee.ImageCollection('NOAA/CDR/AVHRR/NDVI/V5')
.filter(ee.Filter.date('2018-05-01', '2018-06-01'))
//.median()
//.good.lt(0.27).and(good.gt(0.18))
//.map(function(good){return good.lt(0.18).and(good.gt(0.27))})
.map(function(good){return good.clip(roi)});
Map.setCenter (37.577717495842506,0.3597340638009545,12);
var ndvi = good.select('NDVI')
var ndvi2 =ndvi
.where(ndvi.gt(0.27).and(ndvi.lte(0.36)), 4)
.where(ndvi.gt(0.36).and(ndvi.lte(0.74)), 5)
var ndvi2 = ndvi2.clip(roi);
The error shows this
Line 14: ndvi.gt is not a function

I would need to see more of your script to give you a full answer, but from what you have provided, it appears that ndvi is an ee.ImageCollection() and the .gt() and .lte() functions only work on ee.Image(). You will need to create a function that maps your intended rule over each image in the image collection to get what you want.

Related

Applying function to image bands based on table values in Earth Engine?

firstly apologies: I am a beginner in Earth Engine, but googling my question hasn't yielded any results. I have a reasonable amount of experience with other languages/platforms.
I have a table of data with headers 'name' and 'value' with N entries, I also have a multiband images in which the bands are named the same as the 'name' column in my table.
I want to apply a functions to each band in the image, based on its corresponding value in the table.
I'm struggling to find a way to do this without using loops and getInfo(), both of which I understand are not efficient and generally frowned upon.
I think perhaps I'm missing something fundamental here regarding the interaction between local variables and things occuring serverside - help would be greatly appreciated!
You could perhaps iterate over the band names in the image:
var updatedImage = ee.Image(
image.bandNames().iterate(
function (bandName, acc) {
bandName = ee.String(bandName) // Must cast from ee.Element to actual type
var feature = features
.filter(ee.Filter.eq('name', bandName))
.first()
var value = feature.getNumber('value')
var bandWithFunctionApplied = image.select(bandName)
.add(value) // Apply some function
return ee.Image(acc)
.addBands(bandWithFunctionApplied)
},
ee.Image([])
)
)
https://code.earthengine.google.com/082411908a7525a4c8a87916b5ea88fc

Every possible combination of lists in google earth engine

I want to get possible combinations of two sets of lists in google earth engine, but my code did not works.
var Per1= ee.Array([[0.1,0.5,0.8],[0.4,0.5,0.2]])
var pre = PercFin1.toList()
var CC=ee.List([1,2,3]);
var ZZ = pre.map(function(hh){
var Per11 = ee.List(pre).get(hh);
var out = CC.zip(Per11);
return out;
});
print (ZZ)
The error I get is:
List.get, argument 'index': Invalid type. Expected: Integer. Actual: List.
Thanks in advance
I don't know if this is what you want, but it looks like you've got the right idea but made an incidental mistake: hh is not an index into pre but an element of it.
I modified and simplified the last part of your code (along with changing PercFin1 to Per1, which I assume was a typo):
var ZZ = pre.map(function(hh){
return CC.zip(hh);
});
print(ZZ);
The result of this is
[
[[1,0.1],[2,0.5],[3,0.8]],
[[1,0.4],[2,0.5],[3,0.2]]
]
which is what I understand you want — each row in Per1 individually zipped with CC.

Reclassify ranges in Google Earth Engine

I would like to reclassify Global Forest Data values i.e like
0 - 20 % --> 1
21 - 49 % --> 0.5
50 - 100 % --> 0
However, I wasn`t able to find how to do this for ranges in GEE. Explanation for reclassifying individual numbers can be found here:
https://sites.google.com/site/globalsnowobservatory/home/Presentations-and-Tutorials/short-tutorial/remap
but simple procedure for ranges (without decision trees) is hard to find.
Could someone provide a simple solution for this?
// Example from https://developers.google.com/earth-engine/resample
// Load a MODIS EVI image.
var modis = ee.Image(ee.ImageCollection('MODIS/006/MOD13A1').first())
.select('EVI');
// Get information about the MODIS projection.
var modisProjection = modis.projection();
// Load and display forest cover data at 30 meters resolution.
var forest = ee.Image('UMD/hansen/global_forest_change_2015')
.select('treecover2000');
// Get the forest cover data at MODIS scale and projection.
var forestMean = forest
// Force the next reprojection to aggregate instead of resampling.
.reduceResolution({
reducer: ee.Reducer.mean(),
maxPixels: 1024,
bestEffort:true
})
// Request the data at the scale and projection of the MODIS image.
.reproject({
crs: modisProjection
});
If you want to make binary decisions about pixel values, you can use the ee.Image.where() algorithm. It takes an image of boolean values to specify where in an image to replace pixels with another image. The tidiest way to use it for this application is to use the ee.Image.expression() syntax (rather than specifying several boolean and constant images):
var reclassified = forestMean.expression('b(0) <= 20 ? 1 : b(0) < 50 ? 0.5 : 0');
b(0) refers to the value of the first band of the input image, and ? ... : is the ?: conditional operator which returns the part between ? and : if the condition to the left is true, and the part to the right of the : if the condition is false. So, you can use a series of ? ... : to write out several conditions concisely.
Runnable example with this line.

How to make ee.Reducer.mean() give me a float instead of a binary number?

I'd like to reduce the resolution for a binary layer of the max extent of water, and I'd like the resulting layer to represent percent of water pixels. However when I use ee.Reducer.mean() as seen below, the resulting layer is only has binary values still. How can I get a float instead?
//The image in question
var water = ee.Image('JRC/GSW1_1/GlobalSurfaceWater').clip(roi);
//Current code
var watermodis = water.select(['max_extent'])
.reproject({
crs:modisproj
}).reduceResolution({
reducer:ee.Reducer.mean(),
});
Turns out I just had the order of the reproject and the reduceResolution wrong, should be
var watermodis = water.select(['max_extent'])
.reduceResolution({
reducer:ee.Reducer.mean(),
maxPixels:1310
}).reproject({
crs:modisproj
});

sunburst.R total frequency count is incorrect

I am plotting a sunburst donut and I cannot figure out why the total is incorrect.
library(sunburstR)
reports <- data.frame(
sequence = c("SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-VP-Dir-end","SVP-No VP-Dir-end","SVP-No VP-Dir-end","SVP-No VP-Dir-end"),
freq = as.numeric(c("167","60","51","32","5","1","1")))
sunburst(reports, count = TRUE)
It is supposed to be 100% 317 of 317 . Anyone know how to fix this? There is not much documentation on this great package.
Also, I would like it to have a default value in the center of donut.
If there is another way to create an interactive donut using R, please let me know.
Thanks you in advance.
It looks like the default function generating the message in the center of the donut rounds the total value to the nearest ten.
But you can customize this function using the explanation argument of sunburst. Oddly, the customized function (in javascript) must be provided as a string.
Try the following function:
custom.message = "function (d) {
root = d;
while (root.parent) {
root = root.parent
}
p = (100*d.value/root.value).toPrecision(3);
msg = p+' %<br/>'+d.value+' of '+root.value;
return msg;
}"
Now:
sunburst(reports, explanation = custom.message )
will generate the donut displaying exact total values. The count argument is no longer needed, as it is used by the default explanation function.
The value returned by custom.message is html code. As you can see, I've just inserted a line break (<br/>). You can modify the msg return value to further customize the look and feel.

Resources