Class: BTAP::Environment::WeatherFile

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio-standards/weather/Weather.Model.rb

Constant Summary collapse

YEAR =
0
MONTH =
1
DAY =
2
HOUR =
3
MINUTE =
4
DATA_SOURCE =
5
DRY_BULB_TEMPERATURE =
6
DEW_POINT_TEMPERATURE =
7
RELATIVE_HUMIDITY =
8
ATMOSPHERIC_STATION_PRESSURE =
9
EXTRATERRESTRIAL_HORIZONTAL_RADIATION =

not used

10
EXTRATERRESTRIAL_DIRECT_NORMAL_RADIATION =

not used

11
HORIZONTAL_INFRARED_RADIATION_INTENSITY =
12
GLOBAL_HORIZONTAL_RADIATION =

not used

13
DIRECT_NORMAL_RADIATION =
14
DIFFUSE_HORIZONTAL_RADIATION =
15
GLOBAL_HORIZONTAL_ILLUMINANCE =

not used

16
DIRECT_NORMAL_ILLUMINANCE =

not used

17
DIFFUSE_HORIZONTAL_ILLUMINANCE =

not used

18
ZENITH_LUMINANCE =

not used

19
WIND_DIRECTION =
20
WIND_SPEED =
21
TOTAL_SKY_COVER =

not used

22
OPAQUE_SKY_COVER =

not used

23
VISIBILITY =

not used

24
CEILING_HEIGHT =

not used

25
PRESENT_WEATHER_OBSERVATION =
26
PRESENT_WEATHER_CODES =
27
PRECIPITABLE_WATER =

not used

28
AEROSOL_OPTICAL_DEPTH =

not used

29
SNOW_DEPTH =
30
DAYS_SINCE_LAST_SNOWFALL =

not used

31
ALBEDO =

not used

32
LIQUID_PRECIPITATION_DEPTH =
33
LIQUID_PRECIPITATION_QUANTITY =
34
CALCULATED_SATURATION_PRESSURE_OF_WATER_VAPOR =

pws

100
CALCULATED_PARTIAL_PRESSURE_OF_WATER_VAPOR =

pw

101
CALCULATED_TOTAL_MIXTURE_PRESSURE =

p

102
CALCULATED_HUMIDITY_RATIO =

w

103
CALCULATED_HUMIDITY_RATIO_AVG_DAILY =

w averaged daily

104
CALCULATED_HUMIDITY_RATIO_AVG_DAILY_DIFF_BASE =

difference of w_averaged_daily from base if w_averaged_daily > base

105

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(weather_file) ⇒ String

This method initializes and returns self.



503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 503

