Tuesday, 10 July 2018

javascript - Split list by chunks Earth Engine with mean



I am calculating mean temperature data based on historical data. I need to calculate the mean through the years (jan-jan-jan-jan...) and the means within a year (jan-feb-mar-may-jun...).


This is what I have but it is not working at all. I am new coding in jave and Google Earth Engine.


How can I approach to solve this issue?


// Load TerraClimate data
var dataset = ee.ImageCollection('IDAHO_EPSCOR/TERRACLIMATE').select('tmmx');

var maximumTemperature = dataset
// Define reference conditions from the first 25 years of data.
.filter(ee.Filter.date('1990-01-01', '2015-12-31'));
// Sort chronologically in descending order.

//.sort('system:time_start', false);

print('maximumTemperature', maximumTemperature);

// list for filter iteration
var months = ee.List.sequence(1,12);


Answer



Well, your code is on the right track but it is not working because it is not complete yet. So far what you have done is to select the required band and the required images from the whole archive limiting your scenes of interest to those between 1990 and 2015 end. The remaining things are to




  1. select all images throughout the years (1990 to 2015) on same month like Jan or Feb or Mar etc and calculate their mean. You can do it this way


var months = ee.List.sequence(1,12);
var monthlyMeanOverTheYears = months.map(function(month){
var monthlyDs = maximumTemperature.filter(ee.Filter.calendarRange(month, month, 'month'));
return monthlyDs.mean().set('month', month);
});


  1. select all images within a year starting from 1990 to 2015 and take their mean



var years = ee.List.sequence(1990,2015);
var yearlyMeans = years.map(function(year){
var yearlyDs = maximumTemperature.filter(ee.Filter.calendarRange(year, year, 'year'));
return yearlyDs.mean().set('year', year);
});

Both of these return a list of mean images. If you want to change them to imagecollection object so you can use those filter functions, you can do this


var monthlyCollection = ee.ImageCollection.fromImages(monthlyMeanOverTheYears);
var yearlyCollection = ee.ImageCollection.fromImages(yearlyMeans);


You can find a working script here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...