Project

General

Profile

Issue with GRIB remap lonlat scanning direction

Added by Matthijs Amesz 10 months ago

When using the 'remap' command to remap a GRIB2 file to a gridtype=lonlat grid with a positive yinc value, the resulting GRIB2 file has the bit flag for 'increments in the y direction' incorrectly set to 0, the value for negative increments.
Specifically, this bit flag is part of GRIB2 Section 3 octet 72, which falls under Grid definition template 3.0 (Latitude/longitude), "scanning mode", defined in GRIB2 Table 3.4, where the second bit is defined as follows:

0: Points in the first row or column scan in the -j (-y) direction
1: Points in the first row or column scan in the +j (+y) direction

With a positive yinc value, this bit should be set to 1, but is instead set to 0 in the resulting file. As a result, ecCodes throws an error whenever it attempts to read the file. Specifically, the following:

ECCODES ERROR : Lat/Lon Geoiterator: First and last latitudes are inconsistent with scanning order: lat1=27.5, lat2=72 jScansPositively=0
ECCODES ERROR : Geoiterator factory: Error instantiating iterator latlon (Grid description is wrong or inconsistent)
ECCODES ERROR : latitudes: Unable to create iterator

I encountered this issue in CDO 2.0.4 (Ubuntu Jammy) and 2.1.1 (Debian Bookworm). I have confirmed that this issue was not yet present in CDO 1.9.10 (Debian Bullseye).
I have been unable to find a previous mention of this issue on the Forums or in the Issues list. I have not been able to test this on CDO 2.2.0 (latest version at time of writing), but this issue is not mentioned in the release notes as a bugfix.
I am using ICON global files as input GRIB2 files, though I believe this issue should occur on every input GRIB2 file.


Replies (5)

RE: Issue with GRIB remap lonlat scanning direction - Added by Matthijs Amesz 10 months ago

I would like to add that I have also tested the same remap conversion with a negative yinc value, i.e. decrementing the latitude. In this case the bit flag is also set to 0, which in this case is correct, and leads to GRIB2 files that can be opened normally.

Also, in case it was unclear in my initial post, the yinc value resides in a 'target_grid.txt' file, which serves as the first parameter for the remap operation (see also section 2.12.8 regarding the remap operation (https://code.mpimet.mpg.de/projects/cdo/embedded/index.html#x1-7130002.12.8) and section 1.5.2.4 regarding CDO Grids (https://code.mpimet.mpg.de/projects/cdo/embedded/index.html#x1-300001.5.2))

RE: Issue with GRIB remap lonlat scanning direction - Added by Momtchil Momtchev 8 months ago

If you simply invert the Y axis, the resulting file is a valid GRIB, but it is still flipped Y side.

Version 2.2.2 fixes this problem for me.

As this is a critical issue - most everyday users of cdo use it exclusively to regrid the ICON high resolution files - I wonder if it is possible to extract this patch and to submit it to the Debian maintainer. Debian policy is to never upgrade packages to a new version, only bugfixes can be applied.

RE: Issue with GRIB remap lonlat scanning direction - Added by Momtchil Momtchev 8 months ago

In order to install the latest cdo 2.2.2 from Debian testing which fixes this problem:

  • Follow this guide to enable installing packages from testing:

https://serverfault.com/questions/22414/how-can-i-run-debian-stable-but-install-some-packages-from-testing

  • install cdo

apt-get install cdo/testing

    (1-5/5)