Skip to content

climateLayers(): let the caller choose the years; add latestHistoricalYear() - #24

Open
eliotmcintire wants to merge 2 commits into
developmentfrom
feat/climate-layers-years
Open

climateLayers(): let the caller choose the years; add latestHistoricalYear()#24
eliotmcintire wants to merge 2 commits into
developmentfrom
feat/climate-layers-years

Conversation

@eliotmcintire

Copy link
Copy Markdown
Collaborator

Two small additions so a project can use more climate years.

  • climateLayers() gains historicalYears (default 1991:2022) and projectedYears (default 2011:2100). The defaults are the years it used before, so existing calls are unchanged.
  • latestHistoricalYear() returns the last year the bundled tile index lists for every tile (2022 today). It only reads the bundled index, so it needs no network.

Tests: tests/testthat/test-climateLayers.R.

Some things I noticed but did not change, since they concern the data rather than the code:

  1. The 2020s zips already hold 2023 and 2024 (checked for two tiles), and NEWS says those years were added, but the tile index still stops at 2022. So getClimateURLs(years = 2023:2024) returns nothing, while 1991:2024 works only because the 2020-2022 rows point to the same zip. With rows for 2023 and 2024, latestHistoricalYear() would return 2024.
  2. available("historical") says 1901:2024. Taking it from the index would keep the two in step.
  3. ClimateNA added 2025 in April 2026 (v7.70). Because the tiles are built from ClimateNA's output ahead of time, the years a project can use are set by that step, whatever these arguments allow.
  4. getClimateURLs() could stop with a message when some requested years have no rows, instead of quietly returning fewer.

Happy to help with any of these.

🤖 Generated with Claude Code

https://claude.ai/code/session_01T5BZwHeHMMhjzRK8eGCTp3

…lYear()

climateLayers() always requested historical years 1991:2022 and projected years 2011:2100.
It gains historicalYears and projectedYears arguments with those defaults, so existing callers
are unchanged.

latestHistoricalYear() returns the last year the bundled tile index lists for every requested
tile, without network access, so a project can ask for the latest year it can fetch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T5BZwHeHMMhjzRK8eGCTp3

@eliotmcintire eliotmcintire left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is entirely backwards compatible as 2 hard coded date ranges are moved to arguments with those same data ranges as defaults.

The 2020-decade Drive archives have contained Year_2023MSY and Year_2024MSY
since they were re-uploaded (b6f2845, "add 2023, 2024 data"), and
available("historical") already reports 1901:2024, but that commit updated
the zips without adding the matching rows to inst/extdata/ClimateNA_tiles.sqlite.
The index therefore stopped at 2022, so getClimateURLs() returned no Drive id
for 2023/2024 and latestHistoricalYear() reported 2022 -- capping downstream
fits at 2022 even though the data was already on disk.

Each new row copies its tile/msy 2022 row and changes only the year: within a
decade every year shares one zipfile and gid, so no new uploads are involved.
492 rows (2 years x 82 tiles x {M, MSY, Y}); historical goes 30012 -> 30504.

Verified: latestHistoricalYear() now returns 2024; climateLayers() accepts
historicalYears = 1985:2024; getClimateURLs(type = "historical", years =
2023:2024) returns the same Drive ids as 2022. The two prepClimateLayers test
errors are pre-existing Google Drive auth failures in a non-interactive
session -- identical with and without this change.
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.

1 participant