diff --git a/.gitignore b/.gitignore index a110372..fb3ed7c 100644 --- a/.gitignore +++ b/.gitignore @@ -273,6 +273,6 @@ cython_debug/ # TODO: verify with Vic EPA that files can be published data/raw/inventories/victoria -data/processed/input4MIPs +data/processed notebooks/*.ipynb notebooks/**/*.ipynb \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c57943..98257a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ + # Changelog All notable changes to this project will be documented in this file. @@ -17,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Add `ssp119`, `ssp126` and `ssp245` scenario configurations [#10](https://github.com/climate-resource/spaemis/pull/10) - Add `default_scaler` to the configuration for the scaler to be used if no specific scaler configuration is provided [#9](https://github.com/climate-resource/spaemis/pull/9) - Move test configuration to `test-data` directory [#8](https://github.com/climate-resource/spaemis/pull/8) - Add functionality to write out a xarray dataset as a set of CSVs that are formatted the same as the input emissions inventory data [#7](https://github.com/climate-resource/spaemis/pull/7) diff --git a/src/spaemis/commands/__init__.py b/src/spaemis/commands/__init__.py index dd5c558..c939a13 100644 --- a/src/spaemis/commands/__init__.py +++ b/src/spaemis/commands/__init__.py @@ -2,5 +2,6 @@ CLI commands """ from .base import cli # noqa +from .generate_command import run_generate_command # noqa from .gse_emis_command import run_gse_command # noqa from .project_command import run_project_command # noqa diff --git a/src/spaemis/commands/generate_command.py b/src/spaemis/commands/generate_command.py new file mode 100644 index 0000000..4033004 --- /dev/null +++ b/src/spaemis/commands/generate_command.py @@ -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()) diff --git a/src/spaemis/commands/project_command.py b/src/spaemis/commands/project_command.py index 6a87200..0ade8c1 100644 --- a/src/spaemis/commands/project_command.py +++ b/src/spaemis/commands/project_command.py @@ -8,10 +8,16 @@ from typing import Dict, Tuple import click +import numpy as np import xarray as xr from spaemis.commands.base import cli -from spaemis.config import DownscalingScenarioConfig, VariableScalerConfig, load_config +from spaemis.config import ( + DownscalingScenarioConfig, + VariableScalerConfig, + converter, + load_config, +) from spaemis.inventory import EmissionsInventory, load_inventory, write_inventory_csvs from spaemis.scaling import get_scaler_by_config @@ -53,6 +59,29 @@ def scale_inventory( return scaled_field.expand_dims(["sector", "year"]).to_dataset(name=cfg.variable) +def _create_output_data(options, config, template: xr.Dataset): + unique_variables = sorted(set([variable for variable, _ in options])) + unique_sectors = sorted(set([sector for _, sector in options])) + unique_years = sorted(config.timeslices) + + coords = dict( + sector=unique_sectors, + year=unique_years, + lat=template.lat, + lon=template.lon, + ) + + return xr.Dataset( + data_vars={ + variable: xr.DataArray( + np.nan, coords=coords, dims=("sector", "year", "lat", "lon") + ) + for variable in unique_variables + }, + coords=coords, + ) + + def calculate_projections( config: DownscalingScenarioConfig, inventory: EmissionsInventory ) -> xr.Dataset: @@ -89,7 +118,7 @@ def calculate_projections( ), ) - projections = [] + output_ds = None for variable_config in scaling_configs.values(): for slice_year in config.timeslices: @@ -99,11 +128,14 @@ def calculate_projections( variable_config.sector, slice_year, ) + res = scale_inventory(variable_config, inventory, slice_year) - projections.append(res) - # Align dims and then merge - return xr.merge(xr.align(*projections, join="outer")) + if output_ds is None: + output_ds = _create_output_data(scaling_configs.keys(), config, res) + output_ds.update(res) + + return output_ds @cli.command(name="project") @@ -112,7 +144,7 @@ def calculate_projections( help="Path to a configuration file for the scenario of interest", required=True, ) -@click.option("-o", "--out_dir", help="Directory to write the updated inventory") +@click.option("-o", "--out-dir", help="Directory to write the updated inventory") def run_project_command(config, out_dir): """ Generate a set of emissions projection using an emissions inventory as a base @@ -125,8 +157,16 @@ def run_project_command(config, out_dir): logger.info(f"Creating output directory: {out_dir}") os.makedirs(out_dir, exist_ok=True) + logger.info("Saving loaded configuration to output directory") + with open(os.path.join(out_dir, "config.yaml"), "w") as handle: + handle.write(converter.dumps(config, DownscalingScenarioConfig)) + dataset = calculate_projections(config, inventory) + logger.info("Writing output dataset as netcdf") + dataset.to_netcdf(os.path.join(out_dir, "projections.nc")) + + logger.info("Writing CSV files") for year in config.timeslices: target_dir = os.path.join(out_dir, str(year)) data_to_write = dataset.sel(year=year) diff --git a/src/spaemis/config.py b/src/spaemis/config.py index 5b1cbed..68c0abc 100644 --- a/src/spaemis/config.py +++ b/src/spaemis/config.py @@ -1,12 +1,15 @@ """ Description of the configuration """ +import os.path +from typing import Any, ClassVar, List, Literal, Optional, Type, Union, get_args -from typing import Any, ClassVar, Literal, Optional, Type, Union, get_args - +import pandas as pd from attrs import define from cattrs.preconf.pyyaml import make_converter +from spaemis.utils import chdir + converter = make_converter() converter.register_unstructure_hook(str, lambda u: str(u)) @@ -48,6 +51,27 @@ class VariableScalerConfig: method: ScalerMethod +def _convert_filename_to_scalers( + value: Union[dict, str], _ +) -> List[VariableScalerConfig]: + if isinstance(value, str): + # load_config updates the current working directory to match the + # directory of a loaded config files otherwise a absolute filename is required + data = pd.read_csv(value).to_dict(orient="records") + + def extract_scaler_info(data_item): + sector_info = {} + for key, value in data_item.copy().items(): + if key.startswith("scaler_"): + sector_info[key[7:]] = value + data_item.pop(key) + return {**data_item, "method": sector_info} + + value = [extract_scaler_info(item) for item in data] + + return [converter.structure(item, VariableScalerConfig) for item in value] + + @define class DownscalingScenarioConfig: """ @@ -56,15 +80,25 @@ class DownscalingScenarioConfig: inventory_name: str inventory_year: int - timeslices: list[int] - scalers: list[VariableScalerConfig] + timeslices: List[int] + scalers: List[VariableScalerConfig] default_scaler: Optional[ScalerMethod] = None +# Ideally we could use converter.register_structure_hook. See +# https://github.com/python-attrs/cattrs/issues/206#issuecomment-1013714386 +converter.register_structure_hook_func( + lambda t: t == List[VariableScalerConfig], _convert_filename_to_scalers +) + + def load_config(config_file: str) -> DownscalingScenarioConfig: """ Load and parse configuration from a file + Any filenames referenced in the configuration are relative to the configuration file + not the current directory. + Parameters ---------- config_file @@ -75,4 +109,5 @@ def load_config(config_file: str) -> DownscalingScenarioConfig: Validated configuration """ with open(config_file) as handle: - return converter.loads(handle.read(), DownscalingScenarioConfig) + with chdir(os.path.dirname(config_file)): + return converter.loads(handle.read(), DownscalingScenarioConfig) diff --git a/src/spaemis/config/mappings/victoria_mappings.yaml b/src/spaemis/config/mappings/victoria_mappings.yaml new file mode 100644 index 0000000..24ce77f --- /dev/null +++ b/src/spaemis/config/mappings/victoria_mappings.yaml @@ -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 \ No newline at end of file diff --git a/src/spaemis/config/scenarios/ssp119.yaml b/src/spaemis/config/scenarios/ssp119.yaml new file mode 100644 index 0000000..c524a9d --- /dev/null +++ b/src/spaemis/config/scenarios/ssp119.yaml @@ -0,0 +1,14 @@ +inventory_name: victoria +inventory_year: 2016 + +timeslices: + - 2020 + - 2040 + - 2060 + - 2080 + - 2100 + +default_scaler: + name: constant + +scalers: ssp119_scalers.csv \ No newline at end of file diff --git a/src/spaemis/config/scenarios/ssp119_scalers.csv b/src/spaemis/config/scenarios/ssp119_scalers.csv new file mode 100644 index 0000000..3caef92 --- /dev/null +++ b/src/spaemis/config/scenarios/ssp119_scalers.csv @@ -0,0 +1,97 @@ +variable,sector,scaler_name,scaler_variable_id,scaler_source_id,scaler_sector +CO,architect_coating,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +CO,bakery,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +CO,crematoria,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +CO,cutback_bitumen,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +CO,domestic_solvents,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,Solvents production and application +CO,dry_cleaning,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +CO,gas_leak,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,Energy Sector +CO,industry_diffuse,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,Waste +CO,industry,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,Industrial Sector +CO,motor_vehicles,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +CO,panel_beaters,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +CO,petcrematoria,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +CO,pizza,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +CO,printing,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +CO,rail,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +CO,servos,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +CO,shipping,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,International Shipping +CO,vicbakery,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +CO,woodheater,relative_change,CO-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +NOx,architect_coating,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +NOx,bakery,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +NOx,crematoria,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +NOx,cutback_bitumen,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +NOx,domestic_solvents,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,Solvents production and application +NOx,dry_cleaning,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +NOx,gas_leak,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,Energy Sector +NOx,industry_diffuse,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,Waste +NOx,industry,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,Industrial Sector +NOx,motor_vehicles,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +NOx,panel_beaters,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +NOx,petcrematoria,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +NOx,pizza,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +NOx,printing,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +NOx,rail,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +NOx,servos,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +NOx,shipping,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,International Shipping +NOx,vicbakery,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +NOx,woodheater,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +SO2,architect_coating,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +SO2,bakery,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +SO2,crematoria,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +SO2,cutback_bitumen,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +SO2,domestic_solvents,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,Solvents production and application +SO2,dry_cleaning,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +SO2,gas_leak,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,Energy Sector +SO2,industry_diffuse,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,Waste +SO2,industry,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,Industrial Sector +SO2,motor_vehicles,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +SO2,panel_beaters,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +SO2,petcrematoria,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +SO2,pizza,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +SO2,printing,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +SO2,rail,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +SO2,servos,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +SO2,shipping,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,International Shipping +SO2,vicbakery,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +SO2,woodheater,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +PM10,architect_coating,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +PM10,bakery,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +PM10,crematoria,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +PM10,cutback_bitumen,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +PM10,domestic_solvents,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Solvents production and application +PM10,dry_cleaning,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +PM10,gas_leak,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Energy Sector +PM10,industry_diffuse,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Waste +PM10,industry,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Industrial Sector +PM10,motor_vehicles,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +PM10,panel_beaters,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +PM10,petcrematoria,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +PM10,pizza,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +PM10,printing,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +PM10,rail,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +PM10,servos,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +PM10,shipping,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,International Shipping +PM10,vicbakery,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +PM10,woodheater,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +VOC,architect_coating,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +VOC,bakery,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +VOC,crematoria,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +VOC,cutback_bitumen,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +VOC,domestic_solvents,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Solvents production and application +VOC,dry_cleaning,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +VOC,gas_leak,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Energy Sector +VOC,industry_diffuse,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Waste +VOC,industry,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Industrial Sector +VOC,motor_vehicles,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +VOC,panel_beaters,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +VOC,petcrematoria,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +VOC,pizza,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +VOC,printing,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +VOC,rail,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,Transportation Sector +VOC,servos,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +VOC,shipping,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,International Shipping +VOC,vicbakery,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" +VOC,woodheater,relative_change,BC-em-anthro,IAMC-IMAGE-ssp119-1-1,"Residential, Commercial, Other" + diff --git a/src/spaemis/config/scenarios/ssp126.yaml b/src/spaemis/config/scenarios/ssp126.yaml new file mode 100644 index 0000000..c3c5d7c --- /dev/null +++ b/src/spaemis/config/scenarios/ssp126.yaml @@ -0,0 +1,14 @@ +inventory_name: victoria +inventory_year: 2016 + +timeslices: + - 2020 + - 2040 + - 2060 + - 2080 + - 2100 + +default_scaler: + name: constant + +scalers: ssp126_scalers.csv \ No newline at end of file diff --git a/src/spaemis/config/scenarios/ssp126_scalers.csv b/src/spaemis/config/scenarios/ssp126_scalers.csv new file mode 100644 index 0000000..4d681ba --- /dev/null +++ b/src/spaemis/config/scenarios/ssp126_scalers.csv @@ -0,0 +1,97 @@ +variable,sector,scaler_name,scaler_variable_id,scaler_source_id,scaler_sector +CO,architect_coating,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +CO,bakery,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +CO,crematoria,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +CO,cutback_bitumen,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +CO,domestic_solvents,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,Solvents production and application +CO,dry_cleaning,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +CO,gas_leak,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,Energy Sector +CO,industry_diffuse,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,Waste +CO,industry,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,Industrial Sector +CO,motor_vehicles,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +CO,panel_beaters,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +CO,petcrematoria,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +CO,pizza,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +CO,printing,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +CO,rail,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +CO,servos,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +CO,shipping,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,International Shipping +CO,vicbakery,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +CO,woodheater,relative_change,CO-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +NOx,architect_coating,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +NOx,bakery,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +NOx,crematoria,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +NOx,cutback_bitumen,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +NOx,domestic_solvents,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,Solvents production and application +NOx,dry_cleaning,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +NOx,gas_leak,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,Energy Sector +NOx,industry_diffuse,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,Waste +NOx,industry,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,Industrial Sector +NOx,motor_vehicles,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +NOx,panel_beaters,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +NOx,petcrematoria,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +NOx,pizza,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +NOx,printing,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +NOx,rail,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +NOx,servos,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +NOx,shipping,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,International Shipping +NOx,vicbakery,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +NOx,woodheater,relative_change,NOx-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +SO2,architect_coating,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +SO2,bakery,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +SO2,crematoria,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +SO2,cutback_bitumen,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +SO2,domestic_solvents,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,Solvents production and application +SO2,dry_cleaning,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +SO2,gas_leak,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,Energy Sector +SO2,industry_diffuse,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,Waste +SO2,industry,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,Industrial Sector +SO2,motor_vehicles,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +SO2,panel_beaters,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +SO2,petcrematoria,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +SO2,pizza,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +SO2,printing,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +SO2,rail,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +SO2,servos,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +SO2,shipping,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,International Shipping +SO2,vicbakery,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +SO2,woodheater,relative_change,SO2-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +PM10,architect_coating,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +PM10,bakery,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +PM10,crematoria,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +PM10,cutback_bitumen,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +PM10,domestic_solvents,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Solvents production and application +PM10,dry_cleaning,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +PM10,gas_leak,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Energy Sector +PM10,industry_diffuse,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Waste +PM10,industry,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Industrial Sector +PM10,motor_vehicles,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +PM10,panel_beaters,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +PM10,petcrematoria,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +PM10,pizza,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +PM10,printing,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +PM10,rail,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +PM10,servos,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +PM10,shipping,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,International Shipping +PM10,vicbakery,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +PM10,woodheater,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +VOC,architect_coating,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +VOC,bakery,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +VOC,crematoria,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +VOC,cutback_bitumen,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +VOC,domestic_solvents,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Solvents production and application +VOC,dry_cleaning,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +VOC,gas_leak,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Energy Sector +VOC,industry_diffuse,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Waste +VOC,industry,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Industrial Sector +VOC,motor_vehicles,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +VOC,panel_beaters,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +VOC,petcrematoria,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +VOC,pizza,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +VOC,printing,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +VOC,rail,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,Transportation Sector +VOC,servos,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +VOC,shipping,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,International Shipping +VOC,vicbakery,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" +VOC,woodheater,relative_change,BC-em-anthro,IAMC-IMAGE-ssp126-1-1,"Residential, Commercial, Other" + diff --git a/src/spaemis/config/scenarios/ssp245.yaml b/src/spaemis/config/scenarios/ssp245.yaml index 4d7e781..a0889e6 100644 --- a/src/spaemis/config/scenarios/ssp245.yaml +++ b/src/spaemis/config/scenarios/ssp245.yaml @@ -6,29 +6,9 @@ timeslices: - 2040 - 2060 - 2080 + - 2100 default_scaler: name: constant -scalers: - - variable: NOx - sector: industry - method: - name: relative_change - source_id: &source IAMC-MESSAGE-GLOBIOM-ssp245-1-1 - variable_id: NOx-em-anthro - sector: Industrial Sector - - variable: NOx - sector: motor_vehicles - method: - name: relative_change - source_id: *source - variable_id: NOx-em-anthro - sector: Transportation Sector - - variable: CO - sector: industry - method: - name: relative_change - source_id: *source - variable_id: CO-em-anthro - sector: Industrial Sector \ No newline at end of file +scalers: ssp245_scalers.csv \ No newline at end of file diff --git a/src/spaemis/config/scenarios/ssp245_scalers.csv b/src/spaemis/config/scenarios/ssp245_scalers.csv new file mode 100644 index 0000000..a230d22 --- /dev/null +++ b/src/spaemis/config/scenarios/ssp245_scalers.csv @@ -0,0 +1,97 @@ +variable,sector,scaler_name,scaler_variable_id,scaler_source_id,scaler_sector +CO,architect_coating,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +CO,bakery,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +CO,crematoria,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +CO,cutback_bitumen,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +CO,domestic_solvents,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Solvents production and application +CO,dry_cleaning,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +CO,gas_leak,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Energy Sector +CO,industry_diffuse,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Waste +CO,industry,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Industrial Sector +CO,motor_vehicles,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +CO,panel_beaters,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +CO,petcrematoria,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +CO,pizza,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +CO,printing,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +CO,rail,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +CO,servos,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +CO,shipping,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,International Shipping +CO,vicbakery,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +CO,woodheater,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +NOx,architect_coating,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +NOx,bakery,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +NOx,crematoria,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +NOx,cutback_bitumen,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +NOx,domestic_solvents,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Solvents production and application +NOx,dry_cleaning,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +NOx,gas_leak,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Energy Sector +NOx,industry_diffuse,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Waste +NOx,industry,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Industrial Sector +NOx,motor_vehicles,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +NOx,panel_beaters,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +NOx,petcrematoria,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +NOx,pizza,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +NOx,printing,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +NOx,rail,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +NOx,servos,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +NOx,shipping,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,International Shipping +NOx,vicbakery,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +NOx,woodheater,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +SO2,architect_coating,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +SO2,bakery,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +SO2,crematoria,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +SO2,cutback_bitumen,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +SO2,domestic_solvents,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Solvents production and application +SO2,dry_cleaning,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +SO2,gas_leak,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Energy Sector +SO2,industry_diffuse,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Waste +SO2,industry,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Industrial Sector +SO2,motor_vehicles,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +SO2,panel_beaters,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +SO2,petcrematoria,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +SO2,pizza,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +SO2,printing,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +SO2,rail,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +SO2,servos,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +SO2,shipping,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,International Shipping +SO2,vicbakery,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +SO2,woodheater,relative_change,SO2-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +PM10,architect_coating,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +PM10,bakery,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +PM10,crematoria,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +PM10,cutback_bitumen,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +PM10,domestic_solvents,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Solvents production and application +PM10,dry_cleaning,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +PM10,gas_leak,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Energy Sector +PM10,industry_diffuse,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Waste +PM10,industry,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Industrial Sector +PM10,motor_vehicles,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +PM10,panel_beaters,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +PM10,petcrematoria,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +PM10,pizza,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +PM10,printing,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +PM10,rail,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +PM10,servos,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +PM10,shipping,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,International Shipping +PM10,vicbakery,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +PM10,woodheater,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +VOC,architect_coating,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +VOC,bakery,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +VOC,crematoria,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +VOC,cutback_bitumen,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +VOC,domestic_solvents,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Solvents production and application +VOC,dry_cleaning,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +VOC,gas_leak,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Energy Sector +VOC,industry_diffuse,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Waste +VOC,industry,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Industrial Sector +VOC,motor_vehicles,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +VOC,panel_beaters,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +VOC,petcrematoria,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +VOC,pizza,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +VOC,printing,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +VOC,rail,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +VOC,servos,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +VOC,shipping,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,International Shipping +VOC,vicbakery,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" +VOC,woodheater,relative_change,BC-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,"Residential, Commercial, Other" + diff --git a/src/spaemis/input_data.py b/src/spaemis/input_data.py index 46458ae..6202d42 100644 --- a/src/spaemis/input_data.py +++ b/src/spaemis/input_data.py @@ -82,6 +82,9 @@ def parse_filename(dataset_fname) -> Optional[dict]: def load(self, variable_id, source_id) -> Optional[xr.Dataset]: subset = self.available_data + if not len(self.available_data): + raise ValueError("No input data has been found") + subset = subset[subset.source_id == source_id] subset = subset[subset.variable_id == variable_id] diff --git a/src/spaemis/inventory.py b/src/spaemis/inventory.py index 14fdc46..a11accd 100644 --- a/src/spaemis/inventory.py +++ b/src/spaemis/inventory.py @@ -223,7 +223,7 @@ def write_inventory_csvs(ds: xr.Dataset, output_dir: str): output_fname = f"{sector}_projected.csv" - logger.info(f"Writing output file: {output_fname}") + logger.info(f"Writing output file: {os.path.join(output_dir, output_fname)}") df = sector_data.fillna(0).to_dataframe(["lon", "lat"]).reset_index() # Round to be similar to the input inventory files diff --git a/src/spaemis/main.py b/src/spaemis/main.py index 83d3cfc..449316e 100644 --- a/src/spaemis/main.py +++ b/src/spaemis/main.py @@ -1,8 +1,12 @@ """ CLI """ +import dotenv + from spaemis.commands import cli +dotenv.load_dotenv() + if __name__ == "__main__": # Run the CLI tool cli() diff --git a/src/spaemis/utils.py b/src/spaemis/utils.py index 2c14beb..2a748f6 100644 --- a/src/spaemis/utils.py +++ b/src/spaemis/utils.py @@ -1,7 +1,8 @@ """ General utility functions """ - +import os +from contextlib import contextmanager from typing import Union import geopandas @@ -150,3 +151,23 @@ def weighted_annual_mean( obs_sum = (target * weights).resample(time="AS").sum(dim="time") ones_out = (ones * weights).resample(time="AS").sum(dim="time") return obs_sum / ones_out + + +@contextmanager +def chdir(current_directory: str) -> None: + """ + Context manager to temporarily change the current working directory + + Should not be used in async or parallel methods as it changes + the global state + + Parameters + ---------- + current_directory + """ + previous = os.getcwd() + try: + os.chdir(current_directory) + yield + finally: + os.chdir(previous) diff --git a/tests/test-data/config/test-config-with-csv.yaml b/tests/test-data/config/test-config-with-csv.yaml new file mode 100644 index 0000000..41061fd --- /dev/null +++ b/tests/test-data/config/test-config-with-csv.yaml @@ -0,0 +1,9 @@ +inventory_name: victoria +inventory_year: 2016 + +timeslices: + - 2020 + - 2040 + - 2060 + +scalers: test_scalers.csv \ No newline at end of file diff --git a/tests/test-data/config/test_scalers.csv b/tests/test-data/config/test_scalers.csv new file mode 100644 index 0000000..30e2682 --- /dev/null +++ b/tests/test-data/config/test_scalers.csv @@ -0,0 +1,4 @@ +variable,sector,scaler_name,scaler_variable_id,scaler_source_id,scaler_sector +NOx,industry,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Industrial Sector +NOx,motor_vehicles,relative_change,NOx-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Transportation Sector +CO,industry,relative_change,CO-em-anthro,IAMC-MESSAGE-GLOBIOM-ssp245-1-1,Industrial Sector diff --git a/tests/unit/commands/test_project.py b/tests/unit/commands/test_project.py index d52b01c..ae8e494 100644 --- a/tests/unit/commands/test_project.py +++ b/tests/unit/commands/test_project.py @@ -43,7 +43,7 @@ def test_cli_project(runner, config_file, tmpdir, mocker, inventory): "project", "--config", config_file, - "--out_dir", + "--out-dir", str(out_dir), ], ) diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index f856a94..0862d93 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -12,13 +12,16 @@ from spaemis.constants import TEST_DATA_DIR -def test_load_config(): - res = load_config(os.path.join(TEST_DATA_DIR, "config", "test-config.yaml")) +@pytest.mark.parametrize("fname", ["test-config.yaml", "test-config-with-csv.yaml"]) +def test_load_config(fname, config): + res = load_config(os.path.join(TEST_DATA_DIR, "config", fname)) assert isinstance(res, DownscalingScenarioConfig) assert res.inventory_name == "victoria" assert res.inventory_year == 2016 + assert res == config + def test_structuring_constant(): res = converter.structure({"name": "constant"}, ScalerMethod)