2

GEE Link here

I would like to export monthly temperature from TerraClimate, But instead of getting the 12 months period It has index of 9rows and from the year that I desire from 1995 to 2020 I got only until 2004. This is very confusing to me as I am new to Google Earth Engine. This also some modification from any post but I couldn't track from where.

//var geometry = ee.Point([76.50672654438921,35.35824030837368]);
var fg_points = geometry;
// Set years and month
var startYear = 1995;
var endYear = 2020;
var years = ee.List.sequence(startYear, endYear);
var months = ee.List.sequence(1,12);
// load the image collection
//var Daily = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY");
var Daily = ee.ImageCollection("IDAHO_EPSCOR/TERRACLIMATE").select('tmmx');
// make monthly summed mosaics
// loop over the years and months to get summed monthly images
var byMonth = ee.ImageCollection(ee.FeatureCollection(years.map(function(y){
  var yearCollection = Daily.filter(ee.Filter.calendarRange(y, y, 'year'));
  var byYear = ee.ImageCollection.fromImages(
    months.map(function(m) {
      var summedImage = yearCollection.filter(ee.Filter.calendarRange(m, m, 'month'))
                  .reduce(ee.Reducer.sum()); 
      var date = ee.Date.fromYMD(y, m, 1).format("MM_dd_YYYY");
      return summedImage.set('system:time_start', ee.Date.fromYMD(y, m, 1)).rename(date);
      //.set('month', m).set('year', y); // eventually set year and month 
  }));
  return byYear;
})).flatten());
// filter the empty one out
var outputMonthly = byMonth.filter(ee.Filter.listContains('system:band_names', 'constant').not())
                    .sort('system:time_start').toBands();
print(outputMonthly);
var features = outputMonthly.reduceRegions(fg_points, ee.Reducer.first(), 30);
print(features);
Export.table.toDrive(features,
"PrecipitationHTL",
"PrecipitationHTL",
"PrecipitationHTL");

1 Answer 1

3

First, you should watch product description here. There, you can observe it is a monthly product, not daily, with a scale of 0.1 (in ºC). So, between '1995-01-01' and '2021-01-01' (your dates) must have 312 images; as effectively I could corroborate. So, you can export directly your data to Google drive with a different function. In following script, I used your point (76.50672654438921,35.35824030837368) for retrieving and exporting data to my Google Drive. It looks as follows:

var pt = ee.Geometry.Point(76.50672654438921,35.35824030837368);

Map.centerObject(pt);
Map.addLayer(pt);

var starDate = '1995-01-01';
var endDate = '2021-01-01';

var Monthly = ee.ImageCollection("IDAHO_EPSCOR/TERRACLIMATE").select('tmmx')
  .filterDate(starDate, endDate);

print(Monthly);

var allDates = ee.List(Monthly.aggregate_array('system:time_start'));

var allDatesSimple = allDates.map(function(date){
  return ee.Date(date).format().slice(0,10);
  });

print(allDatesSimple);

var getTemp = function(image) {

  // Reducing region and getting value
  var value_tmmx = ee.Image(image)
    .reduceRegion(ee.Reducer.first(), pt)
    .get('tmmx');

  return ee.Number(value_tmmx).multiply(0.1);

};

var count = Monthly.size();

var tmmx_list = Monthly.toList(count).map(getTemp);

print("tmmx_list", tmmx_list);

var paired = allDatesSimple.zip(tmmx_list);

print ("paired", paired);

var myFeatures = ee.FeatureCollection(paired.map(function(el){
  el = ee.List(el); // cast every element of the list
  return ee.Feature(null, {
    'date': ee.String(el.get(0)),
    'tmmx':ee.Number(el.get(1))
  });
}));

//print(myFeatures);

// Export features, specifying corresponding names.
Export.table.toDrive(myFeatures,
"export_tmmx", //my task
"GEE_Folder", //my export folder
"tmmx_pt",  //file name
"CSV");

After running above script in GEE code editor, I exported successfully CSV file to Google drive. An extract of 312 paired values (dates and tmax) can be observed as follows. It is a very cold area.

system:index,date,tmmx,.geo
0,1995-01-01,-21.8,
1,1995-02-01,-19.0,
2,1995-03-01,-15.9,
3,1995-04-01,-10.3,
4,1995-05-01,-1.4000000000000001,
5,1995-06-01,4.2,
6,1995-07-01,8.6,
7,1995-08-01,7.7,
8,1995-09-01,3.2,
9,1995-10-01,-1.7000000000000002,
10,1995-11-01,-8.4,
.
.
.
302,2020-03-01,-13.5,
303,2020-04-01,-7.5,
304,2020-05-01,-0.4,
305,2020-06-01,5.4,
306,2020-07-01,9.4,
307,2020-08-01,9.4,
308,2020-09-01,5.7,
309,2020-10-01,2.1,
310,2020-11-01,-6.1000000000000005,
311,2020-12-01,-14.700000000000001,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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