Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix* emissions reporting #231

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions measures/emissions_reporting/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ def resources(model)

def enduses
enduses = [
'Cooling',
'Heating',
# 'Fans',
# 'Pumps',
# 'HeatRejection',
# 'HeatRecovery',
'InteriorLights',
'ExteriorLights',
'InteriorEquipment',
Expand All @@ -217,12 +222,12 @@ def enduses

def hvac_uses
hvac_uses = [
'Heating',
'Cooling',
'Heating',
'Fans',
'Pumps',
'HeatRejection',
'Humidification',
# 'Humidification',
'HeatRecovery'
]
return hvac_uses
Expand Down Expand Up @@ -301,27 +306,23 @@ def energyPlusOutputRequests(runner, user_arguments)
# add enduse meters
enduses.each do |enduse|
# lights, refrigeration only use electricity
next if (enduse.include?("Lights") || enduse.include?("Refrigeration")) && resource != "Electricity"
next if (enduse.include?('Lights') || enduse.include?('Refrigeration')) && resource != 'Electricity'
result << OpenStudio::IdfObject.load("Output:Meter,#{enduse}:#{resource},#{frequency};").get
end

# custom meters for hvac
# custom meters for HVAC
total_hvac_string = "Meter:Custom,TotalHVAC:#{resource},#{resource},"
hvac_uses.each_with_index do |use,i|
if hvac_uses.size == i+1

hvac_uses.each_with_index do |use, i|
if hvac_uses.size == i + 1
total_hvac_string << ",#{use}:#{resource};"
else
total_hvac_string << ",#{use}:#{resource},"
end
end

cooling_string = "Meter:Custom,CoolingHVAC:#{resource},#{resource},,Cooling:#{resource},,HeatRejection:#{resource};"

result << OpenStudio::IdfObject.load(total_hvac_string).get
result << OpenStudio::IdfObject.load(cooling_string).get
result << OpenStudio::IdfObject.load("Output:Meter,TotalHVAC:#{resource},#{frequency};").get
result << OpenStudio::IdfObject.load("Output:Meter,CoolingHVAC:#{resource},#{frequency};").get

end

Expand Down Expand Up @@ -466,22 +467,19 @@ def run(runner, user_arguments)
return false
end

# hourly_electricity_kwh = []
hourly_electricity_mwh = []
# electricity_values.each { |val| hourly_electricity_kwh << val * j_to_kwh }
electricity_values.each { |val| hourly_electricity_mwh << val * j_to_mwh }
hourly_electricity_mwh = electricity_values.map{ |val| val * j_to_mwh }

# get end-use electricity values
electricity_enduse_results = {}
enduses.push(["TotalHVAC","CoolingHVAC"]).flatten.each do |enduse|
enduses.push(['TotalHVAC']).flatten.each do |enduse|
electricity_enduse_results["#{enduse}_mwh"] = []
electricity_enduse_query = "SELECT VariableValue FROM ReportMeterData WHERE ReportMeterDataDictionaryIndex IN (SELECT ReportMeterDataDictionaryIndex from ReportMeterDataDictionary WHERE VariableType='Sum' AND upper(VariableName)='#{enduse.upcase}:ELECTRICITY' AND ReportingFrequency='Hourly' AND VariableUnits='J') AND TimeIndex IN (SELECT TimeIndex FROM Time WHERE EnvironmentPeriodIndex='#{env_period_ix}')"
electricity_enduse_values = sqlFile.execAndReturnVectorOfDouble(electricity_enduse_query).get
electricity_enduse_values = sqlFile.execAndReturnVectorOfDouble(electricity_enduse_query).get.to_a
if electricity_enduse_values.empty?
runner.registerWarning("Unable to get hourly timeseries #{enduse} electricity use from the model. Cannot calculate results")
electricity_enduse_results["#{enduse}_mwh"] << 0
end
electricity_enduse_values.each { |val| electricity_enduse_results["#{enduse}_mwh"] << val * j_to_mwh}
electricity_enduse_values.each { |val| electricity_enduse_results["#{enduse}_mwh"] << val * j_to_mwh }
end

# get run period natural gas values
Expand Down Expand Up @@ -522,8 +520,8 @@ def run(runner, user_arguments)
runner.registerValue('annual_propane_ghg_emissions_kg', annual_propane_emissions_co2e_kg)

# fuel end-use emissions
enduses.push("TotalHVAC").each do |enduse|
next if (enduse.include?("Lights") || enduse.include?("Refrigeration"))
enduses.push(['TotalHVAC']).flatten.each do |enduse|
next if (enduse.include?('Lights') || enduse.include?('Refrigeration'))

# get run period natural gas end-use values
gas_enduse_query = "SELECT VariableValue FROM ReportMeterData WHERE ReportMeterDataDictionaryIndex IN (SELECT ReportMeterDataDictionaryIndex from ReportMeterDataDictionary WHERE VariableType='Sum' AND upper(VariableName)='#{enduse.upcase}:#{gas.upcase}' AND ReportingFrequency='Run Period' AND VariableUnits='J') AND TimeIndex IN (SELECT TimeIndex FROM Time WHERE EnvironmentPeriodIndex='#{env_period_ix}')"
Expand Down
Loading