1

https://developers.google.com/earth-engine/datasets/catalog/NASA_NEX-DCP30_ENSEMBLE_STATS

From the above link I need to download daily data for two variables (pr, tasmax) for two time periods: 1980-2005 and 2040-2060 for two sites: site a (lon = 83.1499, lat = 23.14985) and site b (79.477034, 11.015846)

Using the link below I managed to do it for a single site X variable X date combination as shown

Download NASA Earth Exchange Global Daily Downscaled Projections for single lat lon

var startDate = ee.Date('1980-01-01');
var endDate = ee.Date('2006-01-01');

// get the dataset between date range and extract band on interest
var dataset = ee.ImageCollection('NASA/NEX-GDDP')
              .filter(ee.Filter.date(startDate,endDate));
var maximumAirTemperature = dataset.select('tasmax');

// get projection information
var proj = maximumAirTemperature.first().projection();

var point = ee.Geometry.Point([83.1499, 23.14985]);

// calculate number of days to map and extract data for
var n = endDate.difference(startDate,'day').subtract(1);

// map over each date and extract all climate model values
var timeseries = ee.FeatureCollection(
ee.List.sequence(0,n).map(function(i){
var t1 = startDate.advance(i,'day');
var t2 = t1.advance(1,'day');
var feature = ee.Feature(point);
var dailyColl = maximumAirTemperature.filterDate(t1, t2);
var dailyImg = dailyColl.toBands();
// rename bands to handle different names by date
var bands = dailyImg.bandNames();
var renamed = bands.map(function(b){
var split = ee.String(b).split('_');
return ee.String(split.get(0)).cat('_').cat(ee.String(split.get(1)));
 });
// extract the data for the day and add time information
var dict = dailyImg.rename(renamed).reduceRegion({
reducer: ee.Reducer.mean(),
  geometry: point,
  scale: proj.nominalScale()
}).combine(
  ee.Dictionary({'system:time_start':t1.millis(),'isodate':t1.format('YYYY-MM-dd')})
);
return ee.Feature(point,dict);
})
);

Map.addLayer(point);
Map.centerObject(point,6);

// export feature collection to CSV
Export.table.toDrive({
  collection: timeseries,
  description: 'a_hist_tmax',
  fileFormat: 'CSV',
 });

How do I create a loop to process all of the combinations (each site X variable X dateset combination) and save them as unique files in my drive

5
  • For question 2: yes, this is how you export in Code Editor. At least 2 clicks for every export. For question 1: you can write a for loop as in normal JavaScript, as long as the variable(s) of the loop, for example the i in for (i = 0; i < 10; i++) is not an ee object.
    – Kevin
    Nov 21, 2019 at 7:10
  • Thanks Kevin. I am not familiar with the syntax used by earth engine so find it difficult to write a loop. It it was R, I could have done it and hence I posted the question
    – 89_Simple
    Nov 21, 2019 at 12:36
  • 1
    Please ask only one question per Question.
    – Vince
    Nov 21, 2019 at 13:39
  • 1
    The bounty has been removed from this question so that it can be placed On Hold until its scope is reduced to a single question (as per the Tour).
    – PolyGeo
    Nov 25, 2019 at 6:43
  • Okay. Thank you. I have edited the question now
    – 89_Simple
    Nov 25, 2019 at 11:48

1 Answer 1

2

Something like this should do the trick:

var sites = [
  [83.1499, 23.14985],
  [79.477034, 11.015846],
]

var yearRanges = [
  [1980, 2006],
  [2040, 2060]
]

sites.forEach(function (site) {
  yearRanges.forEach(function (yearRange) {
    exportTimeseries(site, yearRange)
  })
})

function exportTimeseries(site, yearRange) {
  // Most of your code goes here

  var name = yearRange.join('-') + '_' + site.join('-')
  Map.addLayer(point, null, name);

  // export feature collection to CSV
  Export.table.toDrive({
    collection: timeseries,
    description: 'a_hist_tmax_' + name,
    fileFormat: 'CSV',
  });
}

https://code.earthengine.google.com/c7978c0ac6cb6c1d9d9fd009679e1b8d

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.