def initialize(weather_file)
  # First check if the epw file exists at a full path.  If not found there,
  # check for the file in the openstudio-standards/data/weather directory.
  weather_file = weather_file.to_s
  @epw_filepath = nil
  @ddy_filepath = nil
  @stat_filepath = nil
  if File.exist?(weather_file)
    @epw_filepath = weather_file.to_s
    @ddy_filepath = weather_file.sub('epw', 'ddy').to_s
    @stat_filepath = weather_file.sub('epw', 'stat').to_s
  else
    # Run differently depending on whether running from embedded filesystem in OpenStudio CLI or not
    if __dir__[0] == ':' # Running from OpenStudio CLI
      # load weather file from embedded files
      epw_string = load_resource_relative("../../../data/weather/#{weather_file}")
      ddy_string = load_resource_relative("../../../data/weather/#{weather_file.gsub('.epw', '.ddy')}")
      stat_string = load_resource_relative("../../../data/weather/#{weather_file.gsub('.epw', '.stat')}")

      # extract to local weather dir
      weather_dir = File.expand_path(File.join(Dir.pwd, 'extracted_files/weather/'))
      puts "Extracting weather files to #{weather_dir}"
      FileUtils.mkdir_p(weather_dir)
      File.open("#{weather_dir}/#{weather_file}", 'wb') { |f| f << epw_string; f.flush }
      File.open("#{weather_dir}/#{weather_file.gsub('.epw', '.ddy')}", 'wb') { |f| f << ddy_string; f.flush }
      File.open("#{weather_dir}/#{weather_file.gsub('.epw', '.stat')}", 'wb') { |f| f << stat_string; f.flush }
    else # loaded gem from system path
      top_dir = File.expand_path('../../..', File.dirname(__FILE__))
      weather_dir = File.expand_path("#{top_dir}/data/weather")
    end

    @epw_filepath = "#{weather_dir}/#{weather_file}"
    @ddy_filepath = "#{weather_dir}/#{weather_file.sub('epw', 'ddy')}"
    @stat_filepath = "#{weather_dir}/#{weather_file.sub('epw', 'stat')}"
  end

  # Ensure that epw, ddy, and stat file all exist
  raise("Weather file #{@epw_filepath} not found.") unless File.exist?(@epw_filepath) && @epw_filepath.downcase.include?('.epw')
  raise("Weather file ddy #{@ddy_filepath} not found.") unless File.exist?(@ddy_filepath) && @ddy_filepath.downcase.include?('.ddy')
  raise("Weather file stat #{@stat_filepath} not found.") unless File.exist?(@stat_filepath) && @stat_filepath.downcase.include?('.stat')

  # load file objects.
  @epw_file = OpenStudio::EpwFile.new(OpenStudio::Path.new(@epw_filepath))
  if OpenStudio::EnergyPlus.loadAndTranslateIdf(@ddy_filepath).empty?
    raise "Unable to load ddy idf file#{@ddy_filepath}."
  else
    @ddy_file = OpenStudio::EnergyPlus.loadAndTranslateIdf(@ddy_filepath).get
  end

  @stat_file = EnergyPlus::StatFile.new(@stat_filepath)

  # assign variables.

  @latitude = @epw_file.latitude
  @longitude = @epw_file.longitude
  @elevation = @epw_file.elevation
  @city = @epw_file.city
  @state_province_region = @epw_file.stateProvinceRegion
  @country = @epw_file.country
  @hdd18 = @stat_file.hdd18
  @cdd18 = @stat_file.cdd18
  @hdd10 = @stat_file.hdd10
  @cdd10 = @stat_file.cdd10
  @heating_design_info = @stat_file.heating_design_info
  @cooling_design_info  = @stat_file.cooling_design_info
  @extremes_design_info = @stat_file.extremes_design_info
  @monthly_dry_bulb = @stat_file.monthly_dry_bulb
  @mean_dry_bulb = @stat_file.mean_dry_bulb
  @delta_dry_bulb = @stat_file.delta_dry_bulb
  @location_name = "#{@country}-#{@state_province_region}-#{@city}"
  @energy_plus_location_name = "#{@city}_#{@state_province_region}_#{@country}"
  @climate_zone = @stat_file.climate_zone
  @standard = @stat_file.standard
  @summer_wet_months = @stat_file.summer_wet_months
  @winter_dry_months = @stat_file.winter_dry_months
  @autumn_months = @stat_file.autumn_months
  @spring_months = @stat_file.spring_months
  @typical_summer_wet_week = @stat_file.typical_summer_wet_week
  @typical_winter_dry_week = @stat_file.typical_winter_dry_week
  @typical_autumn_week = @stat_file.typical_autumn_week
  @typical_spring_week = @stat_file.typical_spring_week
  @db990 = @heating_design_info[2]
  return self
end

Instance Attribute Details

#autumn_monthsObject

Returns the value of attribute autumn_months.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def autumn_months
  @autumn_months
end

#cdd10Object

Returns the value of attribute cdd10.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def cdd10
  @cdd10
end

#cdd18Object

Returns the value of attribute cdd18.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def cdd18
  @cdd18
end

#cityObject

Returns the value of attribute city.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def city
  @city
end

#climate_zoneObject

Returns the value of attribute climate_zone.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def climate_zone
  @climate_zone
end

#cooling_design_infoObject

Returns the value of attribute cooling_design_info.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def cooling_design_info
  @cooling_design_info
end

#countryObject

Returns the value of attribute country.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def country
  @country
end

#db990Object

Returns the value of attribute db990.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def db990
  @db990
end

#ddy_filepathObject

Returns the value of attribute ddy_filepath.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def ddy_filepath
  @ddy_filepath
end

#delta_dry_bulbObject

