Class: Pvwatts

Inherits:
Object
  • Object
show all
Defined in:
lib/pvwatts.rb

Overview

Wrapper around the www.nrel.gov/rredc/pvwatts/ web service API. Calculates the Performance of a Grid-Connected PV System. Use of the Pvwatts web service is restricted to authorized users. For information on obtaining authorization, contact [email protected]

See Also:

Author:

Constant Summary collapse

DEFAULT_DERATE =
0.82

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Pvwatts

Create an instance of the API wrapper.

Parameters:



24
25
26
# File 'lib/pvwatts.rb', line 24

def initialize(api_key)
  @api_key = api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



18
19
20
# File 'lib/pvwatts.rb', line 18

def api_key
  @api_key
end

Instance Method Details

#yearly_production(opts = {}) ⇒ Hash

Calculate the estimated yearly production based on passed options.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :latitude (String, Float)

    Latitude coordinate of the location.

  • :longitude (String, Float)

    Longitude coordinate of the location.

  • :dc_rating (String, Float)
  • :tilt (String, Integer)
  • :orientation (String, Integer)

    Orientation or azimuth value.

  • :shading (String, Integer)

    A percentage value between 0 and 100.

Returns:

  • (Hash)

    A hash with the yearly production with a key for each month and a ‘year’ key to represent the yearly value.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/pvwatts.rb', line 40

def yearly_production(opts={})
  Rails.logger.debug("pvwatts yearly prod called") if Object.const_defined?(:Rails)
  keys = opts.keys 
  client = Savon::Client.new("http://pvwatts.nrel.gov/PVWATTS.asmx?WSDL")
  @latitude, @longitude = [opts[:latitude], opts[:longitude]]
  @dc_rating, @tilt, @orientation = opts[:dc_rating], opts[:tilt], opts[:orientation]
  @shading = opts[:shading]
  if @latitude.nil? || @longitude.nil? || @dc_rating.nil? || @tilt.nil? || @orientation.nil? || @shading.nil?
    raise ArgumentError, "passed -> latitude: #{@latitude}, longitude: #{@longitude}, dc_rating: #{@dc_rating}\
    tilt: #{@tilt} orientation: #{@orientation} shading: #{@shading}"
  end
  req = prep_request(@latitude, @longitude, @dc_rating, @tilt, @orientation, @shading)
  
  response = client.get_pvwatts{|soap| soap.input = "GetPVWATTS"; soap.body = req }
  rdata = response.to_hash
  if rdata[:get_pvwatts_response] && rdata[:get_pvwatts_response][:get_pvwatts_result] && rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo]
    @production_data = {}
    @pvwatt_info = rdata[:get_pvwatts_response][:get_pvwatts_result][:pvwatt_sinfo].compact
    @pvwatt_info.each do |el| 
      if el.respond_to?(:has_key?) && el.has_key?(:month)
        @production_data[el[:month].downcase] = el[:a_cenergy].to_i
      end
    end
  else
    raise 'Problem with the pvwatts response'
  end
  @production_data
end