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

New ResStockArgumentsPostHPXML measure #929

Open
wants to merge 39 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
172879c
Rename ResstockArguments to ResStockArgumentsPreHPXML.
joseph-robertson May 13, 2022
fa408c7
Update measure name in other measures and lookup.
joseph-robertson May 13, 2022
44347c3
Stub new ResStockArgumentsPostHPXML measure.
joseph-robertson May 13, 2022
771042c
Update meta measures for new measure.
joseph-robertson May 13, 2022
2abcc64
Get meta measures working properly.
joseph-robertson May 13, 2022
1587e5b
Update measure descriptions.
joseph-robertson May 13, 2022
7bdf4da
More description updates.
joseph-robertson May 13, 2022
e111940
Merge branch 'develop' into resstock-args-refactor
joseph-robertson May 13, 2022
6fad137
Rename pre hpxml back to original.
joseph-robertson May 13, 2022
fd288ae
Revert lookup.
joseph-robertson May 13, 2022
06133ea
Merge branch 'develop' into resstock-args-refactor
joseph-robertson May 17, 2022
87e876b
Measure updates.
joseph-robertson May 17, 2022
957b9c9
Temp code in building existing model.
joseph-robertson May 17, 2022
3a5effb
Remove project folders before each test.
joseph-robertson May 17, 2022
be0e390
Squashed 'resources/hpxml-measures/' changes from c015c17d0ee..cdaa49…
joseph-robertson May 19, 2022
a8bfe43
Merge commit 'be0e390519975d5028881cfb584b5c89bef9f497' into resstock…
joseph-robertson May 19, 2022
94c5b04
Ignore new debug argument for resstock arguments.
joseph-robertson May 19, 2022
e6736f6
Merge branch 'develop' into resstock-args-refactor
joseph-robertson May 19, 2022
5c23cf2
Request setpoint output vars.
joseph-robertson May 20, 2022
53f3fc0
Latest results.
May 21, 2022
a8fc8d3
Merge branch 'develop' into resstock-args-refactor
joseph-robertson Jun 6, 2022
bfa8478
Merge branch 'develop' into resstock-args-refactor
joseph-robertson Jul 8, 2022
76ef1b6
Latest results.
Jul 8, 2022
d2d0ceb
Merge branch 'develop' into resstock-args-refactor
joseph-robertson Nov 3, 2022
55b9fa5
Clean up top level measures.
joseph-robertson Nov 3, 2022
c7c7948
Latest results.
Nov 4, 2022
4f7106d
Update changelog.
joseph-robertson Nov 4, 2022
87279c6
Update docs.
joseph-robertson Nov 4, 2022
2dac598
Revert output vars request in yml.
joseph-robertson Nov 4, 2022
ecd366d
Latest results.
Nov 4, 2022
abae054
Merge branch 'develop' into resstock-args-refactor
joseph-robertson Nov 14, 2022
b68c82f
Merge branch 'develop' into resstock-args-refactor
joseph-robertson Nov 16, 2022
bd316de
Merge branch 'develop' into resstock-args-refactor
rajeee Oct 14, 2024
18f62ab
Cleanup merge conflicts
rajeee Oct 14, 2024
dae2310
Reimplment calling ResStockArgumentsPostHPXML
rajeee Oct 14, 2024
c454026
Update measures
rajeee Oct 15, 2024
e7b642e
Merge branch 'ci_fix' into resstock-args-refactor
rajeee Oct 15, 2024
17e85f5
Update to use runner method
rajeee Oct 15, 2024
95f5936
Merge branch 'develop' into resstock-args-refactor
rajeee Oct 16, 2024
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
295 changes: 295 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions docs/read_the_docs/source/basic_tutorial/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The BuildExistingModel and ApplyUpgrade meta measures call the following model m
1 ResStockArguments Model No ResStock
2 BuildResidentialHPXML Model No OS-HPXML
3 BuildResidentialScheduleFile Model No OS-HPXML
4 ResStockArgumentsPostHPXML Model No ResStock
===== ============================= ================== ========= ============= ==========================

.. _model-measures:
Expand Down Expand Up @@ -117,6 +118,16 @@ They contribute to the generation of the model.
:start-after: <modeler_description>
:end-before: <

**ResStockArgumentsPostHPXML**

.. include:: ../../../../measures/ResStockArgumentsPostHPXML/measure.xml
:start-after: <description>
:end-before: <

.. include:: ../../../../measures/ResStockArgumentsPostHPXML/measure.xml
:start-after: <modeler_description>
:end-before: <

.. _tutorial-apply-upgrade:

**ApplyUpgrade**
Expand Down
16 changes: 16 additions & 0 deletions docs/read_the_docs/source/changelog/changelog_dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,19 @@ Development Changelog
Specifically, this PR modifies HVAC heating/cooling seasons using number of unavailable days and BAHSP definition for heating/cooling months.

