Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions disscube/client/cube_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ def load(
"Please specify grid_id."
)

if tile_id is None and len(matches) > 1:
candidate_tiles = sorted(set(m.tile_id for m in matches if m.tile_id))
if len(candidate_tiles) > 1:
raise ValueError(
f"Variable '{variable_id}' exists across multiple tiles: {candidate_tiles}. "
"Pass tile_id=<tile> to load a specific tile."
)

# Separate temporal from static matches, skipping stale catalog entries
# whose files no longer exist on disk (catalog can accumulate orphans when
# a source_id or other spec field changes between runs).
Expand Down
8 changes: 7 additions & 1 deletion disscube/utils/bdc_importer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging

import fiona
from shapely.geometry import shape
from disscube.models import SpatialSource
from disscube.client import CubeClient
Expand Down Expand Up @@ -35,6 +34,13 @@ def import_bdc_grids(cube: CubeClient, sm_path: str, md_path: str, lg_path: str)

def _register_tile_sources(cube: CubeClient, paths: dict[str, str]) -> None:
"""Register BDC tile envelopes as SpatialSources."""
try:
import fiona
except ImportError as exc:
raise ImportError(
"fiona is required for BDC import; install disscube[bdc]"
) from exc

level_paths = [
("SM", paths["sm_path"]),
("MD", paths["md_path"]),
Expand Down
7 changes: 5 additions & 2 deletions docs/guides/bdc.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ O Brazil Data Cube (BDC) particionam o Brasil em tiles hierárquicos. DisSCube r

## Registrar grades e tiles BDC

O utilitário `bdc_importer` cria as master grids e registra cada tile como `SpatialSource`:
O utilitário `bdc_importer` indexa as master grids e registra cada tile como `SpatialSource` no catálogo:

```python
from disscube.utils.bdc_importer import import_bdc_grids
Expand All @@ -24,6 +24,9 @@ import_bdc_grids(

Isso registra as master grids e cada tile como `SpatialSource` com `bbox` preenchido.

!!! warning "Ingestão de dados STAC — planejada"
`bdc_importer` indexa a grade BDC e os tiles (geometria e metadados), mas **não realiza ingestão de dados via STAC**. Os `SpatialSource` registrados têm `asset_url` como placeholder (`"planned"`) e não são diretamente carregáveis como dados raster. A integração com o catálogo STAC do BDC está planejada e ainda não implementada. Para usar dados BDC reais, forneça os arquivos localmente via um `SpatialSource` com `asset_url` apontando para o arquivo correto.

## Derivação por tile

```python
Expand Down Expand Up @@ -60,7 +63,7 @@ da = cube.load("slope", grid_id="BR/5km")
```

!!! warning "Carga multi-tile"
`load()` sem `tile_id` retorna silenciosamente o primeiro resultado quando múltiplos tiles da mesma variável existem na mesma grade. Mosaico automático não está implementado. **Sempre especifique `tile_id` em workloads multi-tile.**
`load()` sem `tile_id` levanta `ValueError` quando múltiplos tiles da mesma variável existem na mesma grade. Mosaico automático não está implementado. **Sempre especifique `tile_id` em workloads multi-tile.**

## Grade 100m nacional

Expand Down
2 changes: 1 addition & 1 deletion examples/case_studies/maranhao/03_brmangue_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from disscube.client import CubeClient

try:
from brmangue.executor.raster_executor import BrmangueRasterExecutor
from brmangue.executors.raster_executor import BrmangueRasterExecutor
from dissmodel.executor import ExperimentRecord
except ImportError as e:
print(f"Warning: {e}. Skipping simulation step.")
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ xarray
zarr
rasterio
geopandas
rasterstats
shapely
scipy
numpy
pandas
pyproj
fsspec
s3fs
typer
fastapi
uvicorn
python-multipart
Expand Down
10 changes: 1 addition & 9 deletions tests/test_bdc_master_grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,8 @@ def test_load_with_explicit_tile_id_filters_correctly(self, mock_open_zarr, mock

@patch('disscube.client.cube_client.os.path.exists', return_value=True)
@patch('xarray.open_zarr')
@unittest.expectedFailure
def test_load_without_tile_id_raises_for_ambiguous_tiles(self, mock_open_zarr, mock_exists):
"""
PLANNED (not yet implemented): load(name) without tile_id should raise
ValueError when multiple tiles of the same variable exist on the same grid.

Currently load() silently returns the first match. This test is marked
@expectedFailure to document the planned behavior as a regression guard —
when the feature is implemented, remove the decorator and the test will pass.
"""
"""load(name) without tile_id raises ValueError when multiple tiles exist on the same grid."""
from disscube.models import DerivedVariable

d1 = DerivedVariable(
Expand Down
Loading