I have this toy example that uses numpy and an external package called PyProj. Lat and lon are 2D arrays that contain coordinates of some domain specific information. What I want to do is to calculate distance on a sphere from a central point that I choose arbitrarily. The shape of lat_0 and lon_0 is
(2000,1)
But the API call inv does not like that. I get a run time error -
RuntimeError: Buffer lengths not the same
It wants an array of shape
(2000,50).
So I want lat_0 and lon_0 to be the same shape as lon and lat with all constant values which is the central latitude and longitude. What is the most efficient way to increase the columns of lon_0 and lat_0 and filling it with the central value so that it is the same shape as lon and lat without using for loops?
import numpy as np
from pyproj import Geod
lat = np.empty((2000,50))
lat.fill(1)
lon = np.empty((2000,50))
lon.fill(1)
center = int(np.floor(len(lon[-1]) / 2.))
lon_0 = lon[:,center][...,np.newaxis]
lat_0 = lat[:,center][...,np.newaxis]
g = Geod(ellps='WGS84')
distance = g.inv(lon,lat,lon_0,lat_0,radians=True)