Skip to content

Sun Vectors

Computes solar position vectors for specified dates and times using Ladybug's sunpath model. Used by the time-based carving mode.

  • get_sun_vectors: returns unit direction vectors pointing toward the sun for each sampled date-time of the analysis period (sun_steps_per_hour per hour), dropping positions below min_altitude and rotating by north_deg. The date-times are local standard time, daylight saving time (time_basis="daylight_saving", one hour ahead on every date) or true solar time (time_basis="solar").
  • sample_period: builds the list of Ladybug date-times of the analysis period that the sun positions are computed for.

urbansolarcarver.sun

Sun direction vectors for UrbanSolarCarver.

get_sun_vectors(epw_file, date_list, min_altitude, device, north_deg, time_basis) reads the site location from an EnergyPlus weather (EPW) file, computes the sun position for each Ladybug DateTime (local standard time; daylight saving time, one hour ahead, with time_basis="daylight_saving"; or true solar time with time_basis="solar") with a Ladybug Sunpath, drops positions at or below min_altitude degrees, and returns an (N, 3) float32 tensor of unit vectors pointing from the model toward the sun, in model coordinates.

EPW files are read through the cached weather_file.read_weather_file and Sunpath objects (_initialize_sunpath) are cached, so repeated calls, for example in the daemon, do not re-read or rebuild them.

sample_period turns the analysis period of the preprocessing settings into the Ladybug DateTime list the sun positions are computed for.

get_sun_vectors(epw_file, date_list, min_altitude=5.0, device=torch.device('cpu'), north_deg=0.0, time_basis='standard')

Unit vectors toward the sun at the given times, for times when the sun is above min_altitude.

Args: epw_file : Path to the EPW weather file; only its location (latitude, longitude, time zone) is used. date_list : Iterable of Ladybug DateTime objects, in the clock time_basis names. min_altitude: Sun altitude in degrees; times with the sun at or below it are dropped. device : Torch device for the result. north_deg : Model north in degrees clockwise from the +Y axis (USC convention, same as the north_deg setting). Sun vectors are returned in model coordinates. time_basis : "standard": the times are the EPW's local standard time. "daylight_saving": they are daylight saving time, standard time plus one hour, on every date. "solar": they are true solar time, in which the sun crosses the meridian at 12:00.

Returns: A float32 torch.Tensor of shape (N, 3), N <= len(date_list), one unit vector per kept time pointing from the model toward the sun. Empty (0, 3) with a UserWarning if no time is kept.

Raises: ValueError: If date_list is not iterable, is empty or holds non-DateTime items, min_altitude is not a finite number, or time_basis is not one of TIME_BASES. FileNotFoundError, IOError: If the EPW file is missing or unreadable. RuntimeError: If the sun position calculation fails.

sample_period(settings, steps_per_hour=1)

Build analysis datetimes and HOYs via Ladybug's AnalysisPeriod.

Returns:

Name Type Description
datetimes list[datetime]

Start to end (inclusive) at 1/steps_per_hour-hour steps.

hoys list[int]

Hour-of-year indices (0..8759, 0 = 1 January 00:00) of the period, always hourly: they index EPW records, which are hourly.