From 51d195610137c9d63841d0b3d07d068eccdd735c Mon Sep 17 00:00:00 2001 From: Sven Eggimann Date: Tue, 19 Dec 2017 17:48:36 +0000 Subject: [PATCH] cleaning after major refactoring --- energy_demand/read_write/read_data.py | 13 ++++ energy_demand/read_write/read_weather_data.py | 52 ++++------------ energy_demand/read_write/write_data.py | 2 - energy_demand/scripts/init_scripts.py | 15 +++-- energy_demand/scripts/s_ss_raw_shapes.py | 61 ------------------- .../technologies/fuel_service_switch.py | 23 ++++--- 6 files changed, 47 insertions(+), 119 deletions(-) diff --git a/energy_demand/read_write/read_data.py b/energy_demand/read_write/read_data.py index 7c7d6ee4..5179d1be 100644 --- a/energy_demand/read_write/read_data.py +++ b/energy_demand/read_write/read_data.py @@ -932,6 +932,19 @@ def read_service_tech_by_p(path_to_csv): def read_disaggregated_fuel(path_to_csv, fueltypes_nr): """Read disaggregated fuel + + Arguments + ---------- + path_to_csv : str + Path to csv file + fueltypes_nr : int + Nr of fueltypes + + Returns + ------- + fuel_sector_enduse : dict + Disaggregated fuel + """ fuel_sector_enduse = {} diff --git a/energy_demand/read_write/read_weather_data.py b/energy_demand/read_write/read_weather_data.py index 55c4c735..12e0b2cb 100644 --- a/energy_demand/read_write/read_weather_data.py +++ b/energy_demand/read_write/read_weather_data.py @@ -1,17 +1,14 @@ """Loading weather data (temp) """ import os -import re import csv -import numpy as np -import logging -from energy_demand.basic import date_prop from collections import defaultdict +import numpy as np def read_weather_station_script_data(path_to_csv): """Read in weather stations from script data """ - temp_stations = {} + temp_stations = defaultdict(dict) with open(path_to_csv, 'r') as csvfile: read_lines = csv.reader(csvfile, delimiter=',') @@ -21,54 +18,29 @@ def read_weather_station_script_data(path_to_csv): station_id = str(row[0]) latitude = float(row[1]) longitude = float(row[2]) - try: - temp_stations[station_id]['station_latitude'] = latitude - temp_stations[station_id]['station_longitude'] = longitude - except KeyError: - # Add station - temp_stations[station_id] = {} - temp_stations[station_id]['station_latitude'] = latitude - temp_stations[station_id]['station_longitude'] = longitude - return temp_stations + temp_stations[station_id]['station_latitude'] = latitude + temp_stations[station_id]['station_longitude'] = longitude + + return dict(temp_stations) def read_weather_data_script_data(path_to_csv): """Read in weather data from script data - + Arguments + ---------- + path_to_csv : str + Path """ temp_data = {} all_txt_files_in_folder = os.listdir(path_to_csv) - + # Iterate files for file_path in all_txt_files_in_folder: path_file_to_read = os.path.join(path_to_csv, file_path) file_path_split = file_path.split("__") station_id = str(file_path_split[1]) #str_id - txt_data = np.loadtxt(path_file_to_read, delimiter=',') - - temp_data[station_id] = txt_data + temp_data[station_id] = np.loadtxt(path_file_to_read, delimiter=',') return temp_data - -def read_yearly_weather_data_script_data(path_to_csv): - """Read in weather data from script data - - Read in weather data from script data - """ - temp_data = defaultdict(dict) - all_txt_files_in_folder = os.listdir(path_to_csv) - - # Iterate files - for file_path in all_txt_files_in_folder: - path_file_to_read = os.path.join(path_to_csv, file_path) - file_path_split = file_path.split("__") - station_id = int(file_path_split[1]) - year = int(file_path_split[2]) - - txt_data = np.loadtxt(path_file_to_read, delimiter=',') - - temp_data[station_id][year] = txt_data - - return dict(temp_data) diff --git a/energy_demand/read_write/write_data.py b/energy_demand/read_write/write_data.py index 09e91345..20443f5d 100644 --- a/energy_demand/read_write/write_data.py +++ b/energy_demand/read_write/write_data.py @@ -19,8 +19,6 @@ def write_pop(sim_yr, path_result, pop_y): np.savetxt(path_file, pop_y, delimiter=',') - pass - def create_shp_results(data, results_container, paths, lookups, lu_reg): """Create csv file and merge with shape diff --git a/energy_demand/scripts/init_scripts.py b/energy_demand/scripts/init_scripts.py index c428f18f..29346553 100644 --- a/energy_demand/scripts/init_scripts.py +++ b/energy_demand/scripts/init_scripts.py @@ -386,10 +386,10 @@ def convert_fuel_switches_to_service_switches( Changed services witches including fuel switches """ if regional_specific: - service_switches_incl_fuel_switch = {} + new_service_switches = {} for reg in regions: - service_switches_incl_fuel_switch[reg] = [] + new_service_switches[reg] = [] for tech in service_tech_switched_p[reg]: if tech == 'dummy_tech': @@ -406,9 +406,9 @@ def convert_fuel_switches_to_service_switches( service_share_ey=service_tech_switched_p[reg][tech], switch_yr=switch_yr) - service_switches_incl_fuel_switch[reg].append(switch_new) + new_service_switches[reg].append(switch_new) else: - service_switches_incl_fuel_switch = [] + new_service_switches = [] for tech in service_tech_switched_p: if tech == 'dummy_tech': @@ -425,9 +425,9 @@ def convert_fuel_switches_to_service_switches( service_share_ey=service_tech_switched_p[tech], switch_yr=switch_yr) - service_switches_incl_fuel_switch.append(switch_new) + new_service_switches.append(switch_new) - return service_switches_incl_fuel_switch + return new_service_switches def sig_param_calculation_including_fuel_switch( base_yr, @@ -456,7 +456,7 @@ def sig_param_calculation_including_fuel_switch( fuel switches service_switches : dict service switches - service_tech_by_p : + service_tech_by_p : dict service_fueltype_by_p : dict @@ -597,4 +597,3 @@ def sig_param_calculation_including_fuel_switch( pass #no switches are defined return sig_param_tech, tech_increased_service, tech_decrased_share, tech_constant_share, service_switches_out - diff --git a/energy_demand/scripts/s_ss_raw_shapes.py b/energy_demand/scripts/s_ss_raw_shapes.py index af882da6..47a15218 100644 --- a/energy_demand/scripts/s_ss_raw_shapes.py +++ b/energy_demand/scripts/s_ss_raw_shapes.py @@ -352,64 +352,3 @@ def run(data): print("... finished script %s", os.path.basename(__file__)) return - -''' -def compare_jan_jul(main_dict_dayyear_absolute): - """ COMPARE JAN AND JUL DATA""" - # Percentages for every day: - jan_yearday = range(0, 30) - jul_yearday = range(181, 212) - jan = {k: [] for k in range(24)} - jul = {k: [] for k in range(24)} - - # Read out for the whole months of jan and ful - for day in main_dict_dayyear_absolute: - for h in main_dict_dayyear_absolute[day]: - if day in jan_yearday: - jan[h].append(main_dict_dayyear_absolute[day][h]) - if day in jul_yearday: - jul[h].append(main_dict_dayyear_absolute[day][h]) - #print(jan) - # Average the montly entries - for i in jan: - print("Nr of datapoints in Jan for hour: " + str(len(jan[i]))) - jan[i] = sum(jan[i]) / len(jan[i]) - - for i in jul: - print("Nr of datapoints in Jul for hour:" + str(len(jul[i]))) - jul[i] = sum(jul[i]) / len(jul[i]) - - # Test HEATING_ELEC SHARE DIFFERENCE JAN and JUN [daytype][_month][_hr] - jan = np.array(list(jan.items())) #convert to array - jul = np.array(list(jul.items())) #convert to array - jul_percent_of_jan = (100/jan[:, 1]) * jul[:, 1] - - x_values = range(24) - y_values = list(jan[:, 1]) # to get percentages - plt.plot(x_values, list(jan[:, 1]), label="Jan") - plt.plot(x_values, list(jul[:, 1]), label="Jul") - plt.plot(x_values, list(jul_percent_of_jan), label="% dif of Jan - Jul") - plt.legend() - plt.show() - - - #--- if JAn = 100% - jul_percent_of_jan = (100/jan[:, 1]) * jul[:, 1] - for h ,i in enumerate(jul_percent_of_jan): - print("h: " + str(h) + " %" + str(i) + " Diff: " + str(100-i)) - - plot_load_shape_yd_non_resid(jan) - print("TEST: " + str(jan-jul)) - -def plot_load_shape_yd_non_resid(daily_load_shape): - """With input 2 dim array plot daily load""" - - x_values = range(24) - y_values = list(daily_load_shape[:, 1]) # to get percentages - - plt.plot(x_values, y_values) - - plt.xlabel("ABSOLUTE VALUES TEST NONRESID") - plt.legend(ncol=2, frameon=False) - plt.show() -''' diff --git a/energy_demand/technologies/fuel_service_switch.py b/energy_demand/technologies/fuel_service_switch.py index af301873..09ecc7a4 100644 --- a/energy_demand/technologies/fuel_service_switch.py +++ b/energy_demand/technologies/fuel_service_switch.py @@ -215,9 +215,8 @@ def capacity_installations( if enduses_switch == []: pass else: - # ------------------------- + # Calculate service switches - # ------------------------- service_switches = create_service_switch( enduses_switch, capacity_switches, @@ -246,12 +245,21 @@ def create_service_switch( Enduses capacity_switches : list List containing all capacity_switches - assumptions : dict - Assumptions - fuels : dict - Fuels + technologies : dict + Technologies + other_enduse_mode_info : dict + OTher diffusion information + fuel_shares_enduse_by : dict + Fuel shares per enduse for base year base_yr : dict base year + fuels : dict + Fuels + + Returns + ------ + service_switches : dict + Service switches """ service_switches = [] @@ -285,8 +293,7 @@ def capacity_assumption_to_service( base_yr, other_enduse_mode_info ): - """Convert capacity assumption to service - switches + """Convert capacity assumption to service switches Arguments ---------