0

What I am trying to do is to take a specific range of time (summer) over multiple years and then sum the total amount of precipitation onto a final layer.

This is the code I am working with

var dataset = ee.ImageCollection('IDAHO_EPSCOR/GRIDMET')

var precip = dataset.select('pr');
var precipVIS = {
  min: 0.0,
  max: 10.0,
  palette: ['d8d8d8', '4addff', '5affa3', 'f2ff89', 'ff725c'],
};
Map.setCenter(-86.356, 44.686, 9);

Map.addLayer(
    precip.filterDate("2014-06-15", "2014-07-15"), precipVIS,
    '2014');
Map.addLayer(
    precip.filterDate("2015-06-15", "2015-07-15"), precipVIS,
    '2015');

Now I am looking for the last part where I sum the results of the two map layers '2014' & '2015'.

1

To do this by year, you can reduce the timeframe of each individual year using ee.Reducer.sum() and then add the two years together:

var dataset = ee.ImageCollection('IDAHO_EPSCOR/GRIDMET');

var precip = dataset.select('pr');
var precipVIS = {
  min: 0.0,
  max: 10.0,
  palette: ['d8d8d8', '4addff', '5affa3', 'f2ff89', 'ff725c'],
};
Map.setCenter(-86.356, 44.686, 9);

Map.addLayer(
    precip.filterDate("2014-06-15", "2014-07-15"), precipVIS,
    '2014');
Map.addLayer(
    precip.filterDate("2015-06-15", "2015-07-15"), precipVIS,
    '2015');

var precip2014 = precip.filterDate("2014-06-15", "2014-07-15");
var precip2015 = precip.filterDate("2015-06-15", "2015-07-15");

var total2014 = precip2014.reduce(ee.Reducer.sum());
var total2015 = precip2015.reduce(ee.Reducer.sum());

var final = total2014.add(total2015);
Map.addLayer(final, precipVIS,
    'total');
  • Something is wrong with the reducer function when it comes to this data. Add that code to what I wrote and then compare the layers - there are pockets that show up in the 2014 layer that are not found in the summed layer. Are there other functions that would better serve to sum the layers? – Joey Roses Apr 2 at 16:17
  • That's weird; when I run the complete code (see updated answer) there aren't any holes in the summed layer (final). – JepsonNomad Apr 2 at 18:36
  • It's not that there are "holes" necessarily. But if you look at each year individually, note where you see isolated areas of heavy red. Then look at the final layer - those spots don't show up in the summed layer. For example, look at Kingsley in 2014 and then look at it on the "summed" model (using the parameters for the final model "min: 100 max: 200" And that's my other question: why is the minimum value output for the final layer 100+? The whole layer is entirely red, which means that the value is 100+ everywhere? – Joey Roses Apr 2 at 18:48
  • Ah I see what you're talking about now. There are several layers within each season (e.g. precip2014) so summing across the year racks up values to a quite high value when you get to the point of summing across years. For example use Map.addLayer(total2014, precipVIS, 'total2014'); and you'll see that there is lots of precip over the season (far more than the default visualization of the first layer in precip2014). – JepsonNomad Apr 2 at 19:01
  • Right, i see that now. I'm trying to get just the output for those specific time ranges to "stack" on top of one another. I can run multiple years and turn the opacity down enough where you can see some anomalies, but it turns into a mess after 3+ layers. So is there a way to sum just the final outputs of the the '2014' and '2015' layer so it's not summing each data point within the range (and thus giving that red chaos?) – Joey Roses Apr 2 at 19:40

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.