Skip to content

Commit

Permalink
Merge pull request #968 from NREL/weather_dump_bugfix
Browse files Browse the repository at this point in the history
Weather dump bugfix
  • Loading branch information
shorowit committed Jul 19, 2022
2 parents 5a7201c + 81cc16c commit 78768ee
Show file tree
Hide file tree
Showing 222 changed files with 118,220 additions and 118,220 deletions.
8 changes: 4 additions & 4 deletions resources/hpxml-measures/HPXMLtoOpenStudio/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ def process_weather(hpxml, runner, model, hpxml_path)
cache_path = epw_path.gsub('.epw', '-cache.csv')
if not File.exist?(cache_path)
# Process weather file to create cache .csv
runner.registerWarning("'#{cache_path}' could not be found; regenerating it.")
epw_file = OpenStudio::EpwFile.new(epw_path)
OpenStudio::Model::WeatherFile.setWeatherFile(model, epw_file)
weather = WeatherProcess.new(model, runner)
begin
File.open(cache_path, 'wb') do |file|
runner.registerWarning("'#{cache_path}' could not be found; regenerating it.")
epw_file = OpenStudio::EpwFile.new(epw_path)
OpenStudio::Model::WeatherFile.setWeatherFile(model, epw_file)
weather = WeatherProcess.new(model, runner)
weather.dump_to_csv(file)
end
rescue SystemCallError
Expand Down
50 changes: 25 additions & 25 deletions resources/hpxml-measures/HPXMLtoOpenStudio/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.0</schema_version>
<name>hpxm_lto_openstudio</name>
<uid>b1543b30-9465-45ff-ba04-1d1f85e763bc</uid>
<version_id>76b1bc32-9128-4e71-9725-08493e1714c6</version_id>
<version_modified>20220715T163332Z</version_modified>
<version_id>f661da4a-4a20-4b85-91aa-faeb97cd23c3</version_id>
<version_modified>20220719T191443Z</version_modified>
<xml_checksum>D8922A73</xml_checksum>
<class_name>HPXMLtoOpenStudio</class_name>
<display_name>HPXML to OpenStudio Translator</display_name>
Expand Down Expand Up @@ -361,12 +361,6 @@
<usage_type>resource</usage_type>
<checksum>1C142FA2</checksum>
</file>
<file>
<filename>weather.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>DD49A39B</checksum>
</file>
<file>
<filename>battery.rb</filename>
<filetype>rb</filetype>
Expand Down Expand Up @@ -511,17 +505,6 @@
<usage_type>test</usage_type>
<checksum>D62F7243</checksum>
</file>
<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>F4AF8C45</checksum>
</file>
<file>
<filename>test_defaults.rb</filename>
<filetype>rb</filetype>
Expand Down Expand Up @@ -558,12 +541,6 @@
<usage_type>resource</usage_type>
<checksum>2B0922EC</checksum>
</file>
<file>
<filename>hpxml_schematron/HPXMLvalidator.xml</filename>
<filetype>xml</filetype>
<usage_type>resource</usage_type>
<checksum>7AF2540D</checksum>
</file>
<file>
<filename>test_hvac_sizing.rb</filename>
<filetype>rb</filetype>
Expand All @@ -588,5 +565,28 @@
<usage_type>resource</usage_type>
<checksum>0671923D</checksum>
</file>
<file>
<filename>hpxml_schematron/HPXMLvalidator.xml</filename>
<filetype>xml</filetype>
<usage_type>resource</usage_type>
<checksum>5DD85F0D</checksum>
</file>
<file>
<filename>weather.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>E810B63B</checksum>
</file>
<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>70575CEF</checksum>
</file>
</files>
</measure>

Large diffs are not rendered by default.

49 changes: 21 additions & 28 deletions resources/hpxml-measures/HPXMLtoOpenStudio/resources/weather.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,15 @@ def initialize(model, runner, csv_path = nil)
return
end

@model = model
@runner = runner
epw_path = get_epw_path(model)

@epw_path = WeatherProcess.get_epw_path(@model)

if not File.exist?(@epw_path)
if not File.exist?(epw_path)
fail "Cannot find weather file at #{epw_path}."
end

@epw_file = OpenStudio::EpwFile.new(@epw_path, true)

process_epw
end
epw_file = OpenStudio::EpwFile.new(epw_path, true)

def epw_path
return @epw_path
process_epw(runner, epw_file)
end

def dump_to_csv(csv_path)
Expand Down Expand Up @@ -106,7 +99,7 @@ def to_datatype(data, dataclass)

private

def self.get_epw_path(model)
def get_epw_path(model)
if model.weatherFile.is_initialized

wf = model.weatherFile.get
Expand All @@ -125,23 +118,23 @@ def self.get_epw_path(model)
fail 'Model has not been assigned a weather file.'
end

def process_epw
def process_epw(runner, epw_file)
# Header info:
@header.City = @epw_file.city
@header.State = @epw_file.stateProvinceRegion
@header.Country = @epw_file.country
@header.DataSource = @epw_file.dataSource
@header.Station = @epw_file.wmoNumber
@header.Latitude = @epw_file.latitude
@header.Longitude = @epw_file.longitude
@header.Timezone = @epw_file.timeZone
@header.Altitude = UnitConversions.convert(@epw_file.elevation, 'm', 'ft')
@header.City = epw_file.city
@header.State = epw_file.stateProvinceRegion
@header.Country = epw_file.country
@header.DataSource = epw_file.dataSource
@header.Station = epw_file.wmoNumber
@header.Latitude = epw_file.latitude
@header.Longitude = epw_file.longitude
@header.Timezone = epw_file.timeZone
@header.Altitude = UnitConversions.convert(epw_file.elevation, 'm', 'ft')
@header.LocalPressure = Math::exp(-0.0000368 * @header.Altitude) # atm
@header.RecordsPerHour = @epw_file.recordsPerHour
@header.RecordsPerHour = epw_file.recordsPerHour