Assignees: Joe Robertson

.. change::
:tags: workflow, feature
:pullreq: 929

**Date**: 2024-10-14

Title:
New ResStockArgumentsPostHPXML measure

Description:
This measure is added to the workflow to post-process the output of the BuildResidentialHPXML and BuildResidentialScheduleFile measures.

Assignees: Joe Robertson, Rajendra Adhikari

GitHub: `pull request 929 <https://github.com/NREL/resstock/pull/929>`_
11 changes: 10 additions & 1 deletion measures/ApplyUpgrade/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,19 @@ def run(model, runner, user_arguments)
return false
end

measures['ResStockArgumentsPostHPXML'] = [{ 'hpxml_path' => hpxml_path,
'output_csv_path' => File.expand_path('../schedules.csv') }]
measures_hash = { 'ResStockArgumentsPostHPXML' => measures['ResStockArgumentsPostHPXML'] }
if not apply_measures(measures_dir, measures_hash, new_runner, model, true, 'OpenStudio::Measure::ModelMeasure', nil)
register_logs(runner, new_runner)
return false
end

# Specify measures to run
measures_to_apply_hash = { measures_dir => {} }

upgrade_measures = measures.keys - ['ResStockArguments', 'BuildResidentialHPXML', 'BuildResidentialScheduleFile']
upgrade_measures = measures.keys - ['ResStockArguments', 'BuildResidentialHPXML', 'BuildResidentialScheduleFile',
'ResStockArgumentsPostHPXML']
upgrade_measures.each do |upgrade_measure|
measures_to_apply_hash[measures_dir][upgrade_measure] = measures[upgrade_measure]
end
Expand Down
6 changes: 3 additions & 3 deletions measures/ApplyUpgrade/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.1</schema_version>
<name>apply_upgrade</name>
<uid>33f1654c-f734-43d1-b35d-9d2856e41b5a</uid>
<version_id>e0b6d3af-6941-45e2-8627-9d8f568ebe1a</version_id>
<version_modified>2024-09-04T23:38:38Z</version_modified>
<version_id>a96d3a1a-9d53-4151-a4f0-3a5d1aa05395</version_id>
<version_modified>2024-10-14T21:52:14Z</version_modified>
<xml_checksum>9339BE01</xml_checksum>
<class_name>ApplyUpgrade</class_name>
<display_name>Apply Upgrade</display_name>
Expand Down Expand Up @@ -6342,7 +6342,7 @@
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>8E47BE40</checksum>
<checksum>06F005A1</checksum>
</file>
<file>
<filename>constants.rb</filename>
Expand Down
8 changes: 8 additions & 0 deletions measures/BuildExistingModel/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,14 @@ def run(model, runner, user_arguments)
end
end

measures['ResStockArgumentsPostHPXML'] = [{ 'hpxml_path' => hpxml_path,
'output_csv_path' => File.expand_path('../schedules.csv') }]
measures_hash = { 'ResStockArgumentsPostHPXML' => measures['ResStockArgumentsPostHPXML'] }
if not apply_measures(measures_dir, measures_hash, new_runner, model, true, 'OpenStudio::Measure::ModelMeasure', nil)
register_logs(runner, new_runner)
return false
end

# Copy existing.xml to home.xml for downstream HPXMLtoOpenStudio
# We need existing.xml (and not just home.xml) for UpgradeCosts
in_path = File.expand_path('../home.xml')
Expand Down
6 changes: 3 additions & 3 deletions measures/BuildExistingModel/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.1</schema_version>
<name>build_existing_model</name>
<uid>dedf59bb-3b88-4f16-8755-2c1ff5519cbf</uid>
<version_id>be99be23-ddd9-49c4-804a-cb9853764e3e</version_id>
<version_modified>2024-09-04T21:01:10Z</version_modified>
<version_id>cf3e6167-7071-4ab1-91fc-200ab31c7e3a</version_id>
<version_modified>2024-10-14T21:52:15Z</version_modified>
<xml_checksum>2C38F48B</xml_checksum>
<class_name>BuildExistingModel</class_name>
<display_name>Build Existing Model</display_name>
Expand Down Expand Up @@ -349,7 +349,7 @@
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>18614B0C</checksum>
<checksum>1488CAC4</checksum>
</file>
</files>
</measure>
2 changes: 1 addition & 1 deletion measures/ResStockArguments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Description
Measure that pre-processes the arguments passed to the BuildResidentialHPXML and BuildResidentialScheduleFile measures.

Passes in all arguments from the options lookup, processes them, and then registers values to the runner to be used by other measures.
Passes in all ResStockArguments arguments from the options lookup, processes them, and then registers values to the runner to be used by other measures.

## Arguments

Expand Down
2 changes: 1 addition & 1 deletion measures/ResStockArguments/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def description

