[英]ufunc 'add' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32')) -> dtype('<U32')
I am trying to run this script but it's showing generated error:我正在尝试运行此脚本,但它显示生成的错误:
UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32')) -> dtype('<U32')
This is the code below I am trying to run:这是我试图运行的下面的代码:
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,
dni_extra=None)
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'])
It takes some times to add all the import and missing function for having a minimum reproducible example.需要一些时间来添加所有导入和缺少的 function 以获得最小的可重现示例。 I guess that the get_elevation
function is coming from this question .我猜get_elevation
function 来自这个问题。
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:您的问题出在pvlib.spa
模块中:
@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. observer_longitude
参数是一个字符串,在 numpy 求和运算中不受管理。 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.经过一番探索,我发现这个经度是直接来自Location
object 的,因此将它简单地转换为float
就解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.