Skip to content

Commit

Permalink
cleaned prints and removed negative tests to speed up
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Mar 4, 2019
1 parent 321f8cd commit 8ef1c97
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 156 deletions.
24 changes: 0 additions & 24 deletions energy_demand/basic/basic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,6 @@
import numpy as np
from pyproj import Proj, transform

def remove_neg_rounding_errors(input_array, rounding_crit=0.000000001):
"""Remove negative values which are smaller than the rounding_crit
and replace with zero values.
This function is necessary as some rounding errors occur
due to the fitting function.
"""
only_neg_elements = input_array[input_array < 0]

if len(only_neg_elements) > 0:

# Raise Error if negative value is bigger than -0.1
minimum_value = np.min(only_neg_elements)
raise Exception("NEgative value is too big to round: {}".format(minimum_value))

neg_positions = np.where(((input_array < -1 * rounding_crit)), 0, 1)

# Multiply zero values with original array
output_array = neg_positions * input_array
else:
output_array = input_array

return output_array

def get_result_paths(folder_path):
"""Joins results subfolders to ``folder_path`` and returns a dict
Expand Down
12 changes: 4 additions & 8 deletions energy_demand/basic/demand_supply_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,17 @@ def constrained_results(
key_name = "{}_{}_{}".format(submodel, fueltype_str, tech_simplified)
supply_results[key_name] = fuel_tech[submodel_nr][:, fueltype_int, :]

for key_name, values in supply_results.items():
if testing_functions.test_if_minus_value_in_array(values):
raise Exception("TTT {} {}".format(key_name, np.sum(values)))
#for key_name, values in supply_results.items():
# if testing_functions.test_if_minus_value_in_array(values):
# raise Exception("TTT {} {}".format(key_name, np.sum(values)))

#--------------------------------
# Get all non heating related enduse
# --------------------------------
# Substract constrained fuel from nonconstrained (total) fuel
print("AAA {} {}".format(results_unconstrained.shape()), results_constrained.shape())
non_heating_ed = results_unconstrained - sum(results_constrained.values())

# Remove all rounding errors
##non_heating_ed = basic_functions.remove_neg_rounding_errors(non_heating_ed_unrounded)

assert not testing_functions.test_if_minus_value_in_array(results_unconstrained)
#assert not testing_functions.test_if_minus_value_in_array(results_unconstrained)

# ---------------------------------
# Add non_heating for all fueltypes
Expand Down
1 change: 0 additions & 1 deletion energy_demand/basic/testing_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_if_minus_value_in_array(arraytotest, tolerance_min_max=0.00000000001):
if len(only_neg_elements) > 0:
for element in only_neg_elements:
if (element > tolerance_min_max) or (element < tolerance_min_max):
#print("Negative elements : " + str(only_neg_elements))
print("Sum of all negative: " + str(np.sum(only_neg_elements)))
print("Average negative value: " + str(np.sum(only_neg_elements) / len(only_neg_elements)))
print("Smalles value: " + str(np.min(only_neg_elements)))
Expand Down
19 changes: 9 additions & 10 deletions energy_demand/enduse_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import math
import copy
import numpy as np
import matplotlib.pyplot as plt

from energy_demand.basic import testing_functions
from energy_demand.profiles import load_factors as lf
Expand Down Expand Up @@ -125,7 +124,7 @@ def __init__(
self.enduse_techs = []
else:
#print("------INFO {} {} {} {}".format(self.enduse, sector, region, curr_yr))

#print("strarr")
# Get technologies of enduse
self.enduse_techs = get_enduse_techs(fuel_tech_p_by)

Expand Down Expand Up @@ -199,7 +198,7 @@ def __init__(
strategy_vars['generic_fuel_switch'],
self.fuel_y)
self.fuel_y = _fuel_new_y

#print("eeeemd")
# ----------------------------------
# Hourly Disaggregation
# ----------------------------------
Expand All @@ -226,7 +225,7 @@ def __init__(
make_all_flat=make_all_flat)
else:
#If technologies are defined for an enduse

#print("A")
# Get enduse specific configurations
mode_constrained = get_enduse_configuration(
criterias['mode_constrained'],
Expand Down Expand Up @@ -296,13 +295,14 @@ def __init__(
'''for tech, fuel_tech in fuel_tech_y.items():
if np.sum(fuel_tech) == 0:
self.enduse_techs.remove(tech)'''

# ------------------------------------------
# Assign load profiles
# ------------------------------------------
if self.flat_profile_crit:
pass
else:
#print("B")
fuel_yh = calc_fuel_tech_yh(
enduse,
sector,
Expand All @@ -312,7 +312,7 @@ def __init__(
fueltypes_nr,
fueltypes,
mode_constrained)

#print("C")
# --------------------------------------
# Peak shifting
# --------------------------------------
Expand All @@ -322,6 +322,7 @@ def __init__(
# If no demand management improvenent, no peak shifting
if strategy_vars['dm_improvement'][enduse][curr_yr] == 0:
self.techs_fuel_yh = fuel_yh
#print("D1")
else:
self.techs_fuel_yh = load_shifting_multiple_tech(
enduse,
Expand All @@ -330,14 +331,15 @@ def __init__(
assumptions.technologies,
fuel_yh,
param_lf_improved_cy=strategy_vars['dm_improvement'][enduse][curr_yr])
#print("D2")
else:
self.fuel_yh = load_shifting(
enduse,
fuel_yh,
mode_constrained=False,
param_lf_improved_cy=strategy_vars['dm_improvement'][enduse][curr_yr],
make_all_flat=make_all_flat)

#print("D3")
if testing_functions.test_if_minus_value_in_array(self.fuel_yh):
raise Exception("Minus fuel value detected: {} {} {}".format(enduse, sector, np.sum(self.fuel_yh)))

Expand Down Expand Up @@ -474,8 +476,6 @@ def load_shifting(
loadfactor_yd_cy = lf.calc_lf_d(
fuel_yh, average_fuel_yd, mode_constrained)

#print("Loading shifting .. {} {} {}".format(enduse, curr_yr, param_lf_improved_cy))

# Calculate current year load factors
lf_improved_cy = calc_lf_improvement(
param_lf_improved_cy,
Expand Down Expand Up @@ -900,7 +900,6 @@ def service_to_fuel(
fuel_tech_y[tech] = fuel_tech

fuel_y[fueltype_int] += fuel_tech
#print("S --> F: tech: {} eff: {} fuel: {} service {}".format(tech, tech_eff, fuel_y[fueltype_int], service))
else:
for tech, fuel_tech in service_tech.items():
fuel_y[fueltypes['heat']] += fuel_tech
Expand Down
6 changes: 1 addition & 5 deletions energy_demand/geography/weather_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,13 +644,9 @@ def insert_peak_dh_shape(
Array where on peak day the peak shape is inserted
"""
shape_y_dh_inserted = np.copy(shape_y_dh)
#print(np.sum(shape_y_dh_inserted))

