forked from UOAF/project-tauntaun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coord.py
31 lines (20 loc) · 877 Bytes
/
coord.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
import scipy.interpolate as interp
def lat_lon_to_xz(lat, lon):
return _instance.lat_lon_to_xz(lat, lon)
def xz_to_lat_lon(x, z):
return _instance.xz_to_lat_lon(x, z)
class CoordInterpolator(object):
def __init__(self, fname='data/coords.npy'):
coord_table = np.load('data/coords.npy')
self.t = t = coord_table
lat, lon, x, z = t
self.f0 = interp.bisplrep(lat, lon, x)
self.f1 = interp.bisplrep(lat, lon, z)
self.g0 = interp.bisplrep(x, z, lat)
self.g1 = interp.bisplrep(x, z, lon)
def lat_lon_to_xz(self, lat, lon):
return interp.bisplev(lat, lon, self.f0), interp.bisplev(lat, lon, self.f1)
def xz_to_lat_lon(self, x, z):
return interp.bisplev(x, z, self.g0), interp.bisplev(x, z, self.g1)
_instance = CoordInterpolator()