Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelduchesne committed Apr 8, 2022
1 parent 06fd677 commit f039bb8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 224 deletions.
224 changes: 1 addition & 223 deletions archetypal/idfclass/end_use_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,228 +127,6 @@ def __init__(
self.is_cooling = is_cooling
self.is_heating = is_heating

@classmethod
def from_idf(cls, idf, units="kWh", power_units="kW", outdoor_surfaces_only=True):
assert (
idf.sql_file.exists()
), "Expected an IDF model with simulation results. Run `IDF.simulate()` first."
# get all of the results relevant for gains and losses
_hvac_input = idf.variables.OutputVariable.collect_by_output_name(
cls.HVAC_INPUT_SENSIBLE,
reporting_frequency=idf.outputs.reporting_frequency,
units=power_units,
)
# _hvac_input = cls.apply_multipliers(_hvac_input, idf) # zone-level output

_hvac_input_heated_surface = (
idf.variables.OutputVariable.collect_by_output_name(
cls.HVAC_INPUT_HEATED_SURFACE,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
)
# zone-level output
# _hvac_input_heated_surface = cls.apply_multipliers(_hvac_input_heated_surface, idf)

_hvac_input_cooled_surface = (
idf.variables.OutputVariable.collect_by_output_name(
cls.HVAC_INPUT_COOLED_SURFACE,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
)
# _hvac_input_cooled_surface = cls.apply_multipliers(_hvac_input_cooled_surface, idf) # zone-level output

# convert power to energy assuming the reporting frequency
freq = pd.infer_freq(
_hvac_input.iloc[
:3,
].index
)
assert freq == "H", "A reporting frequency other than H is not yet supported."
freq_to_unit = {"H": "hr"}
_hvac_input = _hvac_input.apply(
lambda row: unit_registry.Quantity(
row.values,
unit_registry(power_units) * unit_registry(freq_to_unit[freq]),
)
.to(units)
.m
)

# concat sensible hvac with heated surfaces
_hvac_input = pd.concat(
filter(
lambda x: not x.empty,
[
_hvac_input,
EndUseBalance.subtract_cooled_from_heated_surface(
_hvac_input_cooled_surface, _hvac_input_heated_surface
),
],
),
axis=1,
verify_integrity=True,
)

# compute rolling sign for each zone (determines if zone is in heating or
# cooling model.)
rolling_sign = cls.get_rolling_sign_change(_hvac_input)

# Create both heating and cooling masks
is_heating = rolling_sign > 0
is_cooling = rolling_sign < 0

heating = _hvac_input[is_heating].fillna(0)
cooling = _hvac_input[is_cooling].fillna(0)

# Get internal gain components: lighting, people, equipment, solar
lighting = idf.variables.OutputVariable.collect_by_output_name(
cls.LIGHTING,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
lighting = cls.apply_multipliers(lighting, idf) # zone-level output
people_gain = idf.variables.OutputVariable.collect_by_output_name(
cls.PEOPLE_GAIN,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
people_gain = cls.apply_multipliers(people_gain, idf) # zone-level output
equipment = idf.variables.OutputVariable.collect_by_output_name(
cls.EQUIP_GAINS,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
equipment = cls.apply_multipliers(equipment, idf) # zone-level output
solar_gain = idf.variables.OutputVariable.collect_by_output_name(
cls.SOLAR_GAIN,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
solar_gain = cls.apply_multipliers(solar_gain, idf) # zone-level output
infil_gain = idf.variables.OutputVariable.collect_by_output_name(
cls.INFIL_GAIN,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
infil_gain = cls.apply_multipliers(infil_gain, idf) # zone-level output
infil_loss = idf.variables.OutputVariable.collect_by_output_name(
cls.INFIL_LOSS,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
infil_loss = cls.apply_multipliers(infil_loss, idf) # zone-level output
vent_loss = idf.variables.OutputVariable.collect_by_output_name(
cls.VENTILATION_LOSS,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
vent_loss = cls.apply_multipliers(vent_loss, idf) # zone-level output
vent_gain = idf.variables.OutputVariable.collect_by_output_name(
cls.VENTILATION_GAIN,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
vent_gain = cls.apply_multipliers(vent_gain, idf) # zone-level output
nat_vent_gain = idf.variables.OutputVariable.collect_by_output_name(
cls.NAT_VENT_GAIN,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
nat_vent_gain = cls.apply_multipliers(nat_vent_gain, idf) # zone-level output
nat_vent_loss = idf.variables.OutputVariable.collect_by_output_name(
cls.NAT_VENT_LOSS,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
nat_vent_loss = cls.apply_multipliers(nat_vent_loss, idf) # zone-level output
mech_vent_gain = idf.variables.OutputVariable.collect_by_output_name(
cls.MECHANICAL_VENT_GAIN,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
mech_vent_gain = cls.apply_multipliers(mech_vent_gain, idf) # zone-level output
mech_vent_loss = idf.variables.OutputVariable.collect_by_output_name(
cls.MECHANICAL_VENT_LOSS,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
mech_vent_loss = cls.apply_multipliers(mech_vent_loss, idf) # zone-level output

# subtract losses from gains
infiltration = None
mech_vent = None
nat_vent = None
if len(infil_gain) == len(infil_loss):
infiltration = cls.subtract_loss_from_gain(infil_gain, infil_loss)
if not any((vent_gain.empty, vent_loss.empty, cooling.empty, heating.empty)):
mech_vent = cls.subtract_loss_from_gain(mech_vent_gain, mech_vent_loss)
if nat_vent_gain.shape == nat_vent_loss.shape:
nat_vent = cls.subtract_loss_from_gain(nat_vent_gain, nat_vent_loss)

# get the surface energy flow
opaque_flow = idf.variables.OutputVariable.collect_by_output_name(
cls.OPAQUE_ENERGY_FLOW,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
opaque_storage = idf.variables.OutputVariable.collect_by_output_name(
cls.OPAQUE_ENERGY_STORAGE,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
opaque_flow = opaque_flow - opaque_storage
window_loss = idf.variables.OutputVariable.collect_by_output_name(
cls.WINDOW_LOSS,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
window_loss = cls.apply_multipliers(window_loss, idf)
window_gain = idf.variables.OutputVariable.collect_by_output_name(
cls.WINDOW_GAIN,
reporting_frequency=idf.outputs.reporting_frequency,
units=units,
)
window_gain = cls.apply_multipliers(window_gain, idf)
window_flow = cls.subtract_loss_from_gain(window_gain, window_loss)
window_flow = cls.subtract_solar_from_window_net(window_flow, solar_gain)

opaque_flow = cls.match_opaque_surface_to_zone(idf, opaque_flow)
opaque_storage = cls.match_opaque_surface_to_zone(idf, opaque_storage)
if outdoor_surfaces_only:
opaque_flow = opaque_flow.drop(
["Surface", float("nan")], level="Outside_Boundary_Condition", axis=1
)
# opaque_storage = opaque_storage.drop(
# ["Surface", float("nan")], level="Outside_Boundary_Condition", axis=1
# )
window_energy_flow = window_flow

bal_obj = cls(
idf,
cooling,
heating,
lighting,
equipment,
None,
None,
people_gain,
solar_gain,
infiltration,
mech_vent,
nat_vent,
window_energy_flow,
opaque_flow,
opaque_storage,
window_flow,
is_cooling,
is_heating,
units,
use_all_solar=True,
)
return bal_obj

@classmethod
def from_sql_file(
cls, sql_file, units="kWh", power_units="kW", outdoor_surfaces_only=True
Expand Down Expand Up @@ -468,7 +246,7 @@ def from_sql_file(
)
opaque_storage_ = opaque_storage.copy()
opaque_storage_.columns = opaque_flow.columns
opaque_flow = - (opaque_flow + opaque_storage_)
opaque_flow = -(opaque_flow + opaque_storage_)
window_loss = sql.timeseries_by_name(cls.WINDOW_LOSS).to_units(units)
window_loss = cls.apply_multipliers(window_loss, zone_multipliers)
window_gain = sql.timeseries_by_name(cls.WINDOW_GAIN).to_units(units)
Expand Down
3 changes: 2 additions & 1 deletion archetypal/zone_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ def plot_graph2d(
Examples:
>>> import networkx as nx
>>> G = BuildingTemplate().from_idf
>>> from archetypal.umi_template import BuildingTemplate
>>> G = BuildingTemplate.from_idf()
>>> G.plot_graph2d(nx.nx_agraph.graphviz_layout, ('dot'),
>>> font_color='w', legend=True, font_size=8,
>>> color_nodes='core',
Expand Down

0 comments on commit f039bb8

Please sign in to comment.