Returns the value of attribute delta_dry_bulb.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def delta_dry_bulb
  @delta_dry_bulb
end

#elevationObject

Returns the value of attribute elevation.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def elevation
  @elevation
end

#energy_plus_location_nameObject

Returns the value of attribute energy_plus_location_name.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def energy_plus_location_name
  @energy_plus_location_name
end

#epw_filepathObject

Returns the value of attribute epw_filepath.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def epw_filepath
  @epw_filepath
end

#extremes_design_infoObject

Returns the value of attribute extremes_design_info.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def extremes_design_info
  @extremes_design_info
end

#hdd10Object

Returns the value of attribute hdd10.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def hdd10
  @hdd10
end

#hdd18Object

Returns the value of attribute hdd18.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def hdd18
  @hdd18
end

#heating_design_infoObject

Returns the value of attribute heating_design_info.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def heating_design_info
  @heating_design_info
end

#latitudeObject

Returns the value of attribute latitude.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def latitude
  @latitude
end

#location_nameObject

Returns the value of attribute location_name.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def location_name
  @location_name
end

#longitudeObject

Returns the value of attribute longitude.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def longitude
  @longitude
end

#monthly_dry_bulbObject

Returns the value of attribute monthly_dry_bulb.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def monthly_dry_bulb
  @monthly_dry_bulb
end

#spring_monthsObject

Returns the value of attribute spring_months.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def spring_months
  @spring_months
end

#standardObject

Returns the value of attribute standard.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def standard
  @standard
end

#stat_filepathObject

Returns the value of attribute stat_filepath.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def stat_filepath
  @stat_filepath
end

#state_province_regionObject

Returns the value of attribute state_province_region.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def state_province_region
  @state_province_region
end

#summer_wet_monthsObject

Returns the value of attribute summer_wet_months.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def summer_wet_months
  @summer_wet_months
end

#typical_autumn_weekObject

Returns the value of attribute typical_autumn_week.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def typical_autumn_week
  @typical_autumn_week
end

#typical_spring_weekObject

Returns the value of attribute typical_spring_week.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def typical_spring_week
  @typical_spring_week
end

#typical_summer_wet_weekObject

Returns the value of attribute typical_summer_wet_week.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def typical_summer_wet_week
  @typical_summer_wet_week
end

#typical_winter_dry_weekObject

Returns the value of attribute typical_winter_dry_week.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def typical_winter_dry_week
  @typical_winter_dry_week
end

#winter_dry_monthsObject

Returns the value of attribute winter_dry_months.



425
426
427
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 425

def winter_dry_months
  @winter_dry_months
end

Instance Method Details

#a169_2006_climate_zoneString

This method returns the Thermal Zone based on cdd10 and hdd18



591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 591

def a169_2006_climate_zone
  cdd10 = self.cdd10.to_f
  hdd18 = self.hdd18.to_f

  if cdd10 > 6000 # Extremely Hot  Humid (0A), Dry (0B)
    return 'ASHRAE 169-2013-0A'

  elsif (cdd10 > 5000) && (cdd10 <= 6000) # Very Hot  Humid (1A), Dry (1B)
    return 'ASHRAE 169-2013-1A'

  elsif (cdd10 > 3500) && (cdd10 <= 5000) # Hot  Humid (2A), Dry (2B)
    return 'ASHRAE 169-2013-2A'

  elsif ((cdd10 > 2500) && (cdd10 < 3500)) && (hdd18 <= 2000) # Warm  Humid (3A), Dry (3B)
    return 'ASHRAE 169-2013-3A' # and 'ASHRAE 169-2013-3B'

  elsif (cdd10 <= 2500) && (hdd18 <= 2000) # Warm  Marine (3C)
    return 'ASHRAE 169-2013-3C'

  elsif ((cdd10 > 1500) && (cdd10 < 3500)) && ((hdd18 > 2000) && (hdd18 <= 3000)) # Mixed  Humid (4A), Dry (4B)
    return 'ASHRAE 169-2013-4A' # and 'ASHRAE 169-2013-4B'

  elsif (cdd10 <= 1500) && ((hdd18 > 2000) && (hdd18 <= 3000)) # Mixed  Marine
    return 'ASHRAE 169-2013-4C'

  elsif ((cdd10 > 1000) && (cdd10 <= 3500)) && ((hdd18 > 3000) && (hdd18 <= 4000)) # Cool Humid (5A), Dry (5B)
    return 'ASHRAE 169-2013-5A' # and 'ASHRAE 169-2013-5B'

  elsif (cdd10 <= 1000) && ((hdd18 > 3000) && (hdd18 <= 4000)) # Cool  Marine (5C)
    return 'ASHRAE 169-2013-5C'

  elsif (hdd18 > 4000) && (hdd18 <= 5000) # Cold  Humid (6A), Dry (6B)
    return 'ASHRAE 169-2013-6A' # and 'ASHRAE 169-2013-6B'

  elsif (hdd18 > 5000) && (hdd18 <= 7000) # Very Cold (7)
    return 'ASHRAE 169-2013-7A'

  elsif hdd18 > 7000 # Subarctic/Arctic (8)
    return 'ASHRAE 169-2013-8A'

  else
    # raise ("invalid cdd10 of #{cdd10} or hdd18 of #{hdd18}")
    return '[INVALID]'
  end
