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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(weather_file) ⇒ String

This method initializes and returns self.

Parameters:

Author:



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 383

def initialize(weather_file)
  # Define the openstudio-standards weather location
  top_dir = File.expand_path('../../..', File.dirname(__FILE__))
  weather_dir = "#{top_dir}/data/weather"

  # 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
  elsif File.exist?("#{weather_dir}/#{weather_file}")
    @epw_filepath = "#{weather_dir}/#{weather_file}"
    @ddy_filepath = "#{weather_dir}/#{weather_file.sub('epw', 'ddy')}"
    @stat_filepath = "#{weather_dir}/#{weather_file.sub('epw', 'stat')}"
  else
    raise("Could not find weather file #{weather_file}.  Make sure file path is correct.")
  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
  return self
end

Instance Attribute Details

#autumn_monthsObject

Returns the value of attribute autumn_months.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def autumn_months
  @autumn_months
end

#cdd10Object

Returns the value of attribute cdd10.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def cdd10
  @cdd10
end

#cdd18Object

Returns the value of attribute cdd18.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def cdd18
  @cdd18
end

#cityObject

Returns the value of attribute city.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def city
  @city
end

#climate_zoneObject

Returns the value of attribute climate_zone.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def climate_zone
  @climate_zone
end

#cooling_design_infoObject

Returns the value of attribute cooling_design_info.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def cooling_design_info
  @cooling_design_info
end

#countryObject

Returns the value of attribute country.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def country
  @country
end

#delta_dry_bulbObject

Returns the value of attribute delta_dry_bulb.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def delta_dry_bulb
  @delta_dry_bulb
end

#elevationObject

Returns the value of attribute elevation.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def elevation
  @elevation
end

#energy_plus_location_nameObject

Returns the value of attribute energy_plus_location_name.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def energy_plus_location_name
  @energy_plus_location_name
end

#extremes_design_infoObject

Returns the value of attribute extremes_design_info.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def extremes_design_info
  @extremes_design_info
end

#hdd10Object

Returns the value of attribute hdd10.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def hdd10
  @hdd10
end

#hdd18Object

Returns the value of attribute hdd18.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def hdd18
  @hdd18
end

#heating_design_infoObject

Returns the value of attribute heating_design_info.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def heating_design_info
  @heating_design_info
end

#latitudeObject

Returns the value of attribute latitude.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def latitude
  @latitude
end

#location_nameObject

Returns the value of attribute location_name.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def location_name
  @location_name
end

#longitudeObject

Returns the value of attribute longitude.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def longitude
  @longitude
end

#monthly_dry_bulbObject

Returns the value of attribute monthly_dry_bulb.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def monthly_dry_bulb
  @monthly_dry_bulb
end

#spring_monthsObject

Returns the value of attribute spring_months.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def spring_months
  @spring_months
end

#standardObject

Returns the value of attribute standard.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def standard
  @standard
end

#state_province_regionObject

Returns the value of attribute state_province_region.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def state_province_region
  @state_province_region
end

#summer_wet_monthsObject

Returns the value of attribute summer_wet_months.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def summer_wet_months
  @summer_wet_months
end

#typical_autumn_weekObject

Returns the value of attribute typical_autumn_week.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def typical_autumn_week
  @typical_autumn_week
end

#typical_spring_weekObject

Returns the value of attribute typical_spring_week.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def typical_spring_week
  @typical_spring_week
end

#typical_summer_wet_weekObject

Returns the value of attribute typical_summer_wet_week.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def typical_summer_wet_week
  @typical_summer_wet_week
end

#typical_winter_dry_weekObject

Returns the value of attribute typical_winter_dry_week.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def typical_winter_dry_week
  @typical_winter_dry_week
end

#winter_dry_monthsObject

Returns the value of attribute winter_dry_months.



315
316
317
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 315

def winter_dry_months
  @winter_dry_months
end

Instance Method Details

#eliminate_all_radiationString

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

Returns:

Author:



519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 519

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.

Returns:

Author:



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 553

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.

Returns:

Author:



542
543
544
545
546
547
548
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 542

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.

Returns:

Author:



573
574
575
576
577
578
579
580
581
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 573

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.

Returns:

Author:



586
587
588
589
590
591
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 586

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

#scanObject

This method scans the epw file into memory.



495
496
497
498
499
500
501
502
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 495

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.

Parameters:

  • dbt (Float) (defaults to: '0.0')

    dry bulb temperature

  • dpt (Float) (defaults to: '-1.1')

    dew point temperature

  • hum (Fixnum) (defaults to: '92')

    humidity

  • press (Fixnum) (defaults to: '98500')

    pressure

Returns:

Author:



600
601
602
603
604
605
606
607
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 600

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.

Parameters:

  • model (OpenStudio::model::Model)

    A model object

Returns:

Author:



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 457

def set_weather_file(model, runner = nil)
  BTAP.runner_register('Info', 'BTAP::Environment::WeatherFile::set_weather', runner)
  OpenStudio::Model::WeatherFile.setWeatherFile(model, @epw_file)
  BTAP.runner_register('Info', "Set model \"#{model.building.get.name}\" to weather file #{model.weatherFile.get.path.get}.\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.

Parameters:

Author:



508
509
510
511
512
513
514
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 508

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.

Parameters:

Author:



612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
# File 'lib/openstudio-standards/weather/Weather.Model.rb', line 612

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