Class: OpenStudio::Weather::Epw

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio/weather/epw.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Epw

Returns a new instance of Epw.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/openstudio/weather/epw.rb', line 25

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

#cityObject (readonly)

Returns the value of attribute city.



10
11
12
# File 'lib/openstudio/weather/epw.rb', line 10

def city
  @city
end

#countryObject (readonly)

Returns the value of attribute country.



12
13
14
# File 'lib/openstudio/weather/epw.rb', line 12

def country
  @country
end

#data_periodObject

Returns the value of attribute data_period.



19
20
21
# File 'lib/openstudio/weather/epw.rb', line 19

def data_period
  @data_period
end

#data_typeObject

Returns the value of attribute data_type.



13
14
15
# File 'lib/openstudio/weather/epw.rb', line 13

def data_type
  @data_type
end

#elevationObject (readonly)

Returns the value of attribute elevation.



18
19
20
# File 'lib/openstudio/weather/epw.rb', line 18

def elevation
  @elevation
end

#filenameObject

Returns the value of attribute filename.



9
10
11
# File 'lib/openstudio/weather/epw.rb', line 9

def filename
  @filename
end

#gmtObject (readonly)

Returns the value of attribute gmt.



17
18
19
# File 'lib/openstudio/weather/epw.rb', line 17

def gmt
  @gmt
end

#header_dataObject (readonly)

access to all the weather data in array of arrays



22
23
24
# File 'lib/openstudio/weather/epw.rb', line 22

def header_data
  @header_data
end

#latObject (readonly)

Returns the value of attribute lat.



15
16
17
# File 'lib/openstudio/weather/epw.rb', line 15

def lat
  @lat
end

#lonObject (readonly)

Returns the value of attribute lon.



16
17
18
# File 'lib/openstudio/weather/epw.rb', line 16

def lon
  @lon
end

#stateObject (readonly)

Returns the value of attribute state.



11
12
13
# File 'lib/openstudio/weather/epw.rb', line 11

def state
  @state
end

#weather_dataObject

Returns the value of attribute weather_data.



23
24
25
# File 'lib/openstudio/weather/epw.rb', line 23

def weather_data
  @weather_data
end

#wmoObject (readonly)

Returns the value of attribute wmo.



14
15
16
# File 'lib/openstudio/weather/epw.rb', line 14

def wmo
  @wmo
end

Class Method Details

.load(filename) ⇒ Object



43
44
45
46
# File 'lib/openstudio/weather/epw.rb', line 43

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

Parameters:

  • filename (String)

    Path to the file that will be appended



98
99
100
101
102
103
104
105
# File 'lib/openstudio/weather/epw.rb', line 98

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_hashObject



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/openstudio/weather/epw.rb', line 107

def 
  {
    city: @city,
    state: @state,
    country: @country,
    data_type: @data_type,
    wmo: @wmo,
    latitude: @lat,
    longitude: @lon,
    elevation: @elevation
  }
end

#save_as(filename) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/openstudio/weather/epw.rb', line 77

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



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/openstudio/weather/epw.rb', line 48

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

Returns:

  • (Boolean)


73
74
75
# File 'lib/openstudio/weather/epw.rb', line 73

def valid?
  return @valid
end