end

#calculate_humidity_ratioObject

This method calculates dehumidification degree days (DDD) Reference: ASHRAE Handbook - Fundamentals > CHAPTER 1. PSYCHROMETRICS



923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 923

def calculate_humidity_ratio
  # coefficients for the calculation of pws (Reference: ASHRAE Handbook - Fundamentals > CHAPTER 1. PSYCHROMETRICS)
  c1 = -5.6745359E+03
  c2 = 6.3925247E+00
  c3 = -9.6778430E-03
  c4 = 6.2215701E-07
  c5 = 2.0747825E-09
  c6 = -9.4840240E-13
  c7 = 4.1635019E+00
  c8 = -5.8002206E+03
  c9 = 1.3914993E+00
  c10 = -4.8640239E-02
  c11 = 4.1764768E-05
  c12 = -1.4452093E-08
  c13 = 6.5459673E+00
  sum_w = 0.0
  w_base = 0.010 # Note: this is base for the calculation of 'dehumidification degree days' (REF: Wright, L. (2019). Setting the Heating/Cooling Performance Criteria for the PHIUS 2018 Passive Building Standard. In ASHRAE Topical Conference Proceedings, pp. 399-409)
  ddd = 0.0 # dehimudifation degree-days
  convert_c_to_k = 273.15 # convert degree C to kelvins (k)

  scan if @filearray.nil?
  @filearray.each do |line|
    unless line.first =~ /\D(.*)/
      # Note: the below Step 1, 2, 3, and 4 are the steps for the calculation of humidity ratio as per ASHRAE Handbook - Fundamentals > CHAPTER 1. PSYCHROMETRICS
      # Step 1: calculate pws (SATURATION_PRESSURE_OF_WATER_VAPOR), [Pascal]
      if line[DRY_BULB_TEMPERATURE].to_f <= 0.0
        line[CALCULATED_SATURATION_PRESSURE_OF_WATER_VAPOR] = c1 / (line[DRY_BULB_TEMPERATURE].to_f + convert_c_to_k) +
                                                              c2 +
                                                              c3 * (line[DRY_BULB_TEMPERATURE].to_f + convert_c_to_k) +
                                                              c4 * (line[DRY_BULB_TEMPERATURE].to_f + convert_c_to_k)**2 +
                                                              c5 * (line[DRY_BULB_TEMPERATURE].to_f + convert_c_to_k)**3 +
                                                              c6 * (line[DRY_BULB_TEMPERATURE].to_f + convert_c_to_k)**4 +
                                                              c7 * Math.log((line[DRY_BULB_TEMPERATURE].to_f + convert_c_to_k), Math.exp(1)) # 2.718281828459
        line[CALCULATED_SATURATION_PRESSURE_OF_WATER_VAPOR] = Math.exp(1)**line[CALCULATED_SATURATION_PRESSURE_OF_WATER_VAPOR].to_f
      else # if line[DRY_BULB_TEMPERATURE].to_f > 0.0
        line[CALCULATED_SATURATION_PRESSURE_OF_WATER_VAPOR] = c8 / (line[DRY_BULB_TEMPERATURE].to_f + convert_c_to_k) +
                                                              c9 +
                                                              c10 * (line[DRY_BULB_TEMPERATURE].to_f + convert_c_to_k) +
                                                              c11 * (line[DRY_BULB_TEMPERATURE].to_f + convert_c_to_k)**2 +
                                                              c12 * (line[DRY_BULB_TEMPERATURE].to_f + convert_c_to_k)**3 +
                                                              c13 * Math.log((line[DRY_BULB_TEMPERATURE].to_f + convert_c_to_k), Math.exp(1))
        line[CALCULATED_SATURATION_PRESSURE_OF_WATER_VAPOR] = Math.exp(1)**line[CALCULATED_SATURATION_PRESSURE_OF_WATER_VAPOR].to_f
      end

      # Step 2: calculate pw (PARTIAL_PRESSURE_OF_WATER_VAPOR), [Pascal]
      # Relative Humidity (RH) = 100 * pw / pws
      line[CALCULATED_PARTIAL_PRESSURE_OF_WATER_VAPOR] = line[CALCULATED_SATURATION_PRESSURE_OF_WATER_VAPOR].to_f * line[RELATIVE_HUMIDITY].to_f / 100.0

      # Step 3: calculate p (TOTAL_MIXTURE_PRESSURE), [Pascal]
      line[CALCULATED_TOTAL_MIXTURE_PRESSURE] = line[CALCULATED_PARTIAL_PRESSURE_OF_WATER_VAPOR].to_f + line[ATMOSPHERIC_STATION_PRESSURE].to_f

      # Step 4: calculate w (HUMIDITY_RATIO)
      line[CALCULATED_HUMIDITY_RATIO] = 0.621945 * line[CALCULATED_PARTIAL_PRESSURE_OF_WATER_VAPOR].to_f / (line[CALCULATED_TOTAL_MIXTURE_PRESSURE].to_f - line[CALCULATED_PARTIAL_PRESSURE_OF_WATER_VAPOR].to_f)

      #-----------------------------------------------------------------------------------------------------------
      # calculate daily average of w AND its difference from base
      if line[HOUR].to_f < 24.0
        sum_w += line[CALCULATED_HUMIDITY_RATIO].to_f
        line[CALCULATED_HUMIDITY_RATIO_AVG_DAILY] = 0.0
      elsif line[HOUR].to_f == 24.0
        line[CALCULATED_HUMIDITY_RATIO_AVG_DAILY] = (sum_w + line[CALCULATED_HUMIDITY_RATIO].to_f) / 24.0
        if line[CALCULATED_HUMIDITY_RATIO_AVG_DAILY].to_f > w_base
          line[CALCULATED_HUMIDITY_RATIO_AVG_DAILY_DIFF_BASE] = line[CALCULATED_HUMIDITY_RATIO_AVG_DAILY].to_f - w_base
        else
          line[CALCULATED_HUMIDITY_RATIO_AVG_DAILY_DIFF_BASE] = 0.0
        end
        sum_w = 0.0
      end

      ddd += line[CALCULATED_HUMIDITY_RATIO_AVG_DAILY_DIFF_BASE].to_f

    end
  end
  return ddd
