44
55# Will Holmgren, University of Arizona, 2014-2016.
66
7- import datetime
87import pathlib
9- from zoneinfo import ZoneInfo
8+ import datetime
109
11- import h5py
1210import pandas as pd
13- # import pytz
11+ import pytz
12+ import h5py
1413
15- from pvlib import atmosphere , clearsky , irradiance , solarposition
16- # from pvlib._deprecation import warn_deprecated
14+ from pvlib import solarposition , clearsky , atmosphere , irradiance
1715from pvlib .tools import _degrees_to_index
1816
1917
@@ -23,12 +21,10 @@ class Location:
2321 timezone, and altitude data associated with a particular
2422 geographic location. You can also assign a name to a location object.
2523
26- Location objects have one timezone attribute:
27-
28- * ``tz`` is a IANA-compatible standard-library zoneinfo.ZoneInfo.
24+ Location objects have two timezone attributes:
2925
30- Thus, the passed timezone must be representable by one of the values in
31- zoneinfo.available_timezones() .
26+ * ``tz`` is a IANA timezone string.
27+ * ``pytz`` is a pytz timezone object .
3228
3329 Location objects support the print method.
3430
@@ -42,13 +38,12 @@ class Location:
4238 Positive is east of the prime meridian.
4339 Use decimal degrees notation.
4440
45- tz : str, int, float, zoneinfo.ZoneInfo, datetime.timezone, or pytz
46- timezone (deprecated), default 'UTC'.
47- See http://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a
48- list of valid time zone strings, or use the function
49- zoneinfo.available_timezones().
50- ints and floats must be in hours N from UTC, and are converted to the
51- Etc/GMT+N or Etc/GMT-N format depending on the sign of N.
41+ tz : str, int, float, or pytz.timezone, default 'UTC'.
42+ See
43+ http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
44+ for a list of valid time zones.
45+ pytz.timezone objects will be converted to strings.
46+ ints and floats must be in hours from UTC.
5247
5348 altitude : float, optional
5449 Altitude from sea level in meters.
@@ -64,43 +59,33 @@ class Location:
6459 pvlib.pvsystem.PVSystem
6560 """
6661
67- def __init__ (
68- self , latitude , longitude , tz = 'UTC' , altitude = None , name = None
69- ):
70-
71- if name is None :
72- name = ""
73-
74- self .name = name
62+ def __init__ (self , latitude , longitude , tz = 'UTC' , altitude = None ,
63+ name = None ):
7564
7665 self .latitude = latitude
7766 self .longitude = longitude
7867
68+ if isinstance (tz , str ):
69+ self .tz = tz
70+ self .pytz = pytz .timezone (tz )
71+ elif isinstance (tz , datetime .timezone ):
72+ self .tz = 'UTC'
73+ self .pytz = pytz .UTC
74+ elif isinstance (tz , datetime .tzinfo ):
75+ self .tz = tz .zone
76+ self .pytz = tz
77+ elif isinstance (tz , (int , float )):
78+ self .tz = tz
79+ self .pytz = pytz .FixedOffset (tz * 60 )
80+ else :
81+ raise TypeError ('Invalid tz specification' )
82+
7983 if altitude is None :
8084 altitude = lookup_altitude (latitude , longitude )
8185
8286 self .altitude = altitude
8387
84- if isinstance (tz , str ):
85- self .tz = ZoneInfo (tz )
86- elif isinstance (tz , int ):
87- self .tz = ZoneInfo (f"Etc/GMT{ - tz :+d} " )
88- elif isinstance (tz , float ):
89- self .tz = ZoneInfo (f"Etc/GMT{ int (- tz ):+d} " )
90- elif isinstance (tz , ZoneInfo ):
91- self .tz = tz
92- elif isinstance (tz , datetime .timezone ):
93- self .tz = ZoneInfo (str (tz ))
94- # elif isinstance(tz, pytz.BaseTzInfo):
95- # warn_deprecated(
96- # "0.11.3",
97- # message='pytz-based timezones are deprecated for locations',
98- # alternative='use zoneinfo.ZoneInfo from standard library',
99- # obj_type='function argument type',
100- # )
101- # self.tz = ZoneInfo(tz.zone)
102- else :
103- raise TypeError (f'Invalid tz specification: { tz } ' )
88+ self .name = name
10489
10590 def __repr__ (self ):
10691 attrs = ['name' , 'latitude' , 'longitude' , 'altitude' , 'tz' ]
0 commit comments