0

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);

1

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

  • Nishanta, thank you very much for helping me. I understand now more how EE works. I have written some lines to export the images (simple or as collection) to my drive, but it is not working. Export.image.toDrive({ image: Jan, description: 'Jan', scale: 1000, region: mexico, fileFormat: 'GeoTIFF', crs:'EPSG:4326', folder:'WSI' }); – Daniel Jun 8 at 22:05
  • It is possible that you might be trying to export an image collection instead of an image. The Export.image will only help you with exporting an individual image. can you share a link? – Nishanta Khanal Jun 10 at 8:18
  • I think I solved it, but it takes to long to actually save them as raster or export them. In the link you shared with me you can find the most recent version. – Daniel Jun 10 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.