-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #929 from NREL/resstock-args-refactor
New ResStockArgumentsPostHPXML measure
- Loading branch information
Showing
15 changed files
with
283 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3827e629e35c9fbbbc53363b9886e22d | ||
357944431a5a88e46e2b12c30da3f703 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# 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 | ||
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('building_id', false) | ||
arg.setDisplayName('Building Unit ID') | ||
arg.setDescription('The building unit number (between 1 and the number of samples).') | ||
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 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 | ||
|
||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?xml version="1.0"?> | ||
<measure> | ||
<schema_version>3.1</schema_version> | ||
<name>res_stock_arguments_post_hpxml</name> | ||
<uid>db102ce5-ac96-4ef9-90d3-abbe53478716</uid> | ||
<version_id>6566f1b1-977e-47da-9d62-b4cd3fae0553</version_id> | ||
<version_modified>2025-02-04T21:19:03Z</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>building_id</name> | ||
<display_name>Building Unit ID</display_name> | ||
<description>The building unit number (between 1 and the number of samples).</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 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>A81E9245</checksum> | ||
</file> | ||
<file> | ||
<filename>test_resstock_arguments_post_hpxml.rb</filename> | ||
<filetype>rb</filetype> | ||
<usage_type>test</usage_type> | ||
<checksum>31C4A0A8</checksum> | ||
</file> | ||
</files> | ||
</measure> |
Oops, something went wrong.