Skip to content

Commit

Permalink
Fix: Tests are working again
Browse files Browse the repository at this point in the history
  • Loading branch information
c0nb4 committed Jan 20, 2025
1 parent 607d041 commit 1cf3a55
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 1,281 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ errorfile.txt
__pycache__/
.idea/
demands/
data/weather/
data/weather/TRY_2015_Jahr

Distribution / packaging
.Python
Expand Down
Empty file added districtgenerator/__init__.py
Empty file.
37 changes: 21 additions & 16 deletions districtgenerator/classes/datahandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

from ..functions import weather_handling as weather_handling
from ..functions import path_checks as path_checks
from ..functions import calculate_holidays as calculate_holidays


RESIDENTIAL_BUILDING_TYPES = ["SFH", "TH", "MFH", "AB"]
NON_RESIDENTIAL_BUILDING_TYPES = ["IWU Hotels, Boarding, Restaurants or Catering", "IWU Office, Administrative or Government Buildings",
Expand Down Expand Up @@ -547,21 +549,22 @@ def generateBuildings(self):
# %% create user object
# containing number occupants, electricity demand,...
nb_of_days = self.timestamp.dt.date.nunique()
building["user"] = NonResidentialUsers(building_usage=building["buildingFeatures"]["building"],
area=building["buildingFeatures"]["area"],
holidays = calculate_holidays.get_holidays(file_path=self.weatherFile)
building["user"] = NonResidentialUsers(building=building,
envelope= building["envelope"],
file=self.filePath, site=self.site, time=self.time, nb_of_days=nb_of_days)
file=self.filePath, site=self.site, time=self.time, nb_of_days=nb_of_days,
night_setback=building["buildingFeatures"]["night_setback"],
holidays=holidays)




# %% calculate design heat loads
# at norm outside temperature
building["heatload"] = building["envelope"].calcHeatLoad(site=self.site, method="design")
building["envelope"].heatload = building["envelope"].calcHeatLoad(site=self.site, method="design")
# at bivalent temperature
building["bivalent"] = building["envelope"].calcHeatLoad(site=self.site, method="bivalent")
# at heatimg limit temperature
building["heatlimit"] = building["envelope"].calcHeatLoad(site=self.site, method="heatlimit")
building["envelope"].bivalent = building["envelope"].calcHeatLoad(site=self.site, method="bivalent")
# at heating limit temperature
building["envelope"].heatlimit = building["envelope"].calcHeatLoad(site=self.site, method="heatlimit")
# for drinking hot water
# To-Do figure hot water demand out for Non Residential
# in DIBS the IWU Approach of Teilenergiekennwerte is chosen
Expand Down Expand Up @@ -633,8 +636,7 @@ def generateDemands(self, calcUserProfiles=True, saveUserProfiles=True,
holidays=self.time["holidays"],
time_resolution=self.time["timeResolution"],
time_horizon=self.time["dataLength"],
building=building,
path=os.path.join(self.resultPath, 'demands'))
building=building)

