示例#1
0
    def generateCompositeProducts(self, dataset, out_path):
        """
        Placeholder
        """

        # create product path
        product_path = os.path.join(out_path, 'composite')
        if not os.path.exists(product_path):
            os.makedirs(product_path, 0o755)

        # get channel images pertaining to product
        print('Creating composite products: {}'.format(product_path))
        for product in self._products['composite']:

            rgb = []
            for index in product['channels']:
                rgb.append(self.getChannelData(dataset, index))

            # save rgb image
            rgb_pathname = os.path.join(product_path, product['name'] + '.jpg')
            save_rgb(rgb_pathname, np.dstack(rgb), stretch=(0.02, 0.98))

            # save decorrelation stretch version of rgb image
            dcs_pathname = rgb_pathname.replace('.jpg', '-dcs.jpg')
            execute(
                os.path.join(os.path.dirname(sys.path[0]), '../bin/dstretch'),
                [rgb_pathname, dcs_pathname])

            # copy dcs image into geotiff
            self.writeGeoImage(dcs_pathname, dataset['srs'])

        return
示例#2
0
    def generatePrincipalComponentProducts(self, dataset, out_path):
        """
        Placeholder
        """

        # create product path
        product_path = os.path.join(out_path, 'pca')
        if not os.path.exists(product_path):
            os.makedirs(product_path, 0o755)

        # get channel images pertaining to product
        print('Creating principal component products: {}'.format(product_path))
        for product in self._products['pca']:

            channels = []
            for index in product['channels']:
                channels.append(self.getChannelData(dataset, index))

            img = np.dstack(channels)

            # compute pca transformation
            pc = principal_components(img)
            img_pc = pc.transform(img)

            # save rgb image
            rgb_pathname = os.path.join(product_path, product['name'] + '.jpg')
            save_rgb(rgb_pathname, img_pc[:, :, :3], stretch=(0.05, 0.95))

            # save decorrelation stretch version of rgb image
            dcs_pathname = rgb_pathname.replace('.jpg', '-dcs.jpg')
            execute(
                os.path.join(os.path.dirname(sys.path[0]), '../bin/dstretch'),
                [rgb_pathname, dcs_pathname])

            # copy dcs image into geotiff
            self.writeGeoImage(dcs_pathname, dataset['srs'])

        return
示例#3
0
    def getPansharpenImage( self, pathname ):

        """
        Placeholder
        """

        # get masked datasets
        code = None

        datasets = self.getMaskedDatasets ( os.path.dirname( pathname ) )
        if len( datasets ) == 3:

            # define pansharpen options
            args = [ os.path.join( os.path.dirname( pathname ), 'B8_merge.tif' ) ] + datasets + [ pathname ]
            options = [ '-co',  'PHOTOMETRIC=RGB', '-co', 'COMPRESS=DEFLATE', '-nodata', '0' ]

            # manage execution of gdal pansharpen
            out, err, code = execute( 'gdal_pansharpen.py', args + options )

        return code
示例#4
0
def checkScene(pathname):

    sceneOK = False

    # decompress product file
    path = os.path.dirname(pathname)

    out, err, code = ps.execute('unzip', ["-o", "-d", path, pathname])
    if (code <= 1):

        filelist = fio.getFileList('*.tiff', path)
        if len(filelist) > 0:

            # open scene and extract gcps
            in_ds = gdal.Open(filelist[0])
            gcps = in_ds.GetGCPs()

            min_x = 180
            max_x = -180
            for gcp in gcps:

                min_x = min(min_x, gcp.GCPX)
                max_x = max(max_x, gcp.GCPX)

            # large longitude difference when crossing antimeridian
            if max_x - min_x < 10:
                sceneOK = True
            else:
                print('... scene crosses antimeridan - skipping: {}'.format(
                    pathname))

    # housekeeping of raw zip sub-folder
    zip_path = os.path.splitext(pathname)[0]
    if (os.path.exists(zip_path)):
        shutil.rmtree(zip_path)

    return sceneOK
示例#5
0
        # generate scene list from arguments
        scene_list = getSceneList(args, product)
        if len(scene_list) > 0:

            # for each scene
            for scene in scene_list:
                print('processing scene: ' + scene)

                # generate multi-band vrt
                out_pathname = compileVrt(scene, product)
                if out_pathname is not None:

                    # execute ingestion
                    out, err, code = ps.execute(
                        '/sac/bin/DBIngest-Raster.py', [
                            out_pathname, args.cfg,
                            product.attributes["name"].value
                        ])
                    code = 0
                    if code != 0:
                        print(str(err))
                    else:
                        print('... ok!')

                else:
                    # missing files
                    print('... unable to create vrt for scene: ' + scene)

        else:
            # configuration issue
            print('... no files added to scene list for path: ' + args.path)