Skip to content

Commit 82f28ba

Browse files
committed
make solarposition.spa_python work without Location
1 parent 27fd18e commit 82f28ba

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

pvlib/clearsky.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222

23-
def ineichen(time, location, linke_turbidity=None,
23+
def ineichen(time, latitude, longitude, linke_turbidity=None,
2424
solarposition_method='pyephem', zenith_data=None,
2525
airmass_model='young1994', airmass_data=None,
2626
interp_turbidity=True):
@@ -40,7 +40,9 @@ def ineichen(time, location, linke_turbidity=None,
4040
-----------
4141
time : pandas.DatetimeIndex
4242
43-
location : pvlib.Location
43+
latitude : float
44+
45+
longitude : float
4446
4547
linke_turbidity : None or float
4648
If None, uses ``LinkeTurbidities.mat`` lookup table.
@@ -101,7 +103,9 @@ def ineichen(time, location, linke_turbidity=None,
101103
I0 = irradiance.extraradiation(time.dayofyear)
102104

103105
if zenith_data is None:
104-
ephem_data = solarposition.get_solarposition(time, location,
106+
ephem_data = solarposition.get_solarposition(time,
107+
latitude=latitude,
108+
longitude=longitude,
105109
method=solarposition_method)
106110
time = ephem_data.index # fixes issue with time possibly not being tz-aware
107111
try:

pvlib/solarposition.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def get_solarposition(time, location=None, latitude=None, longitude=None,
101101
return ephem_df
102102

103103

104-
def spa_c(time, latitude, longitude, pressure=101325, temperature=12, delta_t=67.0,
104+
def spa_c(time, latitude, longitude, pressure=101325,
105+
temperature=12, delta_t=67.0,
105106
raw_spa_output=False):
106107
"""
107108
Calculate the solar position using the C implementation of the NREL
@@ -223,7 +224,8 @@ def _spa_python_import(how):
223224
return spa
224225

225226

226-
def spa_python(time, location, pressure=101325, temperature=12, delta_t=None,
227+
def spa_python(time, latitude, longitude,
228+
altitude=0, pressure=101325, temperature=12, delta_t=None,
227229
atmos_refract=None, how='numpy', numthreads=4):
228230
"""
229231
Calculate the solar position using a python implementation of the
@@ -237,7 +239,9 @@ def spa_python(time, location, pressure=101325, temperature=12, delta_t=None,
237239
Parameters
238240
----------
239241
time : pandas.DatetimeIndex
240-
location : pvlib.Location object
242+
latitude : float
243+
longitude : float
244+
altitude : float
241245
pressure : int or float, optional
242246
avg. yearly air pressure in Pascals.
243247
temperature : int or float, optional
@@ -286,9 +290,9 @@ def spa_python(time, location, pressure=101325, temperature=12, delta_t=None,
286290

287291
pvl_logger.debug('Calculating solar position with spa_python code')
288292

289-
lat = location.latitude
290-
lon = location.longitude
291-
elev = location.altitude
293+
lat = latitude
294+
lon = longitude
295+
elev = altitude
292296
pressure = pressure / 100 # pressure must be in millibars for calculation
293297
delta_t = delta_t or 67.0
294298
atmos_refract = atmos_refract or 0.5667
@@ -299,7 +303,7 @@ def spa_python(time, location, pressure=101325, temperature=12, delta_t=None,
299303
except (TypeError, ValueError):
300304
time = pd.DatetimeIndex([time, ])
301305

302-
unixtime = localize_to_utc(time, location).astype(np.int64)/10**9
306+
unixtime = time.astype(np.int64)/10**9
303307

304308
spa = _spa_python_import(how)
305309

@@ -314,9 +318,9 @@ def spa_python(time, location, pressure=101325, temperature=12, delta_t=None,
314318
index=time)
315319

316320
try:
317-
result = result.tz_convert(location.tz)
321+
result = result.tz_convert(time.tz)
318322
except TypeError:
319-
result = result.tz_localize(location.tz)
323+
result = result.tz_localize(time.tz)
320324

321325
return result
322326

0 commit comments

Comments
 (0)