# human readable description of modeling approach
def modeler_description
return 'Passes in all arguments from the options lookup, processes them, and then registers values to the runner to be used by other measures.'
return 'Passes in all ResStockArguments arguments from the options lookup, processes them, and then registers values to the runner to be used by other measures.'
end

# define the arguments that the user will input
Expand Down
10 changes: 5 additions & 5 deletions measures/ResStockArguments/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<schema_version>3.1</schema_version>
<name>res_stock_arguments</name>
<uid>c984bb9e-4ac4-4930-a399-9d23f8f6936a</uid>
<version_id>534c899e-ac51-4052-92ce-876e8ee58146</version_id>
<version_modified>2024-09-25T03:27:57Z</version_modified>
<version_id>d67a956d-0c18-479a-8d76-520e1e39e737</version_id>
<version_modified>2024-10-14T21:52:16Z</version_modified>
<xml_checksum>2C38F48B</xml_checksum>
<class_name>ResStockArguments</class_name>
<display_name>ResStock Arguments</display_name>
<description>Measure that pre-processes the arguments passed to the BuildResidentialHPXML and BuildResidentialScheduleFile measures.</description>
<modeler_description>Passes in all arguments from the options lookup, processes them, and then registers values to the runner to be used by other measures.</modeler_description>
<modeler_description>Passes in all ResStockArguments arguments from the options lookup, processes them, and then registers values to the runner to be used by other measures.</modeler_description>
<arguments>
<argument>
<name>simulation_control_daylight_saving_enabled</name>
Expand Down Expand Up @@ -7684,7 +7684,7 @@
<filename>README.md</filename>
<filetype>md</filetype>
<usage_type>readme</usage_type>
<checksum>7C3E7B89</checksum>
<checksum>2141A583</checksum>
</file>
<file>
<filename>README.md.erb</filename>
Expand All @@ -7701,7 +7701,7 @@
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>1B03697A</checksum>
<checksum>003048B1</checksum>
</file>
<file>
<filename>constants.rb</filename>
Expand Down
102 changes: 102 additions & 0 deletions measures/ResStockArgumentsPostHPXML/measure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# frozen_string_literal: true

# see the URL below for information on how to write OpenStudio measures
# http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/

# start the measure
class ResStockArgumentsPostHPXML < OpenStudio::Measure::ModelMeasure
# human readable name
def name
# Measure name should be the title case of the class name.
return 'ResStock Arguments Post-HPXML'
end

# human readable description
def description
return 'Measure that post-processes the output of the BuildResidentialHPXML and BuildResidentialScheduleFile measures.'
end

# human readable description of modeling approach
def modeler_description
return 'Passes in all ResStockArgumentsPostHPXML arguments from the options lookup, processes them, and then modifies output of other measures.'
end

# define the arguments that the user will input
def arguments(model) # rubocop:disable Lint/UnusedMethodArgument
args = OpenStudio::Measure::OSArgumentVector.new

arg = OpenStudio::Measure::OSArgument.makeStringArgument('hpxml_path', false)
arg.setDisplayName('HPXML File Path')
arg.setDescription('Absolute/relative path of the HPXML file.')
args << arg

arg = OpenStudio::Measure::OSArgument::makeStringArgument('output_csv_path', false)
arg.setDisplayName('Schedules: Output CSV Path')
arg.setDescription('Absolute/relative path of the csv file containing user-specified occupancy schedules. Relative paths are relative to the HPXML output path.')
args << arg

return args
end

# define what happens when the measure is run
def run(model, runner, user_arguments)
super(model, runner, user_arguments)

# use the built-in error checking
if !runner.validateUserArguments(arguments(model), user_arguments)
return false
end

# assign the user inputs to variables
args = runner.getArgumentValues(arguments(model), user_arguments)

hpxml_path = args[:hpxml_path]
unless (Pathname.new hpxml_path).absolute?
hpxml_path = File.expand_path(File.join(File.dirname(__FILE__), hpxml_path))
end
unless File.exist?(hpxml_path) && hpxml_path.downcase.end_with?('.xml')
fail "'#{hpxml_path}' does not exist or is not an .xml file."
end

_hpxml = HPXML.new(hpxml_path: hpxml_path)

# init
new_schedules = {}

# TODO: populate new_schedules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add the schedules here or is this section just a placeholder for future PRs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a placeholder for future PRs.


# return if not writing schedules
return true if new_schedules.empty?

# write schedules
schedules_filepath = File.join(File.dirname(args[:output_csv_path].get), 'schedules2.csv')
write_new_schedules(new_schedules, schedules_filepath)