epw_file_data = @epw_file.data
epw_file_data = epw_file.data

epwHasDesignData = get_design_info_from_epw
epwHasDesignData = get_design_info_from_epw(epw_file)

# Timeseries data:
rowdata = []
Expand Down Expand Up @@ -215,7 +208,7 @@ def process_epw
@data.WSF = calc_ashrae_622_wsf(rowdata)

if not epwHasDesignData
@runner.registerWarning('No design condition info found; calculating design conditions from EPW weather data.')
runner.registerWarning('No design condition info found; calculating design conditions from EPW weather data.')
calc_design_info(rowdata)
@design.DailyTemperatureRange = @data.MonthlyAvgDailyHighDrybulbs[7] - @data.MonthlyAvgDailyLowDrybulbs[7]
end
Expand Down Expand Up @@ -404,8 +397,8 @@ def calc_ashrae_622_wsf(rowdata)
return wsf.round(2)
end

def get_design_info_from_epw
epw_design_conditions = @epw_file.designConditions
def get_design_info_from_epw(epw_file)
epw_design_conditions = epw_file.designConditions
epwHasDesignData = false
if epw_design_conditions.length > 0
epwHasDesignData = true
Expand Down
6 changes: 3 additions & 3 deletions resources/hpxml-measures/ReportSimulationOutput/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.0</schema_version>
<name>report_simulation_output</name>
<uid>df9d170c-c21a-4130-866d-0d46b06073fd</uid>
<version_id>ae45d060-e226-450a-9da7-5fcd756efb1d</version_id>
<version_modified>20220706T191521Z</version_modified>
<version_id>e52fa508-4a43-4b4c-b257-15f76ce56afd</version_id>
<version_modified>20220719T034751Z</version_modified>
<xml_checksum>9BF1E6AC</xml_checksum>
<class_name>ReportSimulationOutput</class_name>
<display_name>HPXML Simulation Output Report</display_name>
Expand Down Expand Up @@ -1588,7 +1588,7 @@
<filename>output_report_test.rb</filename>
<filetype>rb</filetype>
<usage_type>test</usage_type>
<checksum>EE4F1B37</checksum>
<checksum>3512A07E</checksum>
</file>
</files>
</measure>
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ def test_for_unsuccessful_simulation_infinity
# Create HPXML w/ AFUE=0 to generate Infinity result
hpxml_path = File.join(File.dirname(__FILE__), '../../workflow/sample_files/base.xml')
hpxml = HPXML.new(hpxml_path: hpxml_path)
hpxml.heating_systems[0].heating_efficiency_afue = 0.0
hpxml.heating_systems[0].heating_efficiency_afue = 10.0**-315
XMLHelper.write_file(hpxml.to_oga(), @tmp_hpxml_path)

args_hash = { 'hpxml_path' => @tmp_hpxml_path }
Expand Down
11 changes: 7 additions & 4 deletions resources/hpxml-measures/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,12 @@ def create_hpxmls
# Make all IDs unique so the HPXML is valid
new_building_element.each_node do |node|
next unless node.is_a?(Oga::XML::Element)
next if XMLHelper.get_attribute_value(node, 'id').nil?

XMLHelper.add_attribute(node, 'id', "#{XMLHelper.get_attribute_value(node, 'id')}_#{i}")
if not XMLHelper.get_attribute_value(node, 'id').nil?
XMLHelper.add_attribute(node, 'id', "#{XMLHelper.get_attribute_value(node, 'id')}_#{i}")
elsif not XMLHelper.get_attribute_value(node, 'idref').nil?
XMLHelper.add_attribute(node, 'idref', "#{XMLHelper.get_attribute_value(node, 'idref')}_#{i}")
end
end

hpxml_element.children << new_building_element
Expand Down Expand Up @@ -2479,7 +2482,7 @@ def apply_hpxml_modification_ashrae_140(hpxml)
# ------------ #

hpxml.header.xml_generated_by = 'tasks.rb'
hpxml.header.created_date_and_time = Time.new(2000, 1, 1).strftime('%Y-%m-%dT%H:%M:%S%:z') # Hard-code to prevent diffs
hpxml.header.created_date_and_time = Time.new(2000, 1, 1, 0, 0, 0, '-07:00').strftime('%Y-%m-%dT%H:%M:%S%:z') # Hard-code to prevent diffs
hpxml.header.apply_ashrae140_assumptions = true

# --------------------- #
Expand Down Expand Up @@ -2588,7 +2591,7 @@ def apply_hpxml_modification(hpxml_file, hpxml)

# General logic for all files
hpxml.header.xml_generated_by = 'tasks.rb'
hpxml.header.created_date_and_time = Time.new(2000, 1, 1).strftime('%Y-%m-%dT%H:%M:%S%:z') # Hard-code to prevent diffs
hpxml.header.created_date_and_time = Time.new(2000, 1, 1, 0, 0, 0, '-07:00').strftime('%Y-%m-%dT%H:%M:%S%:z') # Hard-code to prevent diffs

# Logic that can only be applied based on the file name
if ['base-hvac-undersized-allow-increased-fixed-capacities.xml'].include? hpxml_file
Expand Down

0 comments on commit 78768ee

Please sign in to comment.