0

My overall objective is to extract all areas that have a night time temperature <= 0 degrees C from the ERA5 hourly collection on Earth Engine, consideirng the time period 1981-2020 over a entire country (not points, polygons). The steps I have followed are -

  1. Filter entire collection to have images only from 10pm-6am (night time defined in my project) (lines 141)
  2. Convert images to degrees celcius (lines 146-149)
  3. Reclassify all pixels such as pixels with night time temp <=0 is 1 and rest is 0 over the entire collection (lines 151-155)
  4. Reduce the collection by sum to get the number of times a pixel has night time temp <=0 in a day (lines 159-175) 5)Again reclassify like step 3 such that if temperature dropped <=0 in a day, pixel value is 1, else 0 (lines 180-183)
  5. Again reduce by sum like step 4, such that pixel value is number of days in which nigh time temp dropped <=0 in a month (lines 185-201)
  6. Finally reduce by sum again, pixel value is number of days temp dropped <=0 in a year (lines 205-221)
  7. Reclassify again such that all pixels with value > 15 is 1 and rest is 0. This means that all pixels that had more than 15 days of night time temp dropping to <=0 in a year is 1 and rest is 0.
  8. Last reduction by sum where pixel value means number of years in which there was >15 days of nght time temp dropping <=0 10 ) Export to drive.

I have completed above for India as an example and I have initiated the script only for 2 years- Jan 1981 to dec 1982.

Everything runs. However the export stops after 2.5-3.5 hours with the error

Error: reduce.sum: Error in map(ID=0): Image.gt: If one image has no bands, the other must also have no bands. Got 0 and 1. (Error code: 3)

How do I figure out which images (hours) do not have any bands and exclude these images at any step? Alternatively how do I correct this script so it runs and exports out a binary raster, for a country, indicating areas where min 15 days of a year had night time temp dropping below freezing?

Here is the code editor script starting lines 122

2 Answers 2

0

This usually happens to me when one of my filters is not working properly. For example, an ImageCollection filter might not be returning any images.

In this case, I think the cause is that mapping a function over an ImageCollection (e.g., (image.subtract(273.15) in line 148) doesn't conserve the image properties, including the system:time_start and system:time_end properties that GEE uses to filter by date. The later operations that apply a .filterDate() filter then fail to find any images, hence the error.

The workaround I use is to manually set a new system:time_start and system:time_end property for each image when you map a function over an ImageCollection, e.g., in line 152:

var filtered_tempToDegrees = filtered_data.select('temperature_2m').map(function(image){
  return image.subtract(273.15);
});

becomes

var filtered_tempToDegrees = filtered_data.select('temperature_2m').map(function(image){
  return image.subtract(273.15)
              .set("system:time_start", image.get("system:time_start"),
                   "system:time_end", image.get("system:time_end"));  

And so on for each operation.

It is a bit cumbersome to apply this to each step, but it should preserve the date-time property and allow the filters to work. I'd love to know if there is a better way!

-1

You can explicitly filter for images with certain band names:

var result = collection.filter(ee.Filter.listContains('system:band_names', 'temperature_2m'))
3
  • Yes I have done this already in my script and this is not the problem. The image export runs for 5 hours and gives the error that I have provided, without any indication of errors in the script or generally any errors.
    – tg110
    Oct 18, 2021 at 15:25
  • 1
    Also, calendarRange is an expensive filter; you should use the metadata property 'hour' instead, because there will already be an index for it. var filtered_data= hour.filter('hour >= 22 || hour <= 5') Oct 20, 2021 at 16:03
  • 1
    Ah, I think I (finally) see the bigger issue: you're running filterDate on images that no longer have a start time in them, so you're always getting 0 images from all of those steps. When you do math or boolean comparisons on an image, you need to use .copyProperties(image, ["system:time_start"]) at the end of each function, to reassign a time_start to the image. Oct 20, 2021 at 16:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.