Skip to content

basinkit 0.8.3

Choose a tag to compare

@Praddy-GByte Praddy-GByte released this 02 Oct 23:11
· 39 commits to main since this release

Three failures reported from the QGIS plugin by Vitor Castellar, two of which
turned out to be the same bug.

A basin's CRS is now checked rather than assumed

basinkit works in lon/lat throughout, and nothing verified that the geometry it
was handed was in lon/lat. Basin.from_file reprojected; Basin.from_geometry
did not, and the QGIS plugin uses from_geometry. A polygon in a projected CRS
therefore reached the equal-area projection as metres, and a northing of
7,793,981 was passed as a latitude — once in basin_area_km2, once in
morphometry, with two different error messages that looked like two separate
bugs.

  • clip.laea_crs() is now the only place that projection is built. It refuses a
    centre that is not in degrees, with a message that names the real cause rather
    than PROJ's internal one, and builds the CRS from a dict instead of a proj4
    string, which QGIS's bundled PROJ does not reliably parse.
  • Basin.from_geometry accepts crs= and reprojects. The default is unchanged,
    so existing callers are unaffected.
  • The QGIS plugin transforms the layer through source.sourceCrs() on the way
    in. All seven algorithms share that entry point, so all seven are fixed, not
    only the three that were reported.
  • mosaic.merge_tiles took its CRS straight from the first tile, where rasterio
    returns None for a file whose CRS it cannot read — what a PROJ installation
    missing its data directory does. The array then failed much later inside
    rioxarray with "CRS not found", naming the symptom. It now falls back to
    EPSG:4326 and records basinkit_crs_assumed in the mosaic metadata.
    Basin.dem() keeps a second guard at the exit.

auto refines on the DEM below 2,000 km², not below 25

The default backend assembles a basin from whole HydroBASINS level-12 units of
about 130 km² each, so its boundary follows unit edges rather than the terrain
divide and will not match a DEM-derived basin along the margins. Three numbers
described where that stops being good enough: backend="auto" escaped to the
DEM below 25 km², the QGIS plugin warned below 500, and the blind check at
2,550 gauges in docs/verification.md puts the crossover near 2,000. A
catchment between 500 and 2,000 km² got the coarse answer and no warning at all.

The threshold is now delineate.DEM_REFINE_BELOW_KM2, set from that measurement
and carrying both the evidence and the cost in a comment. The plugin's warning
fires on the same number and explains what the coarse polygon is instead of only
recommending an alternative.

Tests

Six new tests. Four cover the CRS work and all four fail without it; one builds
a real EPSG:32645 layer in QGIS and asserts the geometry reaching basinkit is in
degrees; one checks that pyproject.toml, basinkit/__init__.py,
CITATION.cff and the plugin metadata all state the same version, after this
release's own bump missed one of them.

Upgrading

pip install -U basinkit

The QGIS plugin needs 0.8.3 or newer; update it from the QGIS plugin manager.