end

#eliminate_all_radiationString

This method will eliminate all radiation from the weather and returns self.



705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 705

def eliminate_all_radiation
  scan if @filearray.nil?
  setcolumntovalue(EXTRATERRESTRIAL_HORIZONTAL_RADIATION, '0') # not used
  setcolumntovalue(EXTRATERRESTRIAL_DIRECT_NORMAL_RADIATION, '0') # not used
  setcolumntovalue(HORIZONTAL_INFRARED_RADIATION_INTENSITY, '315')
  setcolumntovalue(GLOBAL_HORIZONTAL_RADIATION, '0') # not used
  setcolumntovalue(DIRECT_NORMAL_RADIATION, '0')
  setcolumntovalue(DIFFUSE_HORIZONTAL_RADIATION, '0')
  setcolumntovalue(TOTAL_SKY_COVER, '10') # not used
  setcolumntovalue(OPAQUE_SKY_COVER, '10') # not used
  setcolumntovalue(VISIBILITY, '0') # not used
  setcolumntovalue(CEILING_HEIGHT, '0') # not used
  # lux values
  setcolumntovalue(GLOBAL_HORIZONTAL_ILLUMINANCE, '0') # not used
  setcolumntovalue(DIRECT_NORMAL_ILLUMINANCE, '0') # not used
  setcolumntovalue(DIFFUSE_HORIZONTAL_ILLUMINANCE, '0') # not used
  setcolumntovalue(ZENITH_LUMINANCE, '0') # not used
  return self
