From 329f4e882a1b4d1f85f0002b026ee40554bca23a Mon Sep 17 00:00:00 2001 From: Measrainsey Meng Date: Tue, 22 Oct 2024 16:52:06 +0200 Subject: [PATCH] Update path setting in other scripts --- message_ix_buildings/chilled/core/climate.py | 68 +++++++++++++------ .../chilled/postprocess/postprocess.py | 7 +- .../chilled/preprocess/archetypes.py | 9 ++- 3 files changed, 57 insertions(+), 27 deletions(-) diff --git a/message_ix_buildings/chilled/core/climate.py b/message_ix_buildings/chilled/core/climate.py index 94cdd4c..daf0dfe 100644 --- a/message_ix_buildings/chilled/core/climate.py +++ b/message_ix_buildings/chilled/core/climate.py @@ -48,6 +48,7 @@ from message_ix_buildings.chilled.util.util import ( get_archs, get_logger, + get_paths, load_all_scenarios_data, load_parametric_analysis_data, ) @@ -56,7 +57,11 @@ def create_climate_variables_maps(config: "Config", start_time: datetime.datetime): - out_path = os.path.join(config.project_path, "out", "version", config.vstr) + project_path = get_paths(config, "project_path") + dle_path = get_paths(config, "dle_path") + isimip_bias_adj_path = get_paths(config, "isimip_bias_adj_path") + + out_path = os.path.join(project_path, "out", "version", config.vstr) archetype_path = os.path.join(out_path, "rasters") save_path = os.path.join(out_path, "VDD_ene_calcs") @@ -105,10 +110,10 @@ def map_calculated_variables(args): endstr = ".nc" if str(clim) == "hist": - isi_folder = config.isimip_ewemib_path + isi_folder = isimip_ewemib_path filestr = climate_filestr_hist else: - isi_folder = config.isimip_bias_adj_path + isi_folder = isimip_bias_adj_path filestr = climate_filestr_future filepath = os.path.join( @@ -135,12 +140,12 @@ def map_calculated_variables(args): 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") + os.path.join(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") + os.path.join(dle_path, "EWEMBI_horiz_irrad_1980-2009_avg.nc") ) # Values in daily Wh/m2 if config.arch_setting == "regional": @@ -756,7 +761,8 @@ def read_netcdf_files(input_args): def aggregate_urban_rural_files(config: "Config"): - out_path = os.path.join(config.project_path, "out", "version", config.vstr) + project_path = get_paths(config, "project_path") + out_path = os.path.join(project_path, "out", "version", config.vstr) save_path = os.path.join(out_path, "VDD_ene_calcs") output_path_vdd = os.path.join( @@ -834,7 +840,8 @@ def aggregate_urban_rural_files(config: "Config"): def make_vdd_total_maps(config: "Config"): - out_path = os.path.join(config.project_path, "out", "version", config.vstr) + project_path = get_paths(config, "project_path") + out_path = os.path.join(project_path, "out", "version", config.vstr) save_path = os.path.join(out_path, "VDD_ene_calcs") output_path_vdd = os.path.join( @@ -1133,7 +1140,9 @@ def make_map( def process_construction_shares(config: "Config"): - out_path = os.path.join(config.project_path, "out", "version", config.vstr) + project_path = get_paths(config, "project_path") + dle_path = get_paths(config, "dle_path") + out_path = os.path.join(project_path, "out", "version", config.vstr) floorarea_path = os.path.join(out_path, "floorarea_country") output_path = os.path.join( @@ -1153,7 +1162,7 @@ def process_construction_shares(config: "Config"): # If constr_setting == 1, then process construction shares. Otherwise, skip if config.constr_setting == 1: - input_path = config.dle_path + input_path = dle_path dsc = xr.Dataset() for urt in config.urts: @@ -1226,8 +1235,10 @@ def process_construction_shares(config: "Config"): def process_floor_area_maps(config: "Config"): - input_path = config.dle_path - out_path = os.path.join(config.project_path, "out", "version", config.vstr) + project_path = get_paths(config, "project_path") + dle_path = get_paths(config, "dle_path") + input_path = dle_path + out_path = os.path.join(project_path, "out", "version", config.vstr) save_path = os.path.join(out_path, "floorarea_country") output_path = os.path.join( @@ -1354,8 +1365,11 @@ def process_floor_area_maps(config: "Config"): def process_country_maps(config: "Config"): - input_path = config.dle_path - out_path = os.path.join(config.project_path, "out", "version", config.vstr) + project_path = get_paths(config, "project_path") + dle_path = get_paths(config, "dle_path") + + input_path = dle_path + out_path = os.path.join(project_path, "out", "version", config.vstr) save_path = os.path.join(out_path, "floorarea_country") output_path = os.path.join( @@ -1436,8 +1450,11 @@ def process_country_maps(config: "Config"): def process_final_maps(config: "Config"): - input_path = config.dle_path - out_path = os.path.join(config.project_path, "out", "version", config.vstr) + project_path = get_paths(config, "project_path") + dle_path = get_paths(config, "dle_path") + + input_path = dle_path + out_path = os.path.join(project_path, "out", "version", config.vstr) vdd_path = os.path.join( out_path, "VDD_ene_calcs", @@ -1835,8 +1852,11 @@ def process_final_maps(config: "Config"): 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) + project_path = get_paths(config, "project_path") + dle_path = get_paths(config, "dle_path") + + input_path = dle_path + out_path = os.path.join(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) @@ -2140,7 +2160,11 @@ def aggregate_ncfile(args: tuple) -> xr.Dataset: def create_climate_outputs(config: "Config", start_time: datetime.datetime): - out_path = os.path.join(config.project_path, "out", "version", config.vstr) + project_path = get_paths(config, "project_path") + dle_path = get_paths(config, "dle_path") + isimip_bias_adj_path = get_paths(config, "isimip_bias_adj_path") + isimip_ewemib_path = get_paths(config, "isimip_ewemib_path") + out_path = os.path.join(project_path, "out", "version", config.vstr) archetype_path = os.path.join(out_path, "rasters") save_path = os.path.join(out_path, "VDD_ene_calcs") @@ -2180,10 +2204,10 @@ def create_climate_outputs(config: "Config", start_time: datetime.datetime): nyrs_clim = int(years_clim[1]) - int(years_clim[0]) + 1 if str(clim) == "hist": - isi_folder = config.isimip_ewemib_path + isi_folder = isimip_ewemib_path filestr = config.climate_filestr_hist else: - isi_folder = config.isimip_bias_adj_path + isi_folder = isimip_bias_adj_path filestr = config.climate_filestr_future filepath = os.path.join( @@ -2226,12 +2250,12 @@ def create_climate_outputs(config: "Config", start_time: datetime.datetime): # 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") + os.path.join(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") + os.path.join(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])) diff --git a/message_ix_buildings/chilled/postprocess/postprocess.py b/message_ix_buildings/chilled/postprocess/postprocess.py index fd4316f..bef248b 100644 --- a/message_ix_buildings/chilled/postprocess/postprocess.py +++ b/message_ix_buildings/chilled/postprocess/postprocess.py @@ -3,10 +3,11 @@ import pandas as pd from message_ix_buildings.chilled.util.config import Config -from message_ix_buildings.chilled.util.util import get_logger +from message_ix_buildings.chilled.util.util import get_logger, get_paths log = get_logger(__name__) -cfg = Config() +cfg = Config(user="MEAS") +dle_path = get_paths(cfg, "dle_path") def get_sturm_data(input_path, input_version_name): @@ -254,4 +255,4 @@ def postprocess_electricity_demand(input_path, input_version_name): ) -postprocess_electricity_demand(cfg.dle_path, cfg.vstr) +postprocess_electricity_demand(dle_path, cfg.vstr) diff --git a/message_ix_buildings/chilled/preprocess/archetypes.py b/message_ix_buildings/chilled/preprocess/archetypes.py index 0e1ab0f..ed4cd1a 100644 --- a/message_ix_buildings/chilled/preprocess/archetypes.py +++ b/message_ix_buildings/chilled/preprocess/archetypes.py @@ -15,6 +15,7 @@ from message_ix_buildings.chilled.util.util import ( get_archs, get_logger, + get_paths, read_arch_inputs_df, read_arch_reg_df, ) @@ -23,7 +24,9 @@ def create_archetypes(config: "Config"): - out_path = os.path.join(config.project_path, "out", "version") + project_path = get_paths(config, "dle_path") + + out_path = os.path.join(project_path, "out", "version") archetype_path = os.path.join(out_path, config.vstr, "rasters") # if archetypes folder does not exist, create it @@ -101,7 +104,9 @@ def create_archetypes(config: "Config"): def create_archetype_variables(config: "Config"): - out_path = os.path.join(config.project_path, "out", "version") + project_path = get_paths(config, "dle_path") + + out_path = os.path.join(project_path, "out", "version") archetype_path = os.path.join(out_path, config.vstr, "rasters") # get archs