-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add generate command for generating a scaler CSV file * feat: Read scaler configuration from a CSV * feat: Add configurations for ssp119, ssp126 and ssp245 * fix: Update register hook See python-attrs/cattrs#206 (comment)
- Loading branch information
1 parent
868719b
commit 9c4455e
Showing
21 changed files
with
546 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
generate CLI command | ||
""" | ||
import io | ||
import logging | ||
from typing import Dict | ||
|
||
import click | ||
import pandas as pd | ||
from yaml import safe_load | ||
|
||
from spaemis.commands.base import cli | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@cli.command(name="generate") | ||
@click.option("--scaler", default="relative_change", help="Name of the scaler to use") | ||
@click.option("--scaler-source", help="Source scenario for the scaler") | ||
@click.option( | ||
"--mappings", | ||
help="YAML file containing the sector and variable mappings", | ||
type=click.File(), | ||
required=True, | ||
) | ||
def run_generate_command(scaler, scaler_source, mappings): | ||
""" | ||
Generate a scenario configuration file from a set of defaults | ||
This is helpful for setting up a CSV of scaling options for later tweaking | ||
""" | ||
mappings = safe_load(mappings) | ||
|
||
sector_mapping: Dict[str, str] = mappings["sectors"] | ||
variable_mapping: Dict[str, str] = mappings["variables"] | ||
|
||
scaler_information = [] | ||
for source_variable, target_variable in variable_mapping.items(): | ||
for source_sector, target_sector in sector_mapping.items(): | ||
scaler_information.append( | ||
{ | ||
"variable": source_variable, | ||
"sector": source_sector, | ||
"scaler_name": scaler, | ||
"scaler_variable_id": target_variable, | ||
"scaler_source_id": scaler_source, | ||
"scaler_sector": target_sector, | ||
} | ||
) | ||
|
||
if not scaler_information: | ||
raise click.ClickException("No scaler information generated") | ||
scaler_information = pd.DataFrame(scaler_information) | ||
|
||
buff = io.StringIO() | ||
scaler_information.to_csv(buff, index=False) | ||
|
||
click.echo(buff.getvalue()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
variables: | ||
CO: CO-em-anthro | ||
NOx: NOx-em-anthro | ||
SO2: SO2-em-anthro | ||
PM10: BC-em-anthro | ||
VOC: BC-em-anthro # Need to download VOC-em-anthro | ||
sectors: # Any non-specified sectors are kept constant | ||
# aircraft: # We don't easily have aviation pathways from input4MIPs | ||
architect_coating: Residential, Commercial, Other | ||
bakery: Residential, Commercial, Other | ||
# charcoal | ||
crematoria: Residential, Commercial, Other | ||
cutback_bitumen: Transportation Sector | ||
domestic_solvents: Solvents production and application | ||
dry_cleaning: Residential, Commercial, Other | ||
gas_leak: Energy Sector | ||
industry_diffuse: Waste # or Industrial Sector | ||
industry: Industrial Sector | ||
motor_vehicles: Transportation Sector | ||
panel_beaters: Residential, Commercial, Other | ||
petcrematoria: Residential, Commercial, Other | ||
pizza: Residential, Commercial, Other | ||
printing: Residential, Commercial, Other | ||
rail: Transportation Sector | ||
servos: Residential, Commercial, Other | ||
shipping: International Shipping | ||
vicbakery: Residential, Commercial, Other | ||
woodheater: Residential, Commercial, Other |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
inventory_name: victoria | ||
inventory_year: 2016 | ||
|
||
timeslices: | ||
- 2020 | ||
- 2040 | ||
- 2060 | ||
- 2080 | ||
- 2100 | ||
|
||
default_scaler: | ||
name: constant | ||
|
||
scalers: ssp119_scalers.csv |
Oops, something went wrong.