end

#eliminate_all_radiation_except_solarString

This method will eliminate all radiation except solar and returns self.



739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 739

def eliminate_all_radiation_except_solar
  scan if @filearray.nil?
  setcolumntovalue(EXTRATERRESTRIAL_HORIZONTAL_RADIATION, '0') # not used
  setcolumntovalue(EXTRATERRESTRIAL_DIRECT_NORMAL_RADIATION, '0') # not used
  setcolumntovalue(HORIZONTAL_INFRARED_RADIATION_INTENSITY, '315')
  setcolumntovalue(TOTAL_SKY_COVER, '10') # not used
  setcolumntovalue(OPAQUE_SKY_COVER, '10') # not used
  setcolumntovalue(VISIBILITY, '0') # not used
  setcolumntovalue(CEILING_HEIGHT, '0') # not used
  # lux values
  setcolumntovalue(GLOBAL_HORIZONTAL_ILLUMINANCE, '0') # not used
  setcolumntovalue(DIRECT_NORMAL_ILLUMINANCE, '0') # not used
  setcolumntovalue(DIFFUSE_HORIZONTAL_ILLUMINANCE, '0') # not used
  setcolumntovalue(ZENITH_LUMINANCE, '0') # not used
  return self
end

#eliminate_only_solar_radiationString

This method will eliminate solar radiation and returns self.



728
729
730
731
732
733
734
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 728

def eliminate_only_solar_radiation
  scan if @filearray.nil?
  setcolumntovalue(GLOBAL_HORIZONTAL_RADIATION, '0') # not used
  setcolumntovalue(DIRECT_NORMAL_RADIATION, '0')
  setcolumntovalue(DIFFUSE_HORIZONTAL_RADIATION, '0')
  return self
end

#eliminate_percipitationString

This method will eliminate percipitation and returns self.



759
760
761
762
763
764
765
766
767
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 759

def eliminate_percipitation
  scan if @filearray.nil?
  setcolumntovalue(PRESENT_WEATHER_OBSERVATION, '0')
  setcolumntovalue(PRESENT_WEATHER_CODES, '999999999') # no weather. Clear day.
  setcolumntovalue(SNOW_DEPTH, '0')
  setcolumntovalue(LIQUID_PRECIPITATION_DEPTH, '0')
  setcolumntovalue(LIQUID_PRECIPITATION_QUANTITY, '0')
  return self
end

#eliminate_windString

This method eliminates wind and returns self.



772
773
774
775
776
777
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 772

def eliminate_wind
  scan if @filearray.nil?
  setcolumntovalue(WIND_DIRECTION, '0')
  setcolumntovalue(WIND_SPEED, '0')
  return self
end

#get_annual_ghiObject

This method calculates annual global horizontal irradiance (GHI) This value has been used as ‘Irradiance, Global, Annual’ (IGA) (kWh/m2.yr) for PHIUS performance targets calculation.



830
831
832
833
834
835
836
837
838
839
840
841
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 830

def get_annual_ghi
  sum_hourly_ghi = 0.0
  scan if @filearray.nil?
  @filearray.each do |line|
    unless line.first =~ /\D(.*)/
      ghi_hourly = line[GLOBAL_HORIZONTAL_RADIATION].to_f
      sum_hourly_ghi += ghi_hourly
    end
  end
  annual_ghi_kwh_per_m_sq = sum_hourly_ghi / 1000.0
  return annual_ghi_kwh_per_m_sq
end

#get_ghi_on_cooling_design_dayObject

This method calculates global horizontal irradiance on cooling design day This value has been used as ‘Irradiance, Global, at the cooling design condition’ (IGHL) for PHIUS performance targets calculation.



867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 867

