Skip to content

Commit 5a79608

Browse files
Merge pull request #475 from switchbox-data/474-factor-out-aws_storage_option-out-of-eia-scripts
Refactor get aws storage options function
2 parents bc53691 + 95fbb9c commit 5a79608

32 files changed

Lines changed: 44 additions & 47 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ data/isone/capacity/ara/parquet/
4141
data/isone/capacity/fca/parquet/
4242
data/isone/lmp/parquet/
4343
data/isone/hourly_demand/zones/
44+
data/isone/hourly_demand/utilities/
4445
data/isone/ancillary/parquet/
4546
data/nyiso/icap/parquet/
4647
data/nyiso/lbmp/zips/

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ After individual CAIRO runs complete, post-processing scripts consolidate result
8181
| **`rate_design/`** | Package root. Heat pump rate design lives under `rate_design/hp_rates/`. |
8282
| **`rate_design/hp_rates/`** | Shared scenario entrypoint (`run_scenario.py`), shared **Justfile** (primary task interface for all states). State-specific thin Justfiles and `config/` dirs live under `rate_design/hp_rates/{ny,ri}/`. |
8383
| **`rate_design/hp_rates/{ny,ri}/`** | State-specific thin Justfile (imports shared), `state.env`, and `config/` (tariffs JSON in tariffs/electric and tariffs/gas, tariff_maps CSV in tariff_maps/electric and tariff_maps/gas, marginal_costs). Large artifacts (buildstock raw/processed, cairo_cases) are git-ignored; sync via S3 or keep local. |
84-
| **`data/eia/hourly_loads/`** | EIA zone load fetch and utility load aggregation; eia_region_config (state/utility config, get_aws_storage_options); Justfile for fetch-zone-data and aggregate-utility-loads. |
84+
| **`data/eia/hourly_loads/`** | EIA zone load fetch and utility load aggregation; eia_region_config (state/utility config); Justfile for fetch-zone-data and aggregate-utility-loads. |
8585
| **`data/eia/861/`** | EIA-861 utility stats (PUDL yearly sales); fetch_electric_utility_stat_parquets.py; Justfile build-utility-stats (local parquet), update (upload to s3://data.sb/eia/861/electric_utility_stats/), fetch-utility-stats STATE (CSV to stdout). |
8686
| **`data/fred/cpi/`** | FRED CPI series; Justfile fetch-cpi (local parquet/), upload (sync to s3://data.sb/fred/cpi/). |
8787
| **`data/aspe/fpl/`** | ASPE Federal Poverty Guidelines fetch; Justfile fetch. Output: utils/post/data/fpl_guidelines.yaml (used by LMI discount logic). |

context/code/cairo/cairo_elastic_cluster.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ With a **Dask Distributed** cluster, the driver and scheduler run on one node; w
4040
- **Overhead:** You must deploy workers (e.g. EC2 or Batch) that have the same mount. With Fargate or generic Batch workers, that can be fiddly (custom AMI or entrypoint that mounts S3).
4141

4242
- **B. S3 URIs + storage_options (no shared mount)**\
43-
Pass **S3 URIs** (e.g. `s3://data.sb/nrel/resstock/...`) and **storage_options** (e.g. `{"region_name": "us-west-2"}` or from `get_aws_storage_options()`) through the stack so that workers can call `pd.read_parquet(s3_uri, storage_options=...)` and read directly from S3.
43+
Pass **S3 URIs** (e.g. `s3://data.sb/nrel/resstock/...`) and **storage_options** (e.g. `{"region_name": "us-west-2"}` or from `utils.file_io.get_aws_storage_options()`) through the stack so that workers can call `pd.read_parquet(s3_uri, storage_options=...)` and read directly from S3.
4444
- **Overhead:** Requires code changes in both codebases (see below). No need for a shared mount; any worker with AWS credentials and network can read.
4545

4646
Option **B** is more portable (works with Fargate, Batch, any node with S3 access) and is the one that forces the concrete changes below. Option A is “no code change” but constrains how you run workers.
@@ -92,7 +92,7 @@ CAIRO does **not** need to know about “the cluster”; it only needs to be abl
9292
2. **Pass storage_options into CAIRO**
9393
- Where the platform calls CAIRO (e.g. `_return_load`, `return_buildingstock`, and the top-level `simulate()` or helpers that take paths), it must pass `storage_options` when the paths are S3. That implies:
9494
- CAIRO’s public API (e.g. `MeetRevenueSufficiencySystemWide`, `simulate()`, or the load/buildingstock functions) must accept an optional `storage_options` (or a “run config” that includes it) and pass it through to all parquet-reading code.
95-
- The platform already has `get_aws_storage_options()` (e.g. in `data.eia.hourly_loads.eia_region_config` or similar). When running in “cluster mode” with S3 URIs, the platform should pass that (or equivalent) into CAIRO.
95+
- The platform already has `get_aws_storage_options()` (in `utils.file_io`). When running in “cluster mode” with S3 URIs, the platform should pass that (or equivalent) into CAIRO.
9696

9797
3. **Use Dask Distributed instead of the process scheduler**
9898
- Instead of `dask.config.set(scheduler="processes", num_workers=...)`, the platform (or a cluster launcher script) would create a `distributed.Client` connected to a Dask scheduler (e.g. one started by dask-cloudprovider), and either:

data/eia/hourly_loads/eia_region_config.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
- utility service areas used by utility aggregation scripts
66
"""
77

8-
import os
98
from dataclasses import dataclass
109
from typing import TypedDict
1110

@@ -139,14 +138,3 @@ def get_utility_zone_mapping_for_state(state: str) -> dict[str, list[str]]:
139138
break
140139

141140
return utility_zone_mapping
142-
143-
144-
def get_aws_storage_options() -> dict[str, str]:
145-
"""Return Polars-compatible AWS storage options for S3 access."""
146-
aws_region = (
147-
os.getenv("AWS_DEFAULT_REGION") or os.getenv("AWS_REGION") or "us-west-2"
148-
)
149-
return {
150-
"region": aws_region,
151-
"default_region": aws_region,
152-
}

utils/cairo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from cairo.rates_tool.loads import __timeshift__
1515
from cloudpathlib import S3Path
1616

17-
from data.eia.hourly_loads.eia_region_config import get_aws_storage_options
17+
from utils.file_io import get_aws_storage_options
1818
from utils.types import ElectricUtility
1919

2020
CambiumPathLike = str | Path | S3Path

utils/data_prep/marginal_costs/generate_bulk_tx_mc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
from dotenv import load_dotenv
4242

43-
from data.eia.hourly_loads.eia_region_config import get_aws_storage_options
43+
from utils.file_io import get_aws_storage_options
4444
from utils.data_prep.marginal_costs.bulk_tx_isone import (
4545
AESC_2024_AVOIDED_PTF_KW_YEAR,
4646
DEFAULT_N_PEAK_HOURS,

utils/data_prep/marginal_costs/generate_supply_ancillary_mc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def main() -> None:
120120
)
121121

122122
load_dotenv()
123-
from data.eia.hourly_loads.eia_region_config import get_aws_storage_options
123+
from utils.file_io import get_aws_storage_options
124124

125125
storage_options = get_aws_storage_options()
126126

utils/data_prep/marginal_costs/generate_supply_capacity_mc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from dotenv import load_dotenv
88

9-
from data.eia.hourly_loads.eia_region_config import get_aws_storage_options
9+
from utils.file_io import get_aws_storage_options
1010
from utils.data_prep.marginal_costs.supply_capacity_nyiso import (
1111
N_PEAK_HOURS_PER_MONTH,
1212
compute_supply_capacity_mc,

utils/data_prep/marginal_costs/generate_supply_energy_mc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from dotenv import load_dotenv
88

9-
from data.eia.hourly_loads.eia_region_config import get_aws_storage_options
9+
from utils.file_io import get_aws_storage_options
1010
from utils.data_prep.marginal_costs.supply_energy import (
1111
compute_isone_supply_energy_mc,
1212
compute_pjm_supply_energy_mc,

utils/data_prep/marginal_costs/generate_utility_tx_dx_mc.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@
6060
from cloudpathlib import S3Path
6161
from dotenv import load_dotenv
6262

63-
from data.eia.hourly_loads.eia_region_config import (
64-
get_aws_storage_options,
65-
get_state_config,
66-
)
63+
from data.eia.hourly_loads.eia_region_config import get_state_config
64+
from utils.file_io import get_aws_storage_options
6765
from utils.data_prep.marginal_costs.supply_utils import (
6866
warn_if_multiple_partition_parquets,
6967
)

0 commit comments

Comments
 (0)