Skip to content

Commit

Permalink
cleaning after major refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Dec 19, 2017
1 parent dc0e7c4 commit 51d1956
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 119 deletions.
13 changes: 13 additions & 0 deletions energy_demand/read_write/read_data.py
Expand Up @@ -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 = {}

Expand Down
52 changes: 12 additions & 40 deletions 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=',')
Expand All @@ -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)
2 changes: 0 additions & 2 deletions energy_demand/read_write/write_data.py
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions energy_demand/scripts/init_scripts.py
Expand Up @@ -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':
Expand All @@ -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':
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

61 changes: 0 additions & 61 deletions energy_demand/scripts/s_ss_raw_shapes.py
Expand Up @@ -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()
'''
23 changes: 15 additions & 8 deletions energy_demand/technologies/fuel_service_switch.py
Expand Up @@ -215,9 +215,8 @@ def capacity_installations(
if enduses_switch == []:
pass
else:
# -------------------------

# Calculate service switches
# -------------------------
service_switches = create_service_switch(
enduses_switch,
capacity_switches,
Expand Down Expand Up @@ -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 = []

Expand Down Expand Up @@ -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
---------
Expand Down

0 comments on commit 51d1956

Please sign in to comment.