ValueError: setting an array element with a sequence. Trying to make a Skymap in Python

50 Views Asked by At
# 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)  '

The above code is giving this error.

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (1, 2) + inhomogeneous part.

The error is in line tzw = tzwhere.tzwhere()

How should I rectify this.

0

There are 0 best solutions below