shape_y_dh_inserted[peak_day] = shape_peak_dh

#print(np.sum(shape_y_dh_inserted))
#assert np.sum(shape_y_dh_inserted) == 365.0

return shape_y_dh_inserted

def get_weather_station_selection(
Expand Down Expand Up @@ -680,6 +676,6 @@ def get_weather_station_selection(
# Not enough stations to select position in list
station_id = False
all_weather_stations_out = []
print("... no weather station found")
logging.debug("... no weather station found")

return all_weather_stations_out, station_id
95 changes: 5 additions & 90 deletions energy_demand/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(
# ------------------------
# Create Dwelling Stock
# ------------------------
print("... generating cy dwelling stocks", flush=True)
logging.debug("... generating cy dwelling stocks", flush=True)
lookups = lookup_tables.basic_lookups()

if criterias['virtual_building_stock_criteria']:
Expand All @@ -103,13 +103,13 @@ def __init__(
# -------------------------------------------
# Simulate regions
# -------------------------------------------
print("... generating by dwelling stocks", flush=True)
logging.debug("... generating by dwelling stocks", flush=True)
#_all_closest_weather_stations = []
for reg_array_nr, region in enumerate(tqdm(regions)):

#logging.info("... Simulate: region %s, simulation year: %s, percent: (%s)",
# region, assumptions.curr_yr, round((100/assumptions.reg_nrs)*reg_array_nr, 2))
print("... Simulate: region %s, simulation year: %s, percent: (%s)",
logging.debug("... Simulate: region %s, simulation year: %s, percent: (%s)",
region, assumptions.curr_yr, round((100/assumptions.reg_nrs)*reg_array_nr, 2), flush=True)

all_submodels = simulate_region(
Expand Down Expand Up @@ -396,7 +396,7 @@ def simulate_region(
for submodel_name in submodel_names:
for sector in data['sectors'][submodel_name]:
for enduse in data['enduses'][submodel_name]:

#print("A - 0")
# ------------------------------------------------------
# Configure and select correct Enduse specific inputs
# ------------------------------------------------------
Expand Down Expand Up @@ -776,53 +776,9 @@ def aggregate_single_region(

# Iterate all simulation results
for enduse_object in all_submodels:

'''
if isinstance(get_fuels_yh(enduse_object, 'techs_fuel_yh'), dict):
techs_fueltypes_yh = get_fuels_yh(enduse_object, 'techs_fuel_yh')
enduse_array_nr = lookup_enduses[enduse_object.enduse]
submodel_nr = submodel_to_idx[enduse_object.submodel_name]
#----------
#SCRAP TESTING KAMEL
#----------
print("TECHNOLOGES {} {} {} {}".format(
len(techs_fueltypes_yh.keys()),
len(enduse_object.enduse_techs),
techs_fueltypes_yh.keys(), enduse_object.enduse_techs))
_a = len(enduse_object.enduse_techs)
_b = len(techs_fueltypes_yh.keys())
if _b != _a:
print(_a)
print(_b)
raise Exception("NOT SAME TECHS")'''

# -----------------------------------------------------------------
# Aggregate fuel of constrained technologies for heating
# -----------------------------------------------------------------
'''if mode_constrained:
if enduse_object.enduse in enduse_space_heating:
#_tot_sum_constrained = 0
# Iterate all used heating technologies
for heating_tech in enduse_object.enduse_techs:
tech_fuel = techs_fueltypes_yh[heating_tech]
fueltype_tech_int = technologies[heating_tech].fueltype_int
# Aggregate Submodel (sector) specific enduse for fueltype
if heating_tech in aggr_results['results_constrained'].keys():
aggr_results['results_constrained'][heating_tech][submodel_nr][reg_array_nr][fueltype_tech_int] += tech_fuel.reshape(8760)
#_tot_sum_constrained += tech_fuel.reshape(8760)
else:
if heating_tech not in aggr_results['results_constrained']:
aggr_results['results_constrained'][heating_tech] = np.zeros((len(submodel_to_idx), reg_nrs, fueltypes_nr, 8760), dtype="float")
aggr_results['results_constrained'][heating_tech][submodel_nr][reg_array_nr][fueltype_tech_int] += tech_fuel.reshape(8760)
#_tot_sum_constrained += tech_fuel.reshape(8760)
'''
# -----------------------------------------------------------------
# Aggregate fuel of all technologies
# -----------------------------------------------------------------
#_tot_sum_unconstrained = 0
techs_fueltypes_yh = get_fuels_yh(enduse_object, 'techs_fuel_yh')

if isinstance(techs_fueltypes_yh, dict):
Expand All @@ -842,60 +798,19 @@ def aggregate_single_region(
# Aggregate Submodel (sector) specific enduse for fueltype
if tech in aggr_results['results_constrained'].keys():
aggr_results['results_constrained'][tech][submodel_nr][reg_array_nr][tech_fueltype] += fuel_tech.reshape(8760)
#_tot_sum_constrained += tech_fuel.reshape(8760)
else:
if tech not in aggr_results['results_constrained']:
aggr_results['results_constrained'][tech] = np.zeros((len(submodel_to_idx), reg_nrs, fueltypes_nr, 8760), dtype="float")
aggr_results['results_constrained'][tech][submodel_nr][reg_array_nr][tech_fueltype] += fuel_tech.reshape(8760)

# SUm non heating techs
# Sum non heating techs
aggr_results['ed_enduse_fueltype_regs_yh'][enduse_array_nr][tech_fueltype][reg_array_nr] += fuel_tech.reshape(8760)
#_tot_sum_unconstrained += fuel_tech.reshape(8760)
else:
fueltype_yh_365_24 = get_fuels_yh(enduse_object, 'fuel_yh')
fueltype_yh_8760 = fueltype_yh_365_24.reshape(fueltypes_nr, 8760)

for fueltype_nr, fuels_8760 in enumerate(fueltype_yh_8760):
aggr_results['ed_enduse_fueltype_regs_yh'][enduse_array_nr][fueltype_nr][reg_array_nr] += fuels_8760
#_tot_sum_unconstrained += fuels_8760


# ---------
# TESTING KAMEL
# ---------
'''
if enduse_object.enduse in enduse_space_heating:
if np.sum(_tot_sum_constrained) != np.sum(_tot_sum_unconstrained):
print("Enduse {} TOTAL SUM CONSTRAINED: {} TOT SUM UNCOSNTRAINED: {}".format(
enduse_object.enduse, np.sum(_tot_sum_constrained), np.sum(_tot_sum_unconstrained)))
_diff = _tot_sum_unconstrained - _tot_sum_constrained
print("ZUZ: {}".format(testing_functions.test_if_minus_value_in_array(_diff)))
raise Exception("ERROR NOT SAME SUM")
'''
_results_unconstrained = aggregate_result_unconstrained(
assumptions.nr_of_submodels,
assumptions.lookup_sector_enduses,
aggr_results['ed_enduse_fueltype_regs_yh'],
fueltypes_nr,
reg_nrs)

if testing_functions.test_if_minus_value_in_array(_results_unconstrained):
raise Exception("DIFF NEW t")
'''
_a = copy.deepcopy(aggr_results['ed_enduse_fueltype_regs_yh'])
for tech in aggr_results['results_constrained']:
fueltype_tech_int = technologies[tech].fueltype_int # Fueltype of technology
for submodel_nr in range(aggr_results['results_constrained'][tech].shape[0]):
# reg, 8760 reg, fueltype, 8760
for reg in range(reg_nrs):
_a[enduse_array_nr][fueltype_tech_int][reg] -= aggr_results['results_constrained'][tech][submodel_nr][reg][fueltype_tech_int]
print("NUMM {}".format(str(testing_functions.test_if_minus_value_in_array(_a))))
if testing_functions.test_if_minus_value_in_array(_a):
raise Exception("DIFF NEW ")'''

return aggr_results

Expand Down
2 changes: 1 addition & 1 deletion energy_demand/read_write/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ def load_temp_data(
----
PAarquest file http://pandas.pydata.org/pandas-docs/stable/io.html#io-parquet
"""
print("... loading temperatures", flush=True)
logging.debug("... loading temperatures", flush=True)

temp_data_short = defaultdict(dict)
weather_stations_with_data = defaultdict(dict)
Expand Down
3 changes: 0 additions & 3 deletions energy_demand/result_processing/test.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
print("TEST")

print("_________")
1 change: 0 additions & 1 deletion energy_demand/scripts/s_fuel_to_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ def get_s_fueltype_tech(
s_fueltype_by_p[enduse][sector][fueltype] = 0
else:
s_fueltype_by_p[enduse][sector][fueltype] = s_fueltype_by_p[enduse][sector][fueltype] / total_s
#TODO KAMEL OLD ORIGINAL s_fueltype_by_p[enduse][sector][fueltype] = s_fueltype_by_p[enduse][sector][fueltype] / total_s

# Test if the energy service for all technologies is 100%
# Test if within fueltype always 100 energy service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def run(

# Annual temperature file
for file_name in all_annual_raw_files:
print("... reading in file: " + str(file_name), flush=True)
logging.info("... reading in file: " + str(file_name), flush=True)

path_to_csv = os.path.join(path_files, file_name)
temp_stations = {}
Expand Down
2 changes: 1 addition & 1 deletion energy_demand/technologies/fuel_service_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def autocomplete_switches(

# Iterate enduses
for enduse in switch_enduses:
print("... calculating service switches: {} crit_all_the_same: {}".format(enduse, crit_all_the_same))
logging.debug("... calculating service switches: {} crit_all_the_same: {}".format(enduse, crit_all_the_same))

sectors_of_enduse = get_sectors_of_enduse(
enduse, enduses, sectors)
Expand Down
11 changes: 0 additions & 11 deletions tests/profiles/test_load_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ def test_peak_shaving_max_min():
fuel_yh,
mode_constrained=False)

'''import matplotlib.pyplot as plt
print(fuel_yh.shape)
print(fuel_yh[0][0])
print("--")
print(result[0][0])
plt.plot(fuel_yh[0][0], label="before")
plt.plot(result[0][0], label="after")
plt.legend()
plt.show()
print("----")'''

# ---------
# expected
# ---------
Expand Down

0 comments on commit 8ef1c97

Please sign in to comment.