Class: OpenStudio::Weather::Epw
- Inherits:
-
Object
- Object
- OpenStudio::Weather::Epw
- Defined in:
- lib/measures/ChangeBuildingLocation/resources/epw.rb
Instance Attribute Summary collapse
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#data_period ⇒ Object
Returns the value of attribute data_period.
-
#data_type ⇒ Object
Returns the value of attribute data_type.
-
#elevation ⇒ Object
readonly
Returns the value of attribute elevation.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#gmt ⇒ Object
readonly
Returns the value of attribute gmt.
-
#header_data ⇒ Object
readonly
access to all the weather data in array of arrays.
-
#lat ⇒ Object
readonly
Returns the value of attribute lat.
-
#lon ⇒ Object
readonly
Returns the value of attribute lon.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#weather_data ⇒ Object
Returns the value of attribute weather_data.
-
#wmo ⇒ Object
readonly
Returns the value of attribute wmo.
Class Method Summary collapse
Instance Method Summary collapse
-
#append_weather_data(filename) ⇒ Object
Append the weather data (after data periods) to the end of the weather file.
-
#initialize(filename) ⇒ Epw
constructor
A new instance of Epw.
- #metadata_to_hash ⇒ Object
- #save_as(filename) ⇒ Object
- #to_kml(xml_builder_obj, url) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(filename) ⇒ Epw
Returns a new instance of Epw.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 27 def initialize(filename) @filename = filename @city = '' @state = '' @country = '' @data_type = '' @wmo = '' @lat = '' @lon = '' @gmt = '' @elevation = '' @valid = false @header_data = [] @weather_data = [] process_header end |
Instance Attribute Details
#city ⇒ Object (readonly)
Returns the value of attribute city.
12 13 14 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 12 def city @city end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
14 15 16 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 14 def country @country end |
#data_period ⇒ Object
Returns the value of attribute data_period.
21 22 23 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 21 def data_period @data_period end |
#data_type ⇒ Object
Returns the value of attribute data_type.
15 16 17 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 15 def data_type @data_type end |
#elevation ⇒ Object (readonly)
Returns the value of attribute elevation.
20 21 22 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 20 def elevation @elevation end |
#filename ⇒ Object
Returns the value of attribute filename.
11 12 13 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 11 def filename @filename end |
#gmt ⇒ Object (readonly)
Returns the value of attribute gmt.
19 20 21 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 19 def gmt @gmt end |
#header_data ⇒ Object (readonly)
access to all the weather data in array of arrays
24 25 26 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 24 def header_data @header_data end |
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
17 18 19 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 17 def lat @lat end |
#lon ⇒ Object (readonly)
Returns the value of attribute lon.
18 19 20 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 18 def lon @lon end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
13 14 15 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 13 def state @state end |
#weather_data ⇒ Object
Returns the value of attribute weather_data.
25 26 27 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 25 def weather_data @weather_data end |
#wmo ⇒ Object (readonly)
Returns the value of attribute wmo.
16 17 18 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 16 def wmo @wmo end |
Class Method Details
.load(filename) ⇒ Object
45 46 47 48 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 45 def self.load(filename) raise "EPW file does not exist: #{filename}" unless File.file?(filename) f = OpenStudio::Weather::Epw.new(filename) end |
Instance Method Details
#append_weather_data(filename) ⇒ Object
Append the weather data (after data periods) to the end of the weather file. This allows for the creation of multiyear weather files. Note that the date/order is not checked. It assumes that the data are being added at the end is the more recent data
100 101 102 103 104 105 106 107 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 100 def append_weather_data(filename) to_append = OpenStudio::Weather::Epw.load(filename) prev_length = @weather_data.size @weather_data += to_append.weather_data prev_length + to_append.weather_data.size == @weather_data.size end |
#metadata_to_hash ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 109 def { city: @city, state: @state, country: @country, data_type: @data_type, wmo: @wmo, latitude: @lat, longitude: @lon, elevation: @elevation } end |
#save_as(filename) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 79 def save_as(filename) File.delete filename if File.exist? filename FileUtils.mkdir_p(File.dirname(filename)) unless Dir.exist?(File.dirname(filename)) CSV.open(filename, 'wb') do |csv| @header_data.each { |r| csv << r } csv << [ 'DATA PERIODS', @data_period[:count], @data_period[:records_per_hour], @data_period[:name], @data_period[:start_day_of_week], @data_period[:start_date], @data_period[:end_date] ] @weather_data.each { |r| csv << r } end true end |
#to_kml(xml_builder_obj, url) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 50 def to_kml(xml_builder_obj, url) xml_builder_obj.Placemark do xml_builder_obj.name @city xml_builder_obj.visibility '0' xml_builder_obj.description do xml_builder_obj.cdata!('<img src="kml/ep_header8.png" width=180 align=right><br><table><tr><td colspan="2">'\ "<b>#{@city}</b></href></td></tr>\n" + # "<tr><td></td><td><b>Data Type</td></tr>\n"+ "<tr><td></td><td>WMO <b>#{@wmo}</b></td></tr>\n" + # "<tr><td></td><td>E 3� 15' N 36� 43'</td></tr>\n"+ # "<tr><td></td><td><b>25</b> m</td></tr>\n"+ "<tr><td></td><td>Time Zone GMT <b>#{@gmt}</b> hours</td></tr>\n" + # "<tr><td></td><td>ASHRAE Std 169 Climate Zone <b>4A - Mixed - Humid</b></td></tr>\n"+ # "<tr><td></td><td>99% Heating DB=<b>3.1</b>, 1% Cooling DB=<b>33.2</b></td></tr>\n"+ # "<tr><td></td><td>HDD18 <b>1019</b>, CDD10 <b>2849</b></td></tr>\n"+ "<tr><td></td><td>URL #{url}</td></tr></table>") end xml_builder_obj.styleUrl '#weatherlocation' xml_builder_obj.Point do xml_builder_obj.altitudeMode 'absolute' xml_builder_obj.coordinates "#{@lon},#{@lat},#{elevation}" end end end |
#valid? ⇒ Boolean
75 76 77 |
# File 'lib/measures/ChangeBuildingLocation/resources/epw.rb', line 75 def valid? return @valid end |