comparison globalneighbors/grid.py @ 21:22c384fe954d

add locations to grid; not used or tested yet
author Jeff Hammel <k0scist@gmail.com>
date Sun, 25 Jun 2017 16:28:56 -0700
parents 2fef925fbf37
children
comparison
equal deleted inserted replaced
20:2fef925fbf37 21:22c384fe954d
26 for _ in xrange(self.n[0]): 26 for _ in xrange(self.n[0]):
27 self.grid.append([set() for _ in xrange(self.n[-1])]) 27 self.grid.append([set() for _ in xrange(self.n[-1])])
28 28
29 def add(self, geoid, lat, lon): 29 def add(self, geoid, lat, lon):
30 latlon = (lat, lon) 30 latlon = (lat, lon)
31 self[self.index(lat, lon)].add(geoid) 31 index = self.index(lat, lon)
32 self[index].add(geoid)
33 return index
32 34
33 def __getitem__(self, index): 35 def __getitem__(self, index):
34 """ 36 """
35 index -- 2-tuple or list of i and j indices 37 index -- 2-tuple or list of i and j indices
36 """ 38 """
75 return geoids 77 return geoids
76 78
77 79
78 class GriddedLocations(object): 80 class GriddedLocations(object):
79 81
80 def __init__(self, locations): 82 def __init__(self, _locations, nlat=90, nlon=90):
81 self.locations = locations 83 self.locations = _locations
82 import pdb; pdb.set_trace() 84 self.grid = LatLonGrid(nlat, nlon)
85 self.gridloc = {}
86 for geoid, (lat, lon) in locations.items():
87 gridloc[geoid] = self.grid.add(geoid, lat, lon)
88
83 89
84 def main(args=sys.argv[1:]): 90 def main(args=sys.argv[1:]):
85 """CLI""" 91 """CLI"""
86 92
87 # parse command line 93 # parse command line
90 96
91 # read locations 97 # read locations
92 city_locations = locations(parser.read_cities()) 98 city_locations = locations(parser.read_cities())
93 99
94 # make a grid 100 # make a grid
95 gridded_locations = GriddedLocations(locations) 101 gridded_locations = GriddedLocations(city_locations)
96 102
97 if __name__ == '__main__': 103 if __name__ == '__main__':
98 main() 104 main()
99 105