# HG changeset patch # User Jeff Hammel # Date 1498433336 25200 # Node ID 22c384fe954dce6e433a1ea5ac48106f77342f27 # Parent 2fef925fbf377a9a66e81022196790e840aab9ed add locations to grid; not used or tested yet diff -r 2fef925fbf37 -r 22c384fe954d globalneighbors/grid.py --- a/globalneighbors/grid.py Sun Jun 25 16:12:08 2017 -0700 +++ b/globalneighbors/grid.py Sun Jun 25 16:28:56 2017 -0700 @@ -28,7 +28,9 @@ def add(self, geoid, lat, lon): latlon = (lat, lon) - self[self.index(lat, lon)].add(geoid) + index = self.index(lat, lon) + self[index].add(geoid) + return index def __getitem__(self, index): """ @@ -77,9 +79,13 @@ class GriddedLocations(object): - def __init__(self, locations): - self.locations = locations - import pdb; pdb.set_trace() + def __init__(self, _locations, nlat=90, nlon=90): + self.locations = _locations + self.grid = LatLonGrid(nlat, nlon) + self.gridloc = {} + for geoid, (lat, lon) in locations.items(): + gridloc[geoid] = self.grid.add(geoid, lat, lon) + def main(args=sys.argv[1:]): """CLI""" @@ -92,7 +98,7 @@ city_locations = locations(parser.read_cities()) # make a grid - gridded_locations = GriddedLocations(locations) + gridded_locations = GriddedLocations(city_locations) if __name__ == '__main__': main()