TransWikia.com

How to average data from Sentinel-5p collection ignoring zero?

Geographic Information Systems Asked by Mikhail Svideniuk on June 17, 2021

I am working with CH4 product Sentinel-5p provided by ESA Copernicus.

Remote User Support provided a script to extract averaged CH4 anomalies for a certain period for the Earth Engine.
However, I suspect, that the results provide averaged values that include a ‘zero value’, because they use collection.mean().

Usually, I use conditional operator ‘@ ? @ : @’ in ESA SNAP environment. Thus, I tried to implement this function to the RUS script but it didn’t work.

Please, give me a suggestion, how to average the data ignoring zero from the image collection in the Earth Engine environment

var collection = ee.ImageCollection('COPERNICUS/S5P/OFFL/L3_CH4')
  .select('CH4_column_volume_mixing_ratio_dry_air')
  .filterDate('2020-04-06', '2020-04-10');

Here I put expression('condition ? true_action : false_action) instead of the collection.mean()

var s5p_L3_CH4_APR = collection.expression(('CH4_column_volume_mixing_ratio_dry_air' != 0) ? 1 : 0).clip(geometry)
var band_viz = {
  min: 1750,
  max: 1900,
  palette: ['black', 'blue', 'purple', 'cyan', 'green', 'yellow', 'red']
};

Map.addLayer(s5p_L3_CH4_APR, band_viz, 'S5P CH4');
Map.setCenter(24.436, 49.481, 2);

Export.image.toDrive({
  image: s5p_L3_CH4_APR,
  description: 's5p_L3_CH4_2020APR',
  scale: 7500,
  region: geometry
})

One Answer

There are several problems.

.expression(('CH4_column_volume_mixing_ratio_dry_air' != 0) ? 1 : 0)

First, you have not written an Earth Engine expression but a JavaScript expression, because the expression is outside of the quotes. You must quote the entire expression so that it will be passed to the Earth Engine server.

.expression('(CH4_column_volume_mixing_ratio_dry_air != 0) ? 1 : 0')

Second, you can't refer to a band by writing its name: you need to either use the b() syntax or pass it as an explicitly defined variable. The first is simpler here, so let's do that:

.expression('(b("CH4_column_volume_mixing_ratio_dry_air") != 0) ? 1 : 0')

(Note that the inner quotes must be different from the outer quotes — it doesn't matter whether they're single or double but the can't be the same. Alternatively, you could write b[0] to request the first band regardless of its name, which will work here since you already .select()ed the band you're looking for.)

Third, you can't apply an image expression to an image collection; you must map over the collection to apply the image expression to each element.

var s5p_L3_CH4_APR = collection.map(function (image) {
  return image
    .clip(geometry)
    .expression('(b("CH4_column_volume_mixing_ratio_dry_air") != 0) ? 1 : 0');
});

This is enough to get your script to run. However, it won't actually get the results you want — they will all be zero, because you've just replaced the data with your comparison, but it sounds like you want to mask the data:

var s5p_L3_CH4_APR = collection.map(function (image) {
  return image
    .clip(geometry)
    .updateMask(image.expression('b("CH4_column_volume_mixing_ratio_dry_air") != 0'));
});

Notice I have also removed the ? 1 : 0. This is not because it is wrong, but because it is unnecessary: Earth Engine's boolean operators on images already return 1 for true and 0 for false.

Now we can see the data. One more thing: you haven't requested a mean of this filtered data, so the layer is using most-recent-on-top mosaicing and the export will fail.

var s5p_L3_CH4_APR =
  collection.map(function (image) {
    return image
      .clip(geometry)
      .updateMask(image.expression('b("CH4_column_volume_mixing_ratio_dry_air") != 0'));
  })
  .mean();

This should compute what you asked for.

Answered by Kevin Reid on June 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP