Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Dec 19, 2017
1 parent c6b93a6 commit dc0e7c4
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 67 deletions.
4 changes: 3 additions & 1 deletion energy_demand/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def run_model(args):

data['weather_stations'], data['temp_data'] = data_loader.load_temp_data(data['local_paths'])

data['rs_floorarea'], data['ss_floorarea'] = data_loader.virtual_building_datasets(data['lu_reg'], data['sectors']['all_sectors'], data)
data['rs_floorarea'], data['ss_floorarea'] = data_loader.virtual_building_datasets(
data['lu_reg'], data['sectors']['all_sectors'],
data['local_paths'])

rs_floorarea = defaultdict(dict)
for year in range(2015, 2101):
Expand Down
5 changes: 3 additions & 2 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def energy_demand_model(data, fuel_in=0, fuel_in_elec=0):
data['sim_param']['base_yr'] = 2015
data['sim_param']['curr_yr'] = data['sim_param']['base_yr']
data['sim_param']['simulated_yrs'] = [2015, 2050]
data['lu_reg'] = data_loader.load_LAC_geocodes_info(data['local_paths']['path_dummy_regions'])

data['lu_reg'] = data_loader.load_LAC_geocodes_info(os.path.join(local_data_path, '_raw_data', 'B-census_data', 'regions_local_area_districts', '_quick_and_dirty_spatial_disaggregation', 'infuse_dist_lyr_2011_saved.csv'))

# GVA
gva_data = {}
Expand Down Expand Up @@ -170,7 +171,7 @@ def energy_demand_model(data, fuel_in=0, fuel_in_elec=0):
rs_floorarea, ss_floorarea = data_loader.virtual_building_datasets(
data['lu_reg'],
data['sectors']['all_sectors'],
data)
data['local_paths'])
else:
pass

Expand Down
2 changes: 2 additions & 0 deletions energy_demand/profiles/hdd_cdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ def calc_reg_hdd(temperatures, t_base_heating, model_yeardays):
Temperatures
t_base_heating : float
Base temperature for heating
model_yeardays : dict
Modelled yeardays
Return
------
Expand Down
3 changes: 0 additions & 3 deletions energy_demand/profiles/load_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ def calc_lf_season(seasons, fuel_region_yh, average_fuel_yd):
"""
seasons_lfs = {}
for season, yeardays_modelled in seasons.items():
#max_load_yd_season = np.max(fuel_region_yh[:, yeardays_modelled])

#average_fuel_yd_season = np.average(average_fuel_yd[:, yeardays_modelled], axis=1)
average_fuel_yd_full_year = np.average(average_fuel_yd[:, ], axis=1)

# Calculate maximum hour in year
Expand All @@ -163,7 +161,6 @@ def calc_lf_season(seasons, fuel_region_yh, average_fuel_yd):

# Unable local RuntimeWarning: divide by zero encountered
with np.errstate(divide='ignore', invalid='ignore'):
#season_lf = (average_fuel_yd_season / max_load_h_season) * 100 #convert to percentage
season_lf = (average_fuel_yd_full_year / max_load_h_season) * 100 #convert to percentage

# Replace
Expand Down
20 changes: 16 additions & 4 deletions energy_demand/profiles/load_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ def add_lp(
"""Add load profile to stock
Arguments
----------
---------
unique_identifier : str
Name (unique identifier)
technologies : list
Technologies for which the profile applies
enduses : list
Enduses for which the profile applies
sectors : list
Sectors for which the profile applies
shape_yd : array
Shape yd (from year to day)
shape_yh : array
Shape yh (from year to hour)
sectors : list, default=False
Sectors for which the profile applies
enduse_peak_yd_factor : float
Factor to calculate daily demand from yearly demand
Standard value is average daily amount
Expand Down Expand Up @@ -97,7 +99,7 @@ def get_lp(self, enduse, sector, technology, shape):
Return
------
Load profile
Load profile attribute
"""
# Get key from lookup dict
position_in_dict = self.dict_tuple_keys[(enduse, sector, technology)]
Expand Down Expand Up @@ -155,6 +157,11 @@ def generate_key_lu_dict(dict_tuple_keys, unique_identifier, enduses, sectors, t
List with sectors
technologies : list
List with technologies
Returns
-------
dict_tuple_keys : str
Lookup position in dict
"""
for enduse in enduses:
for sector in sectors:
Expand All @@ -171,6 +178,11 @@ def get_stock_enduses(load_profile_dict):
---------
load_profile_dict : dict
All load profiles of load profile stock
Returns
------
all_enduses : list
All enduses in stock
"""
all_enduses = set([])
for profile_obj in load_profile_dict.values():
Expand Down
2 changes: 1 addition & 1 deletion energy_demand/read_and_plot_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def main(path_data_energy_demand):

# Read scenario data
data['scenario_data'] = {}
data['scenario_data']['population'] = read_data.read_pop(
data['scenario_data']['population'] = read_data.read_scenaric_population_data(
os.path.join(data['local_paths']['data_results'], 'model_run_pop'))

# --------------------------------------------
Expand Down
116 changes: 67 additions & 49 deletions energy_demand/read_write/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,56 @@
from energy_demand.basic import conversions
from energy_demand.basic import date_prop

def load_basic_lookups():
"""Definition of basic lookups or other related information
Return
------
lookups : dict
Lookup information and other very basic properties
"""
lookups = {}

lookups['dwtype'] = {
0: 'detached',
1: 'semi_detached',
2: 'terraced',
3: 'flat',
4: 'bungalow'}

lookups['fueltype'] = {
'solid_fuel': 0,
'gas': 1,
'electricity': 2,
'oil': 3,
'biomass': 4,
'hydrogen': 5,
'heat': 6}

lookups['fueltypes_nr'] = int(len(lookups['fueltype']))

return lookups

def load_sim_param_ini(path):
"""Load simulation parameter run information
Arguments
---------
path : str
Path to `ini` file
Returns
-------
sim_param : dict
Simulation parameters
enduses : dict
Enduses
assumptions : dict
Assumptions
reg_nrs : dict
Number of regions
lu_reg : dict
Regions
"""
config = configparser.ConfigParser()

Expand Down Expand Up @@ -66,9 +114,7 @@ def read_national_real_elec_data(path_to_csv):
for row in read_lines:
geocode = str.strip(row[2])
tot_consumption_unclean = row[7].strip()
total_consumption = float(tot_consumption_unclean.replace(",", ""))

national_fuel_data[geocode] = total_consumption
national_fuel_data[geocode] = float(tot_consumption_unclean.replace(",", ""))

return national_fuel_data

Expand Down Expand Up @@ -111,51 +157,30 @@ def read_national_real_gas_data(path_to_csv):

return national_fuel_data

def load_basic_lookups():
"""Definition of basic lookups or other related information
Return
------
lookups : dict
Lookup information and other very basic properties
"""
lookups = {}

lookups['dwtype'] = {
0: 'detached',
1: 'semi_detached',
2: 'terraced',
3: 'flat',
4: 'bungalow'}

lookups['fueltype'] = {
'solid_fuel': 0,
'gas': 1,
'electricity': 2,
'oil': 3,
'biomass': 4,
'hydrogen': 5,
'heat': 6
}

lookups['fueltypes_nr'] = int(len(lookups['fueltype']))

return lookups

def virtual_building_datasets(lu_reg, all_sectors, data):
def virtual_building_datasets(lu_reg, all_sectors, local_paths):
"""Load necessary data for virtual building stock
in case the link to the building stock model in
Newcastle is not used
Arguments
---------
lu_reg : dict
Regions
all_sectors : dict
All sectors
Returns
-------
rs_floorarea : dict
Residential floor area
ss_floorarea : dict
Service sector floor area
"""
# --------------------------------------------------
# Floor area for residential buildings for base year
# --------------------------------------------------
resid_footprint, non_res_flootprint = read_data.read_floor_area_virtual_stock(
data['local_paths']['path_floor_area_virtual_stock_by'])
local_paths['path_floor_area_virtual_stock_by'])

rs_floorarea = defaultdict(dict)
for year in range(2015, 2101):
Expand All @@ -166,12 +191,6 @@ def virtual_building_datasets(lu_reg, all_sectors, data):
logging.warning("No virtual residential floor area for region %s %s", reg_geocode, year)
rs_floorarea[year][reg_geocode] = 1

'''
rs_floorarea = defaultdict(dict)
for year in range(2015, 2101):
for region_geocode in lu_reg:
rs_floorarea[year][region_geocode] = 10000
'''
# --------------------------------------------------
# Floor area for service sector buildings
# --------------------------------------------------
Expand Down Expand Up @@ -229,10 +248,8 @@ def load_local_paths(path):
path, '_raw_data', 'D-validation', '02_subnational_gas_demand', 'data_2015_gas.csv'),
'path_employment_statistics': os.path.join(
path, '_raw_data', 'b-census_data', 'employment_statistics_2011_LAD', 'LAD_prior_2015.csv'),
'path_floor_area_virtual_stock_by': os.path.join( #TODO
'path_floor_area_virtual_stock_by': os.path.join(
path, '_raw_data', 'K-floor_area', 'floor_area_by.csv'),
'path_dummy_regions': os.path.join(
path, '_raw_data', 'B-census_data', 'regions_local_area_districts', '_quick_and_dirty_spatial_disaggregation', 'infuse_dist_lyr_2011_saved.csv'),
'path_assumptions_db': os.path.join(
path, '_processed_data', 'assumptions_from_db'),
'data_processed': os.path.join(
Expand Down Expand Up @@ -261,7 +278,7 @@ def load_local_paths(path):
path, '_processed_data', '_post_installation_data', 'load_profiles', 'rs_submodel'),
'ss_load_profiles': os.path.join(
path, '_processed_data', '_post_installation_data', 'load_profiles', 'ss_submodel'),
'dir_disattregated': os.path.join(
'dir_disaggregated': os.path.join(
path, '_processed_data', '_post_installation_data', 'disaggregated'),
'rs_load_profile_txt': os.path.join(
path, '_processed_data', '_post_installation_data', 'load_profiles', 'rs_submodel'),
Expand Down Expand Up @@ -292,7 +309,6 @@ def load_paths(path):
Data container containing dics
"""
paths = {

'path_main': path,

# Path for dwelling stock assumptions
Expand Down Expand Up @@ -326,6 +342,7 @@ def load_paths(path):
path, 'config_data', 'submodel_service', 'capacity_installations.csv'),
'is_path_capacity_installation': os.path.join(
path, 'config_data', 'submodel_industry', 'capacity_installations.csv'),

