Use numeric basename as concat index for bare-wildcard rasters (fixes #1465)#1480
Open
gaoflow wants to merge 2 commits into
Open
Use numeric basename as concat index for bare-wildcard rasters (fixes #1465)#1480gaoflow wants to merge 2 commits into
gaoflow wants to merge 2 commits into
Conversation
open_mfraster determined the concatenation index from a numeric basename only when a non-empty prefix was parsed from the path pattern. For a bare wildcard such as *.tif matching files named 1.tif .. 12.tif (e.g. modis_lai monthly data referenced in a catalog with uri *.tif), the prefix is empty, so the numeric stems were ignored and the index fell back to the file-order position (0 .. 11). The concat order also depended on the filesystem-dependent glob order. Use the numeric basename as the index for bare (prefix- and postfix-less) wildcard patterns, and sort the matched files so the concat order and the variable name are deterministic. Fixes Deltares#1465
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.
Problem
When reading externally-provided rasters named with bare numeric stems — e.g.
modis_laistored as1.tif..12.tifand referenced in a catalog withuri: "*.tif"—open_mfraster(..., concat=True)produced the wrong concatenation index and a non-deterministic order (#1465):[0, 1, ..., 11](file-order fallback) instead of the numeric stems[1, 2, ..., 12];glob()order;The index was only derived from a numeric basename when a non-empty prefix had been parsed from the pattern:
For a bare wildcard
*.tifthe prefix is empty, so the numeric stems were ignored.(This complements #1459, which fixed the write side so hydromt-written mapstacks use
<name>_<index>.tif; #1465 is about reading third-party bare-numeric files.)Fix
Existing prefix /
_-separated / PCRaster-style index parsing is untouched.Reproduction (from #1465)
Verification
TestOpenMFRaster::test_open_mfraster_bare_wildcard_numeric_namesasserts the concat dim equals[1..12]. It fails onmainand passes with this change.tests/data_catalog/drivers/raster/suite passes (56 passed, 5 skipped).ruff checkandruff format --checkclean.