Esempio n. 1
0
 def get_cdl(self):
     self.cdl_mask = os.path.join(self.root, 'cdl_mask.tif')
     if not os.path.isfile(self.cdl_mask):
         print('get {}'.format(self.cdl_mask))
         polygon = self.landsat.get_tile_geometry()
         cdl = Cdl(year=self.year, target_profile=self.landsat.profile)
         cdl.get_mask(clip_geometry=polygon, out_file=self.cdl_mask)
     else:
         print('{} exists'.format(self.cdl_mask))
         self.exclude_rasters.append(self.cdl_mask)
Esempio n. 2
0
 def test_mask(self):
     l8 = Landsat8(self.dir_name_LC8)
     shape = 1, l8.rasterio_geometry['height'], l8.rasterio_geometry[
         'width']
     polygon = l8.get_tile_geometry()
     cdl = Cdl(from_file=os.path.join(self.dir_name_LC8, 'cdl.tif'))
     arr = cdl.get_mask(polygon,
                        out_file=os.path.join(self.dir_name_LC8,
                                              'cdl_mask.tif'))
     self.assertEqual(shape, arr.shape)
     self.assertEqual(arr.max(), 1)
     self.assertEqual(arr.min(), 0)
Esempio n. 3
0
 def get_cdl(self):
     """download cdl and make a mask, save to the
     root directory with filename cdl_mask.tif.
     The cdl is reprojected here.
     """
     self.cdl_mask = os.path.join(self.root, 'cdl_mask.tif')
     if not os.path.isfile(self.cdl_mask):
         print('get {}'.format(self.cdl_mask))
         polygon = self.landsat.get_tile_geometry()
         cdl = Cdl(year=self.year, target_profile=self.landsat.profile)
         cdl.get_mask(clip_geometry=polygon, out_file=self.cdl_mask)
     else:
         print('{} exists'.format(self.cdl_mask))
         self.exclude_rasters.append(self.cdl_mask)
Esempio n. 4
0
    def test_conforming_array(self):
        """ Test shape of Gridmet vs. Landsat image.
        :return:
        """
        l8 = Landsat8(self.dir_name_LC8)
        shape = 1, l8.rasterio_geometry['height'], l8.rasterio_geometry[
            'width']
        polygon = l8.get_tile_geometry()
        cdl = Cdl(year=self.year,
                  target_profile=l8.profile,
                  out_dir=self.dir_name_LC8)
        _ = cdl.get_conforming_data(polygon)
        with rasopen(os.path.join(self.dir_name_LC8, 'cdl.tif')) as dst:
            arr = dst.read()

        self.assertEqual(arr.shape, shape)
Esempio n. 5
0
 def test_conform_cdl(self):
     cdl = Cdl(target_profile=self.target_profile,
               year=self.year,
               out_dir=TEST_DATA)
     cdl.get_original_tif()
Esempio n. 6
0
 def test_download(self):
     cdl = Cdl(target_profile=self.target_profile, year=self.year)
     cdl.download_zipped_cdl()