ValueError:用序列设置数组元素。在Python中尝试制作天图

0 投票
0 回答
48 浏览
提问于 2025-04-12 04:41
# datetime libraries
from datetime import datetime
from geopy.geocoders import Nominatim
from tzwhere import tzwhere
from pytz import timezone, utc

# matplotlib to help display our star map
import matplotlib.pyplot as plt
# skyfield for star data 
from skyfield.api import Star, load, wgs84
from skyfield.data import hipparcos
from skyfield.projections import build_stereographic_projection

# de421 shows position of earth and sun in space
eph = load('de421.bsp')
# hipparcos dataset contains star location data
with load.open(hipparcos.URL) as f:
stars = hipparcos.load_dataframe(f)
location = 'Times Square, New York, NY'
when = '2023-01-01 00:00'

locator = Nominatim(user_agent='myGeocoder')
location = locator.geocode(location)
lat, long = location.latitude, location.longitude code here
 # convert date string into datetime object
 dt = datetime.strptime(when, '%Y-%m-%d %H:%M')
 import pytz
 from pytz import timezone, utc
 # define datetime and convert to utc based on our timezone
 #def timezone(lat, long, dt):
 tzw = tzwhere.tzwhere()
 timezone_str = tzw.tzNameAt(latitude, longitude)
 local = pytz.timezone(timezone_str)
 #tzw = tzwhere.tzwhere()
 #timezone_str = tzw.tzNameAt(lat, long)
 #local = pytz.local(timezone_str)

# get UTC from local timezone and datetime
#dt = datetime.strptime(when, '%Y-%m-%d %H:%M')
local_dt = local.localize(dt, is_dst=None)
utc_dt = local_dt.astimezone(utc)
print(utc_dt)  '

上面的代码出现了这个错误。

错误信息是:ValueError:用一个序列来设置数组元素。请求的数组在两维之后的形状不一致。检测到的形状是 (1, 2) 加上不一致的部分。

错误出现在这一行:tzw = tzwhere.tzwhere()

我该怎么修正这个问题呢。

0 个回答

暂无回答

撰写回答