Exemplo n.º 1
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)
Exemplo n.º 2
0
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))
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