diff --git a/.gitignore b/.gitignore index 358bc77..4aa4bc9 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,7 @@ doc/_build .DS_Store # Scratch code -scratch* \ No newline at end of file +scratch* + +# CHILLED user settings +user_settings.py \ No newline at end of file diff --git a/doc/chilled.rst b/doc/chilled.rst new file mode 100644 index 0000000..2029f8f --- /dev/null +++ b/doc/chilled.rst @@ -0,0 +1,68 @@ +.. currentmodule:: message_ix_buildings.chilled + +CHILLED (:mod:`.chilled`) +************************* + +:mod:`.chilled` (Cooling and HeatIng gLobaL Energy Demand) is a model that assesses the impacts of climate change (temperature change). + +Methods +======= + + +Data +==== + +Input data +---------- + + +Parameters +---------- + +In this module, the "version" refers to the version of the model, not the version of the data. For example, the "ALPS2023" version refers to the set of scenario inputs/parameters for the "ALPS2023" run. +When specifying a version, CHILLED will look in the `/data/chilled/version` directory that the version name exists and that the following files exist as well: + +- `arch_input_reg.xlsx` (or `arch_input.xlsx`) +- `arch_regions.xlsx` +- `par_var.csv` +- `runs.csv` + +Usage +===== + +The preprocessing (preparing MESSAGE region rasters and country codes) happens without specifying GCM or RCP scenario. Therefore, it can be run first on its own using the following command (from within :mod:`chilled.run`): + +.. code-block:: bash + + python -m preprocess.py -version "version_name" + +If the `-version` command is not provided, then the default version is "ALPS2023". + +The main model can be run using the following command: + +.. code-block:: bash + + python -m main.py -version "version_name" -gcm "gcm_name" -rcp "rcp_name" + +If the `-version` command is not provided, then the default version is "ALPS2023". +If the `-gcm` and `-rcp` commands are not provided, then the default GCM is "GFDL-ESM2M" and the default RCP is "baseline". + + +Code reference +============== + +.. automodule:: message_ix_buildings.chilled + :members: + +.. currentmodule:: message_ix_buildings.chilled.preprocess.message_raster + +Create raster of MESSAGE regions (:mod:`~.chilled.preprocess.message_raster`) +----------------------------------------------------------------------------- + +.. automodule:: message_ix_buildings.chilled.preprocess.message_raster + :members: + + .. autosummary:: + + create_message_raster + diff --git a/doc/conf.py b/doc/conf.py index 8e0a5df..b892c07 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -3,6 +3,12 @@ # For the full list of built-in configuration values, see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html +import os +import sys + + +sys.path.insert(0, os.path.abspath("..")) + # -- Project information --------------------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information @@ -14,9 +20,17 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.coverage", + "sphinx.ext.autosummary", + "sphinx.ext.extlinks", "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.todo", + "sphinx.ext.viewcode", ] + templates_path = ["_templates"] exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] diff --git a/doc/index.rst b/doc/index.rst index 31f16a0..7416b57 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -9,18 +9,19 @@ Welcome to MESSAGEix-Buildings's documentation! “MESSAGEix-Buildings” refers to a collection of linked models, including: - ACCESS -- CHILLED +- :doc:`chilled` - :doc:`sturm` …and their integration with the :doc:`MESSAGEix-GLOBIOM model family `. -At present, the package :mod:`message_ix_buildings` contains STURM only. +At present, the package :mod:`message_ix_buildings` contains STURM and CHILLED only. .. toctree:: :maxdepth: 2 :hidden: sturm + chilled dev Indices and tables diff --git a/message_ix_buildings/chilled/run_chilled2023.py b/message_ix_buildings/chilled/analysis/__init__.py similarity index 100% rename from message_ix_buildings/chilled/run_chilled2023.py rename to message_ix_buildings/chilled/analysis/__init__.py diff --git a/message_ix_buildings/chilled/aggregate.py b/message_ix_buildings/chilled/analysis/aggregate.py similarity index 99% rename from message_ix_buildings/chilled/aggregate.py rename to message_ix_buildings/chilled/analysis/aggregate.py index 538b997..9e6edbe 100644 --- a/message_ix_buildings/chilled/aggregate.py +++ b/message_ix_buildings/chilled/analysis/aggregate.py @@ -1,7 +1,7 @@ import glob import os -import pandas as pd # type: ignore +import pandas as pd from sklearn.utils.fixes import parse_version, sp_version # type: ignore from message_ix_buildings.chilled.variable_dicts import SCENARIO_NAMES diff --git a/message_ix_buildings/chilled/check_pop.py b/message_ix_buildings/chilled/analysis/check_pop.py similarity index 97% rename from message_ix_buildings/chilled/check_pop.py rename to message_ix_buildings/chilled/analysis/check_pop.py index 74945d9..97fd736 100644 --- a/message_ix_buildings/chilled/check_pop.py +++ b/message_ix_buildings/chilled/analysis/check_pop.py @@ -1,20 +1,16 @@ import os from itertools import product -import pandas as pd # type: ignore +import pandas as pd import xarray as xr -from message_ix_buildings.chilled.config import Config -from message_ix_buildings.chilled.variable_dicts import ( +from message_ix_buildings.chilled.functions.variable_dicts import ( VARDICT_COOL, VARDICT_HEAT, VARUNDICT_COOL, VARUNDICT_HEAT, ) -cfg = Config() - -dle_path = cfg.dle_path vstr = cfg.vstr vstrcntry = cfg.vstrcntry gcm = cfg.gcm diff --git a/message_ix_buildings/chilled/archive/__init__.py b/message_ix_buildings/chilled/archive/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/message_ix_buildings/chilled/preprocess.py b/message_ix_buildings/chilled/archive/preprocess.py similarity index 99% rename from message_ix_buildings/chilled/preprocess.py rename to message_ix_buildings/chilled/archive/preprocess.py index 08318fa..a8b79d4 100644 --- a/message_ix_buildings/chilled/preprocess.py +++ b/message_ix_buildings/chilled/archive/preprocess.py @@ -3,11 +3,12 @@ from itertools import product import numpy as np -import pandas as pd # type: ignore +import pandas as pd import xarray as xr from dask.diagnostics import ProgressBar -from message_ix_buildings.chilled.buildings_funcs_grid import ( +from message_ix_buildings.chilled.util.config import Config +from message_ix_buildings.chilled.functions.buildings_funcs_grid import ( P_f, Q_c_tmax, Q_h, @@ -30,28 +31,6 @@ calc_vdd_h, calc_vdd_tmax_c, ) -from message_ix_buildings.chilled.config import Config -from message_ix_buildings.chilled.variable_dicts import ( - VARS_ARCHETYPES, - YEARS_BASELINE, - YEARS_OTHERS, -) - -# print(clims + " + " + archs + " + " + parset_name_run + " + " + urts) - - -def create_archetype_template_map( - dle_path, - version_name, - gcm, - rcp_scenario, - message_region_file, - archs_specified, - arch_setting, - urts, - comp, -): - output_path_arch = os.path.join( dle_path, f"output_data_{version_name}", gcm, diff --git a/message_ix_buildings/chilled/setup.py b/message_ix_buildings/chilled/archive/setup.py similarity index 100% rename from message_ix_buildings/chilled/setup.py rename to message_ix_buildings/chilled/archive/setup.py diff --git a/message_ix_buildings/chilled/vdd_functions.py b/message_ix_buildings/chilled/archive/vdd_functions.py similarity index 99% rename from message_ix_buildings/chilled/vdd_functions.py rename to message_ix_buildings/chilled/archive/vdd_functions.py index 5d63270..4ab3759 100644 --- a/message_ix_buildings/chilled/vdd_functions.py +++ b/message_ix_buildings/chilled/archive/vdd_functions.py @@ -7,12 +7,12 @@ import cartopy.feature as cfeature # type: ignore import matplotlib.pyplot as plt # type: ignore import numpy as np -import pandas as pd # type: ignore +import pandas as pd import pyam # type: ignore import xarray as xr from dask.diagnostics import ProgressBar -from message_ix_buildings.chilled.buildings_funcs_grid import ( +from .buildings_funcs_grid import ( P_f, Q_c_tmax, Q_h, @@ -35,7 +35,7 @@ calc_vdd_h, calc_vdd_tmax_c, ) -from message_ix_buildings.chilled.variable_dicts import ( +from .variable_dicts import ( VARDICT_COOL, VARDICT_HEAT, VARS_ARCHETYPES, diff --git a/message_ix_buildings/chilled/z1_VDD_ene_calcs.py b/message_ix_buildings/chilled/archive/z1_VDD_ene_calcs.py similarity index 97% rename from message_ix_buildings/chilled/z1_VDD_ene_calcs.py rename to message_ix_buildings/chilled/archive/z1_VDD_ene_calcs.py index d960f5a..f8fa419 100644 --- a/message_ix_buildings/chilled/z1_VDD_ene_calcs.py +++ b/message_ix_buildings/chilled/archive/z1_VDD_ene_calcs.py @@ -2,13 +2,13 @@ import numpy as np -from message_ix_buildings.chilled.aggregate import ( +from message_ix_buildings.chilled.analysis.aggregate import ( aggregate_ISO_tables_to_regions, create_prereg_data, ) -from message_ix_buildings.chilled.regression import apply_regression -from message_ix_buildings.chilled.user_settings import DICT_USER_SETTINGS -from message_ix_buildings.chilled.vdd_functions import ( +from message_ix_buildings.chilled.functions.regression import apply_regression +from message_ix_buildings.chilled.functions.user_settings import DICT_USER_SETTINGS +from message_ix_buildings.chilled.functions.vdd_functions import ( aggregate_urban_rural_files, calculate_cumulative_carbon_emissions, create_archetype_template_map, diff --git a/message_ix_buildings/chilled/config.py b/message_ix_buildings/chilled/config.py deleted file mode 100644 index f14ef46..0000000 --- a/message_ix_buildings/chilled/config.py +++ /dev/null @@ -1,218 +0,0 @@ -import datetime -import os -from dataclasses import dataclass - -import numpy as np - -from message_ix_buildings.chilled.user_settings import DICT_USER_SETTINGS -from message_ix_buildings.chilled.vdd_functions import ( - load_all_scenarios_data, - load_parametric_analysis_data, -) - - -@dataclass -class Config: - """Configuration for :mod:`.message_ix_buildings.chilled`.""" - - # SPECIFY USER - user = "MEAS" # options: ALE, ED, MEAS - # print(f"USER: {user}") - - dle_path = DICT_USER_SETTINGS[user]["dle_path"] - message_region_file = DICT_USER_SETTINGS[user]["message_region_map_file"] - isimip_bias_adj_path = DICT_USER_SETTINGS[user]["isimip_bias_adj_path"] - isimip_ewemib_path = DICT_USER_SETTINGS[user]["isimip_ewembi_path"] - chunk_size = DICT_USER_SETTINGS[user]["chunk_size"] - input_path = os.path.join(dle_path, "input_data") # type: ignore - - # RUN SETTINGS - paranalysis_mode = 1 # 1 = run entire parametric analysis; 0 = run only ref case - runsdd = 0 # 1= run simple (standard) degree days calculation; 0 = don't run - - # Netcdf settings - netcdf4_format = "NETCDF4_CLASSIC" - comp = dict(zlib=True, complevel=5) # Compression between 0 and 9 (highest) - - # TESTING MODE - testing_mode = 0 # 1= selects only two years for testing; 0= select all years (full calculation) - - # VERSION SETTINGS - vstr = "v19_ALPS2023" # version input data - vstrcntry = "v4" # version string for country data and floor surface - gcm = "MRI-ESM2-0" # options: GFDL-ESM4, IPSL-CM6A-LR, MPI-ESM1-2-HR, MRI-ESM2-0, and UKESM1-0-LL - - # SCENARIO SETTINGS - rcps = ["ssp126", "ssp370", "ssp585", "baseline"] # list all possible scenarios - rcp = "ssp126" # options: "ssp126", "ssp370", "ssp585", "baseline" - - if rcp == "baseline": - rcpdata = "ssp126" - else: - rcpdata = rcp - - # CLIMATIC DATA INPUTS - if rcp == "baseline": - yeardic = { - "2015": ("2015", "2020"), - "2020": ("2015", "2020"), - "2030": ("2015", "2020"), - "2040": ("2015", "2020"), - "2050": ("2015", "2020"), - "2060": ("2015", "2020"), - "2070": ("2015", "2020"), - "2080": ("2015", "2020"), - "2090": ("2015", "2020"), - "2100": ("2015", "2020"), - } - else: - yeardic = { - "2015": ("2015", "2020"), - "2020": ("2015", "2025"), - "2030": ("2015", "2045"), - "2040": ("2025", "2055"), - "2050": ("2035", "2065"), - "2060": ("2045", "2075"), - "2070": ("2055", "2085"), - "2080": ("2065", "2095"), - "2090": ("2080", "2100"), - "2100": ("2095", "2100"), - } - - # climatic inputs for sensitivity runs - # clims = ["hist"] # options: "hist", "1p5" - clims = list(yeardic.keys()) - - # POPULATION SETTINGS - popfix = True # If True, fix to SSP2, else.... (see script 4/5) - - # BUILDING SCENARIO SETTINGS - - # CONMSTRUCTION MATERIAL SHARES - constr_setting = 0 - - # FLOOR_SETTING CHOICE - # Choose per_cap for different values by MESSAGE region or std_cap for fixed values - floor_setting = "std_cap" # v16; options: "std_cap", "per_cap" - - # BUILDING ARCHETYPE SETTINGS - # Choose "regional" for different values by MESSAGE region or "fixed" for fixed values - # (same for all regions) - arch_setting = "regional" # options: ["fixed", "regional"] - - # URBAN/RURAL DISAGGREGATIONS - urts = ["urban", "rural"] # options (mult): "urban", "rural" - - # ARCHETYPES - archs = ["new", "exist"] - - # PARAMETERS FOR STEP 2 SCRIPT - verbose = True - - ## SWITCH COOLING/HEATING CALCULATIONS - ## 1=calculate; 0=skip - heat = 0 - cool = 1 - - # CHOICE: SOLAR GAIN CALCULATION - solar_gains = "TOT" # from windows and roof - # solar_gains = 'VERT' #from windows only - # solar_gains = 'HOR' #from windows only - - # SELECT VAR - var = "tas" - - if var == "tas": - davar = "tas" - elif var == "twb": - davar = "twb" - - overwrite = 0 - - # Climate input variable format - climate_filestr_hist = f"tas_day_{gcm}_{rcpdata}_r1i1p1_EWEMBI_landonly_" # ISIMIP2 - - if gcm == "UKESM1-0-LL": - climate_filestr_future = f"{gcm}_r1i1p1f2_w5e5_{rcpdata}_{var}_global_daily_" - else: - climate_filestr_future = f"{gcm}_r1i1p1f1_w5e5_{rcpdata}_{var}_global_daily_" - - endstr = ".nc" - - # BULDING PARAMETERS - # Fixed values - bal_temps = [18.3, 21.1, 26] # [21.1] # For simple cooling degree days - arb_fan = 2 - t_sp_h = np.int8(20) # Indoor setpoint temperature for heating - P_f = 55 # power of fan (W) - area_fan = 25 # Numer of m2 per fan - gridshape2 = (360, 720) - - y2_attrs_dic = { - "title": "map_area_env", - "authors": "Alessio Mastrucci & Edward Byers", - "date": str(datetime.datetime.now()), - "institution": "IIASA Energy Program", - "contact": "mastrucc@iiasa.ac.at; byers@iiasa.ac.at; ", - "arch_setting": arch_setting, - } - - # Final maps (y4) parameters - nd_thresh = 5 - - # Load scenarios data - s_runs = load_all_scenarios_data( - input_dle_path=DICT_USER_SETTINGS[user]["dle_path"], input_version_name=vstr - ) - - # Load paramtric analysis data - par_var = load_parametric_analysis_data( - input_dle_path=DICT_USER_SETTINGS[user]["dle_path"], - input_version_name=vstr, - input_paranalysis_mode=paranalysis_mode, - ) - - # #: Base year for projections. - # base_year: int = BASE_YEAR - - # #: Year of convergence; used when :attr:`.method` is "convergence". See - # #: :func:`.create_projections_converge`. - # convergence_year: int = 2050 - - # #: Rate of increase/decrease of fixed operating and maintenance costs. - # fom_rate: float = 0.025 - - # #: Format of output. One of: - # #: - # #: - "iamc": IAMC time series data structure. - # #: - "message": :mod:`message_ix` parameter data. - # format: Literal["iamc", "message"] = "message" - - # #: Spatial resolution - # node: Literal["R11", "R12", "R20"] = "R12" - - # #: Projection method; one of: - # #: - # #: - "convergence": uses :func:`.create_projections_converge` - # #: - "gdp": :func:`.create_projections_gdp` - # #: - "learning": :func:`.create_projections_converge` - # method: Literal["convergence", "gdp", "learning"] = "gdp" - - # #: Model variant to prepare data for. - # module: Literal["base", "materials"] = "base" - - # #: Reference region; default "{node}_NAM". - # ref_region: Optional[str] = None - - # #: Set of SSPs referenced by :attr:`scenario`. One of: - # #: - # #: - "original": :obj:`SSP_2017` - # #: - "updated": :obj:`SSP_2024` - # scenario_version: Literal["original", "updated"] = "updated" - - # #: Scenario(s) for which to create data. - # scenario: Literal["all", "LED", "SSP1", "SSP2", "SSP3", "SSP4", "SSP5"] = "all" - - # def __post_init__(self): - # if self.ref_region is None: - # self.ref_region = f"{self.node}_NAM" diff --git a/message_ix_buildings/chilled/core/__init__.py b/message_ix_buildings/chilled/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/message_ix_buildings/chilled/core/climate.py b/message_ix_buildings/chilled/core/climate.py new file mode 100644 index 0000000..5b5cec2 --- /dev/null +++ b/message_ix_buildings/chilled/core/climate.py @@ -0,0 +1,3029 @@ +import datetime +import os +from itertools import product + +import cartopy # type: ignore +import cartopy.crs as ccrs # type: ignore +import cartopy.feature as cfeature # type: ignore +import matplotlib.pyplot as plt # type: ignore +import numpy as np +import pandas as pd +import xarray as xr +from dask.diagnostics import ProgressBar + +from message_ix_buildings.chilled.functions.buildings_funcs_grid import ( + P_f, + Q_c_tmax, + Q_h, + calc_E_c_ac, + calc_E_c_fan, + calc_E_h, + calc_gn_sol, + calc_gn_sol_h, + calc_gn_sol_tot, + calc_H_tr, + calc_H_v_cl, + calc_H_v_op, + calc_Nd, + calc_Nf, + calc_SCDD_m, + calc_SHDD_m, + calc_t_bal_c, + calc_t_bal_h, + calc_t_max_c, + calc_vdd_h, + calc_vdd_tmax_c, +) +from message_ix_buildings.chilled.functions.variable_dicts import ( + VARDICT_COOL, + VARDICT_HEAT, + VARS_ARCHETYPES, + VARUNDICT_COOL, + VARUNDICT_HEAT, +) +from message_ix_buildings.chilled.preprocess.message_raster import ( + create_message_raster, # type: ignore +) +from message_ix_buildings.chilled.util.config import Config # type: ignore +from message_ix_buildings.chilled.util.util import ( + get_archs, + load_all_scenarios_data, + load_parametric_analysis_data, +) + + +def create_climate_variables_maps(config: "Config", start_time: datetime.datetime): + out_path = os.path.join(config.project_path, "out", "version", config.vstr) + archetype_path = os.path.join(out_path, "rasters") + save_path = os.path.join(out_path, "VDD_ene_calcs") + + output_path_vdd = os.path.join( + save_path, + config.gcm, + config.rcp, + ) + + if not os.path.exists(output_path_vdd): + os.makedirs(output_path_vdd) + + vers_archs = get_archs(config) + par_var = load_parametric_analysis_data(config) + + def map_calculated_variables(args): + clim, arch, parset, urt = args + + print(str(clim) + " + " + arch + " + " + parset.name_run + " + " + urt) + + years_clim = config.yeardic[str(clim)] + # << this selects the correct years. + # But when testing you’ll want to use just say 3 years data, + # so set years manually, e.g. + # years_clim = yeardic6p0[str(s_run.clim)] + + # this will be the shortcut line to make the testing faster (2 years data) + if config.testing_mode == 1: + years_clim = ( + years_clim[0], + str(int(years_clim[0]) + 1), + ) + + nyrs_clim = int(years_clim[1]) - int(years_clim[0]) + 1 + + # Climate input variable format + climate_filestr_hist = ( + f"tas_day_{config.gcm}_{config.rcpdata}_r1i1p1_EWEMBI_landonly_" # ISIMIP2 + ) + + if config.gcm == "UKESM1-0-LL": + climate_filestr_future = f"{config.gcm}_r1i1p1f2_w5e5_{config.rcpdata}_{config.var}_global_daily_" + else: + climate_filestr_future = f"{config.gcm}_r1i1p1f1_w5e5_{config.rcpdata}_{config.var}_global_daily_" + + endstr = ".nc" + + if str(clim) == "hist": + isi_folder = config.isimip_ewemib_path + filestr = climate_filestr_hist + else: + isi_folder = config.isimip_bias_adj_path + filestr = climate_filestr_future + + filepath = os.path.join( + isi_folder, config.rcpdata, config.gcm, f"{filestr.lower()}*{endstr}" + ) + + print("Reading: " + filepath) + if config.rcp == "rcp26": + dst = xr.open_mfdataset( + filepath, + chunks={"lon": config.chunk_size}, + concat_dim="time", + use_cftime=True, + ) # Setting for RCP2.6 + else: + dst = xr.open_mfdataset( + filepath, + chunks={"lon": config.chunk_size}, + ) # , concat_dim='time' ) # Setting for RCP6.0 + + dst_crop = dst.sel(time=slice(years_clim[0], years_clim[1])) + t_out_ave = dst_crop[config.davar].astype("float32") - 273.16 + t_out_ave = t_out_ave.transpose("lat", "lon", "time") + t_oa_gbm = t_out_ave.groupby("time.month") + + i_sol_v = xr.open_dataarray( + os.path.join(config.dle_path, "EWEMBI_vert_irrad_1980-2009_avg.nc") + ) # Values in daily Wh/m2 + + # Horizontal irradiation + i_sol_h = xr.open_dataarray( + os.path.join(config.dle_path, "EWEMBI_horiz_irrad_1980-2009_avg.nc") + ) # Values in daily Wh/m2 + + if config.arch_setting == "regional": + xr.open_dataset( + os.path.join( + archetype_path, + "arch_map_" + config.arch_setting + "_" + arch + ".nc", + ) + ) + + dfa = pd.DataFrame(columns=["H_v_cl", "H_v_op", "H_tr"], index=par_var.index) + + suff = str(clim) + "_" + arch # suffix + # suff = clim+'_'+arch+'_'+str(parset.name_run) #suffix + suff1 = arch # only arch (for imports arch data) + + print("Starting: " + suff + "_" + str(parset.name_run)) + if config.cool == 1: + cop = parset.cop + t_sp_c = np.int8( + parset.t_sp_c + ) # Indoor setpoint temperature for cooling -> 26 + t_sp_c_max = np.int8( + parset.t_sp_c_max + ) # Indoor max temperature when fans are on (°C) -> 28 + + f_c = parset.f_c + f_f = parset.f_f + + if config.heat == 1: + t_sp_h = np.int8( + parset.t_sp_h + ) # Indoor max temperature when fans are on (°C) -> 20 + eff = parset.eff # Efficiency heating system + + f_h = parset.f_h + + # # Archetypes should be in parset to execute this (OLD CODE) + # if arch_setting == 'fixed': + # au = parset.arch_u + # ar = parset.arch_r + # al = [ar, au] + + # print(sddf) + + if config.runsdd == 1: + # ============================================================= + # Simple CDD calculation + # ============================================================= + + for bal_temp in config.bal_temps: + with ProgressBar(): + print("Stage 3 - Simple HDDCDD - cooling") + print("Balance temp " + str(bal_temp) + "C") + sdd_c = calc_SCDD_m(t_out_ave, bal_temp) + sdd_c = sdd_c.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + sdd_c.attrs = { + "name": "sdd_c", + "description": "Simple cooling degree days", + "units": "degC", + "short name": "CDD.", + # 'urt': urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + "bal_temp": str(bal_temp), + } + print(sdd_c) + sdd_c = sdd_c.to_dataset(name="sdd_c") + encoding = {"sdd_c": config.comp} + # fname = suff+'_'+str(parset.Index)+'_sdd_c_'+str(bal_temp)+'.nc' + fname = suff + "_sdd_c_" + str(bal_temp) + ".nc" + filestr = os.path.join(output_path_vdd, fname) + sdd_c.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + sdd_c = xr.open_dataarray(filestr) + + # ============================================================== + # Simple HDD calculation + # ============================================================== + + for bal_temp in config.bal_temps: + with ProgressBar(): + print("Stage 3 - Simple HDDCDD - heating") + print("Balance temp " + str(bal_temp) + "C") + sdd_h = calc_SHDD_m(t_out_ave, bal_temp) + sdd_h = sdd_h.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + sdd_h.attrs = { + "name": "sdd_h", + "description": "Simple heating degree days", + "units": "degC", + "short name": "HDD.", + # 'urt': urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + "bal_temp": str(bal_temp), + } + sdd_h = sdd_h.to_dataset(name="sdd_h") + encoding = {"sdd_h": config.comp} + # fname = suff+'_'+str(parset.Index)+'_sdd_h_'+str(bal_temp)+'.nc' + fname = suff + "_sdd_h_" + str(bal_temp) + ".nc" + filestr = os.path.join(output_path_vdd, fname) + sdd_h.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + sdd_h = xr.open_dataarray(filestr) + + def read_netcdf_files(input_args): + varname, arch, urt = input_args + var = xr.open_dataset( + os.path.join( + archetype_path, "arch_" + arch + "_" + str(varname) + ".nc" + ) + )[urt] + + return var + + list_args = product(VARS_ARCHETYPES, [arch], [urt]) + list_netcdf = list(map(read_netcdf_files, list_args)) + dict_netcdf = dict(zip(VARS_ARCHETYPES, list_netcdf)) + + if config.solar_gains == "VERT": + # Solar gains - From windows only + with ProgressBar(): + print("Stage 3 - calc gn_sol") + gn_sol = calc_gn_sol( + i_sol_v, + dict_netcdf["gl_perc"], + dict_netcdf["gl_g"], + dict_netcdf["gl_sh"], + ) + gn_sol = gn_sol.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + gn_sol.attrs = { + "name": "gn_sol", + "description": "Solar gains - Windows", + "units": "W/m2", + "short name": "Solar gains - Windows", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + gn_sol = gn_sol.to_dataset(name="gn_sol") + encoding = {"gn_sol": config.comp} + fname = suff + "_" + str(parset.Index) + "_gn_sol_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + gn_sol.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + gn_sol = xr.open_dataarray(filestr).load() + + elif config.solar_gains == "TOT": + # Solar gains - Total + with ProgressBar(): + print("Stage 3 - calc gn_sol") + gn_sol = calc_gn_sol_tot( + i_sol_v, + dict_netcdf["gl_perc"], + dict_netcdf["gl_g"], + dict_netcdf["gl_sh"], + i_sol_h, + dict_netcdf["roof_area"], + dict_netcdf["roof_abs"], + dict_netcdf["u_roof"], + ) + gn_sol = gn_sol.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + gn_sol.attrs = { + "name": "gn_sol", + "description": "Solar gains", + "units": "W/m2", + "short name": "Solar gains", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + gn_sol = gn_sol.to_dataset(name="gn_sol") + encoding = {"gn_sol": config.comp} + fname = suff + "_" + str(parset.Index) + "_gn_sol_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + gn_sol.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + gn_sol = xr.open_dataarray(filestr).load() + + elif config.solar_gains == "HOR": + # Solar gains - Total + with ProgressBar(): + print("Stage 3 - calc gn_sol") + gn_sol = calc_gn_sol_h( + i_sol_h, + dict_netcdf["roof_area"], + dict_netcdf["roof_abs"], + dict_netcdf["u_roof"], + ) + gn_sol = gn_sol.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + gn_sol.attrs = { + "name": "gn_sol", + "description": "Solar gains", + "units": "W/m2", + "short name": "Solar gains", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + gn_sol = gn_sol.to_dataset(name="gn_sol") + encoding = {"gn_sol": config.comp} + fname = suff + "_" + str(parset.Index) + "_gn_sol_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + gn_sol.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + gn_sol = xr.open_dataarray(filestr).load() + + # ============================================================================== + # Heat transfer functions + # ============================================================================== + with ProgressBar(): + H_v_cl = calc_H_v_cl(dict_netcdf["vol"], dict_netcdf["ach_cl"]) + if config.verbose: + print("Stage 3 - calc_H_v_cl") + # print(datetime.datetime.now() - start_time) + # H_v_cl = xr.open_dataarray(output_folder2+'H_v_cl_'+urt+'.nc').load() + + with ProgressBar(): + H_v_op = calc_H_v_op(dict_netcdf["vol"], dict_netcdf["ach_op"]) + if config.verbose: + print("Stage 3 - calc_H_v_op") + # print(datetime.datetime.now() - start_time) + # H_v_op = xr.open_dataarray(output_folder2+'H_v_op_'+urt+'.nc').load() + + with ProgressBar(): + H_tr = calc_H_tr(dict_netcdf["u_val"], dict_netcdf["area_env"]) + if config.verbose: + print("Stage 3 - calc_H_tr") + # print(datetime.datetime.now() - start_time) + # H_tr = xr.open_dataarray(output_folder2+'H_tr_'+urt+'.nc').load() + dfa.loc[parset.Index, :] = [H_v_cl, H_v_op, H_tr] + + if config.cool == 1: + # ============================================================================== + # Variable CDD functions + # ============================================================================== + with ProgressBar(): + print("t_bal_c") + t_bal_c = calc_t_bal_c( + t_sp_c, dict_netcdf["gn_int"], gn_sol, H_tr, H_v_cl + ).astype("float32") # , x_diff0 + t_bal_c = t_bal_c.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + t_bal_c.attrs = { + "name": "t_bal_c", + "description": "Balance (base) temperature", + "units": "degC", + "short name": "Balance temp.", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + t_bal_c = t_bal_c.to_dataset( + name="t_bal_c" + ) # comment out because already a Dataset + encoding = {"t_bal_c": config.comp} + fname = suff + "_" + str(parset.Index) + "_t_bal_c_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + t_bal_c.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + t_bal_c = xr.open_dataarray(filestr) + + # ============================================================================= + # t_max_c + # ============================================================================= + with ProgressBar(): + print("Calc_t_max_c") + t_max_c = calc_t_max_c( + t_sp_c_max, dict_netcdf["gn_int"], gn_sol, H_tr, H_v_op + ) # , x_diff0) + t_max_c.attrs = { + "name": "t_max_c", + "description": "This returns the max temperature", + "units": "degC", + "short name": "Max temp.", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + t_max_c = t_max_c.to_dataset(name="t_max_c") + encoding = {"t_max_c": config.comp} + fname = suff + "_" + str(parset.Index) + "_t_max_c_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + t_max_c.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + t_max_c = xr.open_dataarray(filestr).load() + # ============================================================================= + # Nd - only this one uses daily + # ============================================================================= + # Days per month over t_max_c + with ProgressBar(): + print("Calc Nd") + Nd = calc_Nd(t_out_ave, t_max_c, nyrs_clim) + Nd.attrs = { + "name": "Nd", + "description": "This returns the days per month over t_max_c", + "units": "days/month", + "short name": "Days > t_max_c", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + Nd = Nd.to_dataset(name="Nd") + encoding = {"Nd": config.comp} + fname = suff + "_" + str(parset.Index) + "_Nd_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + Nd.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + Nd = xr.open_dataarray(filestr) + + # ============================================================================= + # Nf - only this one uses daily + # ============================================================================= + # Days per month over t_max_c + with ProgressBar(): + print("Calc Nf") + Nf = calc_Nf(t_out_ave, t_bal_c, nyrs_clim) + Nf.attrs = { + "name": "Nf", + "description": "This returns the days per month above t_bal_c", + "units": "days/month", + "short name": "Days > t_bal_c", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + Nf = Nf.to_dataset(name="Nf") + encoding = {"Nf": config.comp} + fname = suff + "_" + str(parset.Index) + "_Nf_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + Nf.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + Nf = xr.open_dataarray(filestr) + + # ============================================================================= + # vdd_tmax_c + # ============================================================================= + # Days per month over t_max_c + with ProgressBar(): + print("Calc_vdd_tmax_c") + vdd_tmax_c = calc_vdd_tmax_c(t_oa_gbm, t_max_c) + vdd_tmax_c = vdd_tmax_c.chunk(chunks={"lon": config.chunk_size}) + vdd_tmax_c = ( + vdd_tmax_c.groupby("time.month").sum("time") / nyrs_clim + ) # <<< divide by years + + # old = xr.open_dataarray("D:\\mengm\\IIASA\\DLE - Data\\output_data_v19_ALPS2023\\GFDL-ESM4\\ssp585\\2_VDD_ene_calcs\\archive\\2015_new_0_vdd_tmax_c_urban.nc") + vdd_tmax_c.attrs = { + "name": "vdd_tmax_c", + "description": "This returns the sum of variable cooling degree days per month based on Tmax", + "units": "degC", + "short name": "Var. cooling DD", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + vdd_tmax_c = vdd_tmax_c.to_dataset(name="vdd_tmax_c") + encoding = {"vdd_tmax_c": config.comp} + fname = suff + "_" + str(parset.Index) + "_vdd_tmax_c_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + vdd_tmax_c.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + vdd_tmax_c = xr.open_dataarray(filestr) + + # ============================================================================= + # qctmax + # ============================================================================= + # t_bal_c = xr.open_dataarray( + # os.path.join( + # output_path_vdd, + # suff + "_" + str(parset.Index) + "_t_bal_c_" + urt + ".nc", + # ) + # ) + with ProgressBar(): + print("Calc_qctmax") + qctmax = Q_c_tmax(H_tr, H_v_cl, vdd_tmax_c, t_max_c, t_bal_c, Nd, f_c) + qctmax.attrs = { + "name": "qctmax", + "description": "This returns the monthly cooling energy (MJ) based on variable degree days", + "units": "MJ/month", + "short name": "Sensible load", + "AC_hours": str(f_c), + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + + qctmax = qctmax.to_dataset(name="qctmax") + encoding = {"qctmax": config.comp} + fname = suff + "_" + str(parset.Index) + "_qctmax_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + qctmax.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + # t_bal_c.close() + qctmax = xr.open_dataarray(filestr) + + # ============================================================================= + # E_c_ac electricity + # ============================================================================= + # qlat_month = xr.open_dataarray(output_folder2+'qlat_month_'+urt+'.nc') + with ProgressBar(): + print("E_c AC") + E_c_ac = calc_E_c_ac(qctmax, cop) + E_c_ac.attrs = { + "name": "E_c_ac", + "description": "monthly electricity requirement for air conditioning - sensible (MJ)", + "units": "MJ/month", + "short name": "AC energy sens", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + + E_c_ac = E_c_ac.to_dataset(name="E_c_ac") + encoding = {"E_c_ac": config.comp} + fname = suff + "_" + str(parset.Index) + "_E_c_ac_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + E_c_ac.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + # qlat_month = xr.open_dataarray(output_folder2+'qlat_month_'+urt+'.nc') + with ProgressBar(): + print("E_f fans") + E_c_fan = calc_E_c_fan( + f_f, P_f, Nf, config.area_fan + ) # Where Nf is same as Nd + E_c_fan.attrs = { + "name": "E_c_fan", + "description": "monthly electricity requirement for fans (MJ)", + "units": "MJ/month", + "short name": "Fan energy", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + E_c_fan = E_c_fan.to_dataset(name="E_c_fan") + encoding = {"E_c_fan": config.comp} + fname = suff + "_" + str(parset.Index) + "_E_c_fan_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + E_c_fan.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + # ============================================================================= + # dfa.to_csv(output_folder2+'constant_vars_out.csv') + # print('Finished!: '+str(parset)) + # print(datetime.datetime.now()-start) + # ============================================================================= + + # ============================================================================== + # HEATING CALCULATIONS + # ============================================================================== + + if config.heat == 1: + # ============================================================================== + # Variable HDD functions + # ============================================================================== + with ProgressBar(): + print("calc_t_bal_h") + t_bal_h = calc_t_bal_h( + t_sp_h, dict_netcdf["gn_int"], gn_sol, H_tr, H_v_cl + ).astype("float32") # , x_diff0 + t_bal_h = t_bal_h.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + t_bal_h.attrs = { + "name": "t_bal_h", + "description": "Balance (base) temperature", + "units": "degC", + "short name": "Balance temp.", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + t_bal_h = t_bal_h.to_dataset(name="t_bal_h") + encoding = {"t_bal_h": config.comp} + fname = suff + "_" + str(parset.Index) + "_t_bal_h_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + t_bal_h.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + t_bal_h = xr.open_dataarray(filestr) + + # ============================================================================= + # vdd_h + # ============================================================================= + + with ProgressBar(): + print("calc_vdd_h") + vdd_h = calc_vdd_h(t_oa_gbm, t_bal_h) + vdd_h = vdd_h.chunk(chunks={"lon": config.chunk_size}) + vdd_h = ( + vdd_h.groupby("time.month").sum("time") / nyrs_clim + ) # <<< divide by years + vdd_h.attrs = { + "name": "vdd_h", + "description": "This returns the sum of variable heating degree days per month", + "units": "degC", + "short name": "Var. heating DD", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + vdd_h = vdd_h.to_dataset(name="vdd_h") + encoding = {"vdd_h": config.comp} + fname = suff + "_" + str(parset.Index) + "_vdd_h_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + vdd_h.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + vdd_h = xr.open_dataarray(filestr) + + # ============================================================================= + # qh + # ============================================================================= + # t_bal_h = xr.open_dataarray( + # os.path.join( + # output_path_vdd, + # suff + "_" + str(parset.Index) + "_t_bal_h_" + urt + ".nc", + # ) + # ) + with ProgressBar(): + print("Calc_qh") + qh = Q_h(H_tr, H_v_cl, f_h, vdd_h) + qh.attrs = { + "name": "qh", + "description": "This returns the monthly heating energy (MJ) based on variable degree days", + "units": "MJ/month", + "short name": "Sensible load", + "heating_hours": str(f_h), + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + + qh = qh.to_dataset(name="qh") + encoding = {"qh": config.comp} + fname = suff + "_" + str(parset.Index) + "_qh_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + qh.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + qh = xr.open_dataarray(filestr) + + # ============================================================================= + # E_h final energy + # ============================================================================= + # qlat_month = xr.open_dataarray(output_folder2+'qlat_month_'+urt+'.nc') + with ProgressBar(): + print("E_h") + E_h = calc_E_h(qh, eff) + E_h.attrs = { + "name": "E_h", + "description": "monthly final energy for heating (MJ)", + "units": "MJ/month", + "short name": "heating energy", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + + E_h = E_h.to_dataset(name="E_h") + encoding = {"E_h": config.comp} + fname = suff + "_" + str(parset.Index) + "_E_h_" + urt + ".nc" + filestr = os.path.join(output_path_vdd, fname) + E_h.to_netcdf(filestr, encoding=encoding) + if config.verbose: + print(datetime.datetime.now() - start_time) + # qlat_month = xr.open_dataarray(output_folder2+'qlat_month_'+urt+'.nc') + dfa.to_csv( + os.path.join(output_path_vdd, suff + "_" + "constant_vars_out.csv") + ) + # print('Finished!: '+suff+'+str(parset)) + # print('Finished!') + print(datetime.datetime.now() - start_time) + + s_runs = load_all_scenarios_data(config).clim + inputs = product(s_runs, vers_archs, par_var.itertuples(), config.urts) + list(map(map_calculated_variables, inputs)) + + # mypool = Pool(4) + # return list(mypool.map(map_calculated_variables, inputs)) + + +def aggregate_urban_rural_files(config: "Config"): + out_path = os.path.join(config.project_path, "out", "version", config.vstr) + save_path = os.path.join(out_path, "VDD_ene_calcs") + + output_path_vdd = os.path.join( + save_path, + config.gcm, + config.rcp, + ) + + vers_archs = get_archs(config) + par_var = load_parametric_analysis_data(config) + runs_clims = load_all_scenarios_data(config).clim + + if not os.path.exists(output_path_vdd): + os.makedirs(output_path_vdd) + + for clim in runs_clims: + for arch in vers_archs: + suff = str(clim) + "_" + arch # suffix + + print("Aggregating results for " + suff) + # Aggregate archetypes into same files. + varlist = [] + + if config.cool == 1: + varlist.extend( + [ + "t_bal_c", + "vdd_tmax_c", + "qctmax", + "Nd", + "Nf", + "E_c_ac", + "E_c_fan", + "t_max_c", + ] + ) + + if config.heat == 1: + varlist.extend(["t_bal_h", "vdd_h", "qh", "E_h"]) + + comp = {"zlib": True} + + for parset in par_var.itertuples(): + for var in varlist: + print("." + var) + mds = xr.open_mfdataset( + os.path.join( + output_path_vdd, + suff + "_" + str(parset.Index) + "_" + var + "_*.nc", + ), + concat_dim="urt", + combine="nested", + ) # +urt[0] + # mds['arch'] = al #arcs#[:4] + mds["urt"] = config.urts # arcs#[:4] + + mds.attrs = { + "title": mds[var].attrs["name"], + "authors": "Edward Byers & Alessio Mastrucci", + "date": str(datetime.datetime.now()), + "institution": "IIASA Energy Program", + "contact": "byers@iiasa.ac.at; mastrucc@iiasa.ac.at", + # 'archetypes': al, + "urb_rur": config.urts, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + encoding = {var: comp for var in mds.data_vars} + filestr = os.path.join( + output_path_vdd, + suff + "_" + str(parset.Index) + "_" + var + "ALL.nc", + ) + mds.to_netcdf(filestr, encoding=encoding) + print("...Saved " + filestr) + + +def make_vdd_total_maps(config: "Config"): + out_path = os.path.join(config.project_path, "out", "version", config.vstr) + save_path = os.path.join(out_path, "VDD_ene_calcs") + + output_path_vdd = os.path.join( + save_path, + config.gcm, + config.rcp, + ) + + vers_archs = get_archs(config) + par_var = load_parametric_analysis_data(config) + s_runs = load_all_scenarios_data(config) + run_clims = s_runs.clim + + # TODO: (meas) the original code does not query for clims, + # but without it the code will crash if not all years have been run + # clims_int = list(map(int, run_clims)) + # print(clims_int) + + for s_run in s_runs.itertuples(): + for arch in vers_archs: + for urt in config.urts: + suff = str(s_run.clim) + "_" + arch # suffix + + print("Running " + suff) + + def make_map( + data, + ax=None, + add_features=True, + cbar=True, + grid=False, + logNorm=False, + crs=ccrs.PlateCarree(), + plotargs={}, + ): + if ax is None: + fig, ax = plt.subplots(subplot_kw=dict(projection=crs)) + elif not isinstance(ax, cartopy.mpl.geoaxes.GeoAxesSubplot): + msg = "Must provide a cartopy axes object, not: {}" + raise ValueError(msg.format(type(ax))) + + # ax = plt.axes(projection=ccrs.Robinson()) + if add_features: + # ax.add_feature(cartopy.feature.LAND, zorder=0) + + ax.add_feature( + cartopy.feature.OCEAN, facecolor="#bde6ed", zorder=0 + ) + ax.add_feature( + cartopy.feature.LAND, facecolor=[0.8, 0.8, 0.8] + ) # , zorder=0) + + ax.coastlines(linewidth=0.3, edgecolor="k") # '#778899' + ax.add_feature( + cfeature.BORDERS, linewidth=0.3, edgecolor="#778899" + ) + + # ax.add_feature(cartopy.feature.COASTLINE) + # ax.add_feature(cartopy.feature.BORDERS) + + if logNorm: + from matplotlib.colors import LogNorm # type: ignore + + plotargs["norm"] = LogNorm( + vmin=plotargs["vmin"], vmax=plotargs["vmax"] + ) + + if data is not None: + p = data.plot( + transform=ccrs.PlateCarree(), + ax=ax, + add_colorbar=cbar, + **plotargs, + ) + + if grid: + import matplotlib.ticker as mticker # type: ignore + from cartopy.mpl.gridliner import ( + LATITUDE_FORMATTER, + LONGITUDE_FORMATTER, + ) + + gl = ax.gridlines( + crs=crs, + draw_labels=True, + linewidth=1, + color="gray", + alpha=0.5, + linestyle="--", + ) + gl.xlabels_top = False + gl.ylabels_left = False + gl.xlines = False + gl.xlocator = mticker.FixedLocator([-180, -90, 0, 90, 180]) + gl.ylocator = mticker.FixedLocator( + [-90, -60, -30, 0, 30, 60, 90] + ) + gl.xformatter = LONGITUDE_FORMATTER + gl.yformatter = LATITUDE_FORMATTER + gl.xlabel_style = {"size": 15, "color": "gray"} + gl.xlabel_style = {"color": "black"} # , 'weight': 'bold'} + + return p + + if config.cool == 1: + vdd_c_in = xr.open_dataarray( + os.path.join( + output_path_vdd, suff + "_0_vdd_tmax_c_" + urt + ".nc" + ) + ).load() + vdd_c_year = vdd_c_in.sum(dim="month") + E_c_ac_in = xr.open_dataarray( + os.path.join(output_path_vdd, suff + "_0_E_c_ac_" + urt + ".nc") + ).load() + (E_c_ac_in.sum(dim="month") * 0.2777778) # Yearly total in kWh/m2 + + if config.heat == 1: + vdd_h_in = xr.open_dataarray( + os.path.join(output_path_vdd, suff + "_0_vdd_h_" + urt + ".nc") + ).load() + vdd_h_year = vdd_h_in.sum(dim="month") + E_h_in = xr.open_dataarray( + os.path.join(output_path_vdd, suff + "_0_E_h_" + urt + ".nc") + ).load() + (E_h_in.sum(dim="month") * 0.2777778) # Yearly total in kWh/m2 + + cbloc = [ + 0.86, + 0.185, + 0.03, + 0.61, + ] # [0.3, 0.07, 0.4, cbh] #color bar location + cbor = "vertical" + + proj = ccrs.PlateCarree() + rows = 1 + fw = "bold" + tfs = 9 + cmap = "magma_r" + + # cb8 = plt.colorbar(im8, cax=cbaxes8, orientation=cbor, extend='max') + # cb8.ax.tick_params(labelsize=tfs-2) + # cbaxes8.text(-3,-0.12, u'people/km\u00b2', fontsize=10) + + poplog = False + + # Cooling Degree Days + if config.cool == 1: + vmin = 0 + vmax = 4000 + plotargs = {"cmap": cmap, "vmin": vmin, "vmax": vmax} + + dvar = eval("vdd_c_year") # / larea + # dvar = dvar[urt] + fig = plt.figure(figsize=(6, 4)) + ax8 = fig.add_subplot(rows, 1, 1, projection=proj) + im8 = make_map( + dvar.where(dvar > 0), + ax=ax8, + cbar=False, + grid=False, + logNorm=poplog, + plotargs=plotargs, + ) + plt.title("Cooling Degree Days", fontsize=tfs, fontweight=fw) + cbaxes8 = fig.add_axes(cbloc) + cb8 = plt.colorbar(im8, cax=cbaxes8, orientation=cbor) + cb8.ax.tick_params(labelsize=tfs - 2) + + # cbaxes8.text(-3,-0.12, u'VDD/year', fontsize=10) + plt.tight_layout() + fig.subplots_adjust( + left=0.05, right=0.85, top=0.95, bottom=0.03 + ) # subplot margins + plt.savefig( + os.path.join( + output_path_vdd, + suff + "_VDD_c_" + cmap + str(poplog) + ".png", + ), + dpi=300, + bbox_inches="tight", + ) + + # Heating Degree Days + if config.heat == 1: + vmin = 0 + vmax = 10000 + plotargs = {"cmap": cmap, "vmin": vmin, "vmax": vmax} + + dvar = eval("vdd_h_year") # / larea + # dvar = dvar[urt] + fig = plt.figure(figsize=(6, 4)) + ax8 = fig.add_subplot(rows, 1, 1, projection=proj) + im8 = make_map( + dvar.where(dvar > 0), + ax=ax8, + cbar=False, + grid=False, + logNorm=poplog, + plotargs=plotargs, + ) + plt.title("Heating Degree Days", fontsize=tfs, fontweight=fw) + cbaxes8 = fig.add_axes(cbloc) + cb8 = plt.colorbar(im8, cax=cbaxes8, orientation=cbor) + cb8.ax.tick_params(labelsize=tfs - 2) + + # cbaxes8.text(-3,-0.12, u'VDD/year', fontsize=10) + plt.tight_layout() + fig.subplots_adjust( + left=0.05, right=0.85, top=0.95, bottom=0.03 + ) # subplot margins + plt.savefig( + os.path.join( + output_path_vdd, + suff + "_VDD_h_" + cmap + str(poplog) + ".png", + ), + dpi=300, + bbox_inches="tight", + ) + + # Energy demand - Heating [kWh/m2] + if config.heat == 1: + vmin = 0 + vmax = 300 + plotargs = {"cmap": cmap, "vmin": vmin, "vmax": vmax} + + dvar = eval("E_h_year") # / larea + # dvar = dvar[urt] + fig = plt.figure(figsize=(6, 4)) + ax8 = fig.add_subplot(rows, 1, 1, projection=proj) + im8 = make_map( + dvar.where(dvar > 0), + ax=ax8, + cbar=False, + grid=False, + logNorm=poplog, + plotargs=plotargs, + ) + plt.title("Energy demand - Heating", fontsize=tfs, fontweight=fw) + cbaxes8 = fig.add_axes(cbloc) + cb8 = plt.colorbar(im8, cax=cbaxes8, orientation=cbor) + cb8.ax.tick_params(labelsize=tfs - 2) + + # cbaxes8.text(-3,-0.12, u'VDD/year', fontsize=10) + plt.tight_layout() + fig.subplots_adjust( + left=0.05, right=0.85, top=0.95, bottom=0.03 + ) # subplot margins + plt.savefig( + os.path.join( + output_path_vdd, + suff + "_E_h_" + cmap + str(poplog) + ".png", + ), + dpi=300, + bbox_inches="tight", + ) + + # Energy demand - Cooling - AC only [kWh/m2] + if config.cool == 1: + vmin = 0 + vmax = 100 + plotargs = {"cmap": cmap, "vmin": vmin, "vmax": vmax} + + dvar = eval("vdd_c_year") # / larea + # dvar = dvar[urt] + fig = plt.figure(figsize=(6, 4)) + ax8 = fig.add_subplot(rows, 1, 1, projection=proj) + im8 = make_map( + dvar.where(dvar > 0), + ax=ax8, + cbar=False, + grid=False, + logNorm=poplog, + plotargs=plotargs, + ) + plt.title( + "Energy demand - Cooling (AC only)", fontsize=tfs, fontweight=fw + ) + cbaxes8 = fig.add_axes(cbloc) + cb8 = plt.colorbar(im8, cax=cbaxes8, orientation=cbor) + cb8.ax.tick_params(labelsize=tfs - 2) + + # cbaxes8.text(-3,-0.12, u'VDD/year', fontsize=10) + plt.tight_layout() + fig.subplots_adjust( + left=0.05, right=0.85, top=0.95, bottom=0.03 + ) # subplot margins + plt.savefig( + os.path.join( + output_path_vdd, + suff + "_E_c_ac_" + cmap + str(poplog) + ".png", + ), + dpi=300, + bbox_inches="tight", + ) + + +def process_construction_shares(config: "Config"): + out_path = os.path.join(config.project_path, "out", "version", config.vstr) + floorarea_path = os.path.join(out_path, "floorarea_country") + + output_path = os.path.join( + floorarea_path, + config.gcm, + config.rcp, + ) + + if not os.path.exists(output_path): + os.makedirs(output_path) + + vers_archs = get_archs(config) + par_var = load_parametric_analysis_data(config) + + # get raster file and message map + country_ras, reg_ras, map_reg, iso_attrs = create_message_raster(config) + + # If constr_setting == 1, then process construction shares. Otherwise, skip + if config.constr_setting == 1: + input_path = config.dle_path + + dsc = xr.Dataset() + for urt in config.urts: + # Read in excel files + conshare = pd.read_csv( + os.path.join(input_path, "constr_share_" + urt + ".csv") + ) + tl = list(conshare.columns) + arcs = [s for s in tl if s[0] == urt[0]] + + # build dummy dataset + block = np.full((360, 720, 20), np.nan) + lats = country_ras.lat + lons = country_ras.lon + coords = {"lat": lats, "lon": lons, "arch": arcs} + ds = xr.DataArray(block, coords=coords, dims=["lat", "lon", "arch"]) + + for row in iso_attrs.itertuples(): + conshare.loc[conshare.ISO == row.ISO, "regnum"] = row.Index + + # missing AND, Andorra DMA, Dominica GRD,Grenada LIE, + # liechenstein ATG, Antigua & barbuda KNA, Saint kitts SYC seychelles + for arch in arcs: # For each arch + ai = arcs.index(arch) + ta = ds.sel(arch=arch).values + + for row in iso_attrs.itertuples(): # For each country + ats = conshare.loc[conshare.ISO == row.ISO, :] + + try: + ta[country_ras == int(row.Index)] = ats.loc[ + ats.ISO == row.ISO, arch + ].values[0] + except IndexError: + print("map:" + row.ISO) + ds.values[:, :, ai] = ta + + ds.attrs = { + "title": "Construction shares by archetype", + "urb_rur": urt, + "authors": "Edward Byers & Alessio Mastrucci", + "date": str(datetime.datetime.now()), + "institution": "IIASA Energy Program", + "contact": "byers@iiasa.ac.at; mastrucc@iiasa.ac.at", + } + ds = ds.to_dataset(name=urt) + comp = {"zlib": True} + encoding = {var: comp for var in ds.data_vars} + ds.to_netcdf( + os.path.join(output_path, "constr_share_" + urt + ".nc"), + encoding=encoding, + ) + dsc[urt] = ds[urt] + + dsc.attrs = { + "title": "Construction share by archetype", + "authors": "Edward Byers & Alessio Mastrucci", + "date": str(datetime.datetime.now()), + "institution": "IIASA Energy Program", + "contact": "byers@iiasa.ac.at; mastrucc@iiasa.ac.at", + } + + encoding = {var: comp for var in dsc.data_vars} + dsc.to_netcdf( + os.path.join(output_path, "constr_share_urbanrural.nc"), encoding=encoding + ) + print("Completed construction share maps") + else: + print("Skipping construction share maps because constr_setting != 1") + + +def process_floor_area_maps(config: "Config"): + input_path = config.dle_path + out_path = os.path.join(config.project_path, "out", "version", config.vstr) + save_path = os.path.join(out_path, "floorarea_country") + + output_path = os.path.join( + save_path, + config.gcm, + config.rcp, + ) + + if not os.path.exists(output_path): + os.makedirs(output_path) + + vers_archs = get_archs(config) + par_var = load_parametric_analysis_data(config) + country_ras, reg_ras, map_reg, iso_attrs = create_message_raster(config) + s_runs = load_all_scenarios_data(config) + + if config.floor_setting == "std_cap": + floorarea = pd.read_csv( + os.path.join(input_path, "floor_std_cap.csv") + ) # STD conditioned floor area (same for all regions, based on DLE) + + floormap = xr.Dataset( + { + "urban": reg_ras.MESSAGE11.copy(deep=True), + "rural": reg_ras.MESSAGE11.copy(deep=True), + } + ) + + for row in floorarea.itertuples(): + floormap["urban"].values[floormap.urban == row.RegNum] = float(row.urban) + floormap["rural"].values[floormap.rural == row.RegNum] = float(row.rural) + # floormap['urban'].values[floormap.urban==row.RegNum] = getattr(row,'urban'+suff) + # floormap['rural'].values[floormap.rural==row.RegNum] = getattr(row,'rural'+suff) + + floormap = floormap.astype(float) + for urt in config.urts: + floormap[urt].values[floormap[urt] == -1] = np.nan + + plt.figure() + floormap.urban.plot() + plt.figure() + floormap.rural.plot() + + # % Write out to netcdf + floormap.attrs = { + "title": "Floor area by region", + "authors": "Edward Byers & Alessio Mastrucci", + "date": str(datetime.datetime.now()), + "institution": "IIASA Energy Program", + "contact": "byers@iiasa.ac.at; mastrucc@iiasa.ac.at", + "floor_setting": config.floor_setting, + } + comp = {"zlib": True} + encoding = {var: comp for var in floormap.data_vars} + floormap.to_netcdf( + os.path.join(output_path, "floor_area_map_std_cap.nc"), encoding=encoding + ) + print("Completed floor area maps") + + elif config.floor_setting == "per_cap": + for s_run in s_runs.itertuples(): + suff = ( + str(s_run.scen) + "_" + str(s_run.year) + "_" + str(s_run.clim) + ) # suffix + suff2 = ( + str(s_run.scen) + "_" + str(s_run.year) + ) # suffix: only scen and year + + floorarea = pd.read_excel( + os.path.join(input_path, "floor_per_cap_" + config.vstrcntry + ".xlsx"), + sheet_name=suff2, + ) + + floormap = xr.Dataset( + { + "urban": reg_ras.MESSAGE11.copy(deep=True), + "rural": reg_ras.MESSAGE11.copy(deep=True), + } + ) + + for row in floorarea.itertuples(): + floormap["urban"].values[floormap.urban == row.RegNum] = float( + row.urban + ) + floormap["rural"].values[floormap.rural == row.RegNum] = float( + row.rural + ) + # floormap['urban'].values[floormap.urban==row.RegNum] = getattr(row,'urban'+suff) + # floormap['rural'].values[floormap.rural==row.RegNum] = getattr(row,'rural'+suff) + + floormap = floormap.astype(float) + for urt in config.urts: + floormap[urt].values[floormap[urt] == -1] = np.nan + + plt.figure() + floormap.urban.plot() + plt.figure() + floormap.rural.plot() + + # % Write out to netcdf + + floormap.attrs = { + "title": "Floor area by region", + "authors": "Edward Byers & Alessio Mastrucci", + "date": str(datetime.datetime.now()), + "institution": "IIASA Energy Program", + "contact": "byers@iiasa.ac.at; mastrucc@iiasa.ac.at", + "floor_setting": config.floor_setting, + } + comp = {"zlib": True} + encoding = {var: comp for var in floormap.data_vars} + floormap.to_netcdf( + os.path.join( + output_path, + "floor_area_map_" + config.floor_setting + "_" + suff + ".nc", + ), + encoding=encoding, + ) + + print("Completed floor area maps") + + else: + print("Skipping floor area maps because floor_setting != std_cap or per_cap") + + +def process_country_maps(config: "Config"): + input_path = config.dle_path + out_path = os.path.join(config.project_path, "out", "version", config.vstr) + save_path = os.path.join(out_path, "floorarea_country") + + output_path = os.path.join( + save_path, + config.gcm, + config.rcp, + ) + + if not os.path.exists(output_path): + os.makedirs(output_path) + + vers_archs = get_archs(config) + par_var = load_parametric_analysis_data(config) + s_runs = load_all_scenarios_data(config) + country_ras, reg_ras, map_reg, iso_attrs = create_message_raster(config) + + for s_run in s_runs.itertuples(): + suff = str(s_run.scen) + "_" + str(s_run.year) + "_" + str(s_run.clim) # suffix + str(s_run.scen) + "_" + str(s_run.year) # suffix: only scen and year + + # Read in country_data for AC penetration, electricity access, slumpop + # country_data = pd.read_excel(input_folder+'country_data_'+vstrcntry+'.xlsx', sheet_name = 'suff2') + country_data = pd.read_excel( + os.path.join(input_path, "country_data_" + config.vstrcntry + ".xlsx"), + sheet_name="ssp2_2010", + ) # hack to use same sheet every time + + # Column names + # cols = ['AC_penetr','access_elec','slum_pop'] + cols = [ + "AC_penetr", + "AC_penetr_U", + "AC_penetr_R", + "access_elec", + "slum_pop", + "GLOBAL_SOUTH", + ] + # cols = ['AC_penetr'+suff,'AC_penetr_U'+suff,'AC_penetr_R'+suff,'access_elec'+suff,'slum_pop'+suff,'GLOBAL_SOUTH'] + + # Match the GAUL country numbers to the ISOs in country_data table (just in case) + iso_attrs["GAULi"] = iso_attrs.index.astype(float) + country_data = country_data.merge(iso_attrs, on="ISO", how="outer") + + # create dataset four country data + cd_map = xr.Dataset({cols[0]: country_ras.copy(deep=True).astype("float")}) + for col in cols[1:]: + cd_map[col] = country_ras.copy(deep=True).astype("float") + + # Populate the dataset with country data + for col in cols: + for idx in iso_attrs.GAULi: + cd_map[col].values[cd_map[col] == idx] = country_data.loc[ + country_data.GAULi == idx, col + ] + + plt.figure() + cd_map[col].plot() + plt.close() + + # Write out to netcdf + cd_map.attrs = { + "title": "Maps of country data", + "authors": "Edward Byers & Alessio Mastrucci", + "date": str(datetime.datetime.now()), + "institution": "IIASA Energy Program", + "contact": "byers@iiasa.ac.at; mastrucc@iiasa.ac.at", + "variables": cols, + } + + comp = {"zlib": True, "complevel": 5} + encoding = {var: comp for var in cd_map.data_vars} + cd_map.to_netcdf( + os.path.join(output_path, "country_data_maps_" + suff + ".nc"), + encoding=encoding, + ) + + print("Finished country data maps") + + +def process_final_maps(config: "Config"): + input_path = config.dle_path + out_path = os.path.join(config.project_path, "out", "version", config.vstr) + vdd_path = os.path.join( + out_path, + "VDD_ene_calcs", + config.gcm, + config.rcp, + ) + floorarea_path = os.path.join( + out_path, + "floorarea_country", + config.gcm, + config.rcp, + ) + finalmaps_path = os.path.join(out_path, "final_maps", config.gcm, config.rcp) + + if not os.path.exists(finalmaps_path): + os.makedirs(finalmaps_path) + + vers_archs = get_archs(config) + par_var = load_parametric_analysis_data(config) + s_runs = load_all_scenarios_data(config) + # country_ras, reg_ras, map_reg, iso_attrs = create_message_raster(config) + + # country_maps_path = os.path.join( + # input_dle_path, + # f"output_data_{input_version_name}", + # input_gcm, + # input_rcp_scenario, + # "3_floorarea_country_data", + # ) + + # ene_calcs_path = os.path.join( + # input_dle_path, + # f"output_data_{input_version_name}", + # input_gcm, + # input_rcp_scenario, + # "2_VDD_ene_calcs", + # ) + + # final_maps_path = os.path.join( + # input_dle_path, + # f"output_data_{input_version_name}", + # input_gcm, + # input_rcp_scenario, + # "4_final_maps", + # ) + + vardic = {} + varundic = {} + + # Update dictionaries if config.cool == 1 + if config.cool == 1: + vardic.update(VARDICT_COOL) + varundic.update(VARUNDICT_COOL) + # Update dictionaries if config.heat == 1 + if config.heat == 1: + vardic.update(VARDICT_HEAT) + varundic.update(VARUNDICT_HEAT) + + [key for key in varundic.keys()] + + if ( + config.paranalysis_mode == 0 + ): # If running in ref mode, keep only the ref parameter set + par_var = par_var.loc[par_var.name_run == "ref", :] + + # TODO: (meas) the original code does not query for clims, + # but without it the code will crash if not all years have been run + # clims_int = list(map(int, config.clims)) + # print("Years of data available: " + str(clims_int)) + # s_runs = s_runs.query("clim in @clims_int") + + for s_run in s_runs.itertuples(): + for arch in vers_archs: + suff = ( + str(s_run.scen) + + "_" + + str(s_run.year) + + "_" + + str(s_run.clim) + + "_" + + arch + ) # suffix + suff1 = str(s_run.clim) + "_" + arch # suffix + if config.popfix is True: + suff2 = "ssp2_" + str(s_run.year) + else: + suff2 = ( + str(s_run.scen) + "_" + str(s_run.year) + ) # suffix: only scen and year + suff3 = ( + str(s_run.scen) + "_" + str(s_run.year) + "_" + str(s_run.clim) + ) # suffix: scen, year and arch + + print("Starting " + suff) + + # Load country data + country_data = xr.open_dataset( + os.path.join(floorarea_path, "country_data_maps_" + suff3 + ".nc") + ) + + # Load population data + popdata = xr.Dataset() + popdata["urban"] = xr.open_dataarray( + os.path.join( + input_path, "population", "population", suff2 + "_urban_hd.nc4" + ) + ) + popdata["rural"] = xr.open_dataarray( + os.path.join( + input_path, "population", "population", suff2 + "_rural_hd.nc4" + ) + ) + popdata["total"] = xr.open_dataarray( + os.path.join( + input_path, "population", "population", suff2 + "_total_hd.nc4" + ) + ) + + # Floor area data + if config.floor_setting == "std_cap": + floorarea = xr.open_dataset( + os.path.join( + floorarea_path, + "floor_area_map_" + config.floor_setting + ".nc", + ) + ) + elif config.floor_setting == "per_cap": + floorarea = xr.open_dataset( + os.path.join( + floorarea_path, + "floor_area_map_" + config.floor_setting + "_" + suff3 + ".nc", + ) + ) + + # Construction shares + # constr = xr.open_dataset(input_folder+'map_constr_floorarea\\constr_share_urbanrural.nc') + + # ============================================================================= + # First apply population weighting to energy demand: + # ============================================================================= + + for parset in par_var.itertuples(): + if config.cool == 1: + Nd1 = xr.open_dataarray( + os.path.join( + vdd_path, + suff1 + "_" + str(parset.Index) + "_NdALL.nc", + ) + ).load() # For calculation + # Nd = Nd.sum(dim=['arch','month'])/2 #<<< divide by 2 because 2 archetypes + Nd1 = ( + Nd1.sum(dim=["urt", "month"]) / 2 + ) # <<< divide by 2 (rural + urban) + + Ndr = xr.open_dataarray( + os.path.join( + vdd_path, + suff1 + "_" + str(parset.Index) + "_NdALL.nc", + ) + ).load() # For reporting + # Nd = Nd.sum(dim=['arch','month'])/2 #<<< divide by 2 because 2 archetypes + # Nd = Nd.sum(dim=['month']) #<<< divide by 2 (rural + urban) + + Nfr = xr.open_dataarray( + os.path.join( + vdd_path, + suff1 + "_" + str(parset.Index) + "_NfALL.nc", + ) + ).load() + # Nf = Nf.sum(dim=['arch','month'])/2 #<<< divide by 2 because 2 archetypes + # Nf = Nf.sum(dim=['month']) #<<< divide by 2 (rural + urban) + + E_c_ac = ( + xr.open_dataarray( + os.path.join( + vdd_path, + suff1 + "_" + str(parset.Index) + "_E_c_ac" + "ALL.nc", + ) + ).where(Nd1 >= config.nd_thresh) + ).load() + E_c_fan = ( + xr.open_dataarray( + os.path.join( + vdd_path, + suff1 + "_" + str(parset.Index) + "_E_c_fan" + "ALL.nc", + ) + ).where(Nd1 >= config.nd_thresh) + ).load() + E_c = E_c_ac + E_c_fan + vdd_c_in = xr.open_dataarray( + os.path.join( + vdd_path, + suff1 + "_" + str(parset.Index) + "_vdd_tmax_cALL.nc", + ) + ).load() + + if config.heat == 1: + E_h = ( + xr.open_dataarray( + os.path.join( + vdd_path, + suff1 + "_" + str(parset.Index) + "_E_h" + "ALL.nc", + ) + ).where(Nd1 >= 0) + ).load() # ****************************** + vdd_h_in = xr.open_dataarray( + os.path.join( + vdd_path, + suff1 + "_" + str(parset.Index) + "_vdd_hALL.nc", + ) + ).load() + # vdd_in = vdd_in.sum(dim='arch') + + # if (runsdd==1) and (parset.Index==0): + # for bal_temp in bal_temps: + # sdd_c_in = xr.open_dataarray(input_folder2+str(parset.Index)+'_s_cddALL.nc').load() + # sdd_h_in = xr.open_dataarray(input_folder2+str(parset.Index)+'_s_hddALL.nc').load() + # print(xkss) + + if config.cool == 1: + # Cooling outputs + E_c_perpix = ( + xr.Dataset() + ) # Pixel / person per gridsquare energy demand + E_c_ac_popwei = ( + xr.Dataset() + ) # Total Energy, population weighted, per pixel + E_c_fan_popwei = xr.Dataset() + E_c_popwei = xr.Dataset() + E_c_ac_wAccess = xr.Dataset() + E_c_ac_gap = xr.Dataset() + E_c_fan_wAccess = xr.Dataset() + E_c_fan_gap = xr.Dataset() + E_c_wAccess = xr.Dataset() + E_c_gap = xr.Dataset() + Nf = xr.Dataset() + Nd = xr.Dataset() + vdd_c_popwei = xr.Dataset() # Degree Days multiplied by population + # sdd_c = xr.Dataset() + + P_c_ac_potential = xr.Dataset() + P_c_ac_gap = xr.Dataset() + P_c_fan_gap = xr.Dataset() + P_c_fanNoAC = xr.Dataset() + + if config.heat == 1: + # Heating outputs + E_h_perpix = ( + xr.Dataset() + ) # Pixel / person per gridsquare energy demand + E_h_popwei = xr.Dataset() # population weighted (FULL demand) + + P_h_potential = xr.Dataset() + + vdd_h_popwei = xr.Dataset() # Degree Days multiplied by population + # sdd_h = xr.Dataset() + + # % Produce spatial results + for urt in config.urts: + if config.cool == 1: + if urt == "urban": + # at = au + acp = "AC_penetr_U" + elif urt == "rural": + # at = ar + acp = "AC_penetr_R" + + # print(sddddd) + E_c_perpix[urt] = ( + floorarea[urt] * E_c["urt" == urt] + ) # energy per person per pixel + E_c_ac_popwei[urt] = ( + popdata[urt] * floorarea[urt] * E_c_ac["urt" == urt] + ) # Total Energy, population weighted, per pixel + E_c_fan_popwei[urt] = ( + popdata[urt] * floorarea[urt] * E_c_fan["urt" == urt] + ) # Total Energy, population weighted, per pixel + E_c_popwei[urt] = ( + popdata[urt] * E_c_perpix[urt] + ) # Total Energy, population weighted, per pixel + # E_c_pwpercap = E_c_popwei[urt] / popdata[urt] + + E_c_ac_wAccess[urt] = ( + E_c_ac_popwei[urt] * country_data[acp] + ) # AC energy incl AC penetre + E_c_ac_gap[urt] = E_c_ac_popwei[urt] * ( + 1 - country_data[acp] + ) # AC energy gap + + E_c_fan_wAccess[urt] = ( + E_c_fan_popwei[urt] * country_data["access_elec"] + ) # Fan energy incl elec access + E_c_fan_gap[urt] = E_c_fan_popwei[urt] * ( + 1 - country_data["access_elec"] + ) # Fan energy gap + + E_c_wAccess[urt] = ( + E_c_ac_wAccess[urt] + E_c_fan_wAccess[urt] + ) # << Current energy usage + E_c_gap[urt] = ( + E_c_ac_gap[urt] + E_c_fan_gap[urt] + ) # Total energy gap + + Nd[urt] = Ndr[ + "urt" == urt + ] # .sum(dim='month') # summed later over months + Nf[urt] = Nfr["urt" == urt] + + vdd_c_popwei[urt] = ( + popdata[urt] * vdd_c_in["urt" == urt] + ) # Degree Days multiplied by population + # if (runsdd==1) and (parset.Index==0): + # sdd_c[urt] = sdd_c_in # popdata[urt] * + + # Population that needs access to AC (AC market) + P_c_ac_potential[urt] = popdata[urt].where( + E_c_ac["urt" == urt].sum(dim="month") > 0 + ) + # Population (unsatisfied) that needs access to AC + P_c_ac_gap[urt] = popdata[urt].where( + E_c_ac["urt" == urt].sum(dim="month") > 0 + ) * (1 - country_data[acp]) + P_c_fan_gap[urt] = popdata[urt].where( + E_c_fan["urt" == urt].sum(dim="month") > 0 + ) * (1 - country_data["access_elec"]) + P_c_fanNoAC[urt] = P_c_ac_gap[urt] - P_c_fan_gap[urt] + + if config.heat == 1: + # Heating results + E_h_perpix[urt] = ( + floorarea[urt] * E_h["urt" == urt] + ) # energy per person per pixel + E_h_popwei[urt] = ( + popdata[urt] * floorarea[urt] * E_h["urt" == urt] + ) # Total Energy, population weighted, per pixel + + P_h_potential[urt] = popdata[urt].where( + E_h["urt" == urt].sum(dim="month") > 0 + ) # Population that needs access to heating + + vdd_h_popwei[urt] = ( + popdata[urt] * vdd_h_in["urt" == urt] + ) # Degree Days multiplied by population + # if (runsdd==1) and (parset.Index==0): + # sdd_h[urt] = sdd_h_in # popdata[urt] * + + for var in vardic.keys(): + # if (runsdd==1) and (var=='sdd_c' or var =='sdd_h') and (parset.Index>0): + # print('do nothing') + # else: + ds = eval(var) + # ds['arch'] = al + ds["urt"] = config.urts + ds.attrs = { + "title": var, + "description": vardic[var], + "units": varundic[var], + "authors": "Edward Byers & Alessio Mastrucci", + "date": str(datetime.datetime.now()), + "institution": "IIASA Energy Program", + "contact": "byers@iiasa.ac.at; mastrucc@iiasa.ac.at", + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + + # if (runsdd==1) and (var=='sdd_c' or var=='sdd_h'): + # ds.attrs['bal_temps'] = str(bal_temps) + # else: + # ds.attrs['archetypes'] = al + + encoding = {vari: config.comp for vari in ds.data_vars} + fname = suff + "_" + str(parset.Index) + "_" + var + ".nc" + filestr = os.path.join(finalmaps_path, fname) + ds.to_netcdf(filestr, encoding=encoding) + + if varundic[var][-5:] == "month": + dsy = ds.sum(dim="month") + for urt in config.urts: + # if (runsdd==1) and (var == 'sdd_c' or var=='sdd_h'): + # dsy[urt] = (['bal_temp', 'lat','lon',], dsy[urt].values) #.sum(dim='arch') + # else: + dsy[urt] = ( + ["lat", "lon"], + dsy[urt].values, + ) # .sum(dim='arch') + + dsy.attrs = ds.attrs + dsy.attrs["units"] = varundic[var][:-5] + "year" + encoding = {vari: config.comp for vari in dsy.data_vars} + fname = suff + "_" + str(parset.Index) + "_" + var + "_year.nc" + filestr = os.path.join(finalmaps_path, fname) + dsy.to_netcdf(filestr, encoding=encoding) + + +def process_iso_tables(config: "Config"): + start = datetime.datetime.now() + + input_path = config.dle_path + out_path = os.path.join(config.project_path, "out", "version", config.vstr) + vdd_path = os.path.join(out_path, "VDD_ene_calcs", config.gcm, config.rcp) + floorarea_path = os.path.join(out_path, "floorarea_country", config.gcm, config.rcp) + finalmaps_path = os.path.join(out_path, "final_maps", config.gcm, config.rcp) + iso_path = os.path.join(out_path, "iso_tables", config.gcm, config.rcp) + + if not os.path.exists(iso_path): + os.makedirs(iso_path) + + vers_archs = get_archs(config) + par_var = load_parametric_analysis_data(config) + s_runs = load_all_scenarios_data(config) + # ras, map_reg, iso_attrs = create_message_raster(config) + + updated_urts = config.urts + ["total"] + + # final_maps_path = os.path.join( + # input_dle_path, + # f"output_data_{input_version_name}", + # input_gcm, + # input_rcp_scenario, + # "4_final_maps", + # ) + + # iso_tables_path = os.path.join( + # input_dle_path, + # f"output_data_{input_version_name}", + # input_gcm, + # input_rcp_scenario, + # "5_ISO_tables", + # ) + + vardic = {} + varundic = {} + + # Update dictionaries if config.cool == 1 + if config.cool == 1: + vardic.update(VARDICT_COOL) + varundic.update(VARUNDICT_COOL) + # Update dictionaries if config.heat == 1 + if config.heat == 1: + vardic.update(VARDICT_HEAT) + varundic.update(VARUNDICT_HEAT) + + varlist_cool = [key for key in VARDICT_COOL.keys()] + varlist_heat = [key for key in VARDICT_HEAT.keys()] + + # TODO: (meas) the original code does not query for clims, + # but without it the code will crash if not all years have been run + # clims_int = list(map(int, config.clims)) + # print("Years of data available: " + str(clims_int)) + # s_runs = s_runs.query("clim in @clims_int") + + # Read raster data + raster = xr.open_dataarray(os.path.join(input_path, "gaul_lvl0_hybrid_05_3.nc")) + + # Read country data + dfd = pd.read_csv( + os.path.join(input_path, "GAUL_lvl0_raster0.5.csv"), index_col="ID" + ).assign(ISONUM=lambda x: x.index) + + # Import MESSAGE regions and North/South classification + msgNS = pd.read_excel( + os.path.join(input_path, "country_data_" + config.vstrcntry + ".xlsx"), + sheet_name="ssp2_2010", + ) + + # Add 'GLOBAL_SOUTH' and 'REGION_GEA' to dfd + dfd = dfd.merge( + msgNS.reindex(columns=["ISO", "GLOBAL_SOUTH", "REGION_GEA"]), + left_on="ISO3", + right_on="ISO", + ).set_index("ISONUM") + + # Load population data + print("Opening population data....") + l_popdata = [] + for s_run in s_runs.itertuples(): + suff = str(s_run.scen) + "_" + str(s_run.year) + print(suff) + + popdata = xr.Dataset() + for urt in updated_urts: + popdata[urt] = xr.open_dataarray( + os.path.join( + input_path, + "population", + "population", + suff + "_" + urt + "_hd.nc4", + ) + ) + + agg_popdata = ( + popdata.groupby(raster) + .sum() + .to_dataframe() + .reset_index() + .melt(id_vars="gaul_lvl0", var_name="urt", value_name="popsum") + .assign(population_scenario=s_run.scen, year=s_run.year) + ) + + l_popdata.append(agg_popdata) + + pop_agg = ( + pd.concat(l_popdata) + .reset_index(drop=True) + .assign(year=lambda x: x.year.astype(int)) + ) + + # map s_runs, archs, updated_urts, and par_var to a tuple + # then map the tuple to the process_data function + # then convert the map object to a list + inputs_cool = product( + s_runs.itertuples(), + vers_archs, + updated_urts, + par_var.itertuples(), + varlist_cool, + ) + inputs_heat = product( + s_runs.itertuples(), + vers_archs, + updated_urts, + par_var.itertuples(), + varlist_heat, + ) + + def aggregate_ncfile(args: tuple) -> xr.Dataset: + s_run, arch, urt, parset, varname = args + str_varname = str(varname) + + print( + f"Opening {varname} data for: {s_run.scen}_{s_run.year}_{s_run.clim}_{arch}_{urt}_{parset.Index}" + ) + suff = ( + str(s_run.scen) + "_" + str(s_run.year) + "_" + str(s_run.clim) + "_" + arch + ) + + # if urt is "urban" or "rural" then load the data from the file + # otherwise if urt is "total" then add the data from the "urban" and "rural" files + if (urt == "urban") or (urt == "rural"): + varname = xr.open_dataset( + os.path.join( + finalmaps_path, + suff + "_" + str(parset.Index) + "_" + varname + ".nc", + ) + )[urt] + + elif urt == "total": + varname = ( + xr.open_dataset( + os.path.join( + finalmaps_path, + suff + "_" + str(parset.Index) + "_" + varname + ".nc", + ) + )["urban"] + + xr.open_dataset( + os.path.join( + finalmaps_path, + suff + "_" + str(parset.Index) + "_" + varname + ".nc", + ) + )["rural"] + ) + + # If varname is Nd or Nf, then take the mean. Otherwise, take the sum + if str_varname in ["Nd", "Nf"]: + # Group varname by raster index and take the mean + print("...Aggregating data by raster") + agg_ras_month = ( + varname.groupby(raster).mean().to_dataframe(name="value").reset_index() + ) + + # Group by gaul_lvl0 and take the mean + print(".....Aggregating data by gaul_lvl0") + agg_gaul_lvl0 = ( + agg_ras_month.groupby("gaul_lvl0")["value"] + .agg(lambda x: x.mean() / 2) + .reset_index() + ) + else: + # Group varname by raster index and sum + print("...Aggregating data by raster") + agg_ras_month = ( + varname.groupby(raster).sum().to_dataframe(name="value").reset_index() + ) + + # Group by gaul_lvl0 and sum + print(".....Aggregating data by gaul_lvl0") + agg_gaul_lvl0 = ( + agg_ras_month.groupby("gaul_lvl0")["value"].sum().reset_index() + ) + + # Add columns for: + # - s_run.scen + # - s_run.year + # - s_run.clim + # - arch + # - urt + # - varname + df = agg_gaul_lvl0.assign( + gcm=str(config.gcm), + scenario=str(config.rcp), + scen=str(s_run.scen), + year=str(s_run.year), + clim=str(s_run.clim), + arch=str(arch), + urt=str(urt), + par_var=str(parset.Index), + name_run=str(parset.name_run), + varname=str_varname, + ) + + return df + + if config.cool == 1: + list_cool = list(map(aggregate_ncfile, inputs_cool)) + df_agg = ( + pd.concat(list_cool) + .reset_index(drop=True) + .merge(dfd, left_on="gaul_lvl0", right_on="ISONUM") + ) + if config.heat == 1: + list_heat = list(map(aggregate_ncfile, inputs_heat)) + df_heat = ( + pd.concat(list_heat) + .reset_index(drop=True) + .merge(dfd, left_on="gaul_lvl0", right_on="ISONUM") + ) + # Add df_heat to df_agg + df_agg = df_agg.append(df_heat, ignore_index=True) + + print("Completed aggregating raster data! Now processing and saving...") + + # Merge df_agg with pop_agg + df_agg = df_agg.assign(year=lambda x: x.year.astype(int)).merge( + pop_agg, + left_on=["gaul_lvl0", "urt", "year"], + right_on=["gaul_lvl0", "urt", "year"], + ) + + # Convert from long to wide on varname + df_agg_wide = df_agg.pivot_table( + index=[ + "gaul_lvl0", + "ADM0_CODE", + "ADM0_NAME", + "CONTINENT", + "FAO_CODE", + "ISO3", + "UN_CODE", + "UN_REGION", + "ISO", + "GLOBAL_SOUTH", + "REGION_GEA", + "gcm", + "scenario", + "scen", + "population_scenario", + "year", + "clim", + "arch", + "urt", + "par_var", + "name_run", + "popsum", + ], + columns="varname", + values="value", + ).reset_index() + + # Calculate population-averaged degree days + if config.cool == 1: + df_agg_wide = df_agg_wide.assign(vdd_c_avg=lambda x: x.vdd_c_popwei / x.popsum) + if config.heat == 1: + df_agg_wide = df_agg_wide.assign(vdd_h_avg=lambda x: x.vdd_h_popwei / x.popsum) + + # Drop and rename columns + df_agg_wide = df_agg_wide.drop( + columns=["ADM0_CODE", "CONTINENT", "FAO_CODE", "ISO3", "UN_CODE", "UN_REGION"] + ).rename(columns={"gaul_lvl0": "id", "ADM0_NAME": "NAME"}) + + # Save to excel and csv + df_agg_wide.to_excel( + os.path.join( + iso_path, + "ISO_agg_data_" + config.vstr + ".xlsx", + ) + ) + df_agg_wide.to_csv( + os.path.join( + iso_path, + "ISO_agg_data_" + config.vstr + ".csv", + ), + index=False, + ) + + end = datetime.datetime.now() + print( + "Done! Total time to aggregate variables and process ISO tables: " + + str(end - start) + ) + + +def create_climate_outputs(config: "Config", start_time: datetime.datetime): + out_path = os.path.join(config.project_path, "out", "version", config.vstr) + archetype_path = os.path.join(out_path, "rasters") + save_path = os.path.join(out_path, "VDD_ene_calcs") + + output_path_vdd = os.path.join( + save_path, + config.gcm, + config.rcp, + ) + + if not os.path.exists(output_path_vdd): + os.makedirs(output_path_vdd) + + vers_archs = get_archs(config) + par_var = load_parametric_analysis_data(config) + + for clim in config.clims: + print(f"Starting {clim} ######################") + + ## ============================================================================= + # Mean air temperature + ## ============================================================================= + + # output_folder_scen = output_folder+scen+'\\' + years_clim = config.yeardic[clim] + # << this selects the correct years. + # But when testing you’ll want to use just say 3 years data, + # so set years manually, e.g. + # years_clim = yeardic6p0[str(s_run.clim)] + + # this will be the shortcut line to make the testing faster (2 years data) + if config.testing_mode == 1: + years_clim = ( + years_clim[0], + str(int(years_clim[0]) + 1), + ) + + nyrs_clim = int(years_clim[1]) - int(years_clim[0]) + 1 + + if str(clim) == "hist": + isi_folder = config.isimip_ewemib_path + filestr = config.climate_filestr_hist + else: + isi_folder = config.isimip_bias_adj_path + filestr = config.climate_filestr_future + + filepath = os.path.join( + isi_folder, config.rcpdata, config.gcm, f"{filestr.lower()}*{config.endstr}" + ) + if config.rcp == "rcp26": + dst = xr.open_mfdataset( + filepath, + chunks={"lon": config.chunk_size}, + concat_dim="time", + use_cftime=True, + ) # Setting for RCP2.6 + else: + dst = xr.open_mfdataset( + filepath, + chunks={"lon": config.chunk_size}, + ) # , concat_dim='time' ) # Setting for RCP6.0 + + dst_crop = dst.sel(time=slice(years_clim[0], years_clim[1])) + t_out_ave = dst_crop[config.davar].astype("float32") - 273.16 + t_out_ave = t_out_ave.transpose("lat", "lon", "time") + + t_oa_gbm = t_out_ave.groupby("time.month") + + # ============================================================================= + # %% Solar Irradiation - Building parameters + # ============================================================================= + # Fixed values + # arb_fan = 2 + # t_sp_h = np.int8(20) # Indoor setpoint temperature for heating + # + # P_f = 55 # power of fan (W) + # area_fan = 25 # Numer of m2 per fan + # + # gains = np.int8(50) # Heat gains + # gridshape2 = (360,720) + # + # 3D - time variable + # i_sol = xr.open_dataarray('P:\\watxene\\Wat-Data\\ISI-MIP2b\\multi-GCM_input\\historical\\HadGEM2-ES\\rsds_day_HadGEM2-ES_historical_r1i1p1_EWEMBI_19710101-19801231.nc4') + # Vertical irradiation + # i_sol_v = xr.open_dataarray(input_folder+'CERES_vert_irrad_2001-13_avg.nc') #Values in daily Wh/m2 + i_sol_v = xr.open_dataarray( + os.path.join(config.dle_path, "EWEMBI_vert_irrad_1980-2009_avg.nc") + ) # Values in daily Wh/m2 + + # Horizontal irradiation + i_sol_h = xr.open_dataarray( + os.path.join(config.dle_path, "EWEMBI_horiz_irrad_1980-2009_avg.nc") + ) # Values in daily Wh/m2 + + # i_sol = i_sol.sel(time=slice(years_clim[0],years_clim[1])) + + # ============================================================================= + # Start Degree Days calculations + # ============================================================================= + + for arch in vers_archs: + # Read in archetype parameters + if config.arch_setting == "regional": + xr.open_dataset( + os.path.join( + archetype_path, + "arch_map_" + config.arch_setting + "_" + arch + ".nc", + ) + ) + # elif floor_setting == 'per_cap': + # floorarea = xr.open_dataset(input_folder3+'floor_area_map_'+floor_setting+'_'+suff+'.nc') + + dfa = pd.DataFrame( + columns=["H_v_cl", "H_v_op", "H_tr"], index=par_var.index + ) + # suff = arch+'_'+clim + # + # suff2 = str(s_run.scen)+'_'+str(s_run.year) #suffix: only scen and year + # #suff3 = str(s_run.scen)+'_'+str(s_run.year)+'_'+arch #suffix: scen, year and arch + + for parset in par_var.itertuples(): + # parset = par_var.iloc[0] # Placeholder select first row + + suff = clim + "_" + arch # suffix + # suff = clim+'_'+arch+'_'+str(parset.name_run) #suffix + suff1 = arch # only arch (for imports arch data) + + print("Starting: " + suff + "_" + str(parset.name_run)) + if config.cool == 1: + cop = parset.cop + t_sp_c = np.int8( + parset.t_sp_c + ) # Indoor setpoint temperature for cooling -> 26 + t_sp_c_max = np.int8( + parset.t_sp_c_max + ) # Indoor max temperature when fans are on (°C) -> 28 + + f_c = parset.f_c + f_f = parset.f_f + + if config.heat == 1: + t_sp_h = np.int8( + parset.t_sp_h + ) # Indoor max temperature when fans are on (°C) -> 20 + eff = parset.eff # Efficiency heating system + + f_h = parset.f_h + + # # Archetypes should be in parset to execute this (OLD CODE) + # if arch_setting == 'fixed': + # au = parset.arch_u + # ar = parset.arch_r + # al = [ar, au] + + # print(sddf) + + if config.runsdd == 1: + # ============================================================= + # Simple CDD calculation + # ============================================================= + + for bal_temp in config.bal_temps: + with ProgressBar(): + print("Stage 3 - Simple HDDCDD - cooling") + print("Balance temp " + str(bal_temp) + "C") + sdd_c = calc_SCDD_m(t_out_ave, bal_temp) + sdd_c = sdd_c.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + sdd_c.attrs = { + "name": "sdd_c", + "description": "Simple cooling degree days", + "units": "degC", + "short name": "CDD.", + # 'urt': urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + "bal_temp": str(bal_temp), + } + sdd_c = sdd_c.to_dataset(name="sdd_c") + encoding = {"sdd_c": config.comp} + # fname = suff+'_'+str(parset.Index)+'_sdd_c_'+str(bal_temp)+'.nc' + fname = suff + "_sdd_c_" + str(bal_temp) + ".nc" + filestr = os.path.join(output_path_vdd, fname) + sdd_c.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + sdd_c = xr.open_dataarray(filestr) + + # ============================================================== + # Simple HDD calculation + # ============================================================== + + for bal_temp in config.bal_temps: + with ProgressBar(): + print("Stage 3 - Simple HDDCDD - heating") + print("Balance temp " + str(bal_temp) + "C") + sdd_h = calc_SHDD_m(t_out_ave, bal_temp) + sdd_h = sdd_h.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + sdd_h.attrs = { + "name": "sdd_h", + "description": "Simple heating degree days", + "units": "degC", + "short name": "HDD.", + # 'urt': urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + "bal_temp": str(bal_temp), + } + sdd_h = sdd_h.to_dataset(name="sdd_h") + encoding = {"sdd_h": config.comp} + # fname = suff+'_'+str(parset.Index)+'_sdd_h_'+str(bal_temp)+'.nc' + fname = suff + "_sdd_h_" + str(bal_temp) + ".nc" + filestr = os.path.join(output_path_vdd, fname) + sdd_h.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + sdd_h = xr.open_dataarray(filestr) + + for urt in config.urts: + if config.cool == 1: + # AC penetration values + if urt == "urban": + pass + elif urt == "rural": + pass + + area_env = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_area_env.nc") + )[urt] # Area of the building envelope + gl_perc = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_gl_perc.nc") + )[urt] # 0.1 + vol = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_vol.nc") + )[urt] # 3 + xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_fl_cnd.nc") + )[urt] # 1 + u_val = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_u_val.nc") + )[urt] # 2.4 # Average U-value of building envelope # float + ach_cl = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_ach_cl.nc") + )[urt] # 0.5 + ach_op = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_ach_op.nc") + )[urt] # 1.5 # TAB - ACH (1/h) - open windows + gn_int = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_gn_int.nc") + )[urt] # 5 # FIX Internal gains (W/m2) + gl_g = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_gl_g.nc") + )[urt] # 0.85 # TAB g-value for glazing + gl_sh = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_gl_sh.nc") + )[urt] # 0.9 # TAB shading coeff for openings + roof_area = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_roof_area.nc") + )[urt] + roof_abs = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_roof_abs.nc") + )[urt] + u_roof = xr.open_dataset( + os.path.join(archetype_path, "arch_" + suff1 + "_u_roof.nc") + )[urt] + + # ============================================================================== + # Heat gains functions + # ============================================================================== + + if config.solar_gains == "VERT": + # Solar gains - From windows only + with ProgressBar(): + print("Stage 3 - calc gn_sol") + gn_sol = calc_gn_sol(i_sol_v, gl_perc, gl_g, gl_sh) + gn_sol = gn_sol.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + gn_sol.attrs = { + "name": "gn_sol", + "description": "Solar gains - Windows", + "units": "W/m2", + "short name": "Solar gains - Windows", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + gn_sol = gn_sol.to_dataset(name="gn_sol") + encoding = {"gn_sol": config.comp} + fname = ( + suff + + "_" + + str(parset.Index) + + "_gn_sol_" + + urt + + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + gn_sol.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + gn_sol = xr.open_dataarray(filestr).load() + + elif config.solar_gains == "TOT": + # Solar gains - Total + with ProgressBar(): + print("Stage 3 - calc gn_sol") + gn_sol = calc_gn_sol_tot( + i_sol_v, + gl_perc, + gl_g, + gl_sh, + i_sol_h, + roof_area, + roof_abs, + u_roof, + ) + gn_sol = gn_sol.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + gn_sol.attrs = { + "name": "gn_sol", + "description": "Solar gains", + "units": "W/m2", + "short name": "Solar gains", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + gn_sol = gn_sol.to_dataset(name="gn_sol") + encoding = {"gn_sol": config.comp} + fname = ( + suff + + "_" + + str(parset.Index) + + "_gn_sol_" + + urt + + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + gn_sol.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + gn_sol = xr.open_dataarray(filestr).load() + + elif config.solar_gains == "HOR": + # Solar gains - Total + with ProgressBar(): + print("Stage 3 - calc gn_sol") + gn_sol = calc_gn_sol_h(i_sol_h, roof_area, roof_abs, u_roof) + gn_sol = gn_sol.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + gn_sol.attrs = { + "name": "gn_sol", + "description": "Solar gains", + "units": "W/m2", + "short name": "Solar gains", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + gn_sol = gn_sol.to_dataset(name="gn_sol") + encoding = {"gn_sol": config.comp} + fname = ( + suff + + "_" + + str(parset.Index) + + "_gn_sol_" + + urt + + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + gn_sol.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + gn_sol = xr.open_dataarray(filestr).load() + # + # #Solar gains - From roof only + # with ProgressBar(): + # print('Stage 3 - calc gn_sol_h') + # gn_sol_h = calc_gn_sol_h(i_sol_h, roof_area, roof_abs, u_roof) + # gn_sol_h = gn_sol_h.chunk(chunks={'lon':chunksize2}) + # # t_out_ave = t_out_ave.chunk(chunks={'lon':chunksize2}) + # print('chunked') + # # vdd_c = calc_vdd_c(t_out_ave, t_bal_c, arb_fan=2) # Not needed any more + # print('out') + # gn_sol_h.attrs = {'name':'gn_sol_h', + # 'description':'Solar gains - Roof', + # 'units':'W/m2', + # 'short name': 'Solar gains - Roof', + # 'urt': urt, + # 'name_run': parset.name_run, + # 'id_run': str(parset.Index)} + # gn_sol_h = gn_sol_h.to_dataset(name='gn_sol_h') + # encoding = {'gn_sol_h': comp} + # fname = suff+'_'+str(parset.Index)+'_gn_sol_h_'+urt+'.nc' + # filestr = output_folder2+fname + # gn_sol_h.to_netcdf(filestr, encoding=encoding) + # print(datetime.datetime.now()-start) + # gn_sol_h = xr.open_dataarray(filestr).load() + # + # #Solar gains - From windows only + # with ProgressBar(): + # print('Stage 3 - calc gn_sol_v') + # gn_sol_v = calc_gn_sol_v(i_sol_v, gl_perc, gl_g, gl_sh) + # gn_sol_v = gn_sol_v.chunk(chunks={'lon':chunksize2}) + # # t_out_ave = t_out_ave.chunk(chunks={'lon':chunksize2}) + # print('chunked') + # # vdd_c = calc_vdd_c(t_out_ave, t_bal_c, arb_fan=2) # Not needed any more + # print('out') + # gn_sol_v.attrs = {'name':'gn_sol_v', + # 'description':'Solar gains - Windows', + # 'units':'W/m2', + # 'short name': 'Solar gains - Windows', + # 'urt': urt, + # 'name_run': parset.name_run, + # 'id_run': str(parset.Index)} + # gn_sol_v = gn_sol_v.to_dataset(name='gn_sol_v') + # encoding = {'gn_sol_v': comp} + # fname = suff+'_'+str(parset.Index)+'_gn_sol_v_'+urt+'.nc' + # filestr = output_folder2+fname + # gn_sol_v.to_netcdf(filestr, encoding=encoding) + # print(datetime.datetime.now()-start) + # gn_sol_v = xr.open_dataarray(filestr).load() + + # ============================================================================== + # Heat transfer functions + # ============================================================================== + + with ProgressBar(): + H_v_cl = calc_H_v_cl(vol, ach_cl) + if config.verbose: + print("Stage 3 - calc_H_v_cl") + print(datetime.datetime.now() - start_time) + # H_v_cl = xr.open_dataarray(output_folder2+'H_v_cl_'+urt+'.nc').load() + + with ProgressBar(): + H_v_op = calc_H_v_op(vol, ach_op) + if config.verbose: + print("Stage 3 - calc_H_v_op") + print(datetime.datetime.now() - start_time) + # H_v_op = xr.open_dataarray(output_folder2+'H_v_op_'+urt+'.nc').load() + + with ProgressBar(): + H_tr = calc_H_tr(u_val, area_env) + if config.verbose: + print("Stage 3 - calc_H_tr") + print(datetime.datetime.now() - start_time) + # H_tr = xr.open_dataarray(output_folder2+'H_tr_'+urt+'.nc').load() + dfa.loc[parset.Index, :] = [H_v_cl, H_v_op, H_tr] + + # ============================================================================== + # COOLING CALCULATIONS + # ============================================================================== + + if config.cool == 1: + # ============================================================================== + # Variable CDD functions + # ============================================================================== + with ProgressBar(): + print("t_bal_c") + t_bal_c = calc_t_bal_c( + t_sp_c, gn_int, gn_sol, H_tr, H_v_cl + ).astype("float32") # , x_diff0 + t_bal_c = t_bal_c.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + t_bal_c.attrs = { + "name": "t_bal_c", + "description": "Balance (base) temperature", + "units": "degC", + "short name": "Balance temp.", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + t_bal_c = t_bal_c.to_dataset(name="t_bal_c") + encoding = {"t_bal_c": config.comp} + fname = ( + suff + + "_" + + str(parset.Index) + + "_t_bal_c_" + + urt + + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + t_bal_c.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + t_bal_c = xr.open_dataarray(filestr) + + # ============================================================================= + # t_max_c + # ============================================================================= + with ProgressBar(): + print("Calc_t_max_c") + t_max_c = calc_t_max_c( + t_sp_c_max, gn_int, gn_sol, H_tr, H_v_op + ) # , x_diff0) + t_max_c.attrs = { + "name": "t_max_c", + "description": "This returns the max temperature", + "units": "degC", + "short name": "Max temp.", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + + t_max_c = t_max_c.to_dataset(name="t_max_c") + encoding = {"t_max_c": config.comp} + fname = ( + suff + + "_" + + str(parset.Index) + + "_t_max_c_" + + urt + + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + t_max_c.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + t_max_c = xr.open_dataarray(filestr).load() + # ============================================================================= + # Nd - only this one uses daily + # ============================================================================= + # Days per month over t_max_c + with ProgressBar(): + print("Calc Nd") + Nd = calc_Nd(t_out_ave, t_max_c, nyrs_clim) + Nd.attrs = { + "name": "Nd", + "description": "This returns the days per month over t_max_c", + "units": "days/month", + "short name": "Days > t_max_c", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + Nd = Nd.to_dataset(name="Nd") + encoding = {"Nd": config.comp} + fname = ( + suff + "_" + str(parset.Index) + "_Nd_" + urt + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + Nd.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + Nd = xr.open_dataarray(filestr) + + # ============================================================================= + # Nf - only this one uses daily + # ============================================================================= + # Days per month over t_max_c + with ProgressBar(): + print("Calc Nf") + Nf = calc_Nf(t_out_ave, t_bal_c, nyrs_clim) + Nf.attrs = { + "name": "Nf", + "description": "This returns the days per month above t_bal_c", + "units": "days/month", + "short name": "Days > t_bal_c", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + Nf = Nf.to_dataset(name="Nf") + encoding = {"Nf": config.comp} + fname = ( + suff + "_" + str(parset.Index) + "_Nf_" + urt + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + Nf.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + Nf = xr.open_dataarray(filestr) + + # ============================================================================= + # vdd_tmax_c + # ============================================================================= + # Days per month over t_max_c + with ProgressBar(): + print("Calc_vdd_tmax_c") + vdd_tmax_c = calc_vdd_tmax_c(t_oa_gbm, t_max_c) + vdd_tmax_c = vdd_tmax_c.chunk( + chunks={"lon": config.chunk_size} + ) + vdd_tmax_c = ( + vdd_tmax_c.groupby("time.month").sum("time") / nyrs_clim + ) # <<< divide by years + vdd_tmax_c.attrs = { + "name": "vdd_tmax_c", + "description": "This returns the sum of variable cooling degree days per month based on Tmax", + "units": "degC", + "short name": "Var. cooling DD", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + vdd_tmax_c = vdd_tmax_c.to_dataset(name="vdd_tmax_c") + encoding = {"vdd_tmax_c": config.comp} + fname = ( + suff + + "_" + + str(parset.Index) + + "_vdd_tmax_c_" + + urt + + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + vdd_tmax_c.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + vdd_tmax_c = xr.open_dataarray(filestr) + + # ============================================================================= + # qctmax + # ============================================================================= + t_bal_c = xr.open_dataarray( + os.path.join( + output_path_vdd, + suff + + "_" + + str(parset.Index) + + "_t_bal_c_" + + urt + + ".nc", + ) + ) + with ProgressBar(): + print("Calc_qctmax") + qctmax = Q_c_tmax( + H_tr, H_v_cl, vdd_tmax_c, t_max_c, t_bal_c, Nd, f_c + ) + qctmax.attrs = { + "name": "qctmax", + "description": "This returns the monthly cooling energy (MJ) based on variable degree days", + "units": "MJ/month", + "short name": "Sensible load", + "AC_hours": str(f_c), + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + + qctmax = qctmax.to_dataset(name="qctmax") + encoding = {"qctmax": config.comp} + fname = ( + suff + + "_" + + str(parset.Index) + + "_qctmax_" + + urt + + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + qctmax.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + t_bal_c.close() + qctmax = xr.open_dataarray(filestr) + + # ============================================================================= + # E_c_ac electricity + # ============================================================================= + # qlat_month = xr.open_dataarray(output_folder2+'qlat_month_'+urt+'.nc') + with ProgressBar(): + print("E_c AC") + E_c_ac = calc_E_c_ac(qctmax, cop) + E_c_ac.attrs = { + "name": "E_c_ac", + "description": "monthly electricity requirement for air conditioning - sensible (MJ)", + "units": "MJ/month", + "short name": "AC energy sens", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + + E_c_ac = E_c_ac.to_dataset(name="E_c_ac") + encoding = {"E_c_ac": config.comp} + fname = ( + suff + + "_" + + str(parset.Index) + + "_E_c_ac_" + + urt + + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + E_c_ac.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + # qlat_month = xr.open_dataarray(output_folder2+'qlat_month_'+urt+'.nc') + with ProgressBar(): + print("E_f fans") + E_c_fan = calc_E_c_fan( + f_f, P_f, Nf, config.area_fan + ) # Where Nf is same as Nd + E_c_fan.attrs = { + "name": "E_c_fan", + "description": "monthly electricity requirement for fans (MJ)", + "units": "MJ/month", + "short name": "Fan energy", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + E_c_fan = E_c_fan.to_dataset(name="E_c_fan") + encoding = {"E_c_fan": config.comp} + fname = ( + suff + + "_" + + str(parset.Index) + + "_E_c_fan_" + + urt + + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + E_c_fan.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + # ============================================================================= + # dfa.to_csv(output_folder2+'constant_vars_out.csv') + # print('Finished!: '+str(parset)) + # print(datetime.datetime.now()-start) + # ============================================================================= + + # ============================================================================== + # HEATING CALCULATIONS + # ============================================================================== + + if config.heat == 1: + # ============================================================================== + # Variable HDD functions + # ============================================================================== + with ProgressBar(): + print("calc_t_bal_h") + t_bal_h = calc_t_bal_h( + t_sp_h, gn_int, gn_sol, H_tr, H_v_cl + ).astype("float32") # , x_diff0 + t_bal_h = t_bal_h.chunk(chunks={"lon": config.chunk_size}) + print("chunked") + t_bal_h.attrs = { + "name": "t_bal_h", + "description": "Balance (base) temperature", + "units": "degC", + "short name": "Balance temp.", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + t_bal_h = t_bal_h.to_dataset(name="t_bal_h") + encoding = {"t_bal_h": config.comp} + fname = ( + suff + + "_" + + str(parset.Index) + + "_t_bal_h_" + + urt + + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + t_bal_h.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + t_bal_h = xr.open_dataarray(filestr) + + # ============================================================================= + # vdd_h + # ============================================================================= + + with ProgressBar(): + print("calc_vdd_h") + vdd_h = calc_vdd_h(t_oa_gbm, t_bal_h) + vdd_h = vdd_h.chunk(chunks={"lon": config.chunk_size}) + vdd_h = ( + vdd_h.groupby("time.month").sum("time") / nyrs_clim + ) # <<< divide by years + vdd_h.attrs = { + "name": "vdd_h", + "description": "This returns the sum of variable heating degree days per month", + "units": "degC", + "short name": "Var. heating DD", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + vdd_h = vdd_h.to_dataset(name="vdd_h") + encoding = {"vdd_h": config.comp} + fname = ( + suff + "_" + str(parset.Index) + "_vdd_h_" + urt + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + vdd_h.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + vdd_h = xr.open_dataarray(filestr) + + # ============================================================================= + # qh + # ============================================================================= + t_bal_h = xr.open_dataarray( + os.path.join( + output_path_vdd, + suff + + "_" + + str(parset.Index) + + "_t_bal_h_" + + urt + + ".nc", + ) + ) + with ProgressBar(): + print("Calc_qh") + qh = Q_h(H_tr, H_v_cl, f_h, vdd_h) + qh.attrs = { + "name": "qh", + "description": "This returns the monthly heating energy (MJ) based on variable degree days", + "units": "MJ/month", + "short name": "Sensible load", + "heating_hours": str(f_h), + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + + qh = qh.to_dataset(name="qh") + encoding = {"qh": config.comp} + fname = ( + suff + "_" + str(parset.Index) + "_qh_" + urt + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + qh.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + qh = xr.open_dataarray(filestr) + + # ============================================================================= + # E_h final energy + # ============================================================================= + # qlat_month = xr.open_dataarray(output_folder2+'qlat_month_'+urt+'.nc') + with ProgressBar(): + print("E_h") + E_h = calc_E_h(qh, eff) + E_h.attrs = { + "name": "E_h", + "description": "monthly final energy for heating (MJ)", + "units": "MJ/month", + "short name": "heating energy", + "urt": urt, + "name_run": parset.name_run, + "id_run": str(parset.Index), + } + + E_h = E_h.to_dataset(name="E_h") + encoding = {"E_h": config.comp} + fname = ( + suff + "_" + str(parset.Index) + "_E_h_" + urt + ".nc" + ) + filestr = os.path.join(output_path_vdd, fname) + E_h.to_netcdf(filestr, encoding=encoding) + print("Saved: " + filestr) + if config.verbose: + print(datetime.datetime.now() - start_time) + # qlat_month = xr.open_dataarray(output_folder2+'qlat_month_'+urt+'.nc') + dfa.to_csv( + os.path.join( + output_path_vdd, suff + "_" + "constant_vars_out.csv" + ) + ) + # print('Finished!: '+suff+'+str(parset)) + # print('Finished!') + print(datetime.datetime.now() - start_time) diff --git a/message_ix_buildings/chilled/functions/__init__.py b/message_ix_buildings/chilled/functions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/message_ix_buildings/chilled/buildings_funcs_grid.py b/message_ix_buildings/chilled/functions/buildings_funcs_grid.py similarity index 100% rename from message_ix_buildings/chilled/buildings_funcs_grid.py rename to message_ix_buildings/chilled/functions/buildings_funcs_grid.py diff --git a/message_ix_buildings/chilled/regression.py b/message_ix_buildings/chilled/functions/regression.py similarity index 99% rename from message_ix_buildings/chilled/regression.py rename to message_ix_buildings/chilled/functions/regression.py index cf06fc6..f49c93d 100644 --- a/message_ix_buildings/chilled/regression.py +++ b/message_ix_buildings/chilled/functions/regression.py @@ -1,6 +1,6 @@ import os -import pandas as pd # type: ignore +import pandas as pd import pyam # type: ignore import statsmodels.formula.api as smf # type: ignore diff --git a/message_ix_buildings/chilled/variable_dicts.py b/message_ix_buildings/chilled/functions/variable_dicts.py similarity index 100% rename from message_ix_buildings/chilled/variable_dicts.py rename to message_ix_buildings/chilled/functions/variable_dicts.py diff --git a/message_ix_buildings/chilled/postprocess/__init__.py b/message_ix_buildings/chilled/postprocess/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/message_ix_buildings/chilled/postprocess.py b/message_ix_buildings/chilled/postprocess/postprocess.py similarity index 98% rename from message_ix_buildings/chilled/postprocess.py rename to message_ix_buildings/chilled/postprocess/postprocess.py index 0a8c1b4..9b061c4 100644 --- a/message_ix_buildings/chilled/postprocess.py +++ b/message_ix_buildings/chilled/postprocess/postprocess.py @@ -1,8 +1,8 @@ import os -import pandas as pd # type: ignore +import pandas as pd -from message_ix_buildings.chilled.config import Config +from message_ix_buildings.chilled.util.config import Config cfg = Config() diff --git a/message_ix_buildings/chilled/preprocess/__init__.py b/message_ix_buildings/chilled/preprocess/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/message_ix_buildings/chilled/preprocess/archetypes.py b/message_ix_buildings/chilled/preprocess/archetypes.py new file mode 100644 index 0000000..9dbf41b --- /dev/null +++ b/message_ix_buildings/chilled/preprocess/archetypes.py @@ -0,0 +1,157 @@ +""" +Create buildings archetypes maps using specified inputs +""" + +import datetime +import os +from itertools import product + +import numpy as np +import xarray as xr +from functions.variable_dicts import VARS_ARCHETYPES # type: ignore +from preprocess.message_raster import create_message_raster # type: ignore + +from message_ix_buildings.chilled.util.config import Config # type: ignore +from message_ix_buildings.chilled.util.util import ( + get_archs, + read_arch_inputs_df, + read_arch_reg_df, +) + + +def create_archetypes(config: "Config"): + out_path = os.path.join(config.project_path, "out", "version") + archetype_path = os.path.join(out_path, config.vstr, "rasters") + + # if archetypes folder does not exist, create it + if not os.path.exists(archetype_path): + os.makedirs(archetype_path) + + # get raster file and message map + country_ras, reg_ras, map_reg, iso_attrs = create_message_raster(config) + + # get archs + vers_archs = get_archs(config) + + # save MESSAGE regions map + msg_file = "map_reg_MESSAGE_" + config.node + ".nc" + map_reg.to_netcdf(os.path.join(archetype_path, msg_file)) + print( + "- Saved MESSAGE and raster map data to " + + os.path.join( + archetype_path, + msg_file, + ) + ) + + for arch in vers_archs: + arch_reg = read_arch_reg_df(config, arch) + + # Create map of archetypes based on MESSAGE regions raster + arch_map = xr.Dataset( + { + "urban": reg_ras.MESSAGE11.copy(deep=True), + "rural": reg_ras.MESSAGE11.copy(deep=True), + } + ) + + for row in arch_reg.itertuples(): + arch_map["urban"].values[map_reg == row.RegNum] = float(row.urban) + arch_map["rural"].values[map_reg == row.RegNum] = float(row.rural) + + arch_map = arch_map.astype(float) + + # TODO: NOT WORKING with integers!! + for urt in config.urts: + arch_map[urt].values[arch_map[urt] < 0] = np.nan + + # % Write out to netcdf + + arch_map.attrs = { + "title": "Archetype IDs by region", + "authors": "Edward Byers & Alessio Mastrucci", + "date": str(datetime.datetime.now()), + "institution": "IIASA Energy Program", + "contact": "byers@iiasa.ac.at; mastrucc@iiasa.ac.at", + "arch_setting": config.arch_setting, + } + + encoding = {var: config.comp for var in arch_map.data_vars} + + arch_file = "arch_map_" + config.arch_setting + "_" + arch + ".nc" + arch_map.to_netcdf( + os.path.join( + archetype_path, + arch_file, + ), + encoding=encoding, + ) + + print( + "-- Saved archetype map to " + + os.path.join( + archetype_path, + arch_file, + ) + ) + + +def create_archetype_variables(config: "Config"): + out_path = os.path.join(config.project_path, "out", "version") + archetype_path = os.path.join(out_path, config.vstr, "rasters") + + # get archs + vers_archs = get_archs(config) + + def map_archetype_variables(args): + arch_setting, arch, varname = args + + print( + "Creating archetype map for: " + arch_setting + " " + arch + " " + varname + ) + + # read in input files + arch_inputs = read_arch_inputs_df(config, arch) + + # read in relevant archetype raster + map = xr.open_dataset( + os.path.join( + archetype_path, "arch_map_" + arch_setting + "_" + arch + ".nc" + ) + ) + + # print(".....Writing to netCDF") + for urt in config.urts: + for index, row in arch_inputs.iterrows(): + map[urt].values[map[urt] == row["id"]] = float(row[varname]) + map[urt].values[map[urt] == -1] = np.nan + + map.attrs = { + "title": "map_" + varname, + "authors": "Edward Byers & Alessio Mastrucci", + "date": str(datetime.datetime.now()), + "institution": "IIASA Energy Program", + "contact": "byers@iiasa.ac.at; mastrucc@iiasa.ac.at", + "arch_setting": arch_setting, + } + + encoding = {var: config.comp for var in map.data_vars} + + # save archetype variables maps to netcdf + filename = "arch_" + arch + "_" + varname + ".nc" + + map.to_netcdf( + os.path.join(archetype_path, filename), + encoding=encoding, + ) + + print( + ".......Completed writing to file: " + + os.path.join(archetype_path, filename) + ) + + # create archetype variables maps + + func_inputs = product([config.arch_setting], vers_archs, VARS_ARCHETYPES) + + list(map(map_archetype_variables, func_inputs)) diff --git a/message_ix_buildings/chilled/preprocess/message_raster.py b/message_ix_buildings/chilled/preprocess/message_raster.py new file mode 100644 index 0000000..60b3c17 --- /dev/null +++ b/message_ix_buildings/chilled/preprocess/message_raster.py @@ -0,0 +1,127 @@ +""" +Create raster of MESSAGE regions for CHILLED with specified nodes +""" + +import datetime +import os + +import numpy as np +import pandas as pd +import xarray as xr + +from message_ix_buildings.chilled.util.config import Config + + +def create_message_raster(config: "Config"): + """ + Process global raster into MESSAGE regions + + Parameters + ---------- + config : .Config + The function responds to, or passes on to other functions, the fields: + :attr:`~.Config.dle_path` and + :attr:`~.Config.node`, + + Returns + ------- + country_ras : xarray.DataArray + Raster of countries + reg_ras : xarray.Dataset + Raster of regions + map_reg : xarray.DataArray + Map of regions + iso_attrs : pd.DataFrame + ISO attributes in a dataframe + + """ + input_path = os.path.join(config.dle_path) + + if config.node == "R11": + msgregions = pd.read_excel( + config.message_region_file, + sheet_name="regional definition", + ) + + # Country raster + country_ras = xr.open_dataarray( + os.path.join(input_path, "gaul_lvl0_hybrid_05_3.nc") + ) + + country_ras.values = country_ras.values.astype(float) + country_ras.values[country_ras == -1] = np.nan + + iso_attrs = pd.DataFrame([country_ras.attrs]).T.rename(columns={0: "ISO"}) + + # Region raster + reg_ras = xr.Dataset({"MESSAGE11": country_ras.copy(deep=True)}) + reg_ras["ISO"] = country_ras.copy(deep=True) + + for row in iso_attrs.itertuples(): + code = row.ISO # get country ISO code + regval = msgregions.loc[msgregions.iso_code == code, "RegNum"] + if len(regval.values) != 0: + reg_ras.MESSAGE11.values[ + country_ras.values == float(str(row.Index)) + ] = regval + else: + print(row.Index) + print() + + # % manual post process for pixels with the fill value + # Latin america + tarr = reg_ras.MESSAGE11.sel(lat=slice(25.25, -55.25), lon=slice(-180, -21)) + tarr.values[tarr.values < -10] = 5 + reg_ras.MESSAGE11.sel( + lat=slice(25.25, -55.25), lon=slice(-180, -21) + ).values = tarr + + # Svalbard etc + tarr = reg_ras.MESSAGE11.sel(lat=slice(84, 55), lon=slice(-30, 45)) + tarr.values[tarr.values < -10] = 11 + reg_ras.MESSAGE11.sel(lat=slice(84, 55), lon=slice(-30, 45)).values = tarr + + # SSA etc + tarr = reg_ras.MESSAGE11.sel(lat=slice(24, -55), lon=slice(-30, 75)) + tarr.values[tarr.values < -10] = 1 + reg_ras.MESSAGE11.sel(lat=slice(24, -55), lon=slice(-30, 75)).values = tarr + + # other pacific Asia + tarr = reg_ras.MESSAGE11.sel(lat=slice(25, -55), lon=slice(90, 180)) + tarr.values[tarr.values < -10] = 9 + reg_ras.MESSAGE11.sel(lat=slice(25, -55), lon=slice(90, 180)).values = tarr + + # british Indian Ocean territory to South ASIA + tarr = reg_ras.MESSAGE11.sel(lat=slice(0, -10), lon=slice(65, 75)) + tarr.values[tarr.values < -10] = 10 + reg_ras.MESSAGE11.sel(lat=slice(0, -10), lon=slice(65, 75)).values = tarr + + # St Miquelon island in Canada? + tarr = reg_ras.MESSAGE11.sel(lat=slice(48, 44), lon=slice(-60, -50)) + tarr.values[tarr.values < -10] = 10 + reg_ras.MESSAGE11.sel(lat=slice(48, 44), lon=slice(-60, -50)).values = tarr + + # Midway atoll + tarr = reg_ras.MESSAGE11.sel(lat=slice(80, 20), lon=slice(-180, -150)) + tarr.values[tarr.values < -10] = 10 + reg_ras.MESSAGE11.sel(lat=slice(80, 20), lon=slice(-180, -150)).values = tarr + + reg_ras.MESSAGE11.plot() + + # reg_ras.MESSAGE11.where(reg_ras.MESSAGE11 < -1).plot() # Check if worked.. + + map_reg = reg_ras.MESSAGE11.copy(deep=True) + + # Write out to netcdf + map_reg.attrs = { + "title": "Map MESSAGE R11 regions", + "authors": "Edward Byers & Alessio Mastrucci", + "date": str(datetime.datetime.now()), + "institution": "IIASA Energy Program", + "contact": "byers@iiasa.ac.at; mastrucc@iiasa.ac.at", + } + + return country_ras, reg_ras, map_reg, iso_attrs + + else: + raise TypeError("Only R11 is supported at the moment.") diff --git a/message_ix_buildings/chilled/run_agg.py b/message_ix_buildings/chilled/run_agg.py new file mode 100644 index 0000000..7c472d0 --- /dev/null +++ b/message_ix_buildings/chilled/run_agg.py @@ -0,0 +1,104 @@ +import sys +from argparse import ArgumentParser + +from message_ix_buildings.chilled.core.climate import ( + aggregate_urban_rural_files, + make_vdd_total_maps, + process_construction_shares, + process_country_maps, + process_final_maps, + process_floor_area_maps, + process_iso_tables, +) +from message_ix_buildings.chilled.util.config import Config # type: ignore + + +def parse_arguments(arguments): + """ + + :return: + """ + parser = ArgumentParser(add_help=True) + + parser.add_argument( + "-version", + "--version", + default="ALPS2023", + help="Version of inputs to run. Default: ALPS2023.", + ) + parser.add_argument( + "-gcm", + "--gcm", + default="GFDL-ESM4", + help="GCM to run. Options: GFDL-ESM4, IPSL-CM6A-LR, MPI-ESM1-2-HR, MRI-ESM2-0, UKESM1-0-LL. Default: GFDL-ESM4.", + ) + parser.add_argument( + "-rcp", + "--rcp", + default="baseline", + help="RCP to run. Options: ssp126, ssp370, ssp585, baseline. Default: baseline.", + ) + + # Parse arguments + parsed_arguments = parser.parse_known_args(args=arguments)[0] + + return parsed_arguments + + +def print_arguments(parsed_arguments): + """ + :param parsed_arguments: + + """ + + # Print arguments + print("---------- Parsed arguments ------------") + print("Selected version: " + parsed_arguments.version) + print("Selected GCM: " + parsed_arguments.gcm) + print("Selected RCP scenario: " + parsed_arguments.rcp) + + +def create_config(parsed_arguments): + cfg = Config( + vstr=parsed_arguments.version, + gcm=parsed_arguments.gcm, + rcp=parsed_arguments.rcp, + ) + + return cfg + + +def main(args=None): + if args is None: + args = sys.argv[1:] + + parsed_args = parse_arguments(arguments=args) + + # Run the main function + print_arguments(parsed_arguments=parsed_args) + cfg = create_config(parsed_arguments=parsed_args) + + print("RUNNING aggregate_urban_rural_files()........") + aggregate_urban_rural_files(cfg) + + print("RUNNING make_vdd_total_maps()........") + make_vdd_total_maps(cfg) + + print("RUNNING process_construction_shares()........") + process_construction_shares(cfg) + + print("RUNNING process_floor_area_maps()........") + process_floor_area_maps(cfg) + + print("RUNNING process_country_maps()........") + process_country_maps(cfg) + + print("RUNNING process_final_maps()........") + process_final_maps(cfg) + + print("RUNNING process_iso_tables()........") + process_iso_tables(cfg) + + +if __name__ == "__main__": + main() diff --git a/message_ix_buildings/chilled/run_main.py b/message_ix_buildings/chilled/run_main.py new file mode 100644 index 0000000..365874e --- /dev/null +++ b/message_ix_buildings/chilled/run_main.py @@ -0,0 +1,99 @@ +import datetime +import sys +from argparse import ArgumentParser + +from rich.progress import track # type: ignore + +from message_ix_buildings.chilled.core.climate import ( + aggregate_urban_rural_files, + create_climate_variables_maps, + make_vdd_total_maps, + process_construction_shares, + process_country_maps, + process_final_maps, + process_floor_area_maps, + process_iso_tables, +) +from message_ix_buildings.chilled.util.config import Config # type: ignore + + +def parse_arguments(arguments): + """ + + :return: + """ + parser = ArgumentParser(add_help=True) + + parser.add_argument( + "-version", + "--version", + default="ALPS2023", + help="Version of inputs to run. Default: ALPS2023.", + ) + parser.add_argument( + "-gcm", + "--gcm", + default="GFDL-ESM4", + help="GCM to run. Options: GFDL-ESM4, IPSL-CM6A-LR, MPI-ESM1-2-HR, MRI-ESM2-0, UKESM1-0-LL. Default: GFDL-ESM4.", + ) + parser.add_argument( + "-rcp", + "--rcp", + default="baseline", + help="RCP to run. Options: ssp126, ssp370, ssp585, baseline. Default: baseline.", + ) + + # Parse arguments + parsed_arguments = parser.parse_known_args(args=arguments)[0] + + return parsed_arguments + + +def print_arguments(parsed_arguments): + """ + :param parsed_arguments: + + """ + + # Print arguments + print("---------- Parsed arguments ------------") + print("Selected version: " + parsed_arguments.version) + print("Selected GCM: " + parsed_arguments.gcm) + print("Selected RCP scenario: " + parsed_arguments.rcp) + + +# create climate outputs +def create_config(parsed_arguments): + cfg = Config( + vstr=parsed_arguments.version, + gcm=parsed_arguments.gcm, + rcp=parsed_arguments.rcp, + ) + + return cfg + + +def main(args=None): + if args is None: + args = sys.argv[1:] + + parsed_args = parse_arguments(arguments=args) + + # Run the core functions + start = datetime.datetime.now() + print_arguments(parsed_arguments=parsed_args) + cfg = create_config(parsed_arguments=parsed_args) + + for step in track([cfg], description="Running core functions..."): + (create_climate_variables_maps(step, start),) + (aggregate_urban_rural_files(step),) + (make_vdd_total_maps(step),) + (process_construction_shares(step),) + (process_floor_area_maps(step),) + (process_country_maps(step),) + (process_final_maps(step),) + (process_iso_tables(step),) + + +if __name__ == "__main__": + main() diff --git a/message_ix_buildings/chilled/run_preprocess.py b/message_ix_buildings/chilled/run_preprocess.py new file mode 100644 index 0000000..f4541ca --- /dev/null +++ b/message_ix_buildings/chilled/run_preprocess.py @@ -0,0 +1,67 @@ +import sys +from argparse import ArgumentParser + +from message_ix_buildings.chilled.preprocess.archetypes import ( + create_archetype_variables, + create_archetypes, +) +from message_ix_buildings.chilled.util.config import Config + + +def parse_arguments(arguments): + """ + + :return: + """ + parser = ArgumentParser(add_help=True) + + parser.add_argument( + "-version", + "--version", + default="ALPS2023", + help="Version of inputs to run. Default: ALPS2023.", + ) + + # Parse arguments + parsed_arguments = parser.parse_known_args(args=arguments)[0] + + return parsed_arguments + + +def print_arguments(parsed_arguments): + """ + :param parsed_arguments: + + """ + + # Print arguments + print("---------- Parsed arguments ------------") + print("Selected version: " + parsed_arguments.version) + + +# create climate outputs +def create_config(parsed_arguments): + cfg = Config( + vstr=parsed_arguments.version, + ) + + return cfg + + +def main(args=None): + if args is None: + args = sys.argv[1:] + + parsed_args = parse_arguments(arguments=args) + + # Run the main function + print_arguments(parsed_arguments=parsed_args) + cfg = create_config(parsed_arguments=parsed_args) + create_archetypes(cfg) + print("Archetypes created successfully.") + create_archetype_variables(cfg) + print("Archetype variables created successfully.") + + +if __name__ == "__main__": + main() diff --git a/message_ix_buildings/chilled/user_settings.py b/message_ix_buildings/chilled/user_settings.py deleted file mode 100644 index ff0a1fe..0000000 --- a/message_ix_buildings/chilled/user_settings.py +++ /dev/null @@ -1,38 +0,0 @@ -DICT_USER_SETTINGS = { - "ALE": { - "chunk_size": 30, - "sys_path": "C:\\Users\\mastrucc\\Documents\\cc_ene_dem", - "dle_path": "C:\\Users\\mastrucc.IIASA2003\\IIASA\\DLE - Climate impacts and space conditioning\\Data\\input_data\\", - "isimip_bias_adj_path": "P:\\watxene\\ISIMIP\\ISIMIP3b\\InputData\\climate_updated\\bias-adjusted\\", - "isimip_ewembi_path": "P:\\watxene\\ISIMIP\\ISIMIP2a_hist\\input\\EWEMBI\\", - "message_region_map_file": "P:\\ene.model3\\data\\powerplants\\MESSAGE data\\MESSAGEix_country_region_map.xlsx", - "ar6_snapshot_file": "path\\to\\AR6_Scenarios_Database_World_v1.1.csv", - }, - "ED": { - "chunk_size": 360, - "sys_path": "C:\\github\\cc_ene_dem", - "dle_path": "C:\\Users\\byers\\IIASA\\DLE - Climate impacts and space conditioning\\Data\\input_data", - "isimip_bias_adj_path": "P:\\watxene\\ISIMIP\\ISIMIP3b\\InputData\\climate_updated\\bias-adjusted\\", - "isimip_ewembi_path": "P:\\watxene\\ISIMIP\\ISIMIP2a_hist\\input\\EWEMBI\\", - "message_region_map_file": "P:\\ene.model\\data\\powerplants\\MESSAGE data\\MESSAGEix_country_region_map.xlsx", - "ar6_snapshot_file": "C:\\Users\\byers\\IIASA\\IPCC WG3 Chapter 3 - Documents\\IPCC_AR6DB\\snapshots\\snapshot_ar6_public_v1.1\\uploaded\\AR6_Scenarios_Database_World_v1.1.csv", - }, - "MEAS": { - "chunk_size": 125, - "sys_path": "/Users/meas/iiasagit/cc_ene_dem", - "dle_path": "/Users/meas/Library/CloudStorage/OneDrive-SharedLibraries-IIASA/DLE - Analysis/Climate impacts and space conditioning/Data", - "isimip_bias_adj_path": "/Volumes/mengm.pdrv/watxene/ISIMIP/ISIMIP3b/InputData/climate_updated/bias-adjusted", - "isimip_ewembi_path": "/Volumes/mengm.pdrv/watxene/ISIMIP/ISIMIP2a_hist/input/EWEMBI", - "message_region_map_file": "/Volumes/mengm.pdrv/ene.model/data/powerplants/MESSAGE data/MESSAGEix_country_region_map.xlsx", - "ar6_snapshot_file": "/Users/meas/Documents/data/ar6/1668008312256-AR6_Scenarios_Database_World_v1.1.csv/AR6_Scenarios_Database_World_v1.1.csv", - }, - "MEAS_EBRO": { - "chunk_size": 360, - "sys_path": "H:\\MyDocuments\\repos\\cc_ene_dem", - "dle_path": "D:\\mengm\\IIASA\\DLE - Data", - "isimip_bias_adj_path": "P:\\watxene\\ISIMIP\\ISIMIP3b\\InputData\\climate_updated\\bias-adjusted", - "isimip_ewembi_path": "P:\\watxene\\ISIMIP\\ISIMIP2a_hist\\input\\EWEMBI", - "message_region_map_file": "P:\\ene.model\\data\\powerplants\\MESSAGE data\\MESSAGEix_country_region_map.xlsx", - "ar6_snapshot_file": "D:\\mengm\\IIASA\\DLE - Data\\input_data\\AR6_Scenarios_Database_World\\AR6_Scenarios_Database_World_v1.1.csv", - }, -} diff --git a/message_ix_buildings/chilled/util/__init__.py b/message_ix_buildings/chilled/util/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/message_ix_buildings/chilled/util/config.py b/message_ix_buildings/chilled/util/config.py new file mode 100644 index 0000000..f8ba6cb --- /dev/null +++ b/message_ix_buildings/chilled/util/config.py @@ -0,0 +1,191 @@ +import datetime +from dataclasses import dataclass +from typing import Literal + +import numpy as np + +from message_ix_buildings.chilled.functions.user_settings import DICT_USER_SETTINGS + + +@dataclass +class Config: + """Configuration for :mod:`.message_ix_buildings.chilled`.""" + + #: Select user to set the paths to the project and data directories. + #: + #: One of: "ALE", "ED", "MEAS", "MEAS_EBRO", "MEAS_UNICC". + user: Literal["ALE", "ED", "MEAS", "MEAS_EBRO", "MEAS_UNICC"] = "MEAS_UNICC" + + #: Set the version of the module run. + #: + #: This is used to name the output files and directories. + vstr: str = "ALPS2023" + + #: Select the climate model. + #: + #: One of: "GFDL-ESM4", "IPSL-CM6A-LR", "MPI-ESM1-2-HR", "MRI-ESM2-0", "UKESM1-0-LL" + gcm: Literal[ + "GFDL-ESM4", "IPSL-CM6A-LR", "MPI-ESM1-2-HR", "MRI-ESM2-0", "UKESM1-0-LL" + ] = "GFDL-ESM4" + + #: Select RCP scenario. + #: + #: One of: "ssp126", "ssp370", "ssp585", "baseline". + rcp: Literal["ssp126", "ssp370", "ssp585", "baseline"] = "baseline" + + #: List all possible RCP scenarios. + rcps = ["ssp126", "ssp370", "ssp585", "baseline"] + + #: Set what data to use for the RCP scenario. + #: If rcp is "baseline", then use "ssp126" data. + #: Otherwise, use the data corresponding to the RCP scenario selected. + rcpdata = "ssp126" if rcp == "baseline" else rcp + + #: Select the version of the country data and floor surface. + vstrcntry = "v4" # version string for country data and floor surface + + #: Set paranalysys mode + #: + #: 1 = run entire parametric analysis + #: 0 = run only ref case + paranalysis_mode = 1 # 1 = run entire parametric analysis; 0 = run only ref case + + #: Select whether to run simple (standard) degree days calculation. + #: + #: 1 = run simple (standard) degree days calculation + #: 0 = don't run + runsdd = 0 # 1= run simple (standard) degree days calculation; 0 = don't run + + #: Select whether to run testing mode. + #: + #: 1 = selects only two years for testing + #: 0 = select all years (full calculation) + testing_mode = 0 + + #: Select whether to fix population to SSP2. + popfix = True # If True, fix to SSP2, else.... (see script 4/5) + + #: Select construction setting. + constr_setting = 0 + + #: Select floor setting. One of: + #: + #: - "std_cap": standard capacity + #: - "per_cap": per capita + floor_setting: Literal["std_cap", "per_cap"] = "std_cap" + + #: Select building archetypes setting. One of: + #: + #: - "fixed": fixed values (same for all regions) + #: - "regional": different values by MESSAGE region + arch_setting: Literal["fixed", "regional"] = "regional" + + #: Select urban/rural disaggregations. + #: Multiple options are allowed. Options: + #: + #: - "urban": urban areas + #: - "rural": rural areas + urts = ["urban", "rural"] + + #: Select option whether to have verbose output + verbose = True + + #: Select whether to run cooling calculations. + #: + #: 1 = calculate + #: 0 = skip + cool = 1 + + #: Select whether to run heating calculations. + #: + #: 1 = calculate + #: 0 = skip + heat = 0 + + #: Select solar gain calculation. One of: + #: + #: - "TOT": from windows and roof + #: - "VERT": from windows only + #: - "HOR": from windows only + solar_gains: Literal["TOT", "VERT", "HOR"] = "TOT" + + #: Select temperature variable. One of: + #: + #: - "tas": near-surface air temperature + #: - "twb": wet-bulb temperature + var: Literal["tas", "twb"] = "tas" + + #: Set variable based on temperature variable. + if var == "tas": + davar = "tas" + elif var == "twb": + davar = "twb" + + overwrite = 0 + + #: Spatial resolution + #: Currently only "R11" is supported. + #: TODO: In the future, support "R12". + node: Literal["R11"] = "R11" + + #: Paths settings by user + project_path: str = str(DICT_USER_SETTINGS[user]["project_path"]) + dle_path: str = str(DICT_USER_SETTINGS[user]["dle_path"]) + message_region_file: str = str(DICT_USER_SETTINGS[user]["message_region_map_file"]) + isimip_bias_adj_path: str = str(DICT_USER_SETTINGS[user]["isimip_bias_adj_path"]) + isimip_ewemib_path: str = str(DICT_USER_SETTINGS[user]["isimip_ewembi_path"]) + chunk_size = DICT_USER_SETTINGS[user]["chunk_size"] + + #: NetCDF settings + netcdf4_format = "NETCDF4_CLASSIC" + comp = dict(zlib=True, complevel=5) # Compression between 0 and 9 (highest) + + #: Climate years dictionary settings. + if rcp == "baseline": + yeardic = { + "2015": ("2015", "2020"), + "2020": ("2015", "2020"), + "2030": ("2015", "2020"), + "2040": ("2015", "2020"), + "2050": ("2015", "2020"), + "2060": ("2015", "2020"), + "2070": ("2015", "2020"), + "2080": ("2015", "2020"), + "2090": ("2015", "2020"), + "2100": ("2015", "2020"), + } + else: + yeardic = { + "2015": ("2015", "2020"), + "2020": ("2015", "2025"), + "2030": ("2015", "2045"), + "2040": ("2025", "2055"), + "2050": ("2035", "2065"), + "2060": ("2045", "2075"), + "2070": ("2055", "2085"), + "2080": ("2065", "2095"), + "2090": ("2080", "2100"), + "2100": ("2095", "2100"), + } + + #: Fixed values for buildings settings. + bal_temps = [18.3, 21.1, 26] # [21.1] # For simple cooling degree days + arb_fan = 2 + t_sp_h = np.int8(20) # Indoor setpoint temperature for heating + P_f = 55 # power of fan (W) + area_fan = 25 # Numer of m2 per fan + gridshape2 = (360, 720) + + #: Attributes for netCDF files + y2_attrs_dic = { + "title": "map_area_env", + "authors": "Alessio Mastrucci & Edward Byers", + "date": str(datetime.datetime.now()), + "institution": "IIASA Energy Program", + "contact": "mastrucc@iiasa.ac.at; byers@iiasa.ac.at; ", + "arch_setting": arch_setting, + } + + #: Threshold for number of days (?) + #: TODO: check if this is the correct description. + nd_thresh = 5 diff --git a/message_ix_buildings/chilled/util/util.py b/message_ix_buildings/chilled/util/util.py new file mode 100644 index 0000000..ea7c825 --- /dev/null +++ b/message_ix_buildings/chilled/util/util.py @@ -0,0 +1,142 @@ +import os +from pathlib import Path + +import pandas as pd +from util.config import Config # type: ignore + + +def get_project_root() -> Path: + return Path(__file__).parent.parent.parent + + +def get_archs(config: "Config"): + root_path = get_project_root() + version_path = os.path.join(root_path, "data", "chilled", "version", config.vstr) + + if config.arch_setting == "fixed": + input_file = os.path.join(version_path, "arch_input.xlsx") + + if os.path.exists(input_file): + input_file = os.path.join(version_path, "arch_input.xlsx") + archs = pd.ExcelFile(input_file).sheet_names + + return archs + else: + print( + "Archetypes input file " + + input_file + + " does not exist! Please create file for input." + ) + elif config.arch_setting == "regional": + input_file = os.path.join( + version_path, + "arch_input_reg.xlsx", + ) + + if os.path.exists(input_file): + archs = pd.read_excel(input_file, sheet_name="arch").arch.unique() + + return archs + else: + print( + "Archetypes input file " + + input_file + + " does not exist! Please create file for input." + ) + + +def read_arch_inputs_df(config: "Config", suff: str): + root_path = get_project_root() + version_path = os.path.join(root_path, "data", "chilled", "version", config.vstr) + + if config.arch_setting == "fixed": + input_file = os.path.join(version_path, "arch_input.xlsx") + + if os.path.exists(input_file): + arch_inputs = pd.read_excel(input_file, sheet_name=suff, index_col="id") + + return arch_inputs + else: + print( + "Archetypes input file " + + input_file + + " does not exist! Please create file for input." + ) + elif config.arch_setting == "regional": + input_file = os.path.join( + version_path, + "arch_input_reg.xlsx", + ) + + if os.path.exists(input_file): + arch_inputs = pd.read_excel(input_file, sheet_name="arch") + + return arch_inputs + else: + print( + "Archetypes input file " + + input_file + + " does not exist! Please create file for input." + ) + + +def read_arch_reg_df(config: "Config", arch: str): + root_path = get_project_root() + version_path = os.path.join(root_path, "data", "chilled", "version", config.vstr) + + if config.arch_setting == "regional": + reg_file = os.path.join( + version_path, + "arch_regions.xlsx", + ) + + if os.path.exists(reg_file): + arch_reg = pd.read_excel(reg_file, sheet_name=arch) + return arch_reg + else: + print( + "Regional archetypes input file " + + reg_file + + " does not exist! Please create file for input." + ) + + else: + print("Archetypes are not regional. No regional file to read.") + + +def load_all_scenarios_data(config: "Config"): + root_path = get_project_root() + version_path = os.path.join(root_path, "data", "chilled", "version", config.vstr) + + input_file = os.path.join(version_path, "runs.csv") + + if os.path.exists(input_file): + df = pd.read_csv(input_file, index_col="id") + return df + else: + print( + "Scenarios file " + + input_file + + " does not exist! Please create file for input." + ) + + +def load_parametric_analysis_data(config: "Config"): + root_path = get_project_root() + version_path = os.path.join(root_path, "data", "chilled", "version", config.vstr) + + input_file = os.path.join(version_path, "par_var.csv") + + if os.path.exists(input_file): + df = pd.read_csv(input_file, index_col="id_run") + + if config.paranalysis_mode == 0: + df = df.loc[df.name_run == "ref", :] + + return df + else: + print( + "Parametric analysis data file " + + input_file + + " does not exist! Please create file for input." + ) diff --git a/message_ix_buildings/data/chilled/country/v1.csv b/message_ix_buildings/data/chilled/country/v1.csv new file mode 100755 index 0000000..9f37fb9 --- /dev/null +++ b/message_ix_buildings/data/chilled/country/v1.csv @@ -0,0 +1,197 @@ +REGNUM,ISO,NAME,GLOBAL_SOUTH,REGION_GEA,CDD (Popwtd),GDPpercap2015,AC_penetr,access_elec,slum_pop +106,LSO,Lesotho,1,AFR,121,2708.148539,0.007057831,0.279232388,0.508 +94,KGZ,Kyrgyzstan,1,FSU,135,3237.602937,0.008611505,0.999065552, +152,RWA,Rwanda,1,AFR,337,1715.887074,0.011418056,0.228,0.532 +4,ALB,Albania,0,EEU,309,10971.29252,0.081731497,1, +13,BDI,Burundi,1,AFR,721,748.4152713,0.013895491,0.072520895,0.579 +58,ETH,Ethiopia,1,AFR,704,1533.107632,0.016496607,0.334185905,0.739 +30,CAF,Central African Republic,1,AFR,2308,626.4108725,0.017696637,0.133844233,0.933 +8,ARM,Armenia,0,FSU,160,8195.93365,0.029312546,1,0.144 +2,AFG,Afghanistan,1,SAS,725,1809.016488,0.017816148,0.715,0.627 +10,AUS,Australia,0,PAO,563,43719.50216,0.667499136,1, +11,AUT,Austria,0,WEU,113,44353.87521,0.231362438,1, +12,AZE,Azerbaijan,0,FSU,640,16698.86365,0.322075479,1, +37,COD,Dem. Rep. of the Congo,1,AFR,1921,750.0885772,0.017965046,0.164191647,0.748 +14,BEL,Belgium,0,WEU,86,41722.92186,0.191360952,1, +101,LBR,Liberia,1,AFR,2624,785.2468867,0.018468046,0.138400917,0.657 +113,MDG,Madagascar,1,AFR,1046,1377.168213,0.018475825,0.190350609,0.772 +125,MWI,Malawi,1,AFR,1456,1088.701805,0.018713486,0.108,0.667 +18,BGR,Bulgaria,0,EEU,217,17000.16725,0.17248546,1, +129,NER,Niger,1,AFR,3719,904.5797813,0.01910457,0.166,0.701 +122,MOZ,Mozambique,1,AFR,1981,1118.219536,0.019625672,0.24,0.803 +21,BIH,Bosnia and Herzegovina,0,EEU,133,10932.04871,0.045100697,1, +22,BLR,Belarus,0,FSU,84,17229.55519,0.091236349,1, +174,TJK,Tajikistan,1,FSU,603,2640.58952,0.01979512,0.999973526, +158,SLE,Sierra Leone,1,AFR,2926,1315.973533,0.020955048,0.164683762, +40,COM,Comoros,1,AFR,2018,1413.059277,0.021049141,0.753807144,0.696 +172,TGO,Togo,1,AFR,3244,1349.371568,0.021155963,0.450285454,0.512 +196,ZWE,Zimbabwe,1,AFR,1106,1912.280264,0.021257751,0.337,0.251 +183,UGA,Uganda,1,AFR,1475,1665.949905,0.021444084,0.185,0.536 +68,GNB,Guinea-Bissau,1,AFR,3065,1446.468649,0.021618789,0.140046701,0.823 +67,GMB,Gambia,1,AFR,3115,1568.022914,0.022242681,0.464866638,0.348 +31,CAN,Canada,0,NAM,137,43149.47584,0.264869388,1, +32,CHE,Switzerland,0,WEU,66,57264.1574,0.161173086,1, +16,BFA,Burkina Faso,1,AFR,3658,1596.334538,0.022429188,0.184700813,0.658 +79,HTI,Haiti,1,LAC,2361,1651.228445,0.02247832,0.382211266,0.744 +66,GIN,Guinea,1,AFR,2609,1753.063116,0.023113801,1,0.433 +162,SSD,South Sudan,1,MEA,3577,1808.161714,0.0235528,0.079354277,0.956 +176,TLS,East Timor,1,PAS,2459,1920.150472,0.023968314,0.672815339, +117,MLI,Mali,1,AFR,3702,1919.228421,0.024171765,0.376,0.563 +15,BEN,Benin,1,AFR,3470,1987.167146,0.024541993,0.400334778,0.615 +157,SLB,Solomon Islands,1,PAS,2647,2053.438806,0.024789029,0.551, +134,NPL,Nepal,1,SAS,1442,2314.274881,0.024809729,0.87213623,0.543 +171,TCD,Chad,1,AFR,3424,2047.637179,0.024884187,0.077,0.882 +93,KEN,Kenya,1,AFR,1016,2835.643662,0.025645389,0.416,0.56 +44,CYP,Cyprus,0,WEU,1107,30549.10097,0.841881769,1, +45,CZE,Czech Republic,0,EEU,91,30605.42052,0.190910576,1, +46,DEU,Germany,0,WEU,103,43937.94713,0.216847485,1, +182,TZA,United Republic of Tanzania,1,AFR,1469,2490.957101,0.025928367,0.185,0.507 +193,YEM,Yemen,1,MEA,1286,2641.045829,0.026130823,0.702139053,0.608 +49,DNK,Denmark,0,WEU,24,45458.69715,0.092526348,1, +155,SEN,Senegal,1,AFR,3053,2293.853539,0.026298485,0.605,0.394 +191,VUT,Vanuatu,1,PAS,2036,2806.789686,0.029064691,0.446696129, +121,MNG,Mongolia,1,CPA,61,11411.94211,0.029190579,0.811916275,0.427 +184,UKR,Ukraine,1,FSU,212,7464.939834,0.030552468,1, +17,BGD,Bangladesh,1,SAS,2625,3132.56754,0.031773208,0.682046814,0.551 +47,DJI,Djibouti,1,AFR,3302,3139.273535,0.031983323,0.520257759,0.656 +56,ESP,Spain,0,WEU,448,32291.1552,0.572128521,1, +57,EST,Estonia,0,EEU,31,27549.58137,0.095579082,1, +35,CIV,Cote d'Ivoire,1,AFR,2936,3241.612056,0.032679101,0.640861969,0.56 +59,FIN,Finland,0,WEU,23,38941.7636,0.090387402,1, +36,CMR,Cameroon,1,AFR,2239,3289.064546,0.032688124,0.588651009,0.378 +61,FRA,France,0,WEU,167,37765.75087,0.303053112,1, +195,ZMB,Zambia,1,AFR,1333,3627.202041,0.033022576,0.311,0.54 +63,GBR,United Kingdom,0,WEU,21,38839.16696,0.086989036,1, +64,GEO,Georgia,0,FSU,226,9025.133143,0.044554696,0.999934998, +95,KHM,Cambodia,1,CPA,3300,3290.952454,0.033114883,0.475657387,0.551 +147,PSE,Occupied Palestinian Terr.,1,MEA,959,4339.103693,0.035487757,1, +123,MRT,Mauritania,1,AFR,3732,3601.61435,0.035594033,0.395,0.799 +141,PNG,Papua New Guinea,1,PAS,2092,3866.513529,0.037128157,0.221889343, +65,GHA,Ghana,1,AFR,3261,3929.681044,0.038313522,0.757152786,0.379 +70,GRC,Greece,0,WEU,508,24170.30184,0.524533442,1, +77,HND,Honduras,1,LAC,1696,4311.176397,0.040209805,0.8998171,0.275 +72,GRL,Greenland,0,WEU,,,,1, +154,SDN,Sudan,1,MEA,3683,4290.372249,0.04163877,0.380091553,0.916 +137,PAK,Pakistan,1,SAS,2436,4695.699879,0.045233807,0.935,0.455 +187,UZB,Uzbekistan,1,FSU,906,5700.236028,0.047281906,1, +76,HKG,"China, Hong Kong SAR",0,CPA,1907,53595.24481,0.972987112,1, +131,NIC,Nicaragua,1,LAC,2430,4960.912412,0.048020442,0.811631393,0.455 +78,HRV,Croatia,0,EEU,244,20759.04815,0.272323808,1, +119,MMR,Myanmar,1,PAS,2719,5056.859041,0.049278927,0.605,0.41 +80,HUN,Hungary,0,EEU,225,25034.45073,0.322592051,1, +38,COG,Congo,1,AFR,2448,5542.892982,0.054748212,0.604,0.469 +190,VNM,Viet Nam,1,CPA,2641,5554.858056,0.055058876,1,0.272 +83,IRL,Ireland,0,WEU,4,61543.20777,0.058070329,1, +192,WSM,Samoa,1,PAS,3205,5558.791879,0.055353219,0.999382782, +130,NGA,Nigeria,1,AFR,3087,5670.639443,0.056722283,0.525,0.502 +86,ISL,Iceland,0,WEU,,,,1, +87,ISR,Israel,0,MEA,984,32024.35277,0.822851001,1, +88,ITA,Italy,0,WEU,363,34302.0374,0.509111902,1, +99,LAO,Lao People's Dem. Republic,1,CPA,2136,5755.059505,0.056959904,0.897,0.314 +82,IND,India,1,SAS,2761,5754.064597,0.057645582,0.88,0.24 +91,JPN,Japan,0,PAO,550,37882.98062,0.655437567,1, +92,KAZ,Kazakhstan,0,FSU,416,23522.29052,0.454510614,1, +3,AGO,Angola,1,AFR,1203,6231.067992,0.05800138,0.42,0.555 +111,MAR,Morocco,1,MEA,707,7296.934401,0.060854693,0.995860138,0.131 +24,BOL,Bolivia,1,LAC,1461,6531.519398,0.064625161,0.91522822,0.435 +73,GTM,Guatemala,1,LAC,1053,7292.719104,0.070607826,0.905062943,0.345 +97,KOR,Republic of Korea,0,PAS,538,34177.65447,0.640633059,1, +140,PHL,Philippines,1,PAS,2715,6874.582566,0.073840673,0.8908,0.383 +168,SWZ,Swaziland,1,AFR,996,7758.495563,0.076765288,0.62994545,0.327 +75,GUY,Guyana,1,LAC,2963,7074.207137,0.077310978,0.835683517,0.331 +28,BTN,Bhutan,1,SAS,1032,7743.337996,0.077375656,0.984235229, +90,JOR,Jordan,1,MEA,990,8491.050311,0.089612077,0.999983215,0.129 +159,SLV,El Salvador,1,LAC,2258,7845.157575,0.090453154,0.954,0.289 +23,BLZ,Belize,1,LAC,2547,8061.331831,0.095309455,0.918,0.108 +89,JAM,Jamaica,1,LAC,2264,8095.261867,0.095457224,0.972788849, +25,BRA,Brazil,1,LAC,1665,14666.01817,0.1,0.99710902,0.223 +107,LTU,Lithuania,0,EEU,58,27045.71302,0.134479719,1, +108,LUX,Luxembourg,0,WEU,97,94088.59223,0.208429615,1, +109,LVA,Latvia,0,EEU,42,23018.81611,0.096479666,1, +110,MAC,Macau,0,CPA,,,,1, +33,CHL,Chile,1,LAC,48,22536.61769,0.10155158,0.99714844,0.09 +112,MDA,Republic of Moldova,0,FSU,251,4746.784911,0.018788538,1, +60,FJI,Fiji,1,PAS,2001,8477.644733,0.102643431,0.971194916, +146,PRY,Paraguay,1,LAC,1659,8639.28685,0.104026635,0.99331532, +127,NAM,Namibia,1,AFR,1362,9964.222994,0.132384246,0.507034302,0.332 +116,MKD,TFYR Macedonia,0,EEU,138,12759.8166,0.065256978,1, +53,EGY,Egypt,1,MEA,1428,10095.61017,0.1372239,1,0.106 +118,MLT,Malta,0,WEU,,,,1, +179,TUN,Tunisia,1,MEA,1116,10749.85917,0.147675839,1,0.08 +120,MNE,Montenegro,0,EEU,98,15289.7174,0.077856069,0.999991608, +81,IDN,Indonesia,1,PAS,3012,10367.6953,0.154611223,0.975373674,0.218 +188,VCT,Saint Vincent and the Grenadines,1,LAC,3307,10447.52839,0.157325928,0.994550629, +52,ECU,Ecuador,1,LAC,2086,10749.12887,0.164147412,0.98825883,0.36 +194,ZAF,South Africa,1,AFR,678,12362.58381,0.166792615,0.855,0.23 +139,PER,Peru,1,LAC,971,11767.52174,0.172277415,0.93852179,0.342 +100,LBN,Lebanon,1,MEA,522,13352.71339,0.174377333,1,0.531 +105,LKA,Sri Lanka,1,SAS,2848,11061.84358,0.17712201,0.938899002, +51,DZA,Algeria,1,MEA,900,13724.72385,0.23820818,0.993367081, +39,COL,Colombia,1,LAC,1491,12985.38313,0.239690176,0.98186898,0.131 +50,DOM,Dominican Republic,1,LAC,2073,13371.52499,0.266951881,0.98560364,0.121 +114,MDV,Maldives,1,SAS,3518,13705.00532,0.287866737,0.999940109, +132,NLD,Netherlands,0,WEU,61,46494.36426,0.153146979,1, +133,NOR,Norway,0,WEU,14,64008.28683,0.075521182,1, +175,TKM,Turkmenistan,1,FSU,1207,14992.32314,0.319394584,1, +135,NZL,New Zealand,0,PAO,59,34646.31361,0.147586095,1, +42,CRI,Costa Rica,1,LAC,1871,14914.20675,0.340334716,0.99409804,0.055 +164,SUR,Suriname,1,LAC,3138,14766.79918,0.341559247,0.877446747,0.073 +85,IRQ,Iraq,1,MEA,2278,14928.8864,0.346473364,0.998621826,0.472 +29,BWA,Botswana,1,AFR,1512,15356.45762,0.353570326,0.585287514, +173,THA,Thailand,1,PAS,3116,15236.70646,0.366948938,0.996,0.25 +84,IRN,Iran (Islamic Republic of),1,MEA,1014,16500.90051,0.377280787,0.999750519, +142,POL,Poland,0,EEU,96,25299.97435,0.178685557,1, +185,URY,Uruguay,1,LAC,570,19831.44589,0.426562626,0.9970948, +7,ARG,Argentina,1,LAC,748,19101.29739,0.453799748,0.999952087,0.167 +145,PRT,Portugal,0,WEU,346,26607.83312,0.450801361,1, +62,GAB,Gabon,1,AFR,2600,16836.60591,0.456282675,0.903074722,0.37 +34,CHN,China,1,CPA,879,13569.89153,0.5,1,0.252 +124,MUS,Mauritius,1,AFR,1798,18864.10566,0.559986158,0.987412567, +138,PAN,Panama,1,LAC,2499,20674.29973,0.672683416,0.925548401,0.258 +150,ROU,Romania,0,EEU,209,20545.07714,0.240575252,1, +151,RUS,Russian Federation,0,FSU,170,24516.54995,0.259934235,1, +20,BHS,Bahamas,1,LAC,2401,21081.1124,0.691906054,1, +115,MEX,Mexico,1,LAC,968,16671.91198,0.7,0.99,0.111 +126,MYS,Malaysia,1,PAS,2686,25001.61267,0.849534752,0.999985886, +69,GNQ,Equatorial Guinea,1,AFR,2097,27572.58751,0.898284629,0.674737473,0.662 +156,SGP,Singapore,0,PAS,,,,1, +177,TON,Tonga,1,PAS,2949,31283.45801,0.959427292,0.961754532, +143,PRI,Puerto Rico,1,NAM,2233,35291.80356,0.971034039,1, +136,OMN,Oman,1,MEA,2536,40138.95172,0.987090344,1, +153,SAU,Saudi Arabia,1,MEA,2584,50723.71265,0.992057358,1,0.18 +161,SRB,Serbia,0,EEU,216,13277.80012,0.098156716,0.999827423, +27,BRN,Brunei Darussalam,1,PAS,3006,74600.1643,0.996563081,1, +98,KWT,Kuwait,1,MEA,3008,68476.32504,0.996571565,1, +6,ARE,United Arab Emirates,1,MEA,3052,65975.37555,0.996837326,1, +165,SVK,Slovakia,0,EEU,99,28308.87977,0.196176717,1, +166,SVN,Slovenia,0,EEU,114,29037.74168,0.218919312,1, +167,SWE,Sweden,0,WEU,23,45679.278,0.090836423,1, +149,QAT,Qatar,1,MEA,3226,119749.4285,0.997723159,1, +1,ABW,Aruba,1,LAC,,,,0.952381821, +5,AND,Andorra,,,,,,1, +9,ATG,Antigua & Barbuda,,,,,,0.968262939, +19,BHR,Bahrain,1,MEA,,,,1, +26,BRB,Barbados,1,LAC,,,,1, +41,CPV,Cape Verde,1,AFR,,,,0.902439041, +43,CUB,Cuba,1,LAC,,,,1, +48,DMA,Dominica,,,,,,0.999029694, +54,ERI,Eritrea,1,AFR,,,,0.455133209, +55,ESH,Western Sahara,1,AFR,,,,0, +71,GRD,Granada,,,,,,0.918716888,0.06 +180,TUR,Turkey,0,WEU,403,23388.4813,0.443093808,1,0.119 +74,GUF,French Guiana,1,LAC,,,,0, +96,KNA,Saint Kitts,,,,,,0.999300156, +102,LBY,Libyan Arab Jamahiriya,1,MEA,,,,0.985287628, +103,LCA,St. Lucia,1,LAC,,,,0.971630783,0.119 +104,LIE,Liechtenstein,,,,,,1, +186,USA,United States of America,0,NAM,710,53029.29336,0.74826754,1, +128,NCL,New Caledonia,1,PAS,,,,1, +144,PRK,North Korea,1,CPA,,,,0.374463196, +148,PYF,French Polynesia,1,PAS,,,,1, +160,SOM,Somalia,1,AFR,,,,0.282924042,0.736 +163,STP,Sao Tome and Principe,1,LAC,,,,0.645101471,0.866 +169,SYC,Seichelles,,,,,,0.996783218, +170,SYR,Syrian Arab Republic,1,MEA,,,,0.996365204,0.193 +178,TTO,Trinidad and Tobago,1,LAC,,,,1,0.247 +181,TWN,Taiwan,1,PAS,,,,0, +189,VEN,Venezuela,1,LAC,,,,0.994607391, diff --git a/message_ix_buildings/data/chilled/country/v2.csv b/message_ix_buildings/data/chilled/country/v2.csv new file mode 100755 index 0000000..619619d --- /dev/null +++ b/message_ix_buildings/data/chilled/country/v2.csv @@ -0,0 +1,197 @@ +REGNUM,ISO,NAME,GLOBAL_SOUTH,REGION_GEA,CDD (Popwtd),GDPpercap2015,AC_penetr,access_elec,slum_pop, +106,LSO,Lesotho,1,AFR,121,2708.148539,0.007057831,0.279232388,0.508, +94,KGZ,Kyrgyzstan,0,FSU,135,3237.602937,0.008611505,0.999065552,, +152,RWA,Rwanda,1,AFR,337,1715.887074,0.011418056,0.228,0.532, +4,ALB,Albania,0,EEU,309,10971.29252,0.081731497,1,, +13,BDI,Burundi,1,AFR,721,748.4152713,0.013895491,0.072520895,0.579, +58,ETH,Ethiopia,1,AFR,704,1533.107632,0.016496607,0.334185905,0.739, +30,CAF,Central African Republic,1,AFR,2308,626.4108725,0.017696637,0.133844233,0.933, +8,ARM,Armenia,0,FSU,160,8195.93365,0.029312546,1,0.144, +2,AFG,Afghanistan,1,SAS,725,1809.016488,0.017816148,0.715,0.627, +10,AUS,Australia,0,PAO,563,43719.50216,0.667499136,1,, +11,AUT,Austria,0,WEU,113,44353.87521,0.231362438,1,, +12,AZE,Azerbaijan,0,FSU,640,16698.86365,0.322075479,1,, +37,COD,Dem. Rep. of the Congo,1,AFR,1921,750.0885772,0.017965046,0.164191647,0.748, +14,BEL,Belgium,0,WEU,86,41722.92186,0.191360952,1,, +101,LBR,Liberia,1,AFR,2624,785.2468867,0.018468046,0.138400917,0.657, +113,MDG,Madagascar,1,AFR,1046,1377.168213,0.018475825,0.190350609,0.772, +125,MWI,Malawi,1,AFR,1456,1088.701805,0.018713486,0.108,0.667, +18,BGR,Bulgaria,0,EEU,217,17000.16725,0.17248546,1,, +129,NER,Niger,1,AFR,3719,904.5797813,0.01910457,0.166,0.701, +122,MOZ,Mozambique,1,AFR,1981,1118.219536,0.019625672,0.24,0.803, +21,BIH,Bosnia and Herzegovina,0,EEU,133,10932.04871,0.045100697,1,, +22,BLR,Belarus,0,FSU,84,17229.55519,0.091236349,1,, +174,TJK,Tajikistan,0,FSU,603,2640.58952,0.01979512,0.999973526,, +158,SLE,Sierra Leone,1,AFR,2926,1315.973533,0.020955048,0.164683762,0.559, +40,COM,Comoros,1,AFR,2018,1413.059277,0.021049141,0.753807144,0.696, +172,TGO,Togo,1,AFR,3244,1349.371568,0.021155963,0.450285454,0.512, +196,ZWE,Zimbabwe,1,AFR,1106,1912.280264,0.021257751,0.337,0.251, +183,UGA,Uganda,1,AFR,1475,1665.949905,0.021444084,0.185,0.536, +68,GNB,Guinea-Bissau,1,AFR,3065,1446.468649,0.021618789,0.140046701,0.823, +67,GMB,Gambia,1,AFR,3115,1568.022914,0.022242681,0.464866638,0.348, +31,CAN,Canada,0,NAM,137,43149.47584,0.264869388,1,, +32,CHE,Switzerland,0,WEU,66,57264.1574,0.161173086,1,, +16,BFA,Burkina Faso,1,AFR,3658,1596.334538,0.022429188,0.184700813,0.658, +79,HTI,Haiti,1,LAC,2361,1651.228445,0.02247832,0.382211266,0.744, +66,GIN,Guinea,1,AFR,2609,1753.063116,0.023113801,1,0.433, +162,SSD,South Sudan,1,MEA,3577,1808.161714,0.0235528,0.079354277,0.956, +176,TLS,East Timor,1,PAS,2459,1920.150472,0.023968314,0.672815339,0.284, +117,MLI,Mali,1,AFR,3702,1919.228421,0.024171765,0.376,0.563, +15,BEN,Benin,1,AFR,3470,1987.167146,0.024541993,0.400334778,0.615, +157,SLB,Solomon Islands,1,PAS,2647,2053.438806,0.024789029,0.551,0.284, +134,NPL,Nepal,1,SAS,1442,2314.274881,0.024809729,0.87213623,0.543, +171,TCD,Chad,1,AFR,3424,2047.637179,0.024884187,0.077,0.882, +93,KEN,Kenya,1,AFR,1016,2835.643662,0.025645389,0.416,0.56, +44,CYP,Cyprus,0,WEU,1107,30549.10097,0.841881769,1,, +45,CZE,Czech Republic,0,EEU,91,30605.42052,0.190910576,1,, +46,DEU,Germany,0,WEU,103,43937.94713,0.216847485,1,, +182,TZA,United Republic of Tanzania,1,AFR,1469,2490.957101,0.025928367,0.185,0.507, +193,YEM,Yemen,1,MEA,1286,2641.045829,0.026130823,0.702139053,0.608, +49,DNK,Denmark,0,WEU,24,45458.69715,0.092526348,1,, +155,SEN,Senegal,1,AFR,3053,2293.853539,0.026298485,0.605,0.394, +191,VUT,Vanuatu,1,PAS,2036,2806.789686,0.029064691,0.446696129,0.284, +121,MNG,Mongolia,1,CPA,61,11411.94211,0.029190579,0.811916275,0.427, +184,UKR,Ukraine,0,FSU,212,7464.939834,0.030552468,1,, +17,BGD,Bangladesh,1,SAS,2625,3132.56754,0.031773208,0.682046814,0.551, +47,DJI,Djibouti,1,AFR,3302,3139.273535,0.031983323,0.520257759,0.656, +56,ESP,Spain,0,WEU,448,32291.1552,0.572128521,1,, +57,EST,Estonia,0,EEU,31,27549.58137,0.095579082,1,, +35,CIV,Cote d'Ivoire,1,AFR,2936,3241.612056,0.032679101,0.640861969,0.56, +59,FIN,Finland,0,WEU,23,38941.7636,0.090387402,1,, +36,CMR,Cameroon,1,AFR,2239,3289.064546,0.032688124,0.588651009,0.378, +61,FRA,France,0,WEU,167,37765.75087,0.303053112,1,, +195,ZMB,Zambia,1,AFR,1333,3627.202041,0.033022576,0.311,0.54, +63,GBR,United Kingdom,0,WEU,21,38839.16696,0.086989036,1,, +64,GEO,Georgia,0,FSU,226,9025.133143,0.044554696,0.999934998,, +95,KHM,Cambodia,1,CPA,3300,3290.952454,0.033114883,0.475657387,0.551, +147,PSE,Occupied Palestinian Terr.,1,MEA,959,4339.103693,0.035487757,1,0.249, +123,MRT,Mauritania,1,AFR,3732,3601.61435,0.035594033,0.395,0.799, +141,PNG,Papua New Guinea,1,PAS,2092,3866.513529,0.037128157,0.221889343,0.284, +65,GHA,Ghana,1,AFR,3261,3929.681044,0.038313522,0.757152786,0.379, +70,GRC,Greece,0,WEU,508,24170.30184,0.524533442,1,, +77,HND,Honduras,1,LAC,1696,4311.176397,0.040209805,0.8998171,0.275, +1,ABW,Aruba,1,LAC,,,,0.952381821,0.211, +154,SDN,Sudan,1,MEA,3683,4290.372249,0.04163877,0.380091553,0.916, +137,PAK,Pakistan,1,SAS,2436,4695.699879,0.045233807,0.935,0.455, +187,UZB,Uzbekistan,0,FSU,906,5700.236028,0.047281906,1,, +76,HKG,"China, Hong Kong SAR",1,CPA,1907,53595.24481,0.972987112,1,0.262, +131,NIC,Nicaragua,1,LAC,2430,4960.912412,0.048020442,0.811631393,0.455, +78,HRV,Croatia,0,EEU,244,20759.04815,0.272323808,1,, +119,MMR,Myanmar,1,PAS,2719,5056.859041,0.049278927,0.605,0.41, +80,HUN,Hungary,0,EEU,225,25034.45073,0.322592051,1,, +38,COG,Congo,1,AFR,2448,5542.892982,0.054748212,0.604,0.469, +190,VNM,Viet Nam,1,CPA,2641,5554.858056,0.055058876,1,0.272, +83,IRL,Ireland,0,WEU,4,61543.20777,0.058070329,1,, +192,WSM,Samoa,1,PAS,3205,5558.791879,0.055353219,0.999382782,0.284, +130,NGA,Nigeria,1,AFR,3087,5670.639443,0.056722283,0.525,0.502, +5,AND,Andorra,0,WEU,,,,1,, +87,ISR,Israel,1,MEA,984,32024.35277,0.822851001,1,0.249, +88,ITA,Italy,0,WEU,363,34302.0374,0.509111902,1,, +99,LAO,Lao People's Dem. Republic,1,CPA,2136,5755.059505,0.056959904,0.897,0.314, +82,IND,India,1,SAS,2761,5754.064597,0.057645582,0.88,0.24, +91,JPN,Japan,0,PAO,550,37882.98062,0.655437567,1,, +92,KAZ,Kazakhstan,0,FSU,416,23522.29052,0.454510614,1,, +3,AGO,Angola,1,AFR,1203,6231.067992,0.05800138,0.42,0.555, +111,MAR,Morocco,1,MEA,707,7296.934401,0.060854693,0.995860138,0.131, +24,BOL,Bolivia,1,LAC,1461,6531.519398,0.064625161,0.91522822,0.435, +73,GTM,Guatemala,1,LAC,1053,7292.719104,0.070607826,0.905062943,0.345, +97,KOR,Republic of Korea,1,PAS,538,34177.65447,0.640633059,1,0.284, +140,PHL,Philippines,1,PAS,2715,6874.582566,0.073840673,0.8908,0.383, +168,SWZ,Swaziland,1,AFR,996,7758.495563,0.076765288,0.62994545,0.327, +75,GUY,Guyana,1,LAC,2963,7074.207137,0.077310978,0.835683517,0.331, +28,BTN,Bhutan,1,SAS,1032,7743.337996,0.077375656,0.984235229,0.313, +90,JOR,Jordan,1,MEA,990,8491.050311,0.089612077,0.999983215,0.129, +159,SLV,El Salvador,1,LAC,2258,7845.157575,0.090453154,0.954,0.289, +23,BLZ,Belize,1,LAC,2547,8061.331831,0.095309455,0.918,0.108, +89,JAM,Jamaica,1,LAC,2264,8095.261867,0.095457224,0.972788849,0.211, +25,BRA,Brazil,1,LAC,1665,14666.01817,0.1,0.99710902,0.223, +107,LTU,Lithuania,0,EEU,58,27045.71302,0.134479719,1,, +108,LUX,Luxembourg,0,WEU,97,94088.59223,0.208429615,1,, +109,LVA,Latvia,0,EEU,42,23018.81611,0.096479666,1,, +9,ATG,Antigua & Barbuda,1,LAC,,20154.94749,,0.968262939,0.211, +33,CHL,Chile,1,LAC,48,22536.61769,0.10155158,0.99714844,0.09, +112,MDA,Republic of Moldova,0,FSU,251,4746.784911,0.018788538,1,, +60,FJI,Fiji,1,PAS,2001,8477.644733,0.102643431,0.971194916,0.284, +146,PRY,Paraguay,1,LAC,1659,8639.28685,0.104026635,0.99331532,0.211, +127,NAM,Namibia,1,AFR,1362,9964.222994,0.132384246,0.507034302,0.332, +116,MKD,TFYR Macedonia,0,EEU,138,12759.8166,0.065256978,1,, +53,EGY,Egypt,1,MEA,1428,10095.61017,0.1372239,1,0.106, +19,BHR,Bahrain,1,MEA,,43926.47404,,1,0.249, +179,TUN,Tunisia,1,MEA,1116,10749.85917,0.147675839,1,0.08, +120,MNE,Montenegro,0,EEU,98,15289.7174,0.077856069,0.999991608,, +81,IDN,Indonesia,1,PAS,3012,10367.6953,0.154611223,0.975373674,0.218, +188,VCT,Saint Vincent and the Grenadines,1,LAC,3307,10447.52839,0.157325928,0.994550629,0.211, +52,ECU,Ecuador,1,LAC,2086,10749.12887,0.164147412,0.98825883,0.36, +194,ZAF,South Africa,1,AFR,678,12362.58381,0.166792615,0.855,0.23, +139,PER,Peru,1,LAC,971,11767.52174,0.172277415,0.93852179,0.342, +100,LBN,Lebanon,1,MEA,522,13352.71339,0.174377333,1,0.531, +105,LKA,Sri Lanka,1,SAS,2848,11061.84358,0.17712201,0.938899002,0.313, +51,DZA,Algeria,1,MEA,900,13724.72385,0.23820818,0.993367081,0.119, +39,COL,Colombia,1,LAC,1491,12985.38313,0.239690176,0.98186898,0.131, +50,DOM,Dominican Republic,1,LAC,2073,13371.52499,0.266951881,0.98560364,0.121, +114,MDV,Maldives,1,SAS,3518,13705.00532,0.287866737,0.999940109,0.313, +132,NLD,Netherlands,0,WEU,61,46494.36426,0.153146979,1,, +133,NOR,Norway,0,WEU,14,64008.28683,0.075521182,1,, +175,TKM,Turkmenistan,0,FSU,1207,14992.32314,0.319394584,1,, +135,NZL,New Zealand,0,PAO,59,34646.31361,0.147586095,1,, +42,CRI,Costa Rica,1,LAC,1871,14914.20675,0.340334716,0.99409804,0.055, +164,SUR,Suriname,1,LAC,3138,14766.79918,0.341559247,0.877446747,0.073, +85,IRQ,Iraq,1,MEA,2278,14928.8864,0.346473364,0.998621826,0.472, +29,BWA,Botswana,1,AFR,1512,15356.45762,0.353570326,0.585287514,0.559, +173,THA,Thailand,1,PAS,3116,15236.70646,0.366948938,0.996,0.25, +84,IRN,Iran (Islamic Republic of),1,MEA,1014,16500.90051,0.377280787,0.999750519,0.249, +142,POL,Poland,0,EEU,96,25299.97435,0.178685557,1,, +185,URY,Uruguay,1,LAC,570,19831.44589,0.426562626,0.9970948,0.211, +7,ARG,Argentina,1,LAC,748,19101.29739,0.453799748,0.999952087,0.167, +145,PRT,Portugal,0,WEU,346,26607.83312,0.450801361,1,, +62,GAB,Gabon,1,AFR,2600,16836.60591,0.456282675,0.903074722,0.37, +34,CHN,China,1,CPA,879,13569.89153,0.5,1,0.252, +124,MUS,Mauritius,1,AFR,1798,18864.10566,0.559986158,0.987412567,0.559, +138,PAN,Panama,1,LAC,2499,20674.29973,0.672683416,0.925548401,0.258, +150,ROU,Romania,0,EEU,209,20545.07714,0.240575252,1,, +151,RUS,Russian Federation,0,FSU,170,24516.54995,0.259934235,1,, +20,BHS,Bahamas,1,LAC,2401,21081.1124,0.691906054,1,0.211, +115,MEX,Mexico,1,LAC,968,16671.91198,0.7,0.99,0.111, +126,MYS,Malaysia,1,PAS,2686,25001.61267,0.849534752,0.999985886,0.284, +69,GNQ,Equatorial Guinea,1,AFR,2097,27572.58751,0.674737473,0.674737473,0.662, +26,BRB,Barbados,1,LAC,,,,1,0.211, +177,TON,Tonga,1,PAS,2949,31283.45801,0.959427292,0.961754532,0.284, +143,PRI,Puerto Rico,0,NAM,2233,35291.80356,0.971034039,1,, +136,OMN,Oman,1,MEA,2536,40138.95172,0.987090344,1,0.249, +153,SAU,Saudi Arabia,1,MEA,2584,50723.71265,0.992057358,1,0.18, +161,SRB,Serbia,0,EEU,216,13277.80012,0.098156716,0.999827423,, +27,BRN,Brunei Darussalam,1,PAS,3006,74600.1643,0.996563081,1,0.284, +98,KWT,Kuwait,1,MEA,3008,68476.32504,0.996571565,1,0.249, +6,ARE,United Arab Emirates,1,MEA,3052,65975.37555,0.996837326,1,0.249, +165,SVK,Slovakia,0,EEU,99,28308.87977,0.196176717,1,, +166,SVN,Slovenia,0,EEU,114,29037.74168,0.218919312,1,, +167,SWE,Sweden,0,WEU,23,45679.278,0.090836423,1,, +149,QAT,Qatar,1,MEA,3226,119749.4285,0.997723159,1,0.249, +41,CPV,Cape Verde,1,AFR,,5915.122633,,0.902439041,0.559, +43,CUB,Cuba,1,LAC,2531,,,1,0.211, +48,DMA,Dominica,1,LAC,,9941.894925,,0.999029694,0.211, +54,ERI,Eritrea,1,AFR,1888,1510.458929,0.021397846,0.455133209,0.559, +55,ESH,Western Sahara,1,AFR,1769,,,0,0.559, +71,GRD,Grenada,1,LAC,,12757.96625,,0.918716888,0.06, +72,GRL,Greenland,0,WEU,,,,1,, +74,GUF,French Guiana,1,LAC,2716,,,0,0.211, +86,ISL,Iceland,0,WEU,,43048.12515,,1,, +96,KNA,Saint Kitts,1,LAC,,24169.85992,,0.999300156,0.211, +102,LBY,Libyan Arab Jamahiriya,1,MEA,1487,14847.19705,0.32637951,0.985287628,0.119, +180,TUR,Turkey,0,WEU,403,23388.4813,0.443093808,1,0.119, +103,LCA,St. Lucia,1,LAC,,12522.04023,,0.971630783,0.119, +104,LIE,Liechtenstein,0,WEU,,,,1,, +110,MAC,Macau,1,CPA,,100444.5936,,1,0.262, +118,MLT,Malta,0,WEU,,34087.08151,,1,, +128,NCL,New Caledonia,1,PAS,1321,,,1,0.284, +186,USA,United States of America,0,NAM,710,53029.29336,0.74826754,1,, +144,PRK,North Korea,1,CPA,350,,,0.374463196,0.262, +148,PYF,French Polynesia,1,PAS,1221,,,1,0.284, +156,SGP,Singapore,1,PAS,,81741.09694,,1,0.284, +160,SOM,Somalia,1,AFR,3200,,,0.282924042,0.736, +163,STP,Sao Tome and Principe,1,LAC,,2947.510971,,0.645101471,0.866, +169,SYC,Seichelles,1,AFR,,24856.5599,,0.996783218,0.559, +170,SYR,Syrian Arab Republic,1,MEA,1180,,,0.996365204,0.193, +178,TTO,Trinidad and Tobago,1,LAC,2949,31524.58862,0.961397362,1,0.247, +181,TWN,Taiwan,1,PAS,1229,,,1,0.284, +189,VEN,Venezuela,1,LAC,2419,16745.02198,0.449592952,0.994607391,0.211, diff --git a/message_ix_buildings/data/chilled/country/v3.csv b/message_ix_buildings/data/chilled/country/v3.csv new file mode 100755 index 0000000..ee06b2c --- /dev/null +++ b/message_ix_buildings/data/chilled/country/v3.csv @@ -0,0 +1,197 @@ +REGNUM,ISO,NAME,GLOBAL_SOUTH,REGION_GEA,CDD (Popwtd),GDPpercap2015,AC_penetr,access_elec,slum_pop,AC_penetr_R,AC_penetr_U +106,LSO,Lesotho,1,AFR,121,2708.148539,0.007057831,0.279232388,0.508,0.007057831,0.007057831 +94,KGZ,Kyrgyzstan,0,FSU,135,3237.602937,0.008611505,0.999065552,,0.008611505,0.008611505 +152,RWA,Rwanda,1,AFR,337,1715.887074,0.011418056,0.228,0.532,0.011418056,0.011418056 +4,ALB,Albania,0,EEU,309,10971.29252,0.081731497,1,,0.081731497,0.081731497 +13,BDI,Burundi,1,AFR,721,748.4152713,0.013895491,0.072520895,0.579,0.013895491,0.013895491 +58,ETH,Ethiopia,1,AFR,704,1533.107632,0.016496607,0.334185905,0.739,0.016496607,0.016496607 +30,CAF,Central African Republic,1,AFR,2308,626.4108725,0.017696637,0.133844233,0.933,0.017696637,0.017696637 +8,ARM,Armenia,0,FSU,160,8195.93365,0.029312546,1,0.144,0.029312546,0.029312546 +2,AFG,Afghanistan,1,SAS,725,1809.016488,0.017816148,0.715,0.627,0.017816148,0.017816148 +10,AUS,Australia,0,PAO,563,43719.50216,0.667499136,1,,0.667499136,0.667499136 +11,AUT,Austria,0,WEU,113,44353.87521,0.231362438,1,,0.231362438,0.231362438 +12,AZE,Azerbaijan,0,FSU,640,16698.86365,0.322075479,1,,0.322075479,0.322075479 +37,COD,Dem. Rep. of the Congo,1,AFR,1921,750.0885772,0.017965046,0.164191647,0.748,0.017965046,0.017965046 +14,BEL,Belgium,0,WEU,86,41722.92186,0.191360952,1,,0.191360952,0.191360952 +101,LBR,Liberia,1,AFR,2624,785.2468867,0.018468046,0.138400917,0.657,0.018468046,0.018468046 +113,MDG,Madagascar,1,AFR,1046,1377.168213,0.018475825,0.190350609,0.772,0.018475825,0.018475825 +125,MWI,Malawi,1,AFR,1456,1088.701805,0.018713486,0.108,0.667,0.018713486,0.018713486 +18,BGR,Bulgaria,0,EEU,217,17000.16725,0.17248546,1,,0.17248546,0.17248546 +129,NER,Niger,1,AFR,3719,904.5797813,0.01910457,0.166,0.701,0.01910457,0.01910457 +122,MOZ,Mozambique,1,AFR,1981,1118.219536,0.019625672,0.24,0.803,0.019625672,0.019625672 +21,BIH,Bosnia and Herzegovina,0,EEU,133,10932.04871,0.045100697,1,,0.045100697,0.045100697 +22,BLR,Belarus,0,FSU,84,17229.55519,0.091236349,1,,0.091236349,0.091236349 +174,TJK,Tajikistan,0,FSU,603,2640.58952,0.01979512,0.999973526,,0.01979512,0.01979512 +158,SLE,Sierra Leone,1,AFR,2926,1315.973533,0.020955048,0.164683762,0.559,0.020955048,0.020955048 +40,COM,Comoros,1,AFR,2018,1413.059277,0.021049141,0.753807144,0.696,0.021049141,0.021049141 +172,TGO,Togo,1,AFR,3244,1349.371568,0.021155963,0.450285454,0.512,0.021155963,0.021155963 +196,ZWE,Zimbabwe,1,AFR,1106,1912.280264,0.021257751,0.337,0.251,0.021257751,0.021257751 +183,UGA,Uganda,1,AFR,1475,1665.949905,0.021444084,0.185,0.536,0.021444084,0.021444084 +68,GNB,Guinea-Bissau,1,AFR,3065,1446.468649,0.021618789,0.140046701,0.823,0.021618789,0.021618789 +67,GMB,Gambia,1,AFR,3115,1568.022914,0.022242681,0.464866638,0.348,0.022242681,0.022242681 +31,CAN,Canada,0,NAM,137,43149.47584,0.264869388,1,,0.264869388,0.264869388 +32,CHE,Switzerland,0,WEU,66,57264.1574,0.161173086,1,,0.161173086,0.161173086 +16,BFA,Burkina Faso,1,AFR,3658,1596.334538,0.022429188,0.184700813,0.658,0.022429188,0.022429188 +79,HTI,Haiti,1,LAC,2361,1651.228445,0.02247832,0.382211266,0.744,0.02247832,0.02247832 +66,GIN,Guinea,1,AFR,2609,1753.063116,0.023113801,1,0.433,0.023113801,0.023113801 +162,SSD,South Sudan,1,MEA,3577,1808.161714,0.0235528,0.079354277,0.956,0.0235528,0.0235528 +176,TLS,East Timor,1,PAS,2459,1920.150472,0.023968314,0.672815339,0.284,0.023968314,0.023968314 +117,MLI,Mali,1,AFR,3702,1919.228421,0.024171765,0.376,0.563,0.024171765,0.024171765 +15,BEN,Benin,1,AFR,3470,1987.167146,0.024541993,0.400334778,0.615,0.024541993,0.024541993 +157,SLB,Solomon Islands,1,PAS,2647,2053.438806,0.024789029,0.551,0.284,0.024789029,0.024789029 +134,NPL,Nepal,1,SAS,1442,2314.274881,0.024809729,0.87213623,0.543,0.024809729,0.024809729 +171,TCD,Chad,1,AFR,3424,2047.637179,0.024884187,0.077,0.882,0.024884187,0.024884187 +93,KEN,Kenya,1,AFR,1016,2835.643662,0.025645389,0.416,0.56,0.025645389,0.025645389 +44,CYP,Cyprus,0,WEU,1107,30549.10097,0.841881769,1,,0.841881769,0.841881769 +45,CZE,Czech Republic,0,EEU,91,30605.42052,0.190910576,1,,0.190910576,0.190910576 +46,DEU,Germany,0,WEU,103,43937.94713,0.216847485,1,,0.216847485,0.216847485 +182,TZA,United Republic of Tanzania,1,AFR,1469,2490.957101,0.025928367,0.185,0.507,0.025928367,0.025928367 +193,YEM,Yemen,1,MEA,1286,2641.045829,0.026130823,0.702139053,0.608,0.026130823,0.026130823 +49,DNK,Denmark,0,WEU,24,45458.69715,0.092526348,1,,0.092526348,0.092526348 +155,SEN,Senegal,1,AFR,3053,2293.853539,0.026298485,0.605,0.394,0.026298485,0.026298485 +191,VUT,Vanuatu,1,PAS,2036,2806.789686,0.029064691,0.446696129,0.284,0.029064691,0.029064691 +121,MNG,Mongolia,1,CPA,61,11411.94211,0.029190579,0.811916275,0.427,0.029190579,0.029190579 +184,UKR,Ukraine,0,FSU,212,7464.939834,0.030552468,1,,0.030552468,0.030552468 +17,BGD,Bangladesh,1,SAS,2625,3132.56754,0.031773208,0.682046814,0.551,0.031773208,0.031773208 +47,DJI,Djibouti,1,AFR,3302,3139.273535,0.031983323,0.520257759,0.656,0.031983323,0.031983323 +56,ESP,Spain,0,WEU,448,32291.1552,0.572128521,1,,0.572128521,0.572128521 +57,EST,Estonia,0,EEU,31,27549.58137,0.095579082,1,,0.095579082,0.095579082 +35,CIV,Cote d'Ivoire,1,AFR,2936,3241.612056,0.032679101,0.640861969,0.56,0.032679101,0.032679101 +59,FIN,Finland,0,WEU,23,38941.7636,0.090387402,1,,0.090387402,0.090387402 +36,CMR,Cameroon,1,AFR,2239,3289.064546,0.032688124,0.588651009,0.378,0.032688124,0.032688124 +61,FRA,France,0,WEU,167,37765.75087,0.303053112,1,,0.303053112,0.303053112 +195,ZMB,Zambia,1,AFR,1333,3627.202041,0.033022576,0.311,0.54,0.033022576,0.033022576 +63,GBR,United Kingdom,0,WEU,21,38839.16696,0.086989036,1,,0.086989036,0.086989036 +64,GEO,Georgia,0,FSU,226,9025.133143,0.044554696,0.999934998,,0.044554696,0.044554696 +95,KHM,Cambodia,1,CPA,3300,3290.952454,0.033114883,0.475657387,0.551,0.033114883,0.033114883 +147,PSE,Occupied Palestinian Terr.,1,MEA,959,4339.103693,0.035487757,1,0.249,0.035487757,0.035487757 +123,MRT,Mauritania,1,AFR,3732,3601.61435,0.035594033,0.395,0.799,0.035594033,0.035594033 +141,PNG,Papua New Guinea,1,PAS,2092,3866.513529,0.037128157,0.221889343,0.284,0.037128157,0.037128157 +65,GHA,Ghana,1,AFR,3261,3929.681044,0.038313522,0.757152786,0.379,0.038313522,0.038313522 +70,GRC,Greece,0,WEU,508,24170.30184,0.524533442,1,,0.524533442,0.524533442 +77,HND,Honduras,1,LAC,1696,4311.176397,0.040209805,0.8998171,0.275,0.040209805,0.040209805 +1,ABW,Aruba,1,LAC,,,,0.952381821,0.211,, +154,SDN,Sudan,1,MEA,3683,4290.372249,0.04163877,0.380091553,0.916,0.04163877,0.04163877 +137,PAK,Pakistan,1,SAS,2436,4695.699879,0.045233807,0.935,0.455,0.045233807,0.045233807 +187,UZB,Uzbekistan,0,FSU,906,5700.236028,0.047281906,1,,0.047281906,0.047281906 +76,HKG,"China, Hong Kong SAR",1,CPA,1907,53595.24481,0.972987112,1,0.262,0.972987112,0.972987112 +131,NIC,Nicaragua,1,LAC,2430,4960.912412,0.048020442,0.811631393,0.455,0.048020442,0.048020442 +78,HRV,Croatia,0,EEU,244,20759.04815,0.272323808,1,,0.272323808,0.272323808 +119,MMR,Myanmar,1,PAS,2719,5056.859041,0.049278927,0.605,0.41,0.049278927,0.049278927 +80,HUN,Hungary,0,EEU,225,25034.45073,0.322592051,1,,0.322592051,0.322592051 +38,COG,Congo,1,AFR,2448,5542.892982,0.054748212,0.604,0.469,0.054748212,0.054748212 +190,VNM,Viet Nam,1,CPA,2641,5554.858056,0.055058876,1,0.272,0.055058876,0.055058876 +83,IRL,Ireland,0,WEU,4,61543.20777,0.058070329,1,,0.058070329,0.058070329 +192,WSM,Samoa,1,PAS,3205,5558.791879,0.055353219,0.999382782,0.284,0.055353219,0.055353219 +130,NGA,Nigeria,1,AFR,3087,5670.639443,0.056722283,0.525,0.502,0.056722283,0.056722283 +5,AND,Andorra,0,WEU,,,,1,,, +87,ISR,Israel,1,MEA,984,32024.35277,0.822851001,1,0.249,0.822851001,0.822851001 +88,ITA,Italy,0,WEU,363,34302.0374,0.509111902,1,,0.509111902,0.509111902 +99,LAO,Lao People's Dem. Republic,1,CPA,2136,5755.059505,0.056959904,0.897,0.314,0.056959904,0.056959904 +82,IND,India,1,SAS,2761,5754.064597,0.057645582,0.88,0.24,0.057645582,0.057645582 +91,JPN,Japan,0,PAO,550,37882.98062,0.655437567,1,,0.655437567,0.655437567 +92,KAZ,Kazakhstan,0,FSU,416,23522.29052,0.454510614,1,,0.454510614,0.454510614 +3,AGO,Angola,1,AFR,1203,6231.067992,0.05800138,0.42,0.555,0.05800138,0.05800138 +111,MAR,Morocco,1,MEA,707,7296.934401,0.060854693,0.995860138,0.131,0.060854693,0.060854693 +24,BOL,Bolivia,1,LAC,1461,6531.519398,0.064625161,0.91522822,0.435,0.064625161,0.064625161 +73,GTM,Guatemala,1,LAC,1053,7292.719104,0.070607826,0.905062943,0.345,0.070607826,0.070607826 +97,KOR,Republic of Korea,1,PAS,538,34177.65447,0.640633059,1,0.284,0.640633059,0.640633059 +140,PHL,Philippines,1,PAS,2715,6874.582566,0.073840673,0.8908,0.383,0.073840673,0.073840673 +168,SWZ,Swaziland,1,AFR,996,7758.495563,0.076765288,0.62994545,0.327,0.076765288,0.076765288 +75,GUY,Guyana,1,LAC,2963,7074.207137,0.077310978,0.835683517,0.331,0.077310978,0.077310978 +28,BTN,Bhutan,1,SAS,1032,7743.337996,0.077375656,0.984235229,0.313,0.077375656,0.077375656 +90,JOR,Jordan,1,MEA,990,8491.050311,0.089612077,0.999983215,0.129,0.089612077,0.089612077 +159,SLV,El Salvador,1,LAC,2258,7845.157575,0.090453154,0.954,0.289,0.090453154,0.090453154 +23,BLZ,Belize,1,LAC,2547,8061.331831,0.095309455,0.918,0.108,0.095309455,0.095309455 +89,JAM,Jamaica,1,LAC,2264,8095.261867,0.095457224,0.972788849,0.211,0.095457224,0.095457224 +25,BRA,Brazil,1,LAC,1665,14666.01817,0.1,0.99710902,0.223,0.1,0.1 +107,LTU,Lithuania,0,EEU,58,27045.71302,0.134479719,1,,0.134479719,0.134479719 +108,LUX,Luxembourg,0,WEU,97,94088.59223,0.208429615,1,,0.208429615,0.208429615 +109,LVA,Latvia,0,EEU,42,23018.81611,0.096479666,1,,0.096479666,0.096479666 +9,ATG,Antigua & Barbuda,1,LAC,,20154.94749,,0.968262939,0.211,, +33,CHL,Chile,1,LAC,48,22536.61769,0.10155158,0.99714844,0.09,0.10155158,0.10155158 +112,MDA,Republic of Moldova,0,FSU,251,4746.784911,0.018788538,1,,0.018788538,0.018788538 +60,FJI,Fiji,1,PAS,2001,8477.644733,0.102643431,0.971194916,0.284,0.102643431,0.102643431 +146,PRY,Paraguay,1,LAC,1659,8639.28685,0.104026635,0.99331532,0.211,0.104026635,0.104026635 +127,NAM,Namibia,1,AFR,1362,9964.222994,0.132384246,0.507034302,0.332,0.132384246,0.132384246 +116,MKD,TFYR Macedonia,0,EEU,138,12759.8166,0.065256978,1,,0.065256978,0.065256978 +53,EGY,Egypt,1,MEA,1428,10095.61017,0.1372239,1,0.106,0.1372239,0.1372239 +19,BHR,Bahrain,1,MEA,,43926.47404,,1,0.249,, +179,TUN,Tunisia,1,MEA,1116,10749.85917,0.147675839,1,0.08,0.147675839,0.147675839 +120,MNE,Montenegro,0,EEU,98,15289.7174,0.077856069,0.999991608,,0.077856069,0.077856069 +81,IDN,Indonesia,1,PAS,3012,10367.6953,0.154611223,0.975373674,0.218,0.154611223,0.154611223 +188,VCT,Saint Vincent and the Grenadines,1,LAC,3307,10447.52839,0.157325928,0.994550629,0.211,0.157325928,0.157325928 +52,ECU,Ecuador,1,LAC,2086,10749.12887,0.164147412,0.98825883,0.36,0.164147412,0.164147412 +194,ZAF,South Africa,1,AFR,678,12362.58381,0.166792615,0.855,0.23,0.166792615,0.166792615 +139,PER,Peru,1,LAC,971,11767.52174,0.172277415,0.93852179,0.342,0.172277415,0.172277415 +100,LBN,Lebanon,1,MEA,522,13352.71339,0.174377333,1,0.531,0.174377333,0.174377333 +105,LKA,Sri Lanka,1,SAS,2848,11061.84358,0.17712201,0.938899002,0.313,0.17712201,0.17712201 +51,DZA,Algeria,1,MEA,900,13724.72385,0.23820818,0.993367081,0.119,0.23820818,0.23820818 +39,COL,Colombia,1,LAC,1491,12985.38313,0.239690176,0.98186898,0.131,0.239690176,0.239690176 +50,DOM,Dominican Republic,1,LAC,2073,13371.52499,0.266951881,0.98560364,0.121,0.266951881,0.266951881 +114,MDV,Maldives,1,SAS,3518,13705.00532,0.287866737,0.999940109,0.313,0.287866737,0.287866737 +132,NLD,Netherlands,0,WEU,61,46494.36426,0.153146979,1,,0.153146979,0.153146979 +133,NOR,Norway,0,WEU,14,64008.28683,0.075521182,1,,0.075521182,0.075521182 +175,TKM,Turkmenistan,0,FSU,1207,14992.32314,0.319394584,1,,0.319394584,0.319394584 +135,NZL,New Zealand,0,PAO,59,34646.31361,0.147586095,1,,0.147586095,0.147586095 +42,CRI,Costa Rica,1,LAC,1871,14914.20675,0.340334716,0.99409804,0.055,0.340334716,0.340334716 +164,SUR,Suriname,1,LAC,3138,14766.79918,0.341559247,0.877446747,0.073,0.341559247,0.341559247 +85,IRQ,Iraq,1,MEA,2278,14928.8864,0.346473364,0.998621826,0.472,0.346473364,0.346473364 +29,BWA,Botswana,1,AFR,1512,15356.45762,0.353570326,0.585287514,0.559,0.353570326,0.353570326 +173,THA,Thailand,1,PAS,3116,15236.70646,0.366948938,0.996,0.25,0.366948938,0.366948938 +84,IRN,Iran (Islamic Republic of),1,MEA,1014,16500.90051,0.377280787,0.999750519,0.249,0.377280787,0.377280787 +142,POL,Poland,0,EEU,96,25299.97435,0.178685557,1,,0.178685557,0.178685557 +185,URY,Uruguay,1,LAC,570,19831.44589,0.426562626,0.9970948,0.211,0.426562626,0.426562626 +7,ARG,Argentina,1,LAC,748,19101.29739,0.453799748,0.999952087,0.167,0.453799748,0.453799748 +145,PRT,Portugal,0,WEU,346,26607.83312,0.450801361,1,,0.450801361,0.450801361 +62,GAB,Gabon,1,AFR,2600,16836.60591,0.456282675,0.903074722,0.37,0.456282675,0.456282675 +34,CHN,China,1,CPA,879,13569.89153,0.5,1,0.252,0.254,0.748 +124,MUS,Mauritius,1,AFR,1798,18864.10566,0.559986158,0.987412567,0.559,0.559986158,0.559986158 +138,PAN,Panama,1,LAC,2499,20674.29973,0.672683416,0.925548401,0.258,0.672683416,0.672683416 +150,ROU,Romania,0,EEU,209,20545.07714,0.240575252,1,,0.240575252,0.240575252 +151,RUS,Russian Federation,0,FSU,170,24516.54995,0.259934235,1,,0.259934235,0.259934235 +20,BHS,Bahamas,1,LAC,2401,21081.1124,0.691906054,1,0.211,0.691906054,0.691906054 +115,MEX,Mexico,1,LAC,968,16671.91198,0.7,0.99,0.111,0.7,0.7 +126,MYS,Malaysia,1,PAS,2686,25001.61267,0.849534752,0.999985886,0.284,0.849534752,0.849534752 +69,GNQ,Equatorial Guinea,1,AFR,2097,27572.58751,0.674737473,0.674737473,0.662,0.674737473,0.674737473 +26,BRB,Barbados,1,LAC,,,,1,0.211,, +177,TON,Tonga,1,PAS,2949,31283.45801,0.959427292,0.961754532,0.284,0.959427292,0.959427292 +143,PRI,Puerto Rico,0,NAM,2233,35291.80356,0.971034039,1,,0.971034039,0.971034039 +136,OMN,Oman,1,MEA,2536,40138.95172,0.987090344,1,0.249,0.987090344,0.987090344 +153,SAU,Saudi Arabia,1,MEA,2584,50723.71265,0.992057358,1,0.18,0.992057358,0.992057358 +161,SRB,Serbia,0,EEU,216,13277.80012,0.098156716,0.999827423,,0.098156716,0.098156716 +27,BRN,Brunei Darussalam,1,PAS,3006,74600.1643,0.996563081,1,0.284,0.996563081,0.996563081 +98,KWT,Kuwait,1,MEA,3008,68476.32504,0.996571565,1,0.249,0.996571565,0.996571565 +6,ARE,United Arab Emirates,1,MEA,3052,65975.37555,0.996837326,1,0.249,0.996837326,0.996837326 +165,SVK,Slovakia,0,EEU,99,28308.87977,0.196176717,1,,0.196176717,0.196176717 +166,SVN,Slovenia,0,EEU,114,29037.74168,0.218919312,1,,0.218919312,0.218919312 +167,SWE,Sweden,0,WEU,23,45679.278,0.090836423,1,,0.090836423,0.090836423 +149,QAT,Qatar,1,MEA,3226,119749.4285,0.997723159,1,0.249,0.997723159,0.997723159 +41,CPV,Cape Verde,1,AFR,,5915.122633,,0.902439041,0.559,, +43,CUB,Cuba,1,LAC,2531,,,1,0.211,, +48,DMA,Dominica,1,LAC,,9941.894925,,0.999029694,0.211,, +54,ERI,Eritrea,1,AFR,1888,1510.458929,0.021397846,0.455133209,0.559,0.021397846,0.021397846 +55,ESH,Western Sahara,1,AFR,1769,,,0,0.559,, +71,GRD,Grenada,1,LAC,,12757.96625,,0.918716888,0.06,, +72,GRL,Greenland,0,WEU,,,,1,,, +74,GUF,French Guiana,1,LAC,2716,,,0,0.211,, +86,ISL,Iceland,0,WEU,,43048.12515,,1,,, +96,KNA,Saint Kitts,1,LAC,,24169.85992,,0.999300156,0.211,, +102,LBY,Libyan Arab Jamahiriya,1,MEA,1487,14847.19705,0.32637951,0.985287628,0.119,0.32637951,0.32637951 +180,TUR,Turkey,0,WEU,403,23388.4813,0.443093808,1,0.119,0.443093808,0.443093808 +103,LCA,St. Lucia,1,LAC,,12522.04023,,0.971630783,0.119,, +104,LIE,Liechtenstein,0,WEU,,,,1,,, +110,MAC,Macau,1,CPA,,100444.5936,,1,0.262,, +118,MLT,Malta,0,WEU,,34087.08151,,1,,, +128,NCL,New Caledonia,1,PAS,1321,,,1,0.284,, +186,USA,United States of America,0,NAM,710,53029.29336,0.74826754,1,,0.74826754,0.74826754 +144,PRK,North Korea,1,CPA,350,,,0.374463196,0.262,, +148,PYF,French Polynesia,1,PAS,1221,,,1,0.284,, +156,SGP,Singapore,1,PAS,,81741.09694,,1,0.284,, +160,SOM,Somalia,1,AFR,3200,,0.018,0.282924042,0.736,0.018,0.018 +163,STP,Sao Tome and Principe,1,LAC,,2947.510971,,0.645101471,0.866,, +169,SYC,Seichelles,1,AFR,,24856.5599,,0.996783218,0.559,, +170,SYR,Syrian Arab Republic,1,MEA,1180,,,0.996365204,0.193,, +178,TTO,Trinidad and Tobago,1,LAC,2949,31524.58862,0.961397362,1,0.247,0.961397362,0.961397362 +181,TWN,Taiwan,1,PAS,1229,,,1,0.284,, +189,VEN,Venezuela,1,LAC,2419,16745.02198,0.449592952,0.994607391,0.211,0.449592952,0.449592952 diff --git a/message_ix_buildings/data/chilled/country/v4.csv b/message_ix_buildings/data/chilled/country/v4.csv new file mode 100755 index 0000000..a8e061b --- /dev/null +++ b/message_ix_buildings/data/chilled/country/v4.csv @@ -0,0 +1,197 @@ +REGNUM,ISO,NAME,GLOBAL_SOUTH,REGION_GEA,CDD (Popwtd),GDPpercap,access_elec,slum_pop,AC_penetr,AC_penetr_R,AC_penetr_U +1,ABW,Aruba,1,LAC,,,1,0,,, +2,AFG,Afghanistan,1,SAS,725,,1,0,,, +3,AGO,Angola,1,AFR,1203,,1,0,,, +4,ALB,Albania,0,EEU,309,,1,0,,, +5,AND,Andorra,0,WEU,,,1,0,,, +6,ARE,United Arab Emirates,1,MEA,3052,,1,0,,, +7,ARG,Argentina,1,LAC,748,33731,1,0,0.749613387,0.749613387,0.749613387 +8,ARM,Armenia,0,FSU,160,32590,1,0,0.288298408,0.288298408,0.288298408 +9,ATG,Antigua & Barbuda,1,LAC,,,1,0,,, +10,AUS,Australia,0,PAO,563,85533,1,0,0.668840875,0.668840875,0.668840875 +11,AUT,Austria,0,WEU,113,52103,1,0,0.231698735,0.231698735,0.231698735 +12,AZE,Azerbaijan,0,FSU,640,39382,1,0,0.709264932,0.709264932,0.709264932 +13,BDI,Burundi,1,AFR,721,1920,1,0,0.018235053,0.018235053,0.018235053 +14,BEL,Belgium,0,WEU,86,90680,1,0,0.191978388,0.191978388,0.191978388 +15,BEN,Benin,1,AFR,3470,4335,1,0,0.042042913,0.042042913,0.042042913 +16,BFA,Burkina Faso,1,AFR,3658,2640,1,0,0.02854355,0.02854355,0.02854355 +17,BGD,Bangladesh,1,SAS,2625,5986,1,0,0.06060816,0.06060816,0.06060816 +18,BGR,Bulgaria,0,EEU,217,27648,1,0,0.336985791,0.336985791,0.336985791 +19,BHR,Bahrain,1,MEA,,58462,1,0,0.050996886,0.050996886,0.050996886 +20,BHS,Bahamas,1,LAC,2401,55613,1,0,0.989231548,0.989231548,0.989231548 +21,BIH,Bosnia and Herzegovina,0,EEU,133,32455,1,0,0.25263309,0.25263309,0.25263309 +22,BLR,Belarus,0,FSU,84,32244,1,0,0.183357218,0.183357218,0.183357218 +23,BLZ,Belize,1,LAC,2547,22327,1,0,0.751447164,0.751447164,0.751447164 +24,BOL,Bolivia,1,LAC,1461,13464,1,0,0.259582963,0.259582963,0.259582963 +25,BRA,Brazil,1,LAC,1665,26617,1,0,0.858448923,0.858448923,0.858448923 +26,BRB,Barbados,1,LAC,,28032,1,0,0.047101036,0.047101036,0.047101036 +27,BRN,Brunei Darussalam,1,PAS,3006,24527,1,0,0.837471518,0.837471518,0.837471518 +28,BTN,Bhutan,1,SAS,1032,23723,1,0,0.70109035,0.70109035,0.70109035 +29,BWA,Botswana,1,AFR,1512,34254,1,0,0.926304116,0.926304116,0.926304116 +30,CAF,Central African Republic,1,AFR,2308,3596,1,0,0.035128943,0.035128943,0.035128943 +31,CAN,Canada,0,NAM,137,65651,1,0,0.265475893,0.265475893,0.265475893 +32,CHE,Switzerland,0,WEU,66,59548,1,0,0.161178551,0.161178551,0.161178551 +33,CHL,Chile,1,LAC,48,28795,1,0,0.123910728,0.123910728,0.123910728 +34,CHN,China,1,CPA,879,43065,1,0,0.814685832,0.814685832,0.814685832 +35,CIV,Cote d'Ivoire,1,AFR,2936,5344,1,0,0.052669357,0.052669357,0.052669357 +36,CMR,Cameroon,1,AFR,2239,7714,1,0,0.087886716,0.087886716,0.087886716 +37,COD,Dem. Rep. of the Congo,1,AFR,1921,9163,1,0,0.118110301,0.118110301,0.118110301 +38,COG,Congo,1,AFR,2448,13951,1,0,0.297424371,0.297424371,0.297424371 +39,COL,Colombia,1,LAC,1491,22135,1,0,0.70538725,0.70538725,0.70538725 +40,COM,Comoros,1,AFR,2018,4844,1,0,0.04621694,0.04621694,0.04621694 +41,CPV,Cape Verde,1,AFR,,12191,1,0,0.011245693,0.011245693,0.011245693 +42,CRI,Costa Rica,1,LAC,1871,23609,1,0,0.785758806,0.785758806,0.785758806 +43,CUB,Cuba,1,LAC,2531,31817,1,0,0.959268486,0.959268486,0.959268486 +44,CYP,Cyprus,0,WEU,1107,52481,1,0,0.880038682,0.880038682,0.880038682 +45,CZE,Czech Republic,0,EEU,91,33147,1,0,0.194702888,0.194702888,0.194702888 +46,DEU,Germany,0,WEU,103,44390,1,0,0.216889465,0.216889465,0.216889465 +47,DJI,Djibouti,1,AFR,3302,4779,1,0,0.04646616,0.04646616,0.04646616 +48,DMA,Dominica,1,LAC,,,1,0,,, +49,DNK,Denmark,0,WEU,24,46926,1,0,0.092562491,0.092562491,0.092562491 +50,DOM,Dominican Republic,1,LAC,2073,25277,1,0,0.845821115,0.845821115,0.845821115 +51,DZA,Algeria,1,MEA,900,17798,1,0,0.425441845,0.425441845,0.425441845 +52,ECU,Ecuador,1,LAC,2086,20823,1,0,0.673163861,0.673163861,0.673163861 +53,EGY,Egypt,1,MEA,1428,17581,1,0,0.470584449,0.470584449,0.470584449 +54,ERI,Eritrea,1,AFR,1888,5575,1,0,0.054138473,0.054138473,0.054138473 +55,ESH,Western Sahara,1,AFR,1769,,1,0,,, +56,ESP,Spain,0,WEU,448,67804,1,0,0.589384039,0.589384039,0.589384039 +57,EST,Estonia,0,EEU,31,31966,1,0,0.101153379,0.101153379,0.101153379 +58,ETH,Ethiopia,1,AFR,704,3285,1,0,0.024705608,0.024705608,0.024705608 +59,FIN,Finland,0,WEU,23,58876,1,0,0.090946146,0.090946146,0.090946146 +60,FJI,Fiji,1,PAS,2001,20361,1,0,0.647397091,0.647397091,0.647397091 +61,FRA,France,0,WEU,167,77023,1,0,0.30555072,0.30555072,0.30555072 +62,GAB,Gabon,1,AFR,2600,20033,1,0,0.63996721,0.63996721,0.63996721 +63,GBR,United Kingdom,0,WEU,21,87315,1,0,0.087544967,0.087544967,0.087544967 +64,GEO,Georgia,0,FSU,226,34178,1,0,0.370938814,0.370938814,0.370938814 +65,GHA,Ghana,1,AFR,3261,6309,1,0,0.065433311,0.065433311,0.065433311 +66,GIN,Guinea,1,AFR,2609,4567,1,0,0.044057578,0.044057578,0.044057578 +67,GMB,Gambia,1,AFR,3115,7806,1,0,0.090704402,0.090704402,0.090704402 +68,GNB,Guinea-Bissau,1,AFR,3065,4475,1,0,0.043328634,0.043328634,0.043328634 +69,GNQ,Equatorial Guinea,1,AFR,2097,37667,1,0,0.972987454,0.972987454,0.972987454 +70,GRC,Greece,0,WEU,508,72228,1,0,0.632966608,0.632966608,0.632966608 +71,GRD,Grenada,1,LAC,,,1,0,,, +72,GRL,Greenland,0,WEU,,,1,0,,, +73,GTM,Guatemala,1,LAC,1053,19549,1,0,0.536147487,0.536147487,0.536147487 +74,GUF,French Guiana,1,LAC,2716,,1,0,,, +75,GUY,Guyana,1,LAC,2963,13909,1,0,0.297155835,0.297155835,0.297155835 +76,HKG,"China, Hong Kong SAR",1,CPA,1907,63592,1,0,0.973157796,0.973157796,0.973157796 +77,HND,Honduras,1,LAC,1696,13059,1,0,0.247616077,0.247616077,0.247616077 +78,HRV,Croatia,0,EEU,244,32594,1,0,0.387790772,0.387790772,0.387790772 +79,HTI,Haiti,1,LAC,2361,8118,1,0,0.096144863,0.096144863,0.096144863 +80,HUN,Hungary,0,EEU,225,37094,1,0,0.373322011,0.373322011,0.373322011 +81,IDN,Indonesia,1,PAS,3012,27312,1,0,0.907503289,0.907503289,0.907503289 +82,IND,India,1,SAS,2761,25715,1,0,0.869870509,0.869870509,0.869870509 +83,IRL,Ireland,0,WEU,4,64216,1,0,0.058071131,0.058071131,0.058071131 +84,IRN,Iran (Islamic Republic of),1,MEA,1014,24160,1,0,0.710316384,0.710316384,0.710316384 +85,IRQ,Iraq,1,MEA,2278,28823,1,0,0.923235987,0.923235987,0.923235987 +86,ISL,Iceland,0,WEU,,79711,1,0,0.05099998,0.05099998,0.05099998 +87,ISR,Israel,1,MEA,984,29427,1,0,0.801618074,0.801618074,0.801618074 +88,ITA,Italy,0,WEU,363,77982,1,0,0.518647696,0.518647696,0.518647696 +89,JAM,Jamaica,1,LAC,2264,30760,1,0,0.945250437,0.945250437,0.945250437 +90,JOR,Jordan,1,MEA,990,19823,1,0,0.538853959,0.538853959,0.538853959 +91,JPN,Japan,0,PAO,550,47500,1,0,0.660150108,0.660150108,0.660150108 +92,KAZ,Kazakhstan,0,FSU,416,32295,1,0,0.547563545,0.547563545,0.547563545 +93,KEN,Kenya,1,AFR,1016,9148,1,0,0.103739,0.103739,0.103739 +94,KGZ,Kyrgyzstan,0,FSU,135,34365,1,0,0.257966229,0.257966229,0.257966229 +95,KHM,Cambodia,1,CPA,3300,15924,1,0,0.40580033,0.40580033,0.40580033 +96,KNA,Saint Kitts,1,LAC,,,1,0,,, +97,KOR,Republic of Korea,1,PAS,538,35308,1,0,0.64349521,0.64349521,0.64349521 +98,KWT,Kuwait,1,MEA,3008,40273,1,0,0.992063674,0.992063674,0.992063674 +99,LAO,Lao People's Dem. Republic,1,CPA,2136,10112,1,0,0.144784418,0.144784418,0.144784418 +100,LBN,Lebanon,1,MEA,522,29799,1,0,0.609273709,0.609273709,0.609273709 +101,LBR,Liberia,1,AFR,2624,4120,1,0,0.039814466,0.039814466,0.039814466 +102,LBY,Libyan Arab Jamahiriya,1,MEA,1487,23952,1,0,0.772902871,0.772902871,0.772902871 +103,LCA,St. Lucia,1,LAC,,,1,0,,, +104,LIE,Liechtenstein,0,WEU,,,1,0,,, +105,LKA,Sri Lanka,1,SAS,2848,10263,1,0,0.151212485,0.151212485,0.151212485 +106,LSO,Lesotho,1,AFR,121,5009,1,0,0.011924697,0.011924697,0.011924697 +107,LTU,Lithuania,0,EEU,58,30991,1,0,0.142685366,0.142685366,0.142685366 +108,LUX,Luxembourg,0,WEU,97,199080,1,0,0.208429617,0.208429617,0.208429617 +109,LVA,Latvia,0,EEU,42,31634,1,0,0.118505198,0.118505198,0.118505198 +110,MAC,Macau,1,CPA,,,1,0,,, +111,MAR,Morocco,1,MEA,707,11203,1,0,0.136622084,0.136622084,0.136622084 +112,MDA,Republic of Moldova,0,FSU,251,33174,1,0,0.39678896,0.39678896,0.39678896 +113,MDG,Madagascar,1,AFR,1046,3587,1,0,0.030741441,0.030741441,0.030741441 +114,MDV,Maldives,1,SAS,3518,12398,1,0,0.228749543,0.228749543,0.228749543 +115,MEX,Mexico,1,LAC,968,31534,1,0,0.815287988,0.815287988,0.815287988 +116,MKD,TFYR Macedonia,0,EEU,138,32255,1,0,0.25897147,0.25897147,0.25897147 +117,MLI,Mali,1,AFR,3702,6376,1,0,0.066490629,0.066490629,0.066490629 +118,MLT,Malta,0,WEU,,63709,1,0,0.050999102,0.050999102,0.050999102 +119,MMR,Myanmar,1,PAS,2719,,1,0,,, +120,MNE,Montenegro,0,EEU,98,,1,0,,, +121,MNG,Mongolia,1,CPA,61,13051,1,0,0.039479059,0.039479059,0.039479059 +122,MOZ,Mozambique,1,AFR,1981,4442,1,0,0.042130742,0.042130742,0.042130742 +123,MRT,Mauritania,1,AFR,3732,6916,1,0,0.074891967,0.074891967,0.074891967 +124,MUS,Mauritius,1,AFR,1798,18095,1,0,0.51651044,0.51651044,0.51651044 +125,MWI,Malawi,1,AFR,1456,4175,1,0,0.038069328,0.038069328,0.038069328 +126,MYS,Malaysia,1,PAS,2686,26393,1,0,0.885638001,0.885638001,0.885638001 +127,NAM,Namibia,1,AFR,1362,18770,1,0,0.530951682,0.530951682,0.530951682 +128,NCL,New Caledonia,1,PAS,1321,,1,0,,, +129,NER,Niger,1,AFR,3719,3200,1,0,0.032466651,0.032466651,0.032466651 +130,NGA,Nigeria,1,AFR,3087,11827,1,0,0.205425389,0.205425389,0.205425389 +131,NIC,Nicaragua,1,LAC,2430,8794,1,0,0.111131441,0.111131441,0.111131441 +132,NLD,Netherlands,0,WEU,61,80466,1,0,0.15330642,0.15330642,0.15330642 +133,NOR,Norway,0,WEU,14,92697,1,0,0.07552242,0.07552242,0.07552242 +134,NPL,Nepal,1,SAS,1442,5761,1,0,0.054335083,0.054335083,0.054335083 +135,NZL,New Zealand,0,PAO,59,51365,1,0,0.150084631,0.150084631,0.150084631 +136,OMN,Oman,1,MEA,2536,30121,1,0,0.944092238,0.944092238,0.944092238 +137,PAK,Pakistan,1,SAS,2436,9911,1,0,0.14006375,0.14006375,0.14006375 +138,PAN,Panama,1,LAC,2499,26247,1,0,0.879935786,0.879935786,0.879935786 +139,PER,Peru,1,LAC,971,22451,1,0,0.645134401,0.645134401,0.645134401 +140,PHL,Philippines,1,PAS,2715,11980,1,0,0.210773466,0.210773466,0.210773466 +141,PNG,Papua New Guinea,1,PAS,2092,16318,1,0,0.421169739,0.421169739,0.421169739 +142,POL,Poland,0,EEU,96,40646,1,0,0.206089686,0.206089686,0.206089686 +143,PRI,Puerto Rico,0,NAM,2233,36581,1,0,0.974780419,0.974780419,0.974780419 +144,PRK,North Korea,1,CPA,350,,1,0,,, +145,PRT,Portugal,0,WEU,346,63019,1,0,0.503089567,0.503089567,0.503089567 +146,PRY,Paraguay,1,LAC,1659,13191,1,0,0.252655752,0.252655752,0.252655752 +147,PSE,Occupied Palestinian Terr.,1,MEA,959,,1,0,,, +148,PYF,French Polynesia,1,PAS,1221,,1,0,,, +149,QAT,Qatar,1,MEA,3226,,1,0,,, +150,ROU,Romania,0,EEU,209,32555,1,0,0.348140337,0.348140337,0.348140337 +151,RUS,Russian Federation,0,FSU,170,32456,1,0,0.300711877,0.300711877,0.300711877 +152,RWA,Rwanda,1,AFR,337,3796,1,0,0.018422666,0.018422666,0.018422666 +153,SAU,Saudi Arabia,1,MEA,2584,28144,1,0,0.918403681,0.918403681,0.918403681 +154,SDN,Sudan,1,MEA,3683,9276,1,0,0.124042374,0.124042374,0.124042374 +155,SEN,Senegal,1,AFR,3053,6374,1,0,0.06631409,0.06631409,0.06631409 +156,SGP,Singapore,1,PAS,,79330,1,0,0.050999978,0.050999978,0.050999978 +157,SLB,Solomon Islands,1,PAS,2647,12337,1,0,0.224985918,0.224985918,0.224985918 +158,SLE,Sierra Leone,1,AFR,2926,4653,1,0,0.045069791,0.045069791,0.045069791 +159,SLV,El Salvador,1,LAC,2258,18161,1,0,0.530480372,0.530480372,0.530480372 +160,SOM,Somalia,1,AFR,3200,3317,1,0,0.033299489,0.033299489,0.033299489 +161,SRB,Serbia,0,EEU,216,32850,1,0,0.356923388,0.356923388,0.356923388 +162,SSD,South Sudan,1,MEA,3577,,1,0,,, +163,STP,Sao Tome and Principe,1,LAC,,,1,0,,, +164,SUR,Suriname,1,LAC,3138,35056,1,0,0.981933073,0.981933073,0.981933073 +165,SVK,Slovakia,0,EEU,99,33073,1,0,0.206215855,0.206215855,0.206215855 +166,SVN,Slovenia,0,EEU,114,32720,1,0,0.227011419,0.227011419,0.227011419 +167,SWE,Sweden,0,WEU,23,82616,1,0,0.090951163,0.090951163,0.090951163 +168,SWZ,Swaziland,1,AFR,996,13557,1,0,0.239680262,0.239680262,0.239680262 +169,SYC,Seichelles,1,AFR,,,1,0,,, +170,SYR,Syrian Arab Republic,1,MEA,1180,14284,1,0,0.284060773,0.284060773,0.284060773 +171,TCD,Chad,1,AFR,3424,4561,1,0,0.044247952,0.044247952,0.044247952 +172,TGO,Togo,1,AFR,3244,2100,1,0,0.025171212,0.025171212,0.025171212 +173,THA,Thailand,1,PAS,3116,25743,1,0,0.872899287,0.872899287,0.872899287 +174,TJK,Tajikistan,0,FSU,603,33632,1,0,0.677826558,0.677826558,0.677826558 +175,TKM,Turkmenistan,0,FSU,1207,33475,1,0,0.88061639,0.88061639,0.88061639 +176,TLS,East Timor,1,PAS,2459,16904,1,0,0.459196357,0.459196357,0.459196357 +177,TON,Tonga,1,PAS,2949,,1,0,,, +178,TTO,Trinidad and Tobago,1,LAC,2949,26785,1,0,0.896454377,0.896454377,0.896454377 +179,TUN,Tunisia,1,MEA,1116,20042,1,0,0.569222871,0.569222871,0.569222871 +180,TUR,Turkey,0,WEU,403,26175,1,0,0.490312235,0.490312235,0.490312235 +181,TWN,Taiwan,1,PAS,1229,,1,0,,, +182,TZA,United Republic of Tanzania,1,AFR,1469,4698,1,0,0.042931773,0.042931773,0.042931773 +183,UGA,Uganda,1,AFR,1475,5648,1,0,0.053197309,0.053197309,0.053197309 +184,UKR,Ukraine,0,FSU,212,33165,1,0,0.35294207,0.35294207,0.35294207 +185,URY,Uruguay,1,LAC,570,30669,1,0,0.644586183,0.644586183,0.644586183 +186,USA,United States of America,0,NAM,710,67102,1,0,0.748427242,0.748427242,0.748427242 +187,UZB,Uzbekistan,0,FSU,906,34063,1,0,0.809580362,0.809580362,0.809580362 +188,VCT,Saint Vincent and the Grenadines,1,LAC,3307,,1,0,,, +189,VEN,Venezuela,1,LAC,2419,31035,1,0,0.951062841,0.951062841,0.951062841 +190,VNM,Viet Nam,1,CPA,2641,20492,1,0,0.66465797,0.66465797,0.66465797 +191,VUT,Vanuatu,1,PAS,2036,23550,1,0,0.789796686,0.789796686,0.789796686 +192,WSM,Samoa,1,PAS,3205,24999,1,0,0.852776746,0.852776746,0.852776746 +193,YEM,Yemen,1,MEA,1286,29395,1,0,0.862627281,0.862627281,0.862627281 +194,ZAF,South Africa,1,AFR,678,26253,1,0,0.650795508,0.650795508,0.650795508 +195,ZMB,Zambia,1,AFR,1333,9140,1,0,0.111228643,0.111228643,0.111228643 +196,ZWE,Zimbabwe,1,AFR,1106,1890,1,0,0.021148487,0.021148487,0.021148487 diff --git a/message_ix_buildings/data/chilled/version/ALPS2023/arch_input_reg.xlsx b/message_ix_buildings/data/chilled/version/ALPS2023/arch_input_reg.xlsx new file mode 100755 index 0000000..a97cff8 Binary files /dev/null and b/message_ix_buildings/data/chilled/version/ALPS2023/arch_input_reg.xlsx differ diff --git a/message_ix_buildings/data/chilled/version/ALPS2023/arch_regions.xlsx b/message_ix_buildings/data/chilled/version/ALPS2023/arch_regions.xlsx new file mode 100755 index 0000000..803bbe6 Binary files /dev/null and b/message_ix_buildings/data/chilled/version/ALPS2023/arch_regions.xlsx differ diff --git a/message_ix_buildings/data/chilled/version/ALPS2023/par_var.csv b/message_ix_buildings/data/chilled/version/ALPS2023/par_var.csv new file mode 100755 index 0000000..adb40a3 --- /dev/null +++ b/message_ix_buildings/data/chilled/version/ALPS2023/par_var.csv @@ -0,0 +1,4 @@ +id_run,name_run,cop,eff,t_sp_c,t_sp_c_max,t_sp_h,f_c,f_f,f_h +0,tm23ts23,1,1,23,23,21,0.333,0.333,1 +1,tm28ts26,1,1,26,28,20,0.333,0.333,1 +2,tm26ts26,1,1,26,26,20,0.333,0.333,1 diff --git a/message_ix_buildings/data/chilled/version/ALPS2023/runs.csv b/message_ix_buildings/data/chilled/version/ALPS2023/runs.csv new file mode 100755 index 0000000..813cc1e --- /dev/null +++ b/message_ix_buildings/data/chilled/version/ALPS2023/runs.csv @@ -0,0 +1,11 @@ +id,scen,year,clim +1,ssp2,2015,2015 +2,ssp2,2020,2020 +3,ssp2,2030,2030 +4,ssp2,2040,2040 +5,ssp2,2050,2050 +6,ssp2,2060,2060 +7,ssp2,2070,2070 +8,ssp2,2080,2080 +9,ssp2,2090,2090 +10,ssp2,2100,2100 diff --git a/message_ix_buildings/data/chilled/version/dle_coolssp/arch_input_reg.xlsx b/message_ix_buildings/data/chilled/version/dle_coolssp/arch_input_reg.xlsx new file mode 100644 index 0000000..69dcfe9 Binary files /dev/null and b/message_ix_buildings/data/chilled/version/dle_coolssp/arch_input_reg.xlsx differ diff --git a/message_ix_buildings/data/chilled/version/dle_coolssp/arch_regions.xlsx b/message_ix_buildings/data/chilled/version/dle_coolssp/arch_regions.xlsx new file mode 100644 index 0000000..e318634 Binary files /dev/null and b/message_ix_buildings/data/chilled/version/dle_coolssp/arch_regions.xlsx differ diff --git a/message_ix_buildings/data/chilled/version/dle_coolssp/par_var.csv b/message_ix_buildings/data/chilled/version/dle_coolssp/par_var.csv new file mode 100755 index 0000000..fef10f5 --- /dev/null +++ b/message_ix_buildings/data/chilled/version/dle_coolssp/par_var.csv @@ -0,0 +1,3 @@ +id_run,name_run,cop,eff,t_sp_c,t_sp_c_max,t_sp_h,f_c,f_f,f_h +0,tm23ts23,1,1,23,23,21,0.333,0.333,1 +1,tm26ts26,1,1,26,26,20,0.333,0.333,1 \ No newline at end of file diff --git a/message_ix_buildings/data/chilled/version/dle_coolssp/runs.csv b/message_ix_buildings/data/chilled/version/dle_coolssp/runs.csv new file mode 100755 index 0000000..c890d0f --- /dev/null +++ b/message_ix_buildings/data/chilled/version/dle_coolssp/runs.csv @@ -0,0 +1,5 @@ +id,scen,year,clim +1,ssp2,2015,2015 +2,ssp2,2020,2020 +3,ssp2,2050,2050 +4,ssp2,2100,2100 \ No newline at end of file diff --git a/message_ix_buildings/data/chilled/version/test/arch_input_reg.xlsx b/message_ix_buildings/data/chilled/version/test/arch_input_reg.xlsx new file mode 100755 index 0000000..a97cff8 Binary files /dev/null and b/message_ix_buildings/data/chilled/version/test/arch_input_reg.xlsx differ diff --git a/message_ix_buildings/data/chilled/version/test/arch_regions.xlsx b/message_ix_buildings/data/chilled/version/test/arch_regions.xlsx new file mode 100755 index 0000000..803bbe6 Binary files /dev/null and b/message_ix_buildings/data/chilled/version/test/arch_regions.xlsx differ diff --git a/message_ix_buildings/data/chilled/version/test/par_var.csv b/message_ix_buildings/data/chilled/version/test/par_var.csv new file mode 100755 index 0000000..adb40a3 --- /dev/null +++ b/message_ix_buildings/data/chilled/version/test/par_var.csv @@ -0,0 +1,4 @@ +id_run,name_run,cop,eff,t_sp_c,t_sp_c_max,t_sp_h,f_c,f_f,f_h +0,tm23ts23,1,1,23,23,21,0.333,0.333,1 +1,tm28ts26,1,1,26,28,20,0.333,0.333,1 +2,tm26ts26,1,1,26,26,20,0.333,0.333,1 diff --git a/message_ix_buildings/data/chilled/version/test/runs.csv b/message_ix_buildings/data/chilled/version/test/runs.csv new file mode 100755 index 0000000..804c723 --- /dev/null +++ b/message_ix_buildings/data/chilled/version/test/runs.csv @@ -0,0 +1,2 @@ +id,scen,year,clim +1,ssp2,2070,2070 \ No newline at end of file diff --git a/message_ix_buildings/life_coupling/__init__.py b/message_ix_buildings/life_coupling/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/message_ix_buildings/sturm/__init__.py b/message_ix_buildings/sturm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml index 52bae6b..6350c50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,11 @@ repository = "https://github.com/iiasa/message-ix-buildings" documentation = "https://docs.messageix.org/buildings/" [project.optional-dependencies] +chilled = [ + "numpy", + "pandas", + "xarray", +] docs = [ "Sphinx", # required for sphinx-rtd-theme 1.2.2, remove support is added @@ -35,3 +40,32 @@ tests = [ find = {} [tool.setuptools_scm] + +[tool.ruff] +exclude = [ + ".git", + "__pycache__", + "*.egg-info", + ".pytest_cache", + ".mypy_cache", + ".venv", + "example.py", + "import.py", +] +line-length = 88 + +[tool.ruff.format] +# Enable reformatting of code snippets in docstrings. +docstring-code-format = true + +[tool.ruff.lint] +select = ["C9", "E", "F", "I", "W"] +ignore = ["B008"] + +[tool.ruff.lint.per-file-ignores] +# Ignore unused imports: +"__init__.py" = ["F401"] +"user_settings.py" = ["E501"] + +[tool.ruff.lint.mccabe] +max-complexity = 10