当前位置: 首页>>代码示例>>Python>>正文


Python ephem.Sun方法代码示例

本文整理汇总了Python中ephem.Sun方法的典型用法代码示例。如果您正苦于以下问题:Python ephem.Sun方法的具体用法?Python ephem.Sun怎么用?Python ephem.Sun使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ephem的用法示例。


在下文中一共展示了ephem.Sun方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pyephem_earthsun_distance

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def pyephem_earthsun_distance(time):
    """
    Calculates the distance from the earth to the sun using pyephem.

    Parameters
    ----------
    time : pandas.DatetimeIndex
        Must be localized or UTC will be assumed.

    Returns
    -------
    pd.Series. Earth-sun distance in AU.
    """

    import ephem

    sun = ephem.Sun()
    earthsun = []
    for thetime in time:
        sun.compute(ephem.Date(thetime))
        earthsun.append(sun.earth_distance)

    return pd.Series(earthsun, index=time) 
开发者ID:pvlib,项目名称:pvlib-python,代码行数:25,代码来源:solarposition.py

示例2: __init__

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def __init__(self, carla_weather, dtime=None, animation=False):
        """
        Class constructor
        """
        self.carla_weather = carla_weather
        self.animation = animation

        self._sun = ephem.Sun()  # pylint: disable=no-member
        self._observer_location = ephem.Observer()
        geo_location = CarlaDataProvider.get_map().transform_to_geolocation(carla.Location(0, 0, 0))
        self._observer_location.lon = str(geo_location.longitude)
        self._observer_location.lat = str(geo_location.latitude)

        #@TODO This requires the time to be in UTC to be accurate
        self.datetime = dtime
        if self.datetime:
            self._observer_location.date = self.datetime

        self.update() 
开发者ID:carla-simulator,项目名称:scenario_runner,代码行数:21,代码来源:weather_sim.py

示例3: sun_rise_set_times

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def sun_rise_set_times(datetime_index, coords):
    """
    Returns sunrise and set times for the given datetime_index and coords,
    as a Series indexed by date (days, resampled from the datetime_index).

    """
    sun = ephem.Sun()
    obs = ephem.Observer()
    obs.lat = str(coords[0])
    obs.lon = str(coords[1])

    # Ensure datetime_index is daily
    dtindex = pd.DatetimeIndex(
        datetime_index.to_series().map(pd.Timestamp.date).unique()
    )

    return pd.Series(
        [_get_rise_and_set_time(i, sun, obs) for i in dtindex],
        index=dtindex
    ) 
开发者ID:renewables-ninja,项目名称:gsee,代码行数:22,代码来源:trigon.py

示例4: compute_sun_ned

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def compute_sun_ned(lon_deg, lat_deg, alt_m, timestamp):
    d = datetime.utcfromtimestamp(timestamp)
    #d = datetime.datetime.utcnow()
    
    ed = ephem.Date(d)
    #print 'ephem time utc:', ed
    #print 'localtime:', ephem.localtime(ed)

    ownship = ephem.Observer()
    ownship.lon = '%.8f' % lon_deg
    ownship.lat = '%.8f' % lat_deg
    ownship.elevation = alt_m
    ownship.date = ed

    sun = ephem.Sun(ownship)
    sun_ned = [ math.cos(sun.az), math.sin(sun.az), -math.sin(sun.alt) ]

    return norm(np.array(sun_ned)) 
开发者ID:UASLab,项目名称:ImageAnalysis,代码行数:20,代码来源:illumintation-sensor-test.py

示例5: _ephem_setup

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def _ephem_setup(latitude, longitude, altitude, pressure, temperature,
                 horizon):
    import ephem
    # initialize a PyEphem observer
    obs = ephem.Observer()
    obs.lat = str(latitude)
    obs.lon = str(longitude)
    obs.elevation = altitude
    obs.pressure = pressure / 100.  # convert to mBar
    obs.temp = temperature
    obs.horizon = horizon

    # the PyEphem sun
    sun = ephem.Sun()
    return obs, sun 
开发者ID:pvlib,项目名称:pvlib-python,代码行数:17,代码来源:solarposition.py

示例6: _calculate_simple_day_angle

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def _calculate_simple_day_angle(dayofyear, offset=1):
    """
    Calculates the day angle for the Earth's orbit around the Sun.

    Parameters
    ----------
    dayofyear : numeric
    offset : int, default 1
        For the Spencer method, offset=1; for the ASCE method, offset=0

    Returns
    -------
    day_angle : numeric
    """
    return (2. * np.pi / 365.) * (dayofyear - offset) 
开发者ID:pvlib,项目名称:pvlib-python,代码行数:17,代码来源:solarposition.py

示例7: __init__

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def __init__(self, orb, lon, lat, elev=False):
        """
        :param orb: either 'sun' or 'moon'
        :param lon: longitude of observer in degrees
        :param lat: latitude of observer in degrees
        :param elev: elevation of observer in meters
        """
        if ephem is None:
            logger.warning("Could not find/use ephem!")
            return
        self._obs = ephem.Observer()
        """
        PyEphem: An `Observer` instance allows  to compute the positions of
        celestial bodies as seen from a particular position on the Earth's surface.        
        Following attributes can be set after creation (used defaults are given):        
        `date` - the moment the `Observer` is created
        `lat` - zero degrees latitude
        `lon` - zero degrees longitude
        `elevation` - 0 meters above sea level
        `horizon` - 0 degrees
        `epoch` - J2000
        `temp` - 15 degrees Celsius
        `pressure` - 1010 mBar
"""
        self._obs.long = str(lon)
        self._obs.lat = str(lat)
        if elev:
            self._obs.elevation = int(elev)
        if orb == 'sun':
            self._orb = ephem.Sun()
        elif orb == 'moon':
            self._orb = ephem.Moon()
            self.phase = self._phase
            self.light = self._light 
开发者ID:smarthomeNG,项目名称:smarthome,代码行数:36,代码来源:orb.py

示例8: _ephem_setup

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def _ephem_setup(latitude, longitude, altitude, pressure, temperature):
    # observer
    obs = ephem.Observer()
    obs.lat = str(latitude)
    obs.lon = str(longitude)
    obs.elevation = altitude
    obs.pressure = pressure / 100.
    obs.temp = temperature

    # sun
    sun = ephem.Sun()
    return obs, sun 
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:14,代码来源:solar_equations.py

示例9: declination_degree

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def declination_degree(day_date, TY):
    """The declination of the sun is the angle between Earth's equatorial plane and a line
    between the Earth and the sun. It varies between 23.45 degrees and -23.45 degrees,
    hitting zero on the equinoxes and peaking on the solstices. [1]_

    :param when: datetime.datetime, date/time for which to do the calculation
    :param TY: float, Total number of days in a year. eg. 365 days per year,(no leap days)
    :param DEC: float,  The declination of the Sun

    .. [1] http://pysolar.org/
    """

    return 23.45 * np.vectorize(sin)((2 * pi / (TY)) * (day_date - 81)) 
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:15,代码来源:solar_equations.py

示例10: draw_map

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def draw_map(layer, body, time, night=True, topo=True):
    for x in range(body.width):
        for y in range(body.height):
            if night:
                sun = ephem.Sun()
                obs = ephem.Observer()
                obs.pressure = 0
                lat, lon = body.to_latlon(x, y)
                obs.lat = "{:.8f}".format(lat)
                obs.lon = "{:.8f}".format(lon)
                obs.date = time
                sun.compute(obs)
                # astronomical twilight starts at -18°
                # -0.3141592 = radians(-18)
                night_factor = max(min(sun.alt, 0), -0.3141592) / -0.3141592
            else:
                night_factor = -1

            if body.map[x][y][3] is not None:
                if topo is True:
                    r, g, b, color = body.map[x][y][:4]
                else:
                    r, g, b, color = 0, 249, 114, 48
                if night_factor > -0.001:
                    night_r = 0
                    night_g = g * 0.2
                    night_b = min(b + 40, 255)
                    effective_r = ((1 - night_factor) * r) + (night_factor * night_r)
                    effective_g = ((1 - night_factor) * g) + (night_factor * night_g)
                    effective_b = ((1 - night_factor) * b) + (night_factor * night_b)
                    color = closest_color(effective_r, effective_g, effective_b)
                layer.draw(x, y, "•", color) 
开发者ID:trehn,项目名称:termtrack,代码行数:34,代码来源:draw.py

示例11: _daily_diffuse

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def _daily_diffuse(obs, ks, sunrise, sunset, p=DEFAULT_PARAMS):
    """
    Returns a list of diffuse fractions for the given observer
    which must have its coordinates and date set, and given the ``ks``,
    a list of 24 hourly clearness indices, and sunrise and sunset times.

    """
    date = obs.date.datetime()
    # whether date was set or not, ensure it's at hour 0
    obs.date = datetime.datetime(date.year, date.month, date.day)
    sun = ephem.Sun()
    sun.compute(obs)
    # sunrise, sunset = _sunrise_sunset(obs, sun)
    alpha = sun.alt
    values = []
    k_day = pd.Series(ks).mean()  # using pandas to ignore NaN
    psi = _get_psi_func(sunrise, sunset)
    for hour in range(24):
        if np.isnan(ks[hour]):
            d = np.nan
        else:
            ast = _solartime(obs, sun)
            pwr = (p['a0'] + p['a1'] * ks[hour]
                   + p['b1'] * ast + p['b2'] * alpha
                   + p['b3'] * k_day + p['b4'] * psi(hour, ks))
            d = 1 / (1 + math.e ** pwr)
        values.append(d)
        # Increase obs.date by one hour for the next iteration
        obs.date = obs.date.datetime() + datetime.timedelta(hours=1)
        sun.compute(obs)
    return values 
开发者ID:renewables-ninja,项目名称:gsee,代码行数:33,代码来源:brl_model.py

示例12: getalt

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def getalt(ra, dec, yr, mon, day, hr, minu, sec=0, lon='-111:35:59', lat='31:57:12',
		elev=2000, retSun=False, retDistMoon=False):
	"""computes the altitude in degrees of a given object at the given utc time
	ra dec in degress	
	yr mon day hr minu in utc
	lon lat are in degrees and lon is positive to the East
	retSun means that you'll get height of the sun above the horizon
	retDistMoon means that you'll also get the distance to the moon
	"""
	
	obs = ephem.Observer();
	obs.lon = lon # longitude 
	obs.lat = lat #latitude
	obs.elevation=elev;
	fb = ephem.FixedBody();
	fb._ra=np.deg2rad(ra);
	fb._dec=np.deg2rad(dec)
	obs.date=ephem.Date('%d/%02d/%d %d:%d:0'%(yr,mon,day,hr,minu))
	fb.compute(obs);
	alt = np.rad2deg(1*fb.alt)
	az = np.rad2deg(1*fb.az);
	if retSun:
		fbSun = ephem.Sun();
		fbSun.compute(obs);
		altSun = np.rad2deg(1*(fbSun.alt))
	if retDistMoon:
		fbMoon = ephem.Moon();
		fbMoon.compute(obs);
		altMoon = np.rad2deg(1*fbMoon.alt)
		azMoon = np.rad2deg(1*fbMoon.az);
		distMoon = sphdist.sphdist(az,alt,azMoon,altMoon)
	if retSun or retDistMoon:
		ret = [alt]
	else:	
		ret = alt
	if retSun:
		ret.append(altSun)
	if retDistMoon:
		ret.append(distMoon)
	return ret 
开发者ID:segasai,项目名称:astrolibpy,代码行数:42,代码来源:staralt.py

示例13: solar_zenith_analytical

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def solar_zenith_analytical(latitude, hourangle, declination):
    """
    Analytical expression of solar zenith angle based on spherical
    trigonometry.

    .. warning:: The analytic form neglects the effect of atmospheric
        refraction.

    Parameters
    ----------
    latitude : numeric
        Latitude of location in radians.
    hourangle : numeric
        Hour angle in the local solar time in radians.
    declination : numeric
        Declination of the sun in radians.

    Returns
    -------
    zenith : numeric
        Solar zenith angle in radians.

    References
    ----------
    .. [1] J. A. Duffie and W. A. Beckman,  "Solar Engineering of Thermal
       Processes, 3rd Edition" pp. 14, J. Wiley and Sons, New York (2006)

    .. [2] J. H. Seinfeld and S. N. Pandis, "Atmospheric Chemistry and
       Physics" p. 132, J. Wiley (1998)

    .. [3] Daryl R. Myers, "Solar Radiation: Practical Modeling for
       Renewable Energy Applications", p. 5 CRC Press (2013)

    .. [4] `Wikipedia: Solar Zenith Angle
       <https://en.wikipedia.org/wiki/Solar_zenith_angle>`_

    .. [5] `PVCDROM: Sun's Position
       <http://www.pveducation.org/pvcdrom/2-properties-sunlight/
       suns-position>`_

    See Also
    --------
    declination_spencer71
    declination_cooper69
    hour_angle
    """
    return np.arccos(
        np.cos(declination) * np.cos(latitude) * np.cos(hourangle) +
        np.sin(declination) * np.sin(latitude)
    ) 
开发者ID:pvlib,项目名称:pvlib-python,代码行数:52,代码来源:solarposition.py

示例14: calc_toa_gain_offset

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def calc_toa_gain_offset(meta):
    """
    Compute (gain, offset) tuples for each band of the specified image metadata
    """
    # Set satellite index to look up cal factors
    sat_index = meta['satid'].upper() + "_" + meta['bandid'].upper()

    # Set scale for at sensor radiance
    # Eq is:
    # L = GAIN * DN * (ACF/EBW) + Offset
    # ACF abscal factor from meta data
    # EBW effectiveBandwidth from meta data
    # Gain provided by abscal from const
    # Offset provided by abscal from const
    acf = np.asarray(meta['abscalfactor'])  # Should be nbands length
    ebw = np.asarray(meta['effbandwidth'])  # Should be nbands length
    gain = np.asarray(constants.DG_ABSCAL_GAIN[sat_index])
    scale = (acf / ebw) * gain
    offset = np.asarray(constants.DG_ABSCAL_OFFSET[sat_index])

    e_sun_index = meta['satid'].upper() + "_" + meta['bandid'].upper()
    e_sun = np.asarray(constants.DG_ESUN[e_sun_index])
    sun = ephem.Sun()
    img_obs = ephem.Observer()
    img_obs.lon = meta['latlonhae'][1]
    img_obs.lat = meta['latlonhae'][0]
    img_obs.elevation = meta['latlonhae'][2]
    img_obs.date = datetime.datetime.fromtimestamp(meta['img_datetime_obj_utc']['$date'] / 1000.0).strftime(
        '%Y-%m-%d %H:%M:%S.%f')
    sun.compute(img_obs)
    d_es = sun.earth_distance

    # Pull sun elevation from the image metadata
    # theta_s can be zenith or elevation - the calc below will us either
    # a cos or s in respectively
    # theta_s = float(self.meta_dg.IMD.IMAGE.MEANSUNEL)
    theta_s = 90 - float(meta['mean_sun_el'])
    scale2 = (d_es ** 2 * np.pi) / (e_sun * np.cos(np.deg2rad(theta_s)))

    # Return scaled data
    # Radiance = Scale * Image + offset, Reflectance = Radiance * Scale2
    return zip(scale, scale2, offset)

#from skimage.transform._geometric import GeometricTransform 
开发者ID:DigitalGlobe,项目名称:gbdxtools,代码行数:46,代码来源:util.py

示例15: captureDuration

# 需要导入模块: import ephem [as 别名]
# 或者: from ephem import Sun [as 别名]
def captureDuration(lat, lon, elevation, current_time=None):
    """ Calcualtes the start time and the duration of capturing, for the given geographical coordinates. 
    
    Arguments:
        lat: [float] latitude +N in degrees
        lon: [float] longitude +E in degrees
        elevation: [float] elevation above sea level in meters
    
    Keyword arguments:
        current_time: [datetime object] the given date and time of reference for the capture duration
    
    Return:
        (start_time, duration):
            - start_time: [datetime object] time when the capturing should start, True if capturing should
                start right away
            - duration: [float] seconds of capturing time
    """

    # Initialize the observer
    o = ephem.Observer()  
    o.lat = str(lat)
    o.long = str(lon)
    o.elevation = elevation

    # The Sun should be about 5.5 degrees below the horizon when the capture should begin/end
    o.horizon = '-5:26'

    # Calculate the locations of the Sun
    s = ephem.Sun()  
    s.compute()

    # Calculate the time of next sunrise and sunset
    next_rise = o.next_rising(s).datetime()
    next_set = o.next_setting(s).datetime()
    
    if current_time is None:
        current_time = datetime.datetime.utcnow()

    # If the next sunset is later than the next sunrise, it means that it is night, and capturing should start immediately
    if next_set > next_rise:

        start_time = True

    # Otherwise, start capturing after the next sunset
    else:

        start_time = next_set
        

    # Calculate how long should the capture run
    if start_time == True:
        duration = next_rise - current_time

    else:
        duration = next_rise - next_set

    # Calculate the duration of capture in seconds
    duration = duration.total_seconds()

    return start_time, duration 
开发者ID:CroatianMeteorNetwork,项目名称:RMS,代码行数:62,代码来源:CaptureDuration.py


注:本文中的ephem.Sun方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。