Ecliptic longitude of the sun at *utc_time*.
193542
def sun_ecliptic_longitude(utc_time):
    
    jdate = jdays2000(utc_time) / 36525.0
    # mean anomaly, rad
    m_a = np.deg2rad(357.52910 +
                     35999.05030 * jdate -
                     0.0001559 * jdate * jdate -
                     0.00000048 * jdate * jdate * jdate)
    # mean longitude, deg
    l_0 = 280.46645 + 36000.76983 * jdate + 0.0003032 * jdate * jdate
    d_l = ((1.914600 - 0.004817 * jdate - 0.000014 * jdate * jdate) * np.sin(m_a) +
           (0.019993 - 0.000101 * jdate) * np.sin(2 * m_a) + 0.000290 * np.sin(3 * m_a))
    # true longitude, deg
    l__ = l_0 + d_l
    return np.deg2rad(l__)
5517
def orientality(obj, sun):
    
    dist = angle.distance(sun.lon, obj.lon)
    return OCCIDENTAL if dist < 180 else ORIENTAL
714802
def compute_sun
      # === 太陽が光を発した時刻 t1(JD) の計算
      t_1_jd = calc_t1(:sun, @tdb)
      # === 時刻 t1(= TDB) におけるの位置・速度（ICRS 座標）の計算 (地球, 月, 太陽)
      Const::BODIES.each { |k, v| @icrs_1[k] = get_icrs(v, t_1_jd) }
      # === 時刻 t2 における地球重心から時刻 t1 における太陽への方向ベクトルの計算
      v_12 = calc_unit_vector(@icrs_2[:earth][0,3], @icrs_1[:sun][0,3])
      # === GCRS 座標系: 光行差の補正（方向ベクトルの Lorentz 変換）
      dd = conv_lorentz(v_12)
      pos_sun = calc_pos(dd, @r_e[:sun])
      # === 瞬時の真座標系: GCRS への bias & precession（歳差） & nutation（章動）の適用
      bpn = EphBpn.new(@tdb.strftime("%Y%m%d%H%M%S"))
      pos_sun_bpn = bpn.apply_bpn(pos_sun)
      # === 座標変換
      eq_pol_s  = MkCoord.rect2pol(pos_sun_bpn)
      ec_rect_s = MkCoord.rect_eq2ec(pos_sun_bpn, bpn.eps)
      ec_pol_s  = MkCoord.rect2pol(ec_rect_s)
      # === 視半径／（地平）視差計算
      radius = Math.asin(@asun / (eq_pol_s[2] * Const::AU / 1000))
      radius *= 180 / Math::PI * 3600
      parallax = Math.asin(@re / (eq_pol_s[2] * Const::AU / 1000))
      parallax *= 180 / Math::PI * 3600
      return [eq_pol_s, ec_pol_s, [radius, parallax]]
    rescue => e
      raise
    end
545676
def date_utc(self) -> datetime:
        """"""
        return datetime.utcfromtimestamp(self._node["date"] if "date" in self._node else self._node["taken_at_timestamp"])
1199164
def U(self):
    ""
    if getattr(self.data, 'tzinfo', None):
      return int(calendar.timegm(self.data.utctimetuple()))
    else:
      return int(time.mktime(self.data.timetuple()))
1130664
def timezone(utcoffset):
    '''
    

    '''

    hours, seconds = divmod(abs(utcoffset), 3600)
    minutes = round(float(seconds) / 60)

    if utcoffset >= 0:
        sign = '+'
    else:
        sign = '-'
    return '{0}{1:02d}:{2:02d}'.format(sign, int(hours), int(minutes))
1162580
def mangle(data_point):
    """"""
    temp_dict = {}
    temp_dict.update(data_point)
    temp_dict['utc_datetime'] = \
        datetime.datetime.utcfromtimestamp(temp_dict['time'])
    if 'solar' in data_point:
        temp_dict['GHI (W/m^2)'] = data_point['solar']['ghi']
        temp_dict['DNI (W/m^2)'] = data_point['solar']['dni']
        temp_dict['DHI (W/m^2)'] = data_point['solar']['dhi']
        temp_dict['ETR (W/m^2)'] = data_point['solar']['etr']
        del temp_dict['solar']
    else:
        temp_dict['GHI (W/m^2)'] = 0.0
        temp_dict['DNI (W/m^2)'] = 0.0
        temp_dict['DHI (W/m^2)'] = 0.0
        temp_dict['ETR (W/m^2)'] = 0.0
    return temp_dict
100470
def get_alt_az(utc_time, lon, lat):
    
    lon = np.deg2rad(lon)
    lat = np.deg2rad(lat)

    ra_, dec = sun_ra_dec(utc_time)
    h__ = _local_hour_angle(utc_time, lon, ra_)
    return (np.arcsin(np.sin(lat) * np.sin(dec) +
                      np.cos(lat) * np.cos(dec) * np.cos(h__)),
            np.arctan2(-np.sin(h__), (np.cos(lat) * np.tan(dec) -
                                      np.sin(lat) * np.cos(h__))))
871265
def _altaz_rotation(self, t):
        """"""
        R_lon = rot_z(- self.longitude.radians - t.gast * tau / 24.0)
        return einsum('ij...,jk...,kl...->il...', self.R_lat, R_lon, t.M)
782922
def get_position(self, utc_time, normalize=True):
        

        kep = self._sgdp4.propagate(utc_time)
        pos, vel = kep2xyz(kep)

        if normalize:
            pos /= XKMPER
            vel /= XKMPER * XMNPDA / SECDAY

        return pos, vel
843342
def calculate_sunrise_sunset_from_datetime(self, datetime, depression=0.833,
                                               is_solar_time=False):
        """"""
        # TODO(mostapha): This should be more generic and based on a method
        if datetime.year != 2016 and self.is_leap_year:
            datetime = DateTime(datetime.month, datetime.day, datetime.hour,
                                datetime.minute, True)
        sol_dec, eq_of_time = self._calculate_solar_geometry(datetime)
        # calculate sunrise and sunset hour
        if is_solar_time:
            noon = .5
        else:
            noon = (720 -
                    4 * math.degrees(self._longitude) -
                    eq_of_time +
                    self.time_zone * 60
                    ) / 1440.0

        try:
            sunrise_hour_angle = self._calculate_sunrise_hour_angle(
                sol_dec, depression)
        except ValueError:
            # no sun rise and sunset at this hour
            noon = 24 * noon
            return {
                "sunrise": None,
                "noon": DateTime(datetime.month, datetime.day,
                                 *self._calculate_hour_and_minute(noon),
                                 leap_year=self.is_leap_year),
                "sunset": None
            }
        else:
            sunrise = noon - sunrise_hour_angle * 4 / 1440.0
            sunset = noon + sunrise_hour_angle * 4 / 1440.0
            noon = 24 * noon
            sunrise = 24 * sunrise
            sunset = 24 * sunset

            return {
                "sunrise": DateTime(datetime.month, datetime.day,
                                    *self._calculate_hour_and_minute(sunrise),
                                    leap_year=self.is_leap_year),
                "noon": DateTime(datetime.month, datetime.day,
                                 *self._calculate_hour_and_minute(noon),
                                 leap_year=self.is_leap_year),
                "sunset": DateTime(datetime.month, datetime.day,
                                   *self._calculate_hour_and_minute(sunset),
                                   leap_year=self.is_leap_year)
            }
87098
def _precesion(date):
    

    t = date.change_scale('TT').julian_century

    zeta = (2306.2181 * t + 0.30188 * t ** 2 + 0.017998 * t ** 3) / 3600.
    theta = (2004.3109 * t - 0.42665 * t ** 2 - 0.041833 * t ** 3) / 3600.
    z = (2306.2181 * t + 1.09468 * t ** 2 + 0.018203 * t ** 3) / 3600.

    # print("zeta = {}\ntheta = {}\nz = {}\n".format(zeta, theta, z))
    return zeta, theta, z
1241052
def gha(julian_day, f):
    
    rad = old_div(np.pi, 180.)
    d = julian_day - 2451545.0 + f
    L = 280.460 + 0.9856474 * d
    g = 357.528 + 0.9856003 * d
    L = L % 360.
    g = g % 360.
# ecliptic longitude
    lamb = L + 1.915 * np.sin(g * rad) + .02 * np.sin(2 * g * rad)
# obliquity of ecliptic
    epsilon = 23.439 - 0.0000004 * d
# right ascension (in same quadrant as lambda)
    t = (np.tan(old_div((epsilon * rad), 2)))**2
    r = old_div(1, rad)
    rl = lamb * rad
    alpha = lamb - r * t * np.sin(2 * rl) + \
        (old_div(r, 2)) * t * t * np.sin(4 * rl)
#       alpha=mod(alpha,360.0)
# declination
    delta = np.sin(epsilon * rad) * np.sin(lamb * rad)
    delta = old_div(np.arcsin(delta), rad)
# equation of time
    eqt = (L - alpha)
#
    utm = f * 24 * 60
    H = old_div(utm, 4) + eqt + 180
    H = H % 360.0
    return H, delta
584920
def datetimes(self):
        """"""
        if self.timestep == 1:
            return tuple(dt.add_minute(30) for dt in
                         self.direct_normal_irradiance.datetimes)
        else:
            return self.direct_normal_irradiance.datetimes
1046536
def UTCFromGps(gpsWeek, SOW, leapSecs=14):
    
    secFract = SOW % 1
    epochTuple = gpsEpoch + (-1, -1, 0) 
    t0 = time.mktime(epochTuple) - time.timezone  #mktime is localtime, correct for UTC
    tdiff = (gpsWeek * secsInWeek) + SOW - leapSecs
    t = t0 + tdiff
    (year, month, day, hh, mm, ss, dayOfWeek, julianDay, daylightsaving) = time.gmtime(t)
    #use gmtime since localtime does not allow to switch off daylighsavings correction!!!
    return (year, month, day, hh, mm, ss + secFract)
548403
def get_position(self, dt):
        """"""
        return self.sx + self.dx * dt, self.sy + self.dy * dt
606553
def _calculate_sunrise_hour_angle(self, solar_dec, depression=0.833):
        """"""

        hour_angle_arg = math.degrees(math.acos(
            math.cos(math.radians(90 + depression)) /
            (math.cos(math.radians(self.latitude)) * math.cos(
                math.radians(solar_dec))) -
            math.tan(math.radians(self.latitude)) *
            math.tan(math.radians(solar_dec))
        ))

        return hour_angle_arg