0

I am trying to retrieve the pollution data from Sentinel 5P. When trying to do so even though the key is present I am unable to get it by getting the error.

FeatureCollection (Error) Dictionary.get: Dictionary does not contain key: tropospheric_NO2_column_number_density.

Here I am sharing the total code

var region = nuapada;
var img_co = ee.ImageCollection('COPERNICUS/S5P/OFFL/L3_CO').select('CO_column_number_density');
var img_no2 = ee.ImageCollection('COPERNICUS/S5P/OFFL/L3_NO2').select('tropospheric_NO2_column_number_density');
var img_so2 =  ee.ImageCollection('COPERNICUS/S5P/OFFL/L3_SO2').select('SO2_column_number_density');


var img_map = img_no2.filter(ee.Filter.date('2019-06-01', '2019-08-01'));

var img_map_mean = img_map.mean();

var band_viz = {
  min: 0,
  max: 0.0005,
  palette: ['black', 'blue', 'purple', 'cyan', 'green', 'yellow', 'red']
};
var img_image = img_map_mean.clip(region);
Map.addLayer(img_image, band_viz, 'S5P O3');
Map.centerObject(region);

print (img_image);

var stats = img_image.reduceRegion({
   reducer: ee.Reducer.mean(),
   geometry: region,
   scale: 5000,
});

print(stats);

 var pr_monthlydata = ee.List.sequence(0, 7-1).map(function(n) {
  var start = ee.Date('2019-06-01').advance(n, 'day');
  var end = start.advance(6, 'day');


  var img_map_f_co = img_co.filter(ee.Filter.date(start, end));
  var img_mean_f_co = img_map_f_co.mean();
  var img_img_f_co = img_mean_f_co.clip(region);

  var stats_co = img_img_f_co.reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: region,
    scale: 5000,
  });


  var img_map_f_no2 = img_so2.filter(ee.Filter.date(start, end));
  var img_mean_f_no2 = img_map_f_no2.mean();
  var img_img_f_no2 = img_mean_f_no2.clip(region);

  var stats_no2 = img_img_f_no2.reduceRegion({
     reducer: ee.Reducer.mean(),
     geometry: region,
     scale: 5000,
   });



  var img_map_f_so2 = img_so2.filter(ee.Filter.date(start, end));
  var img_reducer_f_so2 = img_map_f_so2.mean();
  var img_img_f_so2 = img_reducer_f_so2.clip(region);

  var stats_so2 = img_img_f_so2.reduceRegion({
   reducer: ee.Reducer.mean(),
   geometry: region,
   scale: 5000,
 });


 var f = ee.Feature(null, {
   'CO': stats_co.get('CO_column_number_density'),
   'NO2': stats_no2.get('tropospheric_NO2_column_number_density'),
   'SO2': stats_so2.get('SO2_column_number_density'),
   });

   return f;
});

  var prMonths = ee.FeatureCollection(pr_monthlydata)
  print(prMonths);

1 Answer 1

2

The first step when debugging code should be to find information that checks where your assumptions went wrong. You assume that tropospheric_NO2_column_number_density should be present, but the error says it doesn't. Let's find out what's there instead. In your code you have:

var pr_monthlydata = ee.List.sequence(0, 7-1).map(function(n) {
  ...

  var f = ee.Feature(null, {
    'CO': stats_co.get('CO_column_number_density'),
    'NO2': stats_no2.get('tropospheric_NO2_column_number_density'),
    'SO2': stats_so2.get('SO2_column_number_density'),
  });

  return f;
});

We can bypass the error and get a look at what keys are actually present by simply removing the .gets:

  var f = ee.Feature(null, {
    'CO': stats_co,
    'NO2': stats_no2,
    'SO2': stats_so2,
  });

Then, the properties in the collection will be

      "properties": {
        "CO": {
          "CO_column_number_density": 0.02539985420768159
        },
        "NO2": {
          "SO2_column_number_density": 0.000026588702898291228
        },
        "SO2": {
          "SO2_column_number_density": 0.000026588702898291228
        }
      }

So, there isn't a tropospheric_NO2_column_number_density but there is a SO2_column_number_density. This suggests that there's a place where data for SO2 was used where you wanted NO2. Looking at the code for such a case, I find this line above:

  var img_map_f_no2 = img_so2.filter(ee.Filter.date(start, end));

Change img_so2 to img_no2 and your code will succeed.

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.