TLDR
Convert your longitude (and also the latitude for consistency) to float and it will work:
latitude = float(loc_raw['lat'])
longitude = float(loc_raw['lon'])
Longer explanation
It takes some times to add all the import and missing function for having a minimum reproducible example. I guess that the get_elevation
function is coming from this question.
import requests
from geopy.geocoders import Nominatim
from pvlib.location import Location
import pvlib
import pandas as pd
def get_elevation(lat, long):
query = ('https://api.open-elevation.com/api/v1/lookup'
f'?locations={lat},{long}')
r = requests.get(query).json() # json object, various ways you can extract value
# one approach is to use pandas json functionality:
elevation = pd.io.json.json_normalize(r, 'results')['elevation'].values[0]
return elevation
if __name__ == '__main__':
app = Nominatim(user_agent="test_solar")
loc_raw = app.geocode('Postintaival 7, 00230 Helsinki, Finland').raw
latitude = loc_raw['lat']
longitude = loc_raw['lon']
altitude = get_elevation(latitude, longitude)
location_object = Location(latitude, longitude, 'Europe/Helsinki',
altitude, 'relex_solutions')
weather = pvlib.iotools.get_pvgis_tmy(latitude, longitude,
map_variables=True)[0]
times = weather.index
solpos = location_object.get_solarposition(times)
clearsky_values = location_object.get_clearsky(times, model='ineichen',
solar_position=solpos,)
Here where your problem is coming in pvlib.spa
module:
@jcompile('float64(float64, float64, float64)', nopython=True)
def local_hour_angle(apparent_sidereal_time, observer_longitude,
sun_right_ascension):
"""Measured westward from south"""
H = apparent_sidereal_time + observer_longitude - sun_right_ascension
return H % 360
I added some print in order to see the variables (a debug point should also work):
@jcompile('float64(float64, float64, float64)', nopython=True)
def local_hour_angle(apparent_sidereal_time, observer_longitude,
sun_right_ascension):
"""Measured westward from south"""
print(f'{apparent_sidereal_time!r}')
print(f'{observer_longitude!r}')
print(f'{sun_right_ascension!r}')
H = apparent_sidereal_time + observer_longitude - sun_right_ascension
return H % 360
And we get:
array([100.06452967, 115.10559772, 130.14666594, ..., 55.20775781,
70.24882694, 85.28989625])
'24.9181469'
array([280.83336392, 280.87939039, 280.92541462, ..., 280.99011537,
281.03612276, 281.0821279 ])
The observer_longitude
argument is a string which is not manage in numpy sum operation. After some exploration, I find that this longitude is directly coming from the Location
object and thus the simple conversion of it into float
solves the matter.