if saveUserProfiles:
building["user"].saveProfiles(building["unique_name"], os.path.join(self.resultPath, 'demands'))
Expand All @@ -645,11 +647,14 @@ def generateDemands(self, calcUserProfiles=True, saveUserProfiles=True,
building["user"].loadProfiles(building["unique_name"], os.path.join(self.resultPath, 'demands'))
print("Load demands of building " + building["unique_name"])

# check if EV exist
building["clusteringData"] = {
"potentialEV": copy.deepcopy(building["user"].car)
}
building["user"].car *= building["buildingFeatures"]["EV"]
if building["buildingFeatures"]["building"] in RESIDENTIAL_BUILDING_TYPES:
# check if EV exist
# Currently the EV is only supported for residential buildings
building["clusteringData"] = {
"potentialEV": copy.deepcopy(building["user"].car)
}
if building["buildingFeatures"]["EV"] > 0:
building["user"].car *= building["buildingFeatures"]["EV"]

building["envelope"].calcNormativeProperties(self.site["SunRad"], building["user"].gains)

Expand All @@ -664,7 +669,7 @@ def generateDemands(self, calcUserProfiles=True, saveUserProfiles=True,
)

if saveUserProfiles:
building["user"].saveHeatingProfile(building["unique_name"], os.path.join(self.resultPath, 'demands'))
building["user"].saveProfiles(building["unique_name"], os.path.join(self.resultPath, 'demands'))



Expand Down
59 changes: 39 additions & 20 deletions districtgenerator/classes/non_residential_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class NonResidentialUsers():
A dictionary with time resolution and time steps for simulation.
nb_of_days : int
Number of days for which the simulation is to be run.
holidays : list
List of integers representing the day of year for each holiday.
night_setback : integer
Night setback is activated (1) or deactivated (0).
Attributes
----------
Expand Down Expand Up @@ -101,20 +105,24 @@ class NonResidentialUsers():
Loads profiles from previously saved CSV files.
"""
def __init__(self, building_usage: str, area: float, file: str, envelope: Any,
site: Dict[str, Any], time: Dict[str, Any], nb_of_days: int) -> None:
def __init__(self, building: Dict[str, Any], area: Optional[float] = None, file: Optional[str] = None, envelope: Optional[Any] = None,
site: Optional[Dict[str, Any]] = None, time: Optional[Dict[str, Any]] = None, holidays: Optional[List[int]] = None,
nb_of_days: Optional[int] = None, night_setback: Optional[int] = None) -> None:
"""
Constructor of Users Class
"""

self.usage = building_usage
self.area = area

self.building = building
self.usage = building["buildingFeatures"]["building"]
self.area = building["buildingFeatures"]["area"]
self.file = file
self.envelope = envelope
self.envelope = building["envelope"]

self.site = site
self.time = time
self.nb_of_days = nb_of_days
self.holidays = holidays
self.night_setback = night_setback
#self.nb_flats = None
self.annual_appliance_demand = None
self.annual_lightning_demand = None
Expand All @@ -126,7 +134,7 @@ def __init__(self, building_usage: str, area: float, file: str, envelope: Any,
self.elec = None
self.gains = None
self.heat = None
self.cool = None
self.cooling = None
self.occupancy_schedule = None
self.appliance_schedule = None
self.lighntning_schedule = None
Expand Down Expand Up @@ -339,15 +347,17 @@ def generate_dhw_profile(self) -> None:



def calcProfiles(self, site: Dict[str, Any], time_resolution: int,
time_horizon: int, initital_day: int = 1) -> None:
def calcProfiles(self, site: Dict[str, Any], holidays: Optional[List[int]], time_resolution: int,
time_horizon: int, initital_day: int = 1, building: Optional[Dict[str, Any]] = None) -> None:
'''
Calclulate profiles for every flat and summarize them for the whole building
Parameters
----------
site: dict
site data, e.g. weather
holidays : list
List of holidays.
initial_day : integer
Day of the week with which the generation starts
1-7 for monday-sunday.
Expand All @@ -357,7 +367,8 @@ def calcProfiles(self, site: Dict[str, Any], time_resolution: int,
resolution of time steps of output array in seconds.
irradiation: array
if none is given default weather data (TRY 2015 Potsdam) is used
building : dict
Building data, currently not used but kept for consistency.
'''

Expand Down Expand Up @@ -459,7 +470,8 @@ def calculate_gain_profile(self) -> None:


def calcHeatingProfile(self, site: Dict[str, Any],
envelope: Any, time_resolution: int) -> None:
envelope: Any, night_setback : int, holidays: list,
time_resolution: int) -> None:

'''
Calclulate heat demand for each building
Expand All @@ -470,6 +482,10 @@ def calcHeatingProfile(self, site: Dict[str, Any],
site data, e.g. weather
envelope: object
containing all physical data of the envelope
night_setback : integer
Night setback is activated (1) or deactivated (0).
holidays: list
List of holidays.
time_resolution : integer
resolution of time steps of output array in seconds.
Q_HC : float
Expand All @@ -480,15 +496,18 @@ def calcHeatingProfile(self, site: Dict[str, Any],

dt = time_resolution/(60*60)
# calculate the temperatures (Q_HC, T_op, T_m, T_air, T_s)
(Q_HC, T_i, T_s, T_m, T_op) = heating.calculate(envelope, envelope.T_set_min, site["T_e"], dt)
# heating load for the current time step in Watt
self.heat = np.zeros(len(Q_HC))
self.heat = np.maximum(0, Q_HC)
if night_setback == 1:
(Q_H, Q_C, T_op, T_m, T_i, T_s) = heating.calc_night_setback(envelope, site["T_e"], holidays, dt,
self.usage)
elif night_setback == 0:
(Q_H, Q_C, T_op, T_m, T_i, T_s) = heating.calc(envelope, site["T_e"], holidays, dt, self.usage)


self.heat = Q_H
self.cooling = Q_C

(Q_HC, T_i, T_s, T_m, T_op) = heating.calculate(envelope, envelope.T_set_max, site["T_e"], dt)
# Cooling load for the current time step in Watt
self.cool = np.zeros(len(Q_HC))
self.cool = np.minimum(0, Q_HC)
self.annual_heat_demand = np.sum(Q_H)
self.annual_cooling_demand = np.sum(Q_C)


def saveProfiles(self,unique_name: str,path: str) -> None:
Expand All @@ -511,7 +530,7 @@ def saveProfiles(self,unique_name: str,path: str) -> None:
'occ': self.occ,
'gains': self.gains,
'heat': self.heat,
'cool': self.cool
'cool': self.cooling
})
data.to_csv(os.path.join(path, f'{unique_name}.csv'), index=False)

Expand Down
36 changes: 5 additions & 31 deletions districtgenerator/classes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,15 @@ def create_el_wrapper(self):
max_iter=15,
prev_heat_dev=True)

# Create and save light configuration object
# Create and save light configuration object,
lights = light_model.load_lighting_profile(filename=path_light,
index=self.lighting_index[j])

# Create wrapper object
self.el_wrapper.append(wrap.ElectricityProfile(appliances, lights))

def calcProfiles(self, site, holidays, time_resolution, time_horizon, building, path, initial_day=1):

def calcProfiles(self, site, holidays, time_resolution, time_horizon, building, initial_day=1):
"""
Calculate profiles for every flat and summarize them for the whole building
Expand Down Expand Up @@ -382,7 +383,8 @@ def calcProfiles(self, site, holidays, time_resolution, time_horizon, building,
# self.elec = np.loadtxt(path + '/elec_' + unique_name + '.csv', delimiter=',')
# self.gains = np.loadtxt(path + '/gains_' + unique_name + '.csv', delimiter=',')

def calcHeatingProfile(self, site, envelope, night_setback, holidays, time_resolution):
def calcHeatingProfile(self, site, envelope, night_setback,
holidays, time_resolution):
"""
Calculate heat demand for each building.
Expand Down Expand Up @@ -463,34 +465,6 @@ def saveProfiles(self, unique_name, path):
writer.writerow(fields)
'''

def saveHeatingProfile(self, unique_name, path):
"""
Save heating demand to csv.
Parameters
----------
unique_name : string
Unique building name.
path : string
Results path.
Returns
-------
None.
"""

if not os.path.exists(path):
os.makedirs(path)

data = pd.DataFrame({
'elec': self.elec,
'dhw': self.dhw,
'occ': self.occ,
'gains': self.gains,
'heat': self.heat,
'cool': self.cooling
})
data.to_csv(path + f'/{unique_name}' + '.csv', index=False)

def loadProfiles(self, unique_name, path):
"""
Expand Down
Loading

0 comments on commit 1cf3a55

Please sign in to comment.