def get_ghi_on_cooling_design_day
  heating_design_day_number, cooling_design_day_number = get_heating_design_day_number
  hottest_month = @cooling_design_info[0].to_f
  sum_hourly_ghi_on_cooling_design_day = 0.0
  number_of_hours_with_sunshine = 0.0
  scan if @filearray.nil?
  @filearray.each do |line|
    unless line.first =~ /\D(.*)/
      if line[MONTH].to_f == hottest_month && line[DAY].to_f == cooling_design_day_number.to_f && line[GLOBAL_HORIZONTAL_RADIATION].to_f > 0.0
        sum_hourly_ghi_on_cooling_design_day += line[GLOBAL_HORIZONTAL_RADIATION].to_f
        number_of_hours_with_sunshine += 1.0
      end
    end
  end
  ghi_on_cooling_design_day_w_per_m_sq = sum_hourly_ghi_on_cooling_design_day / number_of_hours_with_sunshine
  return ghi_on_cooling_design_day_w_per_m_sq
end

#get_ghi_on_heating_design_dayObject

This method calculates global horizontal irradiance on heating design day This value has been used as ‘Irradiance, Global, at the heating design condition’ (IGHL) for PHIUS performance targets calculation.



846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 846

def get_ghi_on_heating_design_day
  heating_design_day_number, cooling_design_day_number = get_heating_design_day_number
  coldest_month = @heating_design_info[0].to_f
  sum_hourly_ghi_on_heating_design_day = 0.0
  number_of_hours_with_sunshine = 0.0
  scan if @filearray.nil?
  @filearray.each do |line|
    unless line.first =~ /\D(.*)/
      if line[MONTH].to_f == coldest_month && line[DAY].to_f == heating_design_day_number.to_f && line[GLOBAL_HORIZONTAL_RADIATION].to_f > 0.0
        sum_hourly_ghi_on_heating_design_day += line[GLOBAL_HORIZONTAL_RADIATION].to_f
        number_of_hours_with_sunshine += 1.0
      end
    end
  end
  ghi_on_heating_design_day_w_per_m_sq = sum_hourly_ghi_on_heating_design_day / number_of_hours_with_sunshine
  return ghi_on_heating_design_day_w_per_m_sq
end

#get_heating_design_day_numberObject

This method finds which day of the coldest/hottest month is the heating/cooling design day



887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 887

def get_heating_design_day_number
  heating_design_day_number = nil
  cooling_design_day_number = nil
  # which day of the coldest month is the heating design day
  @ddy_file.getObjectsByType('OS:SizingPeriod:DesignDay'.to_IddObjectType).each do |d|
    if d.name.to_s.include?('Htg 99.6% Condns DB')
      idf_object = d.idfObject
      idf_object.dataFields.each do |data_field|
        design_day_field = idf_object.fieldComment(data_field, true)
        if design_day_field.to_s.include?('Day of Month')
          heating_design_day_number = idf_object.getString(data_field)
          heating_design_day_number = heating_design_day_number.to_s
          # puts "heating_design_day_number is #{heating_design_day_number}"
        end
      end
    end

    # which day of the hottest month is the cooling design day
    if d.name.to_s.include?('Clg .4% Condns DB=>MWB')
      idf_object = d.idfObject
      idf_object.dataFields.each do |data_field|
        design_day_field = idf_object.fieldComment(data_field, true)
        if design_day_field.to_s.include?('Day of Month')
          cooling_design_day_number = idf_object.getString(data_field)
          cooling_design_day_number = cooling_design_day_number.to_s
          # puts "cooling_design_day_number is #{cooling_design_day_number}"
        end
      end
    end
  end
  return heating_design_day_number, cooling_design_day_number
end

#scanObject

This method scans the epw file into memory.



681
682
683
684
685
686
687
688
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 681

def scan
  @filearray = []
  file = File.new(@epw_filepath, 'r')
  while (line = file.gets)
    @filearray.push(line.split(','))
  end
  file.close
end

#set_constant_dry_and_dewpoint_temperature_humidity_pressure(dbt = '0.0', dpt = '-1.1', hum = '92', press = '98500') ⇒ String

This method sets Constant Dry and Dew Point Temperature Humidity And Pressure and returns self.



786
787
788
789
790
791
792
793
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 786

def set_constant_dry_and_dewpoint_temperature_humidity_pressure(dbt = '0.0', dpt = '-1.1', hum = '92', press = '98500')
  scan if @filearray.nil?
  setcolumntovalue(DRY_BULB_TEMPERATURE, dbt)
  setcolumntovalue(DEW_POINT_TEMPERATURE, dpt)
  setcolumntovalue(RELATIVE_HUMIDITY, hum)
  setcolumntovalue(ATMOSPHERIC_STATION_PRESSURE, press)
  return self
end

#set_weather_file(model, runner = nil) ⇒ String

This method will set the weather file and returns a log string.



641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 641

def set_weather_file(model, runner = nil)
  BTAP.runner_register('Info', 'BTAP::Environment::WeatherFile::set_weather', runner)
  OpenStudio::Model::WeatherFile.setWeatherFile(model, @epw_file)
  building_name = model.building.get.name
  weather_file_path = model.weatherFile.get.path.get
  BTAP.runner_register('Info', "Set model \"#{building_name}\" to weather file #{weather_file_path}.\n", runner)

  # Add or update site data
  site = model.getSite
  site.setName("#{@epw_file.city}_#{@epw_file.stateProvinceRegion}_#{@epw_file.country}")
  site.setLatitude(@epw_file.latitude)
  site.setLongitude(@epw_file.longitude)
  site.setTimeZone(@epw_file.timeZone)
  site.setElevation(@epw_file.elevation)

  BTAP.runner_register('Info', 'Setting water main temperatures via parsing of STAT file.', runner)
  water_temp = model.getSiteWaterMainsTemperature
  water_temp.setAnnualAverageOutdoorAirTemperature(@stat_file.mean_dry_bulb)
  water_temp.setMaximumDifferenceInMonthlyAverageOutdoorAirTemperatures(@stat_file.delta_dry_bulb)
  BTAP.runner_register('Info', "SiteWaterMainsTemperature.AnnualAverageOutdoorAirTemperature = #{@stat_file.mean_dry_bulb}.", runner)
  BTAP.runner_register('Info', "SiteWaterMainsTemperature.MaximumDifferenceInMonthlyAverageOutdoorAirTemperatures = #{@stat_file.delta_dry_bulb}.", runner)

  # Remove all the Design Day objects that are in the file
  model.getObjectsByType('OS:SizingPeriod:DesignDay'.to_IddObjectType).each(&:remove)

  # Load in the ddy file based on convention that it is in the same directory and has the same basename as the weather
  @ddy_file.getObjectsByType('OS:SizingPeriod:DesignDay'.to_IddObjectType).each do |d|
    # grab only the ones that matter
    ddy_list = /(Htg 99.6. Condns DB)|(Clg .4. Condns WB=>MDB)|(Clg .4% Condns DB=>MWB)/
    if d.name.get =~ ddy_list
      BTAP.runner_register('Info', "Adding design day '#{d.name}'.", runner)
      # add the object to the existing model
      model.addObject(d.clone)
    end
  end
  return true
end

#setcolumntovalue(column, value) ⇒ Object

This method will sets column to a value.



694
695
696
697
698
699
700
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 694

def setcolumntovalue(column, value)
  @filearray.each do |line|
    unless line.first =~ /\D(.*)/
      line[column] = value
    end
  end
end

#writetofile(filename) ⇒ Object

This method writes to a file.



798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 798

def writetofile(filename)
  scan if @filearray.nil?

  begin
    FileUtils.mkdir_p(File.dirname(filename))
    file = File.open(filename, 'w')
    @filearray.each do |line|
      firstvalue = true
      newline = ''
      line.each do |value|
        if firstvalue == true
          firstvalue = false
        else
          newline += ','
        end
        newline += value
      end
      file.puts(newline)
    end
  rescue IOError => e
    # some error occur, dir not writable etc.
  ensure
    file.close unless file.nil?
  end
  # copies original file
  FileUtils.cp(@ddy_filepath, "#{File.dirname(filename)}/#{File.basename(filename, '.epw')}.ddy")
  FileUtils.cp(@stat_filepath, "#{File.dirname(filename)}/#{File.basename(filename, '.epw')}.stat")
end