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 test_to_from_date_string(): """Test the from_date_string method for Date.""" dt1 = Date(6, 21) dt_str = str(dt1) rebuilt_dt = Date.from_date_string(dt_str) assert rebuilt_dt == dt1 assert str(rebuilt_dt) == dt_str
ghenv.Component.SubCategory = '4 :: AlternativeWeather' ghenv.Component.AdditionalHelpFromDocStrings = '3' try: from ladybug.designday import DesignDay from ladybug.dt import Date, DateTime except ImportError as e: raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e)) try: from ladybug_rhino.grasshopper import all_required_inputs except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): # set defaults for relevant items if _dry_bulb_range_ is None: _dry_bulb_range_ = 0 if _barometric_p_ is None: _barometric_p_ = 101325 # process the input date try: date = Date.from_date_string(_date) except ValueError: date = DateTime.from_date_time_string(_date).date design_day = DesignDay.from_design_day_properties( _name, _day_type, _location, date, _dry_bulb_max, _dry_bulb_range_, _humidity_type, _humidity_value, _barometric_p_, _wind_speed, _wind_dir, _sky_type, _sky_properties)
week_start_day = 'Sunday' if _week_start_day_ is None else _week_start_day_.title( ) # process the analysis period if it is input if analysis_period_ is not None: start_date = analysis_period_.st_time.date end_date = analysis_period_.end_time.date timestep = analysis_period_.timestep else: start_date, end_date, timestep = Date(1, 1), Date(12, 31), 1 # process the holidays_ if they are input holidays = None if len(holidays_) != 0 and holidays_[0] is not None: try: holidays = tuple(Date.from_date_string(hol) for hol in holidays_) except ValueError: holidays = tuple( DateTime.from_date_time_string(hol).date for hol in holidays_) # create the DataCollection if isinstance(_schedule, ScheduleRuleset): data = _schedule.data_collection(timestep, start_date, end_date, week_start_day, holidays, leap_year=False) else: # assume that it is a ScheduleFixedInterval data = _schedule.data_collection_at_timestep(timestep, start_date, end_date)
_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 # set the start day of the week if it is input if _start_dow_ is not None: _run_period_.start_day_of_week = _start_dow_.title() # set the default timestep _timestep_ = _timestep_ if _timestep_ is not None else 6 # return final simulation parameters sim_par = SimulationParameter(output=_output_, run_period=_run_period_, timestep=_timestep_,