Example #1
0
 def retrieve_band_information(self, bad_src = ''):
     u"""
     Retrieve all necessary band information, including identifiers of bands
     with known bad quality defined in the given external file.
     """
     # retrieving band count
     if self.img_src is None:
         self.band_count = gdal_utils.get_band_count(self.image_data[0])
     else:
         self.band_count = gdal_utils.get_band_count(self.img_src)
     # retrieving bad bands
     if bad_src and os.path.isfile(bad_src):
         self.bad_bands = [int(b) for b in np.loadtxt(bad_src)]
     else:
         self.bad_bands = list()
     # retrieving good bands by creating difference set with bad bands
     self.good_bands = list(set(range(1, self.band_count + 1)).difference(self.bad_bands))
Example #2
0
 def retrieve_band_information(self, bad_src=""):
     u"""
     Retrieve all necessary band information, including identifiers of bands
     with known bad quality defined in the given external file.
     """
     # retrieving band count
     if self.img_src is None:
         self.band_count = gdal_utils.get_band_count(self.image_data[0])
     else:
         self.band_count = gdal_utils.get_band_count(self.img_src)
     # retrieving bad bands
     if bad_src and os.path.isfile(bad_src):
         self.bad_bands = [int(b) for b in np.loadtxt(bad_src)]
     else:
         self.bad_bands = list()
     # retrieving good bands by creating difference set with bad bands
     self.good_bands = list(set(range(1, self.band_count + 1)).difference(self.bad_bands))
Example #3
0
 def retrieve_band_information(self, bad_src = ''):
     u"""
     Retrieve all necessary band information, including identifiers of bands
     with known bad quality defined in the given external file.
     """
     # retrieving band count
     self.bad_src = bad_src
     try:
         self.band_count = gdal_utils.get_band_count(self.img_src)
     except:
         return
     # retrieving bad bands
     if bad_src and os.path.isfile(bad_src):
         self.bad_bands = [int(b) for b in open(bad_src).readlines()[1].split("\t")]
     else:
         self.bad_bands = list()
     # retrieving good bands by creating difference set with bad bands
     self.good_bands = list(set(range(1, self.band_count + 1)).difference(self.bad_bands))
Example #4
0
 def retrieve_band_information(self, bad_src=''):
     u"""
     Retrieve all necessary band information, including identifiers of bands
     with known bad quality defined in the given external file.
     """
     # retrieving band count
     self.bad_src = bad_src
     try:
         self.band_count = gdal_utils.get_band_count(self.img_src)
     except:
         return
     # retrieving bad bands
     if bad_src and os.path.isfile(bad_src):
         self.bad_bands = [
             int(b) for b in open(bad_src).readlines()[1].split("\t")
         ]
     else:
         self.bad_bands = list()
     # retrieving good bands by creating difference set with bad bands
     self.good_bands = list(
         set(range(1, self.band_count + 1)).difference(self.bad_bands))
Example #5
0
    
    tgt_path, ext = os.path.splitext(img_src)
    
    if ext == '.dat':
        ext = '.img'
    
    tgt_path = tgt_path + "_good_bands_only" + ext
    
    ds = gdal.Open(img_src)
    height = ds.RasterYSize
    width = ds.RasterXSize
    tgt_type = ds.GetRasterBand(1).DataType
    src_gtf = ds.GetGeoTransform()
    src_prj = ds.GetProjection()
    
    band_count = gdal_utils.get_band_count(img_src)
    bad_bands = [int(b) for b in open(bad_src).readlines()[1].split("\t")]
    bad_bands = np.loadtxt(bad_src)
    good_bands = list(set(range(1, band_count + 1)).difference(bad_bands))
    
    print "Creating target dataset '%s'..." % tgt_path
    
    drv = gdal.GetDriverByName('ENVI')
    drv.Create(tgt_path, width, height, len(good_bands), tgt_type)

    tgt_ds = gdal.Open(tgt_path, 1)
    tgt_ds.SetGeoTransform(src_gtf)
    tgt_ds.SetProjection(src_prj)

    print "Extracting good bands..."
Example #6
0
        strip_id = int(re.search("_(\d)_", f).group(1))
        available_strips.append(strip_id)
        image_data[strip_id] = f
    # retrieving plots
    plt_ds = ogr.Open(plt_shp_src)
    plt_ly = plt_ds.GetLayer(0)
    # caching plots
    cached_plots = ogr_utils.cache_locations(plt_ly, ['plot_id'])

    # setting up output
    output = list()

    # iterating over a selection of strip ids
    for strip_id in available_strips:
        # retrieving band count
        band_count = gdal_utils.get_band_count(image_data[strip_id])
        # retrieving good bands by calculating the difference between all
        # bands and those that have been declared bad
        good_bands = list(set(range(1, band_count + 1)).difference(bad_bands))

        tgt_file = "".join(
            (re.search("(.+)_\d_",
                       os.path.basename(image_data[strip_id])).group(1),
             '_spectra.txt'))

        # setting up a list of plots that are linked with the current strip
        strip_locations = list()
        # setting up the output for current strip id
        strip_output = list()
        # retrieving plots that are linked with the current strip
        for cp in sorted(cached_plots, key=itemgetter('attributes')):
        strip_id = int(re.search("_(\d)_", f).group(1))
        available_strips.append(strip_id)
        image_data[strip_id] = f
    # retrieving plots
    plt_ds = ogr.Open(plt_shp_src)
    plt_ly = plt_ds.GetLayer(0)
    # caching plots
    cached_plots = ogr_utils.cache_locations(plt_ly, ['plot_id'])

    # setting up output
    output = list()
    
    # iterating over a selection of strip ids
    for strip_id in available_strips:
        # retrieving band count
        band_count = gdal_utils.get_band_count(image_data[strip_id])
        # retrieving good bands by calculating the difference between all 
        # bands and those that have been declared bad
        good_bands = list(set(range(1, band_count + 1)).difference(bad_bands))

        tgt_file = "".join((re.search("(.+)_\d_", os.path.basename(image_data[strip_id])).group(1), '_spectra.txt'))

        # setting up a list of plots that are linked with the current strip
        strip_locations = list()
        # setting up the output for current strip id
        strip_output = list()
        # retrieving plots that are linked with the current strip
        for cp in sorted(cached_plots, key = itemgetter('attributes')):
            plot_id = cp['attributes']['plot_id']
            if plot_id in image_plt_links[strip_id]:
                strip_locations.append(cp)