|
| 1 | +#!/usr/bin/env python |
| 2 | +"""Generate NY heat pump adoption scenarios with cumulative adoption.""" |
| 3 | + |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +from utils.mixed_adoption_trajectory import ( |
| 7 | + build_adoption_trajectory, |
| 8 | + fetch_baseline_sample, |
| 9 | +) |
| 10 | + |
| 11 | +# Base data directory for NY HP rates (git-ignored raw/processed, configs versioned) |
| 12 | +BASE_DATA_DIR = Path("rate_design/ny/hp_rates/data") |
| 13 | + |
| 14 | +# Configuration |
| 15 | +CONFIG = { |
| 16 | + # ResStock release parameters |
| 17 | + "release_year": "2024", |
| 18 | + "weather_file": "tmy3", |
| 19 | + "release_version": "2", |
| 20 | + "state": "NY", |
| 21 | + # Heat pump upgrade ID (adjust based on your ResStock release) |
| 22 | + "hp_upgrade_id": "1", |
| 23 | + # Download settings |
| 24 | + "output_dir": BASE_DATA_DIR / "buildstock_raw", |
| 25 | + "max_workers": 5, |
| 26 | + # Sampling settings |
| 27 | + "sample_size": 1000, # Number of buildings to sample |
| 28 | + "sample_seed": 123, # Seed for sampling reproducibility (determines building ordering) |
| 29 | + # Adoption scenario settings |
| 30 | + "adoption_fractions": [0.1, 0.2, 0.3, 0.5, 0.8, 1.0], |
| 31 | + # Output settings |
| 32 | + "processed_dir": BASE_DATA_DIR / "buildstock_processed", |
| 33 | +} |
| 34 | + |
| 35 | + |
| 36 | +def main(): |
| 37 | + """Run the complete workflow to generate adoption scenarios.""" |
| 38 | + print("=" * 80) |
| 39 | + print("NY Heat Pump Cumulative Adoption Scenario Generator") |
| 40 | + print("=" * 80) |
| 41 | + print("\nConfiguration:") |
| 42 | + for key, value in CONFIG.items(): |
| 43 | + print(f" {key}: {value}") |
| 44 | + print("\n") |
| 45 | + |
| 46 | + # Step 1: Fetch baseline sample and establish building ID ordering |
| 47 | + print("\n" + "=" * 80) |
| 48 | + print("STEP 1: Fetching baseline sample") |
| 49 | + print("=" * 80) |
| 50 | + print(f"Fetching {CONFIG['sample_size']} baseline buildings (seed={CONFIG['sample_seed']})") |
| 51 | + |
| 52 | + baseline_metadata_path, building_ids = fetch_baseline_sample( |
| 53 | + sample_size=CONFIG["sample_size"], |
| 54 | + random_seed=CONFIG["sample_seed"], |
| 55 | + release_year=CONFIG["release_year"], |
| 56 | + weather_file=CONFIG["weather_file"], |
| 57 | + release_version=CONFIG["release_version"], |
| 58 | + state=CONFIG["state"], |
| 59 | + output_dir=CONFIG["output_dir"], |
| 60 | + max_workers=CONFIG["max_workers"], |
| 61 | + ) |
| 62 | + |
| 63 | + print(f"\n✓ Fetched {len(building_ids)} baseline buildings") |
| 64 | + print(f"✓ Baseline metadata: {baseline_metadata_path}") |
| 65 | + print(f"✓ Building ID ordering established (deterministic from seed)") |
| 66 | + |
| 67 | + # Step 2: Build adoption trajectory |
| 68 | + print("\n" + "=" * 80) |
| 69 | + print("STEP 2: Building adoption trajectory") |
| 70 | + print("=" * 80) |
| 71 | + print(f"Creating scenarios for adoption fractions: {CONFIG['adoption_fractions']}") |
| 72 | + print("Note: Upgrade data will be fetched incrementally for each fraction") |
| 73 | + |
| 74 | + scenario_paths = build_adoption_trajectory( |
| 75 | + baseline_metadata_path=baseline_metadata_path, |
| 76 | + baseline_building_ids=building_ids, |
| 77 | + adoption_fractions=CONFIG["adoption_fractions"], |
| 78 | + upgrade_id=CONFIG["hp_upgrade_id"], |
| 79 | + release_year=CONFIG["release_year"], |
| 80 | + weather_file=CONFIG["weather_file"], |
| 81 | + release_version=CONFIG["release_version"], |
| 82 | + state=CONFIG["state"], |
| 83 | + output_dir=CONFIG["output_dir"], |
| 84 | + max_workers=CONFIG["max_workers"], |
| 85 | + output_processed_dir=CONFIG["processed_dir"], |
| 86 | + ) |
| 87 | + |
| 88 | + # Summary |
| 89 | + print("\n" + "=" * 80) |
| 90 | + print("COMPLETE - Scenario Summary") |
| 91 | + print("=" * 80) |
| 92 | + print(f"\nGenerated {len(scenario_paths)} adoption scenarios:") |
| 93 | + for fraction, path in sorted(scenario_paths.items()): |
| 94 | + n_adopters = int(round(fraction * len(building_ids))) |
| 95 | + print(f" {fraction*100:3.0f}% adoption ({n_adopters:4d} buildings) → {path.name}") |
| 96 | + |
| 97 | + print(f"\nAll scenarios use seed {CONFIG['sample_seed']} ensuring:") |
| 98 | + print(" - Reproducibility: Re-running with same seed gives identical results") |
| 99 | + print(" - Cumulative property: Adopters at X% ⊆ Adopters at Y% for X < Y") |
| 100 | + print(" - Efficiency: Upgrade data fetched only for buildings that adopt") |
| 101 | + |
| 102 | + print("\nNext steps:") |
| 103 | + print(" - Load scenarios with: pl.read_parquet(path)") |
| 104 | + print(" - Check 'adopted' column (0=baseline, 1=upgrade)") |
| 105 | + print(" - Use for GenX/CAIRO modeling") |
| 106 | + print("\n✓ Done!") |
| 107 | + |
| 108 | + |
| 109 | +if __name__ == "__main__": |
| 110 | + main() |
0 commit comments