Optimize latlons() for regular_ll and regular_gg grids for grib2#283
Open
JRPdata wants to merge 1 commit into
Open
Optimize latlons() for regular_ll and regular_gg grids for grib2#283JRPdata wants to merge 1 commit into
JRPdata wants to merge 1 commit into
Conversation
- Tries to skip distinctLatitudes and distinctLongitudes by calculating them manually - Yields ~10x speedup for higher res global grids (i.e. 0.25 deg ECMWF). - Try/except that falls back to original code (use ecCodes decoding for GRIB1 files and column-major layouts). - Added numerical and GRIB1 fallback tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Speed-up (~10x) patch for latlon(), for narrow case of regular_ll and regular_gg in GRIB2 files. This patch does it by replacing the slower distinctLatitudes and distinctLongitudes calls with direct calculations.
Details
It's my understanding that in eccodes the distinctLatitudes and distinctLongitudes first gets the lats and lons from the entire grid of lats and lons and then filtering them to the unique values; this is significantly slower with larger and larger grids.
Generating it ourselves requires some careful handling for wrapping conditions, when wrapping is actually intended, given the irregular nature of how sometimes the keys are set by the various centers.
For instance, in a few of the gribs I tested had a first lon point of +180.0 going eastward, but with the last gridpoint of +179.75 (the original code generates -180 to 179.75). This is handled by the block of if abs(lon_start) == 180.0 etc.
I also put handling for starting at -180 for the reverse case of this going westward even though I don't have a sample of it to confirm.
Testing
I tested it against 24 varied GRIB files I had scattered about from some various products (i.e. from ECMWF,NCEP, CMC, UKMET, NAVGEM), but it definitely doesn't cover all the centers
It is not exhaustive so use with care if you apply this patch.
Further edge-case reports welcome.
Further notes
For another project I had originally disk-cached (h5) the latlons() on all the relevant grib keys to access the latlons() faster to get the 10x speedup (i.e. benchmarked 10x from ECMWF 0.25 deg -- for larger grids it will be a greater speedup, and conversely for smaller grids the speedup will be more modest). It was worthwhile enough to share this PR.