changeset 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 e69cb496324e
files globalneighbors/grid.py
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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()