Skip to content

Refactor geodataset classes to read flowpath attrs from adjacency zarr #173

@taddyb

Description

@taddyb

Context

After #172, the adjacency zarr will contain flowpath physical attributes (length_m, slope, top_width, side_slope, muskingum_x). Currently, these are read from the GeoPackage via gpd.read_file() in both geodataset constructors:

  • lynker_hydrofabric.py:72-75 — reads layer flowpath-attributes-ml
  • merit.py:71-74 — reads the full shapefile

This creates a hard runtime dependency on the GeoPackage.

Proposal

Refactor both geodataset __init__ methods to read flowpath attributes from the adjacency zarr instead of the GeoPackage.

Changes in lynker_hydrofabric.py

  • Replace gpd.read_file(self.cfg.data_sources.geospatial_fabric_gpkg, layer="flowpath-attributes-ml") with reads from self.conus_adjacency["length_m"], self.conus_adjacency["slope"], etc.
  • self.flowpath_attr currently stores a GeoDataFrame indexed by id. Replace with a dict/DataFrame built from zarr arrays indexed by order.
  • Update _build_common_tensors to use the new data source.
  • The phys_means computation (lines 77-84) should read from the same zarr arrays.

Changes in merit.py

  • Same pattern: replace gpd.read_file() with zarr reads.
  • MERIT currently uses lengthkm and slope only. Other fields are empty/constant.

Changes in _build_common_tensors

  • Both implementations index into self.flowpath_attr using wb_ids (Lynker) or compressed_merit_ids (MERIT) via .reindex(). The refactored version should use array indexing into the zarr order array instead.

Files to modify

  • src/ddr/geodatazoo/lynker_hydrofabric.py
  • src/ddr/geodatazoo/merit.py

Acceptance criteria

  • Routing produces identical results with zarr-sourced attrs vs gpkg-sourced attrs
  • gpd.read_file() for flowpath attributes is removed from both constructors
  • No geopandas import needed for routing (only for plotting)
  • Existing unit tests pass
  • New unit tests verify zarr-based attribute loading

Depends on

Blocks

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions