def simulation_par_detailed(directory): sim_par = SimulationParameter() output = SimulationOutput() output.add_zone_energy_use() output.include_html = True output.reporting_frequency = 'Daily' output.add_summary_report('Annual Building Utility Performance Summary') output.add_summary_report('Climatic Data Summary') output.add_summary_report('Envelope Summary') sim_par.output = output run_period = RunPeriod(Date(1, 1), Date(6, 21)) run_period.daylight_saving_time = DaylightSavingTime(Date(3, 12), Date(11, 5)) run_period.start_day_of_week = 'Monday' run_period.holidays = [Date(1, 1), Date(3, 17), Date(7, 4)] sim_par.run_period = run_period sim_par.timestep = 4 sim_control_alt = SimulationControl(run_for_sizing_periods=True, run_for_run_periods=False) sim_par.simulation_control = sim_control_alt shadow_calc_alt = ShadowCalculation( solar_distribution='FullInteriorAndExteriorWithReflections', calculation_method='PixelCounting', calculation_update_method='Timestep') sim_par.shadow_calculation = shadow_calc_alt sizing_alt = SizingParameter(None, 1, 1) relative_path = './scripts/ddy/chicago.ddy' sizing_alt.add_from_ddy_996_004(relative_path) sim_par.sizing_parameter = sizing_alt dest_file = os.path.join(directory, 'simulation_par_detailed.json') with open(dest_file, 'w') as fp: json.dump(sim_par.to_dict(), fp, indent=4)
def test_simulation_parameter_to_dict_detailed(): """Test the to_dict method with a detailed SimulationParameter.""" sim_par = SimulationParameter() output = SimulationOutput() output.add_zone_energy_use() output.include_html = True output.reporting_frequency = 'Daily' output.add_summary_report('Annual Building Utility Performance Summary') output.add_summary_report('Climatic Data Summary') output.add_summary_report('Envelope Summary') sim_par.output = output run_period = RunPeriod(Date(1, 1), Date(6, 21)) run_period.daylight_saving_time = DaylightSavingTime( Date(3, 12), Date(11, 5)) run_period.start_day_of_week = 'Monday' run_period.holidays = [Date(1, 1), Date(3, 17), Date(7, 4)] sim_par.run_period = run_period sim_par.timestep = 4 sim_control_alt = SimulationControl(run_for_sizing_periods=True, run_for_run_periods=False) sim_par.simulation_control = sim_control_alt shadow_calc_alt = ShadowCalculation(calculation_frequency=20) sim_par.shadow_calculation = shadow_calc_alt sizing_alt = SizingParameter(None, 1, 1) relative_path = './tests/ddy/chicago.ddy' sizing_alt.add_from_ddy_996_004(relative_path) sim_par.sizing_parameter = sizing_alt sim_par_dict = sim_par.to_dict() assert 'outputs' in sim_par_dict['output'] assert 'holidays' in sim_par_dict['run_period'] assert 'daylight_saving_time' in sim_par_dict['run_period'] assert 'design_days' in sim_par_dict['sizing_parameter']
def test_run_period_equality(): """Test the equality of RunPeriod objects.""" run_period = RunPeriod() run_period_dup = run_period.duplicate() run_period_alt = RunPeriod(end_date=Date(6, 21)) assert run_period is run_period assert run_period is not run_period_dup assert run_period == run_period_dup run_period_dup.start_day_of_week = 'Monday' assert run_period != run_period_dup assert run_period != run_period_alt
def _load_run_period_str(run_period_str): """Load a RunPeriod from a string of a run period or analysis period. Args: run_period_str: A string of a RunPeriod or AnalysisPeriod to be loaded. """ if run_period_str is not None and run_period_str != '' \ and run_period_str != 'None': if run_period_str.startswith('RunPeriod'): return RunPeriod.from_string(run_period_str) else: return RunPeriod.from_analysis_period( AnalysisPeriod.from_string(run_period_str))
def test_simulation_parameter_setability(): """Test the setting of properties of SimulationParameter.""" sim_par = SimulationParameter() output = SimulationOutput() output.add_zone_energy_use() sim_par.output = output assert sim_par.output == output run_period = RunPeriod(Date(1, 1), Date(6, 21)) sim_par.run_period = run_period assert sim_par.run_period == run_period sim_par.timestep = 4 assert sim_par.timestep == 4 sim_control_alt = SimulationControl(run_for_sizing_periods=True, run_for_run_periods=False) sim_par.simulation_control = sim_control_alt assert sim_par.simulation_control == sim_control_alt shadow_calc_alt = ShadowCalculation('FullExteriorWithReflections') sim_par.shadow_calculation = shadow_calc_alt assert sim_par.shadow_calculation == shadow_calc_alt sizing_alt = SizingParameter(None, 1, 1) relative_path = './tests/ddy/chicago_monthly.ddy' sizing_alt.add_from_ddy(relative_path) sim_par.sizing_parameter = sizing_alt assert sim_par.sizing_parameter == sizing_alt sim_par.north_angle = 20 assert sim_par.north_angle == 20 sim_par.terrain_type = 'Ocean' assert sim_par.terrain_type == 'Ocean'
def custom_sim_par(ddy_file, output_names, run_period_json, filter_des_days, output_file): """Get a SimulationParameter JSON with outputs for thermal load balances. \n Args: ddy_file: Full path to a DDY file that will be used to specify design days within the simulation parameter. output_names: A list of EnergyPlus output names as strings (eg. 'Surface Window System Solar Transmittance'. These outputs will be requested from the simulation. """ try: assert os.path.isfile(ddy_file), 'No DDY file found at {}.'.format( ddy_file) sim_par = SimulationParameter() for output_name in output_names: sim_par.output.add_output(output_name) if run_period_json: assert os.path.isfile(run_period_json), \ 'No run period JSON file found at {}.'.format(run_period_json) with open(run_period_json) as json_file: data = json.load(json_file) sim_par.run_period = RunPeriod.from_dict(data) if filter_des_days: sim_par.sizing_parameter.add_from_ddy_996_004(ddy_file) else: sim_par.sizing_parameter.add_from_ddy(ddy_file) output_file.write(json.dumps(sim_par.to_dict())) except Exception as e: _logger.exception( 'Failed to generate simulation parameter.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
def run_period(start_month, start_day, end_month, end_day, start_day_of_week, holidays, output_file): """Get a RunPeriod string that can be used to set the simulation run period. \b Args: start_month: Start month (1-12). start_day: Start day (1-31). end_month: End month (1-12). end_day: End day (1-31). """ try: # create the run period a_period = AnalysisPeriod(start_month, start_day, 0, end_month, end_day, 23) run_period = RunPeriod.from_analysis_period(a_period) # set the start day of the week if it is input if start_day_of_week is not None: run_period.start_day_of_week = start_day_of_week.title() # set the holidays if requested. if holidays: dates = tuple(Date.from_date_string(date) for date in holidays) run_period.holidays = dates output_file.write(str(run_period)) except Exception as e: _logger.exception('Failed to generate run period.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
def dict_to_simulation(sim_dict, raise_exception=True): """Get a Python object of any Simulation object from a dictionary. Args: sim_dict: A dictionary of any Honeybee energy simulation object. Note that this should be a non-abridged dictionary to be valid. raise_exception: Boolean to note whether an excpetion should be raised if the object is not identified as a simulation object. Default: True. Returns: A Python object derived from the input sim_dict. """ try: # get the type key from the dictionary sim_type = sim_dict['type'] except KeyError: raise ValueError('Simulation dictionary lacks required "type" key.') if sim_type == 'SimulationControl': return SimulationControl.from_dict(sim_dict) elif sim_type == 'RunPeriod': return RunPeriod.from_dict(sim_dict) elif sim_type == 'DaylightSavingTime': return DaylightSavingTime.from_dict(sim_dict) elif sim_type == 'ShadowCalculation': return ShadowCalculation.from_dict(sim_dict) elif sim_type == 'SizingParameter': return SizingParameter.from_dict(sim_dict) elif sim_type == 'SimulationOutput': return SimulationOutput.from_dict(sim_dict) elif sim_type == 'SimulationParameter': return SimulationParameter.from_dict(sim_dict) elif raise_exception: raise ValueError( '{} is not a recognized energy Simulation type'.format(sim_type))
def default_sim_par(ddy_file, run_period_json, filter_des_days, output_file): """Get a SimulationParameter JSON with default outputs for energy use only. \n Args: ddy_file: Full path to a DDY file that will be used to specify design days within the simulation parameter. """ try: assert os.path.isfile(ddy_file), 'No DDY file found at {}.'.format( ddy_file) sim_par = SimulationParameter() sim_par.output.add_zone_energy_use() sim_par.output.add_hvac_energy_use() if run_period_json: assert os.path.isfile(run_period_json), \ 'No run period JSON file found at {}.'.format(run_period_json) with open(run_period_json) as json_file: data = json.load(json_file) sim_par.run_period = RunPeriod.from_dict(data) if filter_des_days: sim_par.sizing_parameter.add_from_ddy_996_004(ddy_file) else: sim_par.sizing_parameter.add_from_ddy(ddy_file) output_file.write(json.dumps(sim_par.to_dict())) except Exception as e: _logger.exception( 'Failed to generate simulation parameter.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
def load_balance_sim_par(ddy_file, load_type, run_period_json, filter_des_days, output_file): """Get a SimulationParameter JSON with outputs for thermal load balances. \n Args: ddy_file: Full path to a DDY file that will be used to specify design days within the simulation parameter. """ try: assert os.path.isfile(ddy_file), 'No DDY file found at {}.'.format( ddy_file) sim_par = SimulationParameter() sim_par.output.add_zone_energy_use(load_type) gl_load_type = load_type if load_type != 'All' else 'Total' sim_par.output.add_gains_and_losses(gl_load_type) sim_par.output.add_surface_energy_flow() if run_period_json: assert os.path.isfile(run_period_json), \ 'No run period JSON file found at {}.'.format(run_period_json) with open(run_period_json) as json_file: data = json.load(json_file) sim_par.run_period = RunPeriod.from_dict(data) if filter_des_days: sim_par.sizing_parameter.add_from_ddy_996_004(ddy_file) else: sim_par.sizing_parameter.add_from_ddy(ddy_file) output_file.write(json.dumps(sim_par.to_dict())) except Exception as e: _logger.exception( 'Failed to generate simulation parameter.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
def test_run_period_init_from_idf(): """Test the initialization of RunPeriod from_idf.""" run_period = RunPeriod() run_period.start_date = Date(1, 1) run_period.end_date = Date(6, 21) run_period.start_day_of_week = 'Monday' run_period.holidays = (Date(1, 1), Date(3, 17)) run_period.daylight_saving_time = DaylightSavingTime() rp_str, holidays, dst = run_period.to_idf() rebuilt_run_period = RunPeriod.from_idf(rp_str, holidays, dst) assert run_period == rebuilt_run_period assert rebuilt_run_period.to_idf() == (rp_str, holidays, dst)
def test_run_period_dict_methods(): """Test the to/from dict methods.""" run_period = RunPeriod() run_period.start_date = Date(1, 1) run_period.end_date = Date(6, 21) run_period.start_day_of_week = 'Monday' run_period.holidays = (Date(1, 1), Date(3, 17)) run_period.daylight_saving_time = DaylightSavingTime() rp_dict = run_period.to_dict() new_run_period = RunPeriod.from_dict(rp_dict) assert new_run_period == run_period assert rp_dict == new_run_period.to_dict()
def test_run_period_string_methods(): """Test the to/from string methods.""" run_period = RunPeriod() run_period.start_date = Date(1, 1) run_period.end_date = Date(6, 21) run_period.start_day_of_week = 'Monday' run_period.holidays = (Date(1, 1), Date(3, 17)) run_period.daylight_saving_time = DaylightSavingTime() new_run_period = RunPeriod.from_string(str(run_period)) assert new_run_period == run_period
def test_run_period(): """Test the run_period command.""" runner = CliRunner() result = runner.invoke(run_period, ['1', '6', '1', '12']) assert result.exit_code == 0 run_per = RunPeriod.from_string(result.output) assert run_per.start_date == Date(1, 6) assert run_per.end_date == Date(1, 12)
def test_simulation_parameter_init(): """Test the initialization of SimulationParameter and basic properties.""" sim_par = SimulationParameter() str(sim_par) # test the string representation assert sim_par.output == SimulationOutput() assert sim_par.run_period == RunPeriod() assert sim_par.timestep == 6 assert sim_par.simulation_control == SimulationControl() assert sim_par.shadow_calculation == ShadowCalculation() assert sim_par.sizing_parameter == SizingParameter()
def test_run_period_setability(): """Test the setting of properties of RunPeriod.""" run_period = RunPeriod() run_period.start_date = Date(1, 1) assert run_period.start_date == Date(1, 1) run_period.end_date = Date(6, 21) assert run_period.end_date == Date(6, 21) run_period.start_day_of_week = 'Monday' assert run_period.start_day_of_week == 'Monday' run_period.holidays = (Date(1, 1), Date(3, 17)) assert run_period.holidays == (Date(1, 1), Date(3, 17)) run_period.daylight_saving_time = DaylightSavingTime() assert run_period.daylight_saving_time == DaylightSavingTime() with pytest.raises(AssertionError): run_period.start_date = Date(11, 10) with pytest.raises(AssertionError): run_period.start_date = Date(3, 10, True) run_period.is_leap_year = True assert run_period.is_leap_year
def test_run_period_init(): """Test the initialization of RunPeriod and basic properties.""" run_period = RunPeriod() str(run_period) # test the string representation assert run_period.start_date == Date(1, 1) assert run_period.end_date == Date(12, 31) assert run_period.start_day_of_week == 'Sunday' assert run_period.holidays is None assert run_period.daylight_saving_time is None assert run_period.is_leap_year is False
def test_simulation_parameter_init_from_idf(): """Test the initialization of SimulationParameter from_idf.""" sim_par = SimulationParameter() output = SimulationOutput() output.add_zone_energy_use() sim_par.output = output run_period = RunPeriod(Date(1, 1), Date(6, 21)) sim_par.run_period = run_period sim_par.timestep = 4 sim_control_alt = SimulationControl(run_for_sizing_periods=True, run_for_run_periods=False) sim_par.simulation_control = sim_control_alt shadow_calc_alt = ShadowCalculation(calculation_frequency=20) sim_par.shadow_calculation = shadow_calc_alt sizing_alt = SizingParameter(1, 1) sim_par.sizing_parameter = sizing_alt idf_str = sim_par.to_idf() rebuilt_sim_par = SimulationParameter.from_idf(idf_str) assert sim_par == rebuilt_sim_par assert rebuilt_sim_par.to_idf() == idf_str
def test_simulation_parameter_dict_methods(): """Test the to/from dict methods.""" sim_par = SimulationParameter() output = SimulationOutput() output.add_zone_energy_use() sim_par.output = output run_period = RunPeriod(Date(1, 1), Date(6, 21)) sim_par.run_period = run_period sim_par.timestep = 4 sim_control_alt = SimulationControl(run_for_sizing_periods=True, run_for_run_periods=False) sim_par.simulation_control = sim_control_alt shadow_calc_alt = ShadowCalculation(calculation_frequency=20) sim_par.shadow_calculation = shadow_calc_alt sizing_alt = SizingParameter(1, 1) sim_par.sizing_parameter = sizing_alt sim_par_dict = sim_par.to_dict() new_sim_par = SimulationParameter.from_dict(sim_par_dict) assert new_sim_par == sim_par assert sim_par_dict == new_sim_par.to_dict()
def test_simulation_parameter_setability(): """Test the setting of properties of SimulationParameter.""" sim_par = SimulationParameter() output = SimulationOutput() output.add_zone_energy_use() sim_par.output = output assert sim_par.output == output run_period = RunPeriod(Date(1, 1), Date(6, 21)) sim_par.run_period = run_period assert sim_par.run_period == run_period sim_par.timestep = 4 assert sim_par.timestep == 4 sim_control_alt = SimulationControl(run_for_sizing_periods=True, run_for_run_periods=False) sim_par.simulation_control = sim_control_alt assert sim_par.simulation_control == sim_control_alt shadow_calc_alt = ShadowCalculation('FullExteriorWithReflections') sim_par.shadow_calculation = shadow_calc_alt assert sim_par.shadow_calculation == shadow_calc_alt sizing_alt = SizingParameter(1, 1) sim_par.sizing_parameter = sizing_alt assert sim_par.sizing_parameter == sizing_alt
def test_simulation_parameter_dict_methods(): """Test the to/from dict methods.""" sim_par = SimulationParameter() output = SimulationOutput() output.add_zone_energy_use() sim_par.output = output run_period = RunPeriod(Date(1, 1), Date(6, 21)) sim_par.run_period = run_period sim_par.timestep = 4 sim_control_alt = SimulationControl(run_for_sizing_periods=True, run_for_run_periods=False) sim_par.simulation_control = sim_control_alt shadow_calc_alt = ShadowCalculation(calculation_frequency=20) sim_par.shadow_calculation = shadow_calc_alt sizing_alt = SizingParameter(None, 1, 1) relative_path = './tests/ddy/chicago.ddy' sizing_alt.add_from_ddy_996_004(relative_path) sim_par.sizing_parameter = sizing_alt sim_par_dict = sim_par.to_dict() new_sim_par = SimulationParameter.from_dict(sim_par_dict) new_sim_par.sizing_parameter.apply_location(sizing_alt[0].location) assert new_sim_par == sim_par assert sim_par_dict == new_sim_par.to_dict()
def test_simulation_parameter_init_from_idf(): """Test the initialization of SimulationParameter from_idf.""" sim_par = SimulationParameter() output = SimulationOutput() output.add_zone_energy_use() sim_par.output = output run_period = RunPeriod(Date(1, 1), Date(6, 21)) sim_par.run_period = run_period sim_par.timestep = 4 sim_control_alt = SimulationControl(run_for_sizing_periods=True, run_for_run_periods=False) sim_par.simulation_control = sim_control_alt shadow_calc_alt = ShadowCalculation(calculation_frequency=20) sim_par.shadow_calculation = shadow_calc_alt sizing_alt = SizingParameter(None, 1, 1) relative_path = './tests/ddy/chicago.ddy' sizing_alt.add_from_ddy_996_004(relative_path) sim_par.sizing_parameter = sizing_alt idf_str = sim_par.to_idf() rebuilt_sim_par = SimulationParameter.from_idf(idf_str) rebuilt_sim_par.sizing_parameter.apply_location(sizing_alt[0].location) assert sim_par == rebuilt_sim_par assert rebuilt_sim_par.to_idf() == idf_str
try: from honeybee_energy.simulation.output import SimulationOutput from honeybee_energy.simulation.runperiod import RunPeriod from honeybee_energy.simulation.daylightsaving import DaylightSavingTime from honeybee_energy.simulation.parameter import SimulationParameter except ImportError as e: raise ImportError('\nFailed to import honeybee_energy:\n\t{}'.format(e)) # set default simulation outputs if _output_ is None: _output_ = SimulationOutput() _output_.add_zone_energy_use() # set default simulation run period _run_period_ = RunPeriod.from_analysis_period(_run_period_) \ if _run_period_ is not None else RunPeriod() # set the daylight savings if it is input if daylight_saving_ is not None: daylight_saving = DaylightSavingTime.from_analysis_period(daylight_saving_) _run_period_.daylight_saving_time = daylight_saving # set the holidays if requested. if len(holidays_) != 0: try: dates = tuple(Date.from_date_string(date) for date in holidays_) except ValueError: dates = tuple(DateTime.from_date_time_string(date).date for date in holidays_) _run_period_.holidays = dates