def test_compare_modes(self):
     nlcd_driver = nlcd.NlcdOriginDriver(TEST_DIR,
                                         data_mode=1,
                                         tile_size=(0.1, 0.1))
     lats = 37.75 + np.arange(0.01, 0.30, 0.001)
     lons = -122.45 + np.arange(0.01, 0.30, 0.001)
     codes1 = nlcd_driver.GetLandCoverCodes(lats, lons)
     nlcd_driver = nlcd.NlcdOriginDriver(TEST_DIR, data_mode=-1)
     codes2 = nlcd_driver.GetLandCoverCodes(lats, lons)
     self.assertEqual(np.max(np.abs(codes1 - codes2)), 0)
 def test_manual_load(self):
     # Test manual mode
     nlcd_driver = nlcd.NlcdOriginDriver(TEST_DIR, data_mode=0)
     nlcd_driver.CacheTileInBox(lat_min=37.7,
                                lat_max=37.8,
                                lon_min=-122.6,
                                lon_max=-122.3)
     self.verify_points(nlcd_driver)
 def test_outside_tile(self):
     # Test manual mode
     nlcd_driver = nlcd.NlcdOriginDriver(TEST_DIR, data_mode=0)
     nlcd_driver.CacheTileInBox(lat_min=37.7,
                                lat_max=37.8,
                                lon_min=-122.6,
                                lon_max=-122.3)
     # Outside database tiles
     code = nlcd_driver.GetLandCoverCodes(lat=37.75, lon=-121.70)
     self.assertEqual(code, 0.0)
     code = nlcd_driver.GetLandCoverCodes(lat=37.75, lon=-122.65)
     self.assertEqual(code, 0.0)
 def test_cache(self):
     nlcd_driver = nlcd.NlcdOriginDriver(TEST_DIR,
                                         data_mode=1,
                                         tile_size=(0.1, 0.1))
     lats = 37.5 + np.arange(0.01, 0.20, 0.01)
     lons = -122.5 + np.arange(0.01, 0.20, 0.01)
     codes1 = nlcd_driver.GetLandCoverCodes(lats, lons)
     self.assertEqual(len(nlcd_driver._tile_cache), 1)
     self.assertEqual(len(nlcd_driver._tile_lru), 1)
     nlcd_driver.data_mode = 2
     codes2 = nlcd_driver.GetLandCoverCodes(lats, lons)
     self.assertEqual(len(nlcd_driver._tile_cache), 2)
     self.assertEqual(len(nlcd_driver._tile_lru), 2)
     self.assertEqual(np.max(np.abs(codes1 - codes2)), 0)
 def test_auto_load1(self):
     nlcd_driver = nlcd.NlcdOriginDriver(TEST_DIR,
                                         data_mode=2,
                                         tile_size=(0.1, 0.1))
     self.verify_points(nlcd_driver)
 def test_full_nlcd(self):
     # Test Full NLCD mode
     nlcd_driver = nlcd.NlcdOriginDriver(TEST_DIR, data_mode=-1)
     self.verify_points(nlcd_driver)
Esempio n. 7
0
    # Discover the already processed NLCD tiles
    nlcd_tiles = glob.glob(os.path.join(REF_DIR, '*.zip'))
    nlcd_tiles = [os.path.basename(tile) for tile in nlcd_tiles]
    processed_latlon = [ParseLatLonFromNlcdFile(tile) for tile in nlcd_tiles]

    # Build the coordinates to retrieve at multiple of 1 arcsec
    coord = np.arange(3600) * 1 / 3600.

    # Loop on original NLCD files
    for orig_file in ORIG_NLCD_FILES:
        print 'Processing NLCD file : %s' % orig_file

        # Initialize the driver - in manual loading mode
        try:
            driver = nlcd_origin.NlcdOriginDriver(os.path.join(
                NLCD_ORIG_DIR, orig_file),
                                                  data_mode=0)
        except Exception:
            print '  ... FILE NOT FOUND'
            continue

        for lat_nw, lon_nw in ned_latlon:

            if (lat_nw, lon_nw) in processed_latlon:
                print 'Tile [%d %d] already done. Skipping...' % (lat_nw,
                                                                  lon_nw)
                continue

            # Create the output file name
            encoding = '%c%02d%c%03d' % ('sn'[lat_nw >= 0], abs(lat_nw),
                                         'we'[lon_nw >= 0], abs(lon_nw))