Class: OpenStudio::Weather::Epw
- Inherits:
-
Object
- Object
- OpenStudio::Weather::Epw
- Defined in:
- lib/openstudio/weather/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.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/openstudio/weather/epw.rb', line 55 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.
40 41 42 |
# File 'lib/openstudio/weather/epw.rb', line 40 def city @city end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
42 43 44 |
# File 'lib/openstudio/weather/epw.rb', line 42 def country @country end |
#data_period ⇒ Object
Returns the value of attribute data_period.
49 50 51 |
# File 'lib/openstudio/weather/epw.rb', line 49 def data_period @data_period end |
#data_type ⇒ Object
Returns the value of attribute data_type.
43 44 45 |
# File 'lib/openstudio/weather/epw.rb', line 43 def data_type @data_type end |
#elevation ⇒ Object (readonly)
Returns the value of attribute elevation.
48 49 50 |
# File 'lib/openstudio/weather/epw.rb', line 48 def elevation @elevation end |
#filename ⇒ Object
Returns the value of attribute filename.
39 40 41 |
# File 'lib/openstudio/weather/epw.rb', line 39 def filename @filename end |
#gmt ⇒ Object (readonly)
Returns the value of attribute gmt.
47 48 49 |
# File 'lib/openstudio/weather/epw.rb', line 47 def gmt @gmt end |
#header_data ⇒ Object (readonly)
access to all the weather data in array of arrays
52 53 54 |
# File 'lib/openstudio/weather/epw.rb', line 52 def header_data @header_data end |
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
45 46 47 |
# File 'lib/openstudio/weather/epw.rb', line 45 def lat @lat end |
#lon ⇒ Object (readonly)
Returns the value of attribute lon.
46 47 48 |
# File 'lib/openstudio/weather/epw.rb', line 46 def lon @lon end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
41 42 43 |
# File 'lib/openstudio/weather/epw.rb', line 41 def state @state end |
#weather_data ⇒ Object
Returns the value of attribute weather_data.
53 54 55 |
# File 'lib/openstudio/weather/epw.rb', line 53 def weather_data @weather_data end |
#wmo ⇒ Object (readonly)
Returns the value of attribute wmo.
44 45 46 |
# File 'lib/openstudio/weather/epw.rb', line 44 def wmo @wmo end |
Class Method Details
.load(filename) ⇒ Object
73 74 75 76 |
# File 'lib/openstudio/weather/epw.rb', line 73 def self.load(filename) raise "EPW file does not exist: #{filename}" unless File.exist?(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
128 129 130 131 132 133 134 135 |
# File 'lib/openstudio/weather/epw.rb', line 128 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
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/openstudio/weather/epw.rb', line 137 def { city: @city, state: @state, country: @country, data_type: @data_type, wmo: @wmo, latitude: @lat, longitude: @lon, elevation: @elevation } end |
#save_as(filename) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/openstudio/weather/epw.rb', line 107 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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/openstudio/weather/epw.rb', line 78 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
103 104 105 |
# File 'lib/openstudio/weather/epw.rb', line 103 def valid? return @valid end |