Chart monthly average NDVI values - google-earth-engine

I am hoping to obtain monthly averages for NDVI derived from Landsat data and then produce a line chart.
I have succeeded in cloudmasking Landsat 8 and adding an NDVI band.
Working with code suggested in another post I was able to create an image collection with one NDVI value per month for 5 years.
Now however, when I try and chart this image collection there is no "system:time_start" available so I cannot produce a time series.
Any help would be appreciated.
Maybe I have to go about calculating the monthly mean NDVI values in a different way.
My code is below.
https://code.earthengine.google.com/7c0abe5c696a4aa246647f4b34e2f48c

This can be fixed by simply replacing the line .set('month', m).set('year', y) by .set('system:time_start', ee.Date.fromYMD(y, m, 1)) in your function calculating byMonthYear.
Using mean() method (or other reducing methods such as median(), max(), etc.) on ImageCollection would result in the loss of all image's properties including system:time_start. This is fairly reasonable as Google Earth Engine has no idea from which image it should take properties.
The above fix just manually adds system:time_start property back to the mean image. This property should hold a ee.Date object (I just made it the first day of the month).

Related

How to create a weighted heatmap using R Leaflet?

I am attempting to create a heatmap using a data set that has only one value per coordinate, with that value being a continuous variable. All of the examples I have found using leaflet.extras::addHeatmap() use data that can have multiple values per coordinate, and create the heatmap based on the density of counts in an area. There doesn't seem to be a way to pass a weight instead.
My ultimate goal is to have something that looks like a raster based on these values:
However I don't want to use a raster due to the pixelation along the coasts.
When I pass the data to addHeatmap() and include the argument intensity = ~my_weighted_value, I get something like this:
And at increased zoom levels, it just ends up being a bunch of circles:
What is the proper way to take weighted spatial data and add a heatmap that looks like the raster?
Try to scale my_weighted_value back by *.00001 or something. Your weighted value appears to be exceeding the max.

Discrete vs continuous (dimension vs measure) for dates in tableau

I'm currently learning tableau and was creating a graph to map the unemployment with respect to each month. As the period of time was a measure, I dragged it in and it resulted in aggregation by month (of all years together) and a graph was displayed as such:
Now to plot it monthly for each subsequent year, I checked online and saw the conversion method where the same MONTH(PERIOD) was converted to a measure and it resulted in a plot like this:
Could someone please explain why does this work and how is a measure responsible for displaying data in such a way and not the month dimension. I cannot understand the plots when both the axes are measures.
Thank you
...saw the conversion method where the same MONTH(PERIOD) was converted to a measure.
It's not converted to a measure. Period is still a dimension, just a Continuous one. Measures and dimensions in Tableau can be either Continuous or Discrete. The ability to convert one to another depends on the data type of your field. For example, Dates can be converted between Continuous and Discrete, but Strings can't. The green colour isn't for measures - it's for the Continuous type of either measure or dimension.

Weird streaks when working with a large Raster

I have a large elevation raster from the ASTER database made by using raster::mosaic(). Each tile represents a one-degree by one-degree portion of the earth with an estimated raster resolution of 30m^2. I include the code that I used to mosaic them below, but I don't believe that it is the problem.
Mosaic <- do.call(mosaic,c(list of rasters, tolerance = 1, fun=mean)
Once that is run, I get the following elevation tif, which you can DOWNLOAD HERE.
I then measure the topographic ruggedness using raster::terrain(), using theTerrain Ruggedness Index as my method:
TRI <- terrain(Mosaic, opt="TRI")
This yields:
As you can see, there are faint streaks in the map which I cannot explain. Due to the full extent of my study, I need to aggregate this raster to a coarser resolution. Therefore I use the aggregate function in the raster package as well.
TRI_Agg <- aggregate(TRI,fact = 255, fun = mean)
This yields the following raster.
Here you can see that the streaks are much more pronounced and fairly consistent throughout the whole map. I tried doing this with other study areas and the problem persisted (i.e this would happen with raster tiles all around the world). I can't explain why those streaks are occurring. I have attempted different ways of going about this which include doing a neighborhood analysis (to fill in missing values if any) and processing the tiles before mosaicing them together. None of these have worked.
When I aggregate the raster before, the roughness calculation, the streaks do not appear which makes me believe this issue arises when using aggregate(). However, for my specific research question, I cannot calculate TRI using an aggregated raster.

Sort Extracted Data Based On Image Region

I have analysed tree core images through the raster package in an attempt to perform image analysis. In the image:
http://dx.doi.org/10.6084/m9.figshare.1555854
You can see the measured "vessels" (black and numbered) and also annual lines (red) which have been drawn using the locator function and represent each year of growth of the tree core.
By generating a list of the maximum y coordinates of each annual line I have been able to sort the vessels into years for this image. Which is what I am looking for. However, it has occurred to me that in reality things can get a little more difficult as seen in the next image:
http://figshare.com/articles/Complicated/1555855
The approach above will not work on this image as vessels from each year overrun so using the maximum y coordinates will not return the correct result.
So can anyone suggest another approach which may overcome this limitation? I have thought about using spatialpolygons but not sure this will achieve what I am looking for.
If you are creating the lines by clicking on the plot, you can use raster function drawLine or, for polygons, drawPoly. You could rasterize the polygons and mask that with the original image to get the vessels grouped by polygon (year).

Plotting time series of image slices

I have a dataset of 2D greyscale images (50 x 50 pixels) taken over a time period. As a means of analysing these images I want to take a slice - the central column of pixels from each image - and 'plot' these as a time series. So that I end up with time on the x-axis, and the column of pixels corresponding to that time vertically above it. (I appreciate this might not be entirely clear, so please let me know if anything needs clarifying).
I'm not sure how this can be achieved in IDL. I can easily pick out the central slice from each image and combine them into a new array, which I then display with TVSCL. This is the sort of thing I'm after, but since the data is not taken at regular time intervals, just bunching it all up into one new image doesn't represent the data properly. I really need a way of displaying the data as a scaled time series.
Can anyone suggest a way of doing this in IDL?
If you need any more details please just let me know.
Thanks
I think you're looking for something similar to a Hovmoller diagram (http://en.wikipedia.org/wiki/Hovm%C3%B6ller_diagram).
Your best bet is probably to use a contour plot, where you can specify the X and Y locations. Something like:
c = CONTOUR(data, time, ylocation)
where data is your 2D array of slices, time is a vector with the time values (which can be irregularly spaced), and ylocation is another vector with the y locations. There are a lot of properties on CONTOUR to control fill/not filled, contour levels, labels, etc.
Hope this helps!
-Chris
It's hard to write without knowing how your data is stored, but let's say you have your images in something like:
images = fltarr(xsize, ysize, ntimes)
times = fltarr(ntimes)
Then you could plot a time series of the values at any pixel x, y with:
plot, times, images[x, y, *]

Resources