# modify the hpxml with the schedules path
doc = XMLHelper.parse_file(hpxml_path)
extension = XMLHelper.create_elements_as_needed(XMLHelper.get_element(doc, '/HPXML'), ['SoftwareInfo', 'extension'])
schedules_filepaths = XMLHelper.get_values(extension, 'SchedulesFilePath', :string)
if !schedules_filepaths.include?(schedules_filepath)
XMLHelper.add_element(extension, 'SchedulesFilePath', schedules_filepath, :string)

# write out the modified hpxml
XMLHelper.write_file(doc, hpxml_path)
runner.registerInfo("Wrote file: #{hpxml_path}")
end

return true
end

def write_new_schedules(schedules, schedules_filepath)
CSV.open(schedules_filepath, 'w') do |csv|
csv << schedules.keys
rows = schedules.values.transpose
rows.each do |row|
csv << row.map { |x| '%.3g' % x }
end
end
end
end

# register the measure to be used by the application
ResStockArgumentsPostHPXML.new.registerWithApplication
56 changes: 56 additions & 0 deletions measures/ResStockArgumentsPostHPXML/measure.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0"?>
<measure>
<schema_version>3.0</schema_version>
<name>res_stock_arguments_post_hpxml</name>
<uid>db102ce5-ac96-4ef9-90d3-abbe53478716</uid>
<version_id>e9a3773b-66b5-48a6-95e5-4ce42262a640</version_id>
<version_modified>20221103T232039Z</version_modified>
<xml_checksum>2C38F48B</xml_checksum>
<class_name>ResStockArgumentsPostHPXML</class_name>
<display_name>ResStock Arguments Post-HPXML</display_name>
<description>Measure that post-processes the output of the BuildResidentialHPXML and BuildResidentialScheduleFile measures.</description>
<modeler_description>Passes in all ResStockArgumentsPostHPXML arguments from the options lookup, processes them, and then modifies output of other measures.</modeler_description>
<arguments>
<argument>
<name>hpxml_path</name>
<display_name>HPXML File Path</display_name>
<description>Absolute/relative path of the HPXML file.</description>
<type>String</type>
<required>false</required>
<model_dependent>false</model_dependent>
</argument>
<argument>
<name>output_csv_path</name>
<display_name>Schedules: Output CSV Path</display_name>
<description>Absolute/relative path of the csv file containing user-specified occupancy schedules. Relative paths are relative to the HPXML output path.</description>
<type>String</type>
<required>false</required>
<model_dependent>false</model_dependent>
</argument>
</arguments>
<outputs />
<provenances />
<tags>
<tag>Whole Building.Space Types</tag>
</tags>
<attributes>
<attribute>
<name>Measure Type</name>
<value>ModelMeasure</value>
<datatype>string</datatype>
</attribute>
</attributes>
<files>
<file>
<version>
<software_program>OpenStudio</software_program>
<identifier>3.3.0</identifier>
<min_compatible>3.3.0</min_compatible>
</version>
<filename>measure.rb</filename>
<filetype>rb</filetype>
<usage_type>script</usage_type>
<checksum>5A9AF6DF</checksum>
</file>
</files>
</measure>
16 changes: 14 additions & 2 deletions measures/UpgradeCosts/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.1</schema_version>
<name>upgrade_costs</name>
<uid>ef51212c-acc4-48d7-9b29-cf2a5c6c4449</uid>
<version_id>7204a97f-58e6-4b3f-a5cf-f09f70cc9833</version_id>
<version_modified>2024-08-22T14:52:49Z</version_modified>
<version_id>8e459be4-c586-4ada-a330-0e1c78b011b0</version_id>
<version_modified>2024-10-14T21:52:18Z</version_modified>
<xml_checksum>B1F14CB4</xml_checksum>
<class_name>UpgradeCosts</class_name>
<display_name>Upgrade Costs</display_name>
Expand Down Expand Up @@ -215,6 +215,18 @@
<usage_type>test</usage_type>
<checksum>083B023F</checksum>
</file>
<file>
<filename>results_annual.csv</filename>
<filetype>csv</filetype>
<usage_type>test</usage_type>
<checksum>5687044D</checksum>
</file>
<file>
<filename>results_design_load_details.csv</filename>
<filetype>csv</filetype>
<usage_type>test</usage_type>
<checksum>19F07CC2</checksum>
</file>
<file>
<filename>upgrade_costs_test.rb</filename>
<filetype>rb</filetype>
Expand Down
13 changes: 13 additions & 0 deletions resources/buildstock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,19 @@ def get_data_for_sample(buildstock_csv_path, building_id, runner)
fail msg
end

def register_logs(runner, new_runner)
new_runner.result.warnings.each do |warning|
runner.registerWarning(warning.logMessage)
end
new_runner.result.info.each do |info|
runner.registerInfo(info.logMessage)
end
new_runner.result.errors.each do |error|
runner.registerError(error.logMessage)
end
return
end

class RunOSWs
require 'openstudio'
require 'csv'
Expand Down