Skip to content

fix: migrate AssimilatorEncoder to H3 v4 API#218

Merged
jacobbieker merged 1 commit into
openclimatefix:mainfrom
AswaniSahoo:fix/h3-v4-assimilator-encoder
Jun 2, 2026
Merged

fix: migrate AssimilatorEncoder to H3 v4 API#218
jacobbieker merged 1 commit into
openclimatefix:mainfrom
AswaniSahoo:fix/h3-v4-assimilator-encoder

Conversation

@AswaniSahoo

Copy link
Copy Markdown
Contributor

Problem

AssimilatorEncoder uses deprecated H3 v3 API calls (geo_to_h3, h3_to_geo, point_dist, k_ring, etc.), but the repo pins h3==4.3.1. This causes AttributeError on instantiation — the class is unusable under the pinned version.

The sibling classes (Encoder, AssimilatorDecoder) were already migrated to v4. This brings AssimilatorEncoder in line.

Changes

assimilator_encoder.py — 6 mechanical name substitutions:

  • h3.uncompact(h3.get_res0_indexes(), ...)h3.uncompact_cells(h3.get_res0_cells(), ...)
  • h3.num_hexagons()h3.get_num_cells()
  • h3.geo_to_h3()h3.latlng_to_cell()
  • h3.h3_to_geo()h3.cell_to_latlng()
  • h3.point_dist()h3.great_circle_distance()
  • h3.k_ring()h3.grid_disk()

tests/test_model.py:

  • 2x h3.num_hexagonsh3.get_num_cells (same migration)
  • 5x np.random.random(1)np.random.random() (fixes numpy 2.x incompatibility that was hidden behind the H3 crash)

Testing

  • test_assimilation_encoder_uneven_grid: was crashing with AttributeError, now passes
  • test_assimilator_model, test_assimilator_model_grad_checkpoint: same, now pass
  • All 14 previously-passing tests remain green (19/21 total, 2 unrelated torch-cluster failures unchanged)

- Replace 6 deprecated h3 v3 calls with v4 equivalents
- Fix np.random.random(1) -> np.random.random() for numpy 2.x
- Matches existing pattern in encoder.py and assimilator_decoder.py
@AswaniSahoo

Copy link
Copy Markdown
Contributor Author

@jacobbieker Gentle ping on this one , just the H3 v3 → v4 API migration (6 call sites in AssimilatorEncoder + numpy 2.x test fixes). No functional changes, all existing tests pass. Let me know if anything needs adjusting.

@jacobbieker

Copy link
Copy Markdown
Collaborator

@jacobbieker Gentle ping on this one , just the H3 v3 → v4 API migration (6 call sites in AssimilatorEncoder + numpy 2.x test fixes). No functional changes, all existing tests pass. Let me know if anything needs adjusting.

Hi,

When you open ones, please assign me as a reviewer, otherwise I don't get notified.

@jacobbieker jacobbieker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this

@jacobbieker jacobbieker merged commit b541b8a into openclimatefix:main Jun 2, 2026
0 of 3 checks passed
@AswaniSahoo AswaniSahoo deleted the fix/h3-v4-assimilator-encoder branch June 3, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants