2424
2525from pvlib import atmosphere
2626from pvlib .tools import datetime_to_djd , djd_to_datetime
27+ from pvlib ._deprecation import deprecated
28+
2729
2830NS_PER_HR = 1.e9 * 3600. # nanoseconds per hour
2931
@@ -40,7 +42,6 @@ def get_solarposition(time, latitude, longitude,
4042 time : pandas.DatetimeIndex
4143
4244 latitude : float
43-
4445 longitude : float
4546
4647 altitude : None or float, default None
@@ -359,9 +360,8 @@ def spa_python(time, latitude, longitude,
359360 return result
360361
361362
362- def get_sun_rise_set_transit (time , latitude , longitude , how = 'numpy' ,
363- delta_t = 67.0 ,
364- numthreads = 4 ):
363+ def sun_rise_set_transit_spa (times , latitude , longitude , how = 'numpy' ,
364+ delta_t = 67.0 , numthreads = 4 ):
365365 """
366366 Calculate the sunrise, sunset, and sun transit times using the
367367 NREL SPA algorithm described in [1].
@@ -373,13 +373,15 @@ def get_sun_rise_set_transit(time, latitude, longitude, how='numpy',
373373
374374 Parameters
375375 ----------
376- time : pandas.DatetimeIndex
377- Only the date part is used
376+ times : pandas.DatetimeIndex
377+ Must be localized to the timezone for ``latitude`` and ``longitude``.
378378 latitude : float
379+ Latitude in degrees, positive north of equator, negative to south
379380 longitude : float
381+ Longitude in degrees, positive east of prime meridian, negative to west
380382 delta_t : float, optional
381383 If delta_t is None, uses spa.calculate_deltat
382- using time .year and time .month from pandas.DatetimeIndex.
384+ using times .year and times .month from pandas.DatetimeIndex.
383385 For most simulations specifing delta_t is sufficient.
384386 Difference between terrestrial time and UT1.
385387 *Note: delta_t = None will break code using nrel_numba,
@@ -394,9 +396,9 @@ def get_sun_rise_set_transit(time, latitude, longitude, how='numpy',
394396
395397 Returns
396398 -------
397- DataFrame
398- The DataFrame will have the following columns:
399- sunrise, sunset, transit
399+ pandas. DataFrame
400+ index is the same as input `times` argument
401+ columns are ' sunrise', ' sunset', and ' transit'
400402
401403 References
402404 ----------
@@ -409,36 +411,40 @@ def get_sun_rise_set_transit(time, latitude, longitude, how='numpy',
409411 lat = latitude
410412 lon = longitude
411413
412- if not isinstance ( time , pd . DatetimeIndex ):
413- try :
414- time = pd . DatetimeIndex ( time )
415- except ( TypeError , ValueError ) :
416- time = pd . DatetimeIndex ([ time , ] )
414+ # times must be localized
415+ if times . tz :
416+ tzinfo = times . tz
417+ else :
418+ raise ValueError ( 'times must be localized' )
417419
418420 # must convert to midnight UTC on day of interest
419- utcday = pd .DatetimeIndex (time .date ).tz_localize ('UTC' )
421+ utcday = pd .DatetimeIndex (times .date ).tz_localize ('UTC' )
420422 unixtime = np .array (utcday .astype (np .int64 )/ 10 ** 9 )
421423
422424 spa = _spa_python_import (how )
423425
424- delta_t = delta_t or spa .calculate_deltat (time .year , time .month )
426+ delta_t = delta_t or spa .calculate_deltat (times .year , times .month )
425427
426428 transit , sunrise , sunset = spa .transit_sunrise_sunset (
427429 unixtime , lat , lon , delta_t , numthreads )
428430
429431 # arrays are in seconds since epoch format, need to conver to timestamps
430432 transit = pd .to_datetime (transit * 1e9 , unit = 'ns' , utc = True ).tz_convert (
431- time . tz ).tolist ()
433+ tzinfo ).tolist ()
432434 sunrise = pd .to_datetime (sunrise * 1e9 , unit = 'ns' , utc = True ).tz_convert (
433- time . tz ).tolist ()
435+ tzinfo ).tolist ()
434436 sunset = pd .to_datetime (sunset * 1e9 , unit = 'ns' , utc = True ).tz_convert (
435- time . tz ).tolist ()
437+ tzinfo ).tolist ()
436438
437- result = pd .DataFrame ({ 'transit ' : transit ,
438- 'sunrise ' : sunrise ,
439- 'sunset ' : sunset }, index = time )
439+ return pd .DataFrame (index = times , data = { 'sunrise ' : sunrise ,
440+ 'sunset ' : sunset ,
441+ 'transit ' : transit } )
440442
441- return result
443+
444+ get_sun_rise_set_transit = deprecated ('0.6.1' ,
445+ alternative = 'sun_rise_set_transit_spa' ,
446+ name = 'get_sun_rise_set_transit' ,
447+ removal = '0.7' )(sun_rise_set_transit_spa )
442448
443449
444450def _ephem_convert_to_seconds_and_microseconds (date ):
@@ -476,10 +482,11 @@ def _ephem_setup(latitude, longitude, altitude, pressure, temperature,
476482 return obs , sun
477483
478484
479- def rise_set_transit_ephem (time , latitude , longitude ,
480- next_or_previous = 'next' ,
481- altitude = 0 ,
482- pressure = 101325 , temperature = 12 , horizon = '0:00' ):
485+ def sun_rise_set_transit_ephem (times , latitude , longitude ,
486+ next_or_previous = 'next' ,
487+ altitude = 0 ,
488+ pressure = 101325 ,
489+ temperature = 12 , horizon = '0:00' ):
483490 """
484491 Calculate the next sunrise and sunset times using the PyEphem package.
485492
@@ -488,9 +495,9 @@ def rise_set_transit_ephem(time, latitude, longitude,
488495 time : pandas.DatetimeIndex
489496 Must be localized
490497 latitude : float
491- positive is north of 0
498+ Latitude in degrees, positive north of equator, negative to south
492499 longitude : float
493- positive is east of 0
500+ Longitude in degrees, positive east of prime meridian, negative to west
494501 next_or_previous : str
495502 'next' or 'previous' sunrise and sunset relative to time
496503 altitude : float, default 0
@@ -523,8 +530,10 @@ def rise_set_transit_ephem(time, latitude, longitude,
523530 raise ImportError ('PyEphem must be installed' )
524531
525532 # times must be localized
526- if not time .tz :
527- raise ValueError ('rise_set_ephem: times must be localized' )
533+ if times .tz :
534+ tzinfo = times .tz
535+ else :
536+ raise ValueError ('times must be localized' )
528537
529538 obs , sun = _ephem_setup (latitude , longitude , altitude ,
530539 pressure , temperature , horizon )
@@ -544,18 +553,18 @@ def rise_set_transit_ephem(time, latitude, longitude,
544553 sunrise = []
545554 sunset = []
546555 trans = []
547- for thetime in time :
556+ for thetime in times :
548557 thetime = thetime .to_pydatetime ()
549558 # pyephem drops timezone when converting to its internal datetime
550559 # format, so handle timezone explicitly here
551560 obs .date = ephem .Date (thetime - thetime .utcoffset ())
552- sunrise .append (_ephem_to_timezone (rising (sun ), time . tz ))
553- sunset .append (_ephem_to_timezone (setting (sun ), time . tz ))
554- trans .append (_ephem_to_timezone (transit (sun ), time . tz ))
561+ sunrise .append (_ephem_to_timezone (rising (sun ), tzinfo ))
562+ sunset .append (_ephem_to_timezone (setting (sun ), tzinfo ))
563+ trans .append (_ephem_to_timezone (transit (sun ), tzinfo ))
555564
556- return pd .DataFrame (index = time , data = {'sunrise' : sunrise ,
557- 'sunset' : sunset ,
558- 'transit' : trans })
565+ return pd .DataFrame (index = times , data = {'sunrise' : sunrise ,
566+ 'sunset' : sunset ,
567+ 'transit' : trans })
559568
560569
561570def pyephem (time , latitude , longitude , altitude = 0 , pressure = 101325 ,
@@ -1371,8 +1380,8 @@ def _times_to_hours_after_local_midnight(times):
13711380 return np .array (hrs )
13721381
13731382
1374- def sunrise_sunset_transit_geometric (times , latitude , longitude , declination ,
1375- equation_of_time ):
1383+ def sun_rise_set_transit_geometric (times , latitude , longitude , declination ,
1384+ equation_of_time ):
13761385 """
13771386 Geometric calculation of solar sunrise, sunset, and transit.
13781387
0 commit comments