# Paths to fuel raw data
'rs_fuel_raw_data_enduses': os.path.join(
path, 'config_data', 'submodel_residential', 'rs_fuel_data.csv'),
Expand Down Expand Up @@ -360,8 +377,9 @@ def load_data_tech_profiles(tech_lp, paths):
Arguments
----------
data : dict
Data container
tech_lp : dict
Load profiles
paths : dict
Returns
------
Expand Down
27 changes: 25 additions & 2 deletions energy_demand/read_write/read_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,18 @@ def read_disaggregated_fuel(path_to_csv, fueltypes_nr):

def read_disaggregated_fuel_sector(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 Expand Up @@ -1045,8 +1057,19 @@ def read_lf_y(path_enduse_specific_results):

return dict(results)

def read_pop(path_enduse_specific_results):
"""Read load factors from txt file
def read_scenaric_population_data(path_enduse_specific_results):
"""Read population data
Arguments
---------
path_enduse_specific_results : str
Path
Returns
-------
results : dict
Population, {year: np.array(fueltype, regions)}
"""
results = defaultdict(dict)

Expand Down
6 changes: 3 additions & 3 deletions energy_demand/scripts/s_disaggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,13 +661,13 @@ def run(data):

#Write to csv file disaggregated demand
write_disagg_fuel(
os.path.join(data['local_paths']['dir_disattregated'], 'rs_fuel_disagg.csv'),
os.path.join(data['local_paths']['dir_disaggregated'], 'rs_fuel_disagg.csv'),
rs_fuel_disagg)
write_disagg_fuel_sector(
os.path.join(data['local_paths']['dir_disattregated'], 'ss_fuel_disagg.csv'),
os.path.join(data['local_paths']['dir_disaggregated'], 'ss_fuel_disagg.csv'),
ss_fuel_disagg)
write_disagg_fuel_sector(
os.path.join(data['local_paths']['dir_disattregated'], 'is_fuel_disagg.csv'),
os.path.join(data['local_paths']['dir_disaggregated'], 'is_fuel_disagg.csv'),
is_fuel_disagg)

logging.debug("... finished script %s", os.path.basename(__file__))
Expand Down
2 changes: 1 addition & 1 deletion energy_demand/scripts/s_post_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def post_install_setup(args):
basic_functions.create_folder(data['local_paths']['load_profiles'])
basic_functions.create_folder(data['local_paths']['rs_load_profiles'])
basic_functions.create_folder(data['local_paths']['ss_load_profiles'])
basic_functions.create_folder(data['local_paths']['dir_disattregated'])
basic_functions.create_folder(data['local_paths']['dir_disaggregated'])

# Read in temperature data from raw files
s_raw_weather_data.run(data)
Expand Down
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def before_model_run(self, data=None):
# Get building related data
if data['criterias']['virtual_building_stock_criteria']:
rs_floorarea, ss_floorarea = data_loader.virtual_building_datasets(
data['lu_reg'], data['sectors']['all_sectors'], data)
data['lu_reg'], data['sectors']['all_sectors'], data['local_paths'])
else:
pass
# Load floor area from newcastle
Expand Down

0 comments on commit dc0e7c4

Please sign in to comment.