Skip to content

Commit 3dcf1db

Browse files
committed
feat: pre-generation state of files
1 parent 2f0b3eb commit 3dcf1db

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

indicator.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from enum import Enum
55
from typing import Dict, Optional, Any, List
66
from hazard import services
7-
from stactools.osc_hazard import commands
87

98
import pydantic
9+
from stactools.osc_hazard.commands import cubify_invocation, collection_invocation, item_invocation
1010

1111
logger = logging.getLogger()
1212
logger.setLevel(logging.INFO)
@@ -63,7 +63,7 @@ def degree_days_indicator(indicator_generation_params: Annotated[IndicatorGenera
6363
bucket=indicator_generation_params.bucket,
6464
prefix=indicator_generation_params.prefix,
6565
store=indicator_generation_params.store,
66-
write_xarray_compatible_zarr=indicator_generation_params.write_xarray_compatible_zarr,
66+
write_xarray_compatible_zarr=False,
6767
dask_cluster_kwargs=indicator_generation_params.dask_cluster_kwargs,
6868
)
6969

@@ -83,7 +83,7 @@ def days_tas_above_indicator(indicator_generation_params: Annotated[IndicatorGen
8383
bucket=indicator_generation_params.bucket,
8484
prefix=indicator_generation_params.prefix,
8585
store=indicator_generation_params.store,
86-
write_xarray_compatible_zarr=indicator_generation_params.write_xarray_compatible_zarr,
86+
write_xarray_compatible_zarr=False,
8787
dask_cluster_kwargs=indicator_generation_params.dask_cluster_kwargs,
8888
)
8989

@@ -95,10 +95,18 @@ def generate_indicators(indicator_generation_params: Annotated[IndicatorGenerati
9595
if indicator_generation_params.indicator == IndicatorType.days_tas_above:
9696
logger.info("Generating Days TAS Above Indicators")
9797
days_tas_above_indicator(indicator_generation_params)
98-
output_dir = indicator_generation_params.store
99-
logger.info("Generated indicators, now generating cubified zarr")
100-
commands.cubify_invocation(store_path=f"{output_dir}/chronic_heat/osc/v2", output_dir=f"{output_dir}/cubified/", indicator_name=indicator_generation_params.indicator.value.replace("_indicator", ""))
101-
logger.info("Generated cubified zarr")
98+
99+
@app.command()
100+
def cubify_indicator(store_path: str, output_dir: str, indicator_name: str):
101+
cubify_invocation(store_path, output_dir, indicator_name)
102+
103+
@app.command()
104+
def create_collection(sources: str, destination: str):
105+
collection_invocation(sources, destination)
106+
107+
@app.command()
108+
def create_item(source: str, destination: str):
109+
item_invocation(source, destination)
102110

103111
if __name__ == "__main__":
104112
app()

indicator.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
python indicator.py generate-indicators "$1"
4+
5+
store=$(echo "$1" | jq -r '.store')
6+
indicator=$(echo "$1" | jq -r '.indicator' | sed 's/_indicator$//')
7+
8+
python indicator.py cubify-indicator $store "$store/cubified" $indicator
9+
10+
python indicator.py create-collection "$store/cubified/*.zarr" "$store/collection.json"
11+
12+
for dir in "$store/cubified"/*; do
13+
if [ -d "$dir" ]; then
14+
echo "Processing directory: $dir"
15+
output_filename=$(basename "$dir" .zarr).json
16+
python indicator.py create-item $dir "$store/$output_filename"
17+
fi
18+
done

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ dependencies = [
1414

1515
[tool.uv.sources]
1616
hazard = { git = "https://github.com/joemoorhouse/hazard", rev = "2a989c87935d8b9b0335f46ff1ba7e327a8b9944" }
17-
stactools-osc-hazard = { git = "https://github.com/developmentseed/osc-hazard", rev = "b6619d110e1db4962df51a5256b8879b554ac3d6" }
17+
stactools-osc-hazard = { git = "https://github.com/developmentseed/osc-hazard", rev = "a07ed977a9627b9c79317c9a21b8bbd7719da187" }

uv.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)