import pysimdeum
import gzip
import pickle
import matplotlib.pyplot as plt
from pysimdeum.core.house import Property
from pysimdeum.core.statistics import Statistics
import pysimdeum.tools.write as writer
# Build a house (two-person household)
house = pysimdeum.built_house(house_type='one_person', duration ='1 day')
You can save the house object as a python pickle object. You can save many different object types as a pickle that can later be read back into Python easily. In this case, we can write the House instance.
# Assuming houses is a list of house objects
with gzip.open('data/house.pkl.gz', 'wb') as f:
pickle.dump(house, f)
Or if you wanted to generate a list of House objects, you could also pickle that.
houses = []
number_of_houses = 2
for _i in range(number_of_houses):
stats = Statistics()
prop = Property(statistics=stats)
house = prop.built_house()
house.populate_house()
house.furnish_house()
for user in house.users:
user.compute_presence(statistics=stats)
house.simulate()
houses.append(house)
houses
[House: id = e8d2cb9e-ab60-4b0b-9bc2-bba7f7569717 type = two_person user = 2 appliances = ['WcNormalSave', 'Bathtub', 'BathroomTap', 'Dishwasher', 'KitchenTap', 'OutsideTap', 'FancyShower', 'WashingMachine'], House: id = e8d2cb9e-ab60-4b0b-9bc2-bba7f7569717 type = family user = 2 appliances = ['WcNewSave', 'BathroomTap', 'Dishwasher', 'KitchenTap', 'OutsideTap', 'FancyShower', 'WashingMachine']]
# Assuming houses is a list of house objects
with gzip.open('data/houses.pkl.gz', 'wb') as f:
pickle.dump(houses, f)
You can read either of these pickle objects back into Python in a similar way and then interact with it in the usual ways you might such as plotting the consumption pattern of a house.
# pickle object can be read back
with gzip.open('data/house.pkl.gz', 'rb') as f:
house_read = pickle.load(f)
house_read
House: id = e8d2cb9e-ab60-4b0b-9bc2-bba7f7569717 type = one_person user = 1 appliances = ['WcNewSave', 'BathroomTap', 'KitchenTap', 'NormalShower', 'WashingMachine']
house_read.consumption.sum(["enduse","user"]).sel(flowtypes="totalflow").plot()
[<matplotlib.lines.Line2D at 0x107e3cad0>]
pySIMDEUM write methods¶
pySIMDEUM includes a number of in-built write methods to provide easy ways to retrieve summary statistics about simulations.
These can be accessed by import functions from the write module, as below
import pysimdeum.tools.write as writer
A summary of these functions are:
writer.export_water_use_distribution: exports summary of water usage data for appliances in a property or house to an excel files containing two sheetsdata: appliance-level water usage datametadata: contains metadata such as total water usage, number of users, and calculation data
write_simdeum_patterns_to_ddg:write_simdeum_patterns_to_xlsx: exports total water usage patterns to an excel file summated to each timestep level specified by the user for all houseswrite_simdeum_patterns_to_xlsx: similar to the above, but specifically forhotwaterflow
For example, you could write the total flows to an excel file summating to minute (60 second) timesteps.
Note that these methods are only currently set up to work for consumption simulations
writer.write_simdeum_patterns_to_xlsx(houses, timestep=60, Q_option='m3/h', patternfile_option=1, output_file='houses.xlsx')