Skip to content

Commit e2ea147

Browse files
committed
Add state dataset loading API and Rhode Island data
New API Methods: - list_state_datasets(): List available state data - load_state(state): Load state data from R2 cloud storage State Data: - Rhode Island (RI) now available on R2 - 326 species, 3407x2264 pixels, ~646 MB - Streaming access via fsspec Storage: - Using Cloudflare R2 for zero-egress cost - URL: https://pub-da6f67cd8f9147418258ed71cc130443.r2.dev/states/ Usage: api = GridFIA() store = api.load_state("RI") biomass = store.biomass[:]
1 parent b4167f2 commit e2ea147

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

gridfia/api.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,21 @@ def validate_zarr(self, zarr_path: Union[str, Path]) -> Dict[str, Any]:
828828
},
829829
}
830830

831+
# Cloud-hosted state datasets (full state coverage)
832+
# Base URL for state data on R2
833+
STATE_DATA_BASE_URL = "https://pub-da6f67cd8f9147418258ed71cc130443.r2.dev/states"
834+
835+
STATE_DATASETS = {
836+
"RI": {
837+
"name": "Rhode Island",
838+
"url": "https://pub-da6f67cd8f9147418258ed71cc130443.r2.dev/states/ri/ri_forest.zarr",
839+
"description": "Full Rhode Island state coverage",
840+
"num_species": 326,
841+
"shape": [326, 3407, 2264],
842+
"approximate_size_mb": 646
843+
},
844+
}
845+
831846
def list_sample_datasets(self) -> List[Dict[str, Any]]:
832847
"""
833848
List available pre-hosted sample datasets.
@@ -852,6 +867,76 @@ def list_sample_datasets(self) -> List[Dict[str, Any]]:
852867
for key, info in self.SAMPLE_DATASETS.items()
853868
]
854869

870+
def list_state_datasets(self) -> List[Dict[str, Any]]:
871+
"""
872+
List available pre-hosted state datasets.
873+
874+
These are full-state forest data hosted on cloud storage, enabling
875+
streaming access to any US state's forest data without local download.
876+
877+
Returns
878+
-------
879+
List[Dict[str, Any]]
880+
List of available state datasets with metadata.
881+
882+
Examples
883+
--------
884+
>>> api = GridFIA()
885+
>>> states = api.list_state_datasets()
886+
>>> for s in states:
887+
... print(f"{s['state']}: {s['name']} ({s['approximate_size_mb']} MB)")
888+
"""
889+
return [
890+
{"state": key, **info}
891+
for key, info in self.STATE_DATASETS.items()
892+
]
893+
894+
def load_state(
895+
self,
896+
state: str,
897+
storage_options: Optional[Dict[str, Any]] = None
898+
) -> ZarrStore:
899+
"""
900+
Load a state's forest data from cloud storage.
901+
902+
This enables streaming access to full-state forest data. Only the chunks
903+
you access are downloaded, making it efficient to analyze specific regions
904+
within a state.
905+
906+
Parameters
907+
----------
908+
state : str
909+
State abbreviation (e.g., "NC", "CA", "RI").
910+
storage_options : Dict[str, Any], optional
911+
Options passed to the filesystem backend.
912+
913+
Returns
914+
-------
915+
ZarrStore
916+
A ZarrStore instance for streaming access to the state data.
917+
918+
Raises
919+
------
920+
ValueError
921+
If the state is not available in cloud storage.
922+
923+
Examples
924+
--------
925+
>>> api = GridFIA()
926+
>>> store = api.load_state("RI")
927+
>>> print(f"Shape: {store.shape}")
928+
>>> print(f"Species: {store.num_species}")
929+
"""
930+
state_upper = state.upper()
931+
if state_upper not in self.STATE_DATASETS:
932+
available = list(self.STATE_DATASETS.keys())
933+
raise ValueError(
934+
f"State '{state}' not available. Available states: {available}"
935+
)
936+
937+
url = self.STATE_DATASETS[state_upper]["url"]
938+
return self.load_from_cloud(url=url, storage_options=storage_options)
939+
855940
def load_from_cloud(
856941
self,
857942
url: Optional[str] = None,

0 commit comments

Comments
 (0)