Skip to content

init() and the shared DATA_ROOT - #37

Merged
gzileni merged 1 commit into
mainfrom
feat/init
Nov 25, 2026
Merged

gzileni merged 1 commit into
mainfrom
feat/init

Conversation

@gzileni

@gzileni gzileni commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

The shared data-root rule of the agent-engineering-studio libraries, and a one-step offline init that Limen can call instead of its own code (limen ingest-fire-history download, limen worldcover-sync).

init

async def init(
    directory: Path | None = None,
    *,
    country: str,
    years: Iterable[int],
    bbox: BBox | None = None,            # (west, south, east, north): WorldCover tiles over it
    products: tuple[ArchiveProduct, ...] = (VIIRS_SNPP,),
    client: httpx.AsyncClient | None = None,
    retry: RetryPolicy | None = None,    # None = one attempt, no library retry
) -> InitReport                          # downloaded, skipped, missing, failed{name: error}, ok
  • Yearly country archives (download_archive) and the whole ESA WorldCover tiles touching bbox (Italy: 23 tiles, 1.3 GB), saved under worldcover/ with the bucket's path, so WorldCover.synced() reads them. Same behaviour as Limen's worldcover.py: stream to .part, rename, 404 = sea tile skipped (in missing), files already there skipped. No rasterio needed.
  • A failed file is recorded and the rest goes on; running again resumes. One file at a time: download_archive, download_worldcover_tile; tile list: worldcover_tiles(bbox).
  • CLI: firms init Italy [--years 2012-2025] [--bbox W,S,E,N] [--product all] [--format json], exit 1 when a file failed.

Data directory (default_directory()): explicit directory= → FIRMS_DATA_DIR (compatibility, out of .env.example) → $DATA_ROOT/firms-client → $XDG_CACHE_HOME or ~/.cache/firms-client. Each from the environment, else the current directory's .env.

Unreleased in the CHANGELOG (minor); no tag, no publish.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VFEUmXwmaxtB7PF8sSP1d4

init(directory=None, *, country, years, bbox=None, products=, client=None,
retry=None) -> InitReport, and firms init: the yearly archives and the whole
WorldCover tiles over a box, once, for offline use. Idempotent and
resumable (.part then rename, files there skipped, failures recorded and
the rest goes on); the caller's httpx client; no retry unless asked; no
rasterio. worldcover_tiles(), download_worldcover_tile().

The data directory is $DATA_ROOT/firms-client (environment or .env);
FIRMS_DATA_DIR still overrides it, for compatibility, and leaves
.env.example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VFEUmXwmaxtB7PF8sSP1d4

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 162fff3d8f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/firms_client/init.py
Comment on lines +154 to +155
for product in products:
for year in years:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Materialize years before iterating over multiple products

When years is a generator or another single-pass iterable and multiple products are requested, the first product exhausts it, so subsequent products receive no archive downloads. For example, years=iter([2024, 2025]) with products=(MODIS, VIIRS_SNPP) downloads only MODIS while returning a successful report. Since the API accepts Iterable[int], materialize the years once before the product loop so every requested product processes them.

Useful? React with 👍 / 👎.

Comment thread src/firms_client/init.py
Comment on lines +172 to +174
if worldcover_path(url, folder).exists():
report.skipped.append(name)
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Distinguish cropped WorldCover files from complete tiles

If the data directory was previously populated by firms sync --worldcover or save_worldcover, existing files at these paths contain only the requested crop, not whole tiles. This existence check skips them even when init requests a larger bounding box, reports success, and leaves offline coverage incomplete. WorldCover.synced() then reads those cropped files, and its shares() returns no data outside their bounds. Distinguish complete downloads from cropped copies and replace or expand cropped files when necessary; the same existence-only check in download_worldcover_tile() also needs to account for this.

Useful? React with 👍 / 👎.

@gzileni
gzileni merged commit f2c7165 into main Nov 25, 2026
6 checks passed
@gzileni
gzileni deleted the feat/init branch November 25, 2026 16:05
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