File size: 1,716 Bytes
fe152d4 2f8199f fe152d4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #!/usr/bin/env python
"""
Main pipeline script for running the ER model calculations.
"""
import sys
from pathlib import Path
import yaml
import click
from er_model_core.er_model import ERModel
# Add the project root to the Python path
sys.path.append(str(Path(__file__).parent.parent))
@click.command()
@click.option(
"--config",
type=click.Path(exists=True, path_type=Path),
required=True,
help="Path to YAML configuration file",
)
@click.option(
"--output",
type=click.Path(path_type=Path),
default=Path("outputs/results.csv"),
help="Path to save results CSV",
)
def main(config: Path, output: Path) -> None:
"""Run the ER model pipeline."""
# Create output directory if it doesn't exist
output.parent.mkdir(parents=True, exist_ok=True)
# Initialize and run model
model = ERModel(config)
results, species_results, scenario_results = model.run()
# Save results
model.save_results(output)
# Save additional results
species_output = output.parent / "species_results.csv"
scenario_output = output.parent / "scenario_results.csv"
species_results.to_csv(species_output, index=False)
scenario_results.to_csv(scenario_output, index=False)
# Print summary
print("\nResults Summary:")
print("-" * 40)
print(f"Total years: {len(results)}")
print(f"Total gross carbon: {results['gross_carbon'].sum():.2f} tCO2")
print(f"Total net carbon: {results['net_carbon'].sum():.2f} tCO2")
print(f"\nResults saved to:")
print(f"- Main results: {output}")
print(f"- Species results: {species_output}")
print(f"- Scenario results: {scenario_output}")
if __name__ == "__main__":
main() |