comparison globalneighbors/grid.py @ 1:1b94f3bf97e5

* limit distance function * start gridding * improve unicode handling
author Jeff Hammel <k0scist@gmail.com>
date Sat, 24 Jun 2017 14:02:14 -0700
parents 5dba84370182
children 7e27e874655b
comparison
equal deleted inserted replaced
0:5dba84370182 1:1b94f3bf97e5
11 self.d = ((self.lat_range[-1] - self.lat_range[0])/self.n[0], 11 self.d = ((self.lat_range[-1] - self.lat_range[0])/self.n[0],
12 (self.lon_range[-1] - self.lon_range[0])/self.n[1]) 12 (self.lon_range[-1] - self.lon_range[0])/self.n[1])
13 self.create_grid() 13 self.create_grid()
14 14
15 def create_grid(self): 15 def create_grid(self):
16 self.grid = [[] for _ in xrange(self.n[-1]) 16 self.grid = []
17 for _ in xrange(self.n[0])] 17 for _ in xrange(self.n[0]):
18 self.grid.append([set() for _ in xrange(self.n[-1])])
18 19
19 def add(self, geoid, lat, lon): 20 def add(self, geoid, lat, lon):
20 latlon = (lat, lon) 21 latlon = (lat, lon)
21 self[self.index(lat, lon)].append(geoid) 22 self[self.index(lat, lon)].add(geoid)
22 23
23 def __getitem__(self, index): 24 def __getitem__(self, index):
24 """ 25 """
25 index -- 2-tuple or list of i and j indices 26 index -- 2-tuple or list of i and j indices
26 """ 27 """
27 import pdb; pdb.set_trace()
28 return self.grid[index[0]][index[1]] 28 return self.grid[index[0]][index[1]]
29 29
30 def index(self, lat, lon): 30 def index(self, lat, lon):
31 return [int(math.floor((val-self.range[i][0])/self.d[i])) 31 return [int(math.floor((val-self.range[i][0])/self.d[i]))
32 for i, val in enumerate((lat, lon))] 32 for i, val in enumerate((lat, lon))]
33 33
34 def neighbors(self, i, j): 34 def neighbors(self, i, j):
35 """ 35 """
36 return neighbors of points i, j 36 return neighbors of points i, j
37 """ 37 """
38 if i:
39 raise NotImplementedError('TODO')