def sky_cie(day, month, time, latitude, longitude, time_zone, sky_type, north, ground, altitude, azimuth, folder, name): """Get a CIE sky file from parameters. These can be a minimal representation of the sky through altitude and azimuth (eg. "cie -alt 71.6 -az 185.2 -type 0"). Or it can be a detailed specification of time and location (eg. "cie 21 Jun 12:00 -lat 41.78 -lon -87.75 -type 0"). Both the altitude and azimuth must be specified for the minimal representation to be used. Otherwise, this command defaults to the detailed specification of time and location. \b Args: day: An intger for the day of the month (between 1 and 28-31). month: Text for the 3-letter abbreviation of the month of the year (eg. "Mar"). time: Text for the time of day (from 0:00 to 23:59). """ try: if altitude is not None and azimuth is not None: sky_obj = hbsky.CIE(altitude, azimuth, sky_type, ground) else: dtime = DateTime.from_date_time_string('{} {} {}'.format( day, month, time)) sky_obj = hbsky.CIE.from_lat_long(latitude, longitude, time_zone, dtime.month, dtime.day, dtime.float_hour, sky_type, north, ground) sky_obj.to_file(folder, name, True) except Exception: _logger.exception('Failed to generate sky.') sys.exit(1)
def test_to_from_date_time_string(): """Test the from_date_time_string method for DateTime.""" dt1 = DateTime(6, 21, 12) dt_str = str(dt1) rebuilt_dt = DateTime.from_date_time_string(dt_str) assert rebuilt_dt == dt1 assert str(rebuilt_dt) == dt_str
def from_string(cls, sky_string): """Create a ClimateBased sky from a string. Args: sky_string: A text string representing a ClimateBased sky. This can either be a minimal string representation of the sky (eg. "climate-based -alt 71.6 -az 185.2 -dni 800 -dhi 120"). Or it can be a detailed specification of time and location (eg. "climate-based 21 Jun 12:00 -lat 41.78 -lon -87.75 -dni 800 -dhi 120"). Any sky string can optionally have a "-g" property of a fractional number, which sets the reflectance of the ground. If unspecified, the ground will have a reflectance of 0.2. The detailed string can optionally have a "-tz" property with an integer between -12 and +14 to denote the time zone. If unspecified, the time will be interpreted as solar time at the given longitude. The detailed string can also have a "-n" property between 0 and 360 to set the counterclockwise difference between the North and the positive Y-axis in degrees. All other properties specified in the string are required. Usage: .. code-block:: python # minimal string representation of the sky sky_string = "climate-based -alt 71.6 -az 185.2 -dni 800 -dhi 120" sky = ClimateBased.from_string(sky_string) # detailed location-specific representation of the sky sky_string = "climate-based 21 Jun 12:00 -lat 41.78 -lon -87.75 -tz -6 " \ " -dni 800 -dhi 120 -n 0 -g 0.2" sky = ClimateBased.from_string(sky_string) """ # check the input and parse the datetime if it exists lower_str = sky_string.lower() assert lower_str.startswith('climate-based'), 'Expected string representation ' \ 'of ClimateBased sky "{}" to start with "climate-based".'.format(sky_string) split_str = shlex.split(lower_str) try: dtime = DateTime.from_date_time_string(' '.join(split_str[1:4])) except (ValueError, IndexError): # simpler sky representation dtime = None # make a parser for all of the other sky properties pars = argparse.ArgumentParser() pars.add_argument('-dni', action='store', dest='dni', type=float, default=0) pars.add_argument('-dhi', action='store', dest='dhi', type=float, default=0) pars.add_argument('-g', action='store', dest='g', type=float, default=0.2) # create the sky object if dtime is None: pars.add_argument('-alt', action='store', dest='alt', type=float, default=90) pars.add_argument('-az', action='store', dest='az', type=float, default=0) props = pars.parse_args(split_str[1:]) return cls(props.alt, props.az, props.dni, props.dhi, props.g) else: pars.add_argument('-lat', action='store', dest='lat', type=float, default=0) pars.add_argument('-lon', action='store', dest='lon', type=float, default=0) pars.add_argument('-tz', action='store', dest='tz', type=int, default=0) pars.add_argument('-n', action='store', dest='n', type=float, default=0) props = pars.parse_args(split_str[4:]) return cls.from_lat_long(props.lat, props.lon, props.tz, dtime.month, dtime.day, dtime.float_hour, props.dni, props.dhi, props.n, props.g)
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)
# 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) # if there are hour inputs on the analysis_period_, apply it to the data if analysis_period_ is not None and \
# 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_, simulation_control=_sim_control_, shadow_calculation=_shadow_calc_,