-2

Input are: NASA/SMAP/SPL4SMGP/007 NASA/GPM_L3/IMERG_MONTHLY_V06

When I try to compute the time series I get the following error:

ImageCollection (Error) reduce.mean: Error in map(ID=20200601_0130): Image.select: Pattern 'ssma' did not match any bands.

Anyone knows what is happening here? I added the code below.

var basin_boundary = geometry2

// Add basin boundary in the map.
Map.addLayer(basin_boundary, {}, 'Area of interest');
Map.centerObject(basin_boundary, 7);

// Define study period.
var startYear = 2020;
var endYear = 2024;
var startMonth = 1;
var endMonth = 12;

var startDate = ee.Date.fromYMD(startYear, startMonth, 1);
var endDate = ee.Date.fromYMD(endYear, endMonth, 31);
var years = ee.List.sequence(startYear, endYear);
var months = ee.List.sequence(1, 12);

// Define a function to convert GPM IMERG from mm/hr to mm/day.
var gpmScale = function(image) {
  return image.multiply(24)
              .copyProperties(image, ['system:time_start']);
};

// Define a function to compute the anomaly for a given month.
var computeAnomalyPrecipitation = function(image) {
  // Get the month of the image.
  var year = image.date().get('year');
  var month = image.date().get('month');
  // Get the corresponding reference image for the month.
  var referenceImage = meanMonthlyPrecipitation.filter(
      ee.Filter.eq('month', month)).first();
  // Check if the images have bands
  var hasBands = image.bandNames().size().gt(0);
  // Compute the anomaly by subtracting reference image from input image.
  var anomalyImage = ee.Algorithms.If(
    hasBands,
    image.subtract(referenceImage),
    image);

  return ee.Image(anomalyImage).set(
    'system:time_start', ee.Date.fromYMD(year, month, 1).millis());
};

// Anomalies surface and subsurface soil moisture (mm).
var ssSusMa =  nasa_usda_smap
  .filterDate(startDate, endDate)
  .sort('system:time_start', true)  // sort a collection in ascending order
  .select(['ssma', 'susma']);  // surface and subsurface soil moisture bands

// Compute monthly anomalies surface and subsurface soil moisture.
var monthlySsSusMa =  ee.ImageCollection.fromImages(
  years.map(function(y) {
    return months.map(function(m) {
      var filtered = ssSusMa.filter(ee.Filter.calendarRange(y, y, 'year'))
                         .filter(ee.Filter.calendarRange(m, m, 'month'))
                         .mean();
      return filtered.set(
        'system:time_start', ee.Date.fromYMD(y, m, 1).millis());
    });
  }).flatten()
);

// Precipitation from monthly GPM IMERG Final product (mm/day).
var rawMonthlyPrecipitation =
  gpm_imerg
  .select('precipitation')
  .filterDate(startDate, endDate)
  .sort('system:time_start', true)
  .map(gpmScale); // convert rainfall unit from mm/hr to mm/d

// Make sure monthly precipitation has same duration as soil moisture.
var monthlyPrecipitation =  ee.ImageCollection.fromImages(
  years.map(function(y) {
    return months.map(function(m) {
      var filtered = rawMonthlyPrecipitation
                          .filter(ee.Filter.calendarRange(y, y, 'year'))
                          .filter(ee.Filter.calendarRange(m, m, 'month'))
                          .mean();
      return filtered.set({
        'month': m,
        'system:time_start': ee.Date.fromYMD(y, m, 1).millis()
      });
    });
  }).flatten()
);

// Compute climatological monthly precipitation.
var meanMonthlyPrecipitation = ee.ImageCollection.fromImages(
  ee.List.sequence(1, 12).map(function(m) {
    var filtered = monthlyPrecipitation.filter(ee.Filter.eq('month', m)).mean();
    return filtered.set('month', m);
  })
);

// Map the function over the monthly precipitation collection to compute
// the anomaly precipitation for each month.
var monthlyPrecipitationAnomalies = monthlyPrecipitation.map(
    computeAnomalyPrecipitation);
    
// Combine two image collections into one collection.
var smpreDatasets  = monthlySsSusMa.combine(monthlyPrecipitationAnomalies);
print('soil moisture and precipitation', smpreDatasets);

var chart =
  ui.Chart.image.series({
      imageCollection: smpreDatasets,
      region: basin_boundary,
      scale: 10000,
      xProperty: 'system:time_start'
    })
    .setSeriesNames(['surface SM', 'subsurface SM', 'precipitation'])
    .setOptions({
      title: 'Anomalies time series: surface soil moisture, sub-surface soil ' +
       'moisture, and precipitation',
      series: {
        0: {
            targetAxisIndex: 0, type: 'line', lineWidth: 3,
            pointSize: 1, color: '#ffc61a'
        },
        1: {
            targetAxisIndex: 0, type: 'line', lineWidth: 3, pointSize: 1,
            lineDashStyle: [2, 2], color: '#330000'
        },
        2: {
            targetAxisIndex: 1, type: 'line', lineWidth: 3, pointSize: 1,
            lineDashStyle: [4, 4], color: '#1a1aff'
        },
      },
      hAxis: {
        title: 'Date',
        titleTextStyle: {italic: false, bold: true}
      },
      vAxes: {
        0: {
            title: 'soil moisture (mm)',
            baseline: 0, titleTextStyle: {bold: true, color: '#ffc61a'},
            viewWindow: {min: -4, max: 4}
        },
        1: {
            title: 'precipitation (mm)',
            baseline: 0, titleTextStyle: {bold: true, color: '#1a1aff'},
            viewWindow: {min: -2.5, max: 2.5}
        }
      },
      curveType: 'function'
    });

print(chart);

// Setup colors for soil moisture anomalies.
var palette = ['8c510a', 'bf812d', 'dfc27d', 'f6e8c3', 'ffffff',
               'ffffff', 'c7eae5', '80cdc1', '35978f', '01665e'];
var smVis = {
  min: -4,
  max: 4,
  opacity: 0.9,
  palette: palette,
};
// Setup colors for precipitation anomalies.
var preVis = {
  min: -3,
  max: 3,
  opacity: 0.9,
  palette: palette,
};
// Filter soil moisture to May 2021, subset first image, and clip to AOI.
var thisSsSusMa = monthlySsSusMa.filterDate(
  '2021-05-01', '2021-05-31').first().clip(basin_boundary);
// Filter precipitation to May 2021, subset first image, and clip to AOI.
var thisPre = monthlyPrecipitationAnomalies.filterDate(
  '2021-05-01', '2021-05-31').first().clip(basin_boundary);

// Display the images on the map.
Map.addLayer(thisSsSusMa.select('ssma'), smVis, 'Surface Soil Moisture');
Map.addLayer(thisSsSusMa.select('susma'), smVis, 'Subsurface Soil Moisture');
Map.addLayer(thisPre, preVis, 'Precipitation');
1
  • could you share your code link, using getlink button in google earth engine. tap the getlink and past your code link here. Commented Feb 26, 2024 at 13:45

1 Answer 1

0

It looks like there might be some confusion regarding the band names you're referencing. When working with datasets from GEE, it's crucial to consult the Data Catalog for accurate and up-to-date information about the datasets, including band names, descriptions, and terms of use.

For the specific datasets you mentioned, I recommend checking out their respective pages on the GEE Data Catalog:

  • For the NASA SMAP SPL4SMGP V007 dataset, visit here.
  • For the NASA GPM L3 IMERG Monthly V06 dataset, visit here.

Upon reviewing these pages, you'll notice that there are no bands named ssma or susma listed for either dataset.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.