예제 #1
0
    def handle(self, **options):
        '''
        In this example command, the values that come from the user input are
        added up and the result is printed in the screen.
        '''
        paths = options['paths']
        print paths
        tiles = options['tiles']
        name = ''.join(options['name'])

        from madmex.mapper.bundle.rapideye import Bundle
        
        if tiles:
            for tile in tiles:
                sensor_id = 1
                product_id = 2
                new_paths = get_images_for_tile(int(tile), sensor_id, product_id)
                reference_array = create_reference_array(new_paths)
                bundle = Bundle(new_paths[0])
                re_raster_metadata = bundle.get_raster().metadata
                create_raster_tiff_from_reference(re_raster_metadata, '%s.tif' % tile, reference_array)
        if paths:
            new_paths = map(util.get_parent, paths)
            bundle = Bundle(new_paths[0])
            re_raster_metadata = bundle.get_raster().metadata
            create_raster_tiff_from_reference(re_raster_metadata, '%s.tif' % name, reference_array)
def create_reference_array(images_references_paths):
    '''
    New implementation of create reference image, performance was sacrificed in
    favor of clarity. This method creates a reference image by calculating the
    median of a set of images pixelwise.
    '''
    from madmex.mapper.bundle.rapideye import Bundle
    import madmex.mapper.sensor.rapideye as sensor
    identified = []
    bands = None
    rows = None
    columns = None
    for image_path in images_references_paths:
        bundle = Bundle(image_path)
        if bundle.can_identify():
            if not bands:
                bands = bundle.get_sensor().get_attribute(sensor.BANDS)
            if not rows:
                rows = bundle.get_sensor().get_attribute(sensor.ROWS)
            if not columns:
                columns = bundle.get_sensor().get_attribute(sensor.COLUMNS)
            identified.append(bundle)
    LOGGER.debug('Bands: %d, Rows: %d, Columns: %d.', bands, rows, columns) 
    number = len(identified)
    LOGGER.debug('Number of identified images: %d', number)
    my_array = numpy.empty((number, bands, rows, columns))
    for index in range(number):
        my_array[index] = identified[index].get_raster().read_data_file_as_array().astype(numpy.float)
    medians = numpy.empty((bands, rows, columns))
    for band in range(bands):
        medians[band] = numpy.median(my_array[:, band, :, :], axis=0)
    return medians
예제 #3
0
    def handle(self, **options):
        '''
        In this example command, the values that come from the user input are
        added up and the result is printed in the screen.
        '''
        paths = options['paths']

        from madmex.mapper.bundle.rapideye import Bundle
        if paths:
            for path in paths:
                bundle = Bundle(path)
                bundle.preprocess()
예제 #4
0
def create_reference_array(images_references_paths):
    '''
    New implementation of create reference image, performance was sacrificed in
    favor of clarity. This method creates a reference image by calculating the
    median of a set of images pixelwise.
    '''
    from madmex.mapper.bundle.rapideye import Bundle
    import madmex.mapper.sensor.rapideye as sensor
    identified = []
    bands = None
    rows = None
    columns = None
    for image_path in images_references_paths:
        bundle = Bundle(image_path)
        if bundle.can_identify():
            if not bands:
                bands = bundle.get_sensor().get_attribute(sensor.BANDS)
            if not rows:
                rows = bundle.get_sensor().get_attribute(sensor.ROWS)
            if not columns:
                columns = bundle.get_sensor().get_attribute(sensor.COLUMNS)
            identified.append(bundle)
    LOGGER.debug('Bands: %d, Rows: %d, Columns: %d.', bands, rows, columns)
    number = len(identified)
    LOGGER.debug('Number of identified images: %d', number)
    my_array = numpy.empty((number, bands, rows, columns))
    for index in range(number):
        my_array[index] = identified[index].get_raster(
        ).read_data_file_as_array().astype(numpy.float)
    medians = numpy.empty((bands, rows, columns))
    for band in range(bands):
        medians[band] = numpy.median(my_array[:, band, :, :], axis=0)
    return medians
예제 #5
0
    def handle(self, **options):
        '''
        In this example command, the values that come from the user input are
        added up and the result is printed in the screen.
        '''
        paths = options['paths']
        print paths
        tiles = options['tiles']
        name = ''.join(options['name'])

        from madmex.mapper.bundle.rapideye import Bundle

        if tiles:
            for tile in tiles:
                sensor_id = 1
                product_id = 2
                new_paths = get_images_for_tile(int(tile), sensor_id,
                                                product_id)
                reference_array = create_reference_array(new_paths)
                bundle = Bundle(new_paths[0])
                re_raster_metadata = bundle.get_raster().metadata
                create_raster_tiff_from_reference(re_raster_metadata,
                                                  '%s.tif' % tile,
                                                  reference_array)
        if paths:
            new_paths = map(util.get_parent, paths)
            reference_array = numpy.sort(
                create_stacked_array_rapideye(new_paths), axis=0)

            medians = numpy.empty(
                (reference_array.shape[1], reference_array.shape[2],
                 reference_array.shape[3]))
            limit = reference_array.shape[1] / 5

            for band in range(reference_array.shape[1]):
                array_band = numpy.ma.array(
                    reference_array[:, band, :, :],
                    mask=reference_array[:, band, :, :] == 0)
                medians[band] = numpy.ma.median(array_band, axis=0)

            bundle = Bundle(new_paths[0])
            re_raster_metadata = bundle.get_raster().metadata
            create_raster_tiff_from_reference(re_raster_metadata,
                                              '%s_max.tif' % name,
                                              reference_array[0])
            create_raster_tiff_from_reference(re_raster_metadata,
                                              '%s_mean.tif' % name,
                                              reference_array[8])
            create_raster_tiff_from_reference(re_raster_metadata,
                                              '%s_median.tif' % name, medians)
            create_raster_tiff_from_reference(
                re_raster_metadata, '%s_min.tif' % name,
                reference_array[reference_array.shape[0] - 1])
예제 #6
0
    def handle(self, **options):
        import time
        start_time = time.time()

        path = options['path'][0]
        print path
        features_array = []

        bundle = Bundle(path)

        raster_path = bundle.file_dictionary[_IMAGE]

        data_array = open_handle(raster_path)
        data_array = numpy.array(data_array)

        print data_array, len(data_array)

        print len(data_array[data_array != 0])

        for i in range(data_array.shape[0]):
            print 'band: %s' % (i + 1)
            band = data_array[i, :, :].ravel()
            band = band[band != 0]
            features_array.append(numpy.nanpercentile(band, 10))
            features_array.append(numpy.nanpercentile(band, 25))
            features_array.append(numpy.nanpercentile(band, 50))
            features_array.append(numpy.nanpercentile(band, 75))
            features_array.append(numpy.nanpercentile(band, 90))
            features_array.append(numpy.mean(band))
            features_array.append(numpy.min(band) * 1.0)
            features_array.append(numpy.max(band) * 1.0)
        geotransform = get_geotransform(raster_path)

        features_array.append(geotransform[0])
        features_array.append(geotransform[3])

        print features_array

        features_array.append((bundle.get_aquisition_date() -
                               datetime.datetime(1970, 1, 1)).total_seconds())
        tile_id = bundle.get_sensor().get_attribute(TILE_ID)

        features = RapideyeFeatures(band_1_quant_10=features_array[0],
                                    band_1_quant_25=features_array[1],
                                    band_1_quant_50=features_array[2],
                                    band_1_quant_75=features_array[3],
                                    band_1_quant_90=features_array[4],
                                    band_1_mean=features_array[5],
                                    band_1_min=features_array[6],
                                    band_1_max=features_array[7],
                                    band_2_quant_10=features_array[8],
                                    band_2_quant_25=features_array[9],
                                    band_2_quant_50=features_array[10],
                                    band_2_quant_75=features_array[11],
                                    band_2_quant_90=features_array[12],
                                    band_2_mean=features_array[13],
                                    band_2_min=features_array[14],
                                    band_2_max=features_array[15],
                                    band_3_quant_10=features_array[16],
                                    band_3_quant_25=features_array[17],
                                    band_3_quant_50=features_array[18],
                                    band_3_quant_75=features_array[19],
                                    band_3_quant_90=features_array[20],
                                    band_3_mean=features_array[21],
                                    band_3_min=features_array[22],
                                    band_3_max=features_array[23],
                                    band_4_quant_10=features_array[24],
                                    band_4_quant_25=features_array[25],
                                    band_4_quant_50=features_array[26],
                                    band_4_quant_75=features_array[27],
                                    band_4_quant_90=features_array[28],
                                    band_4_mean=features_array[29],
                                    band_4_min=features_array[30],
                                    band_4_max=features_array[31],
                                    band_5_quant_10=features_array[32],
                                    band_5_quant_25=features_array[33],
                                    band_5_quant_50=features_array[34],
                                    band_5_quant_75=features_array[35],
                                    band_5_quant_90=features_array[36],
                                    band_5_mean=features_array[37],
                                    band_5_min=features_array[38],
                                    band_5_max=features_array[39],
                                    top=features_array[40],
                                    left=features_array[41],
                                    time=features_array[42],
                                    footprint=tile_id,
                                    path=raster_path)

        klass = sessionmaker(bind=ENGINE, autoflush=False)
        session = klass()

        session.add(features)
        session.commit()

        print tile_id
        print features_array
        print len(features_array)

        print("--- %s seconds ---" % (time.time() - start_time))
예제 #7
0
    def handle(self, **options):
        import time
        start_time = time.time()
        
        path = options['path'][0]
        print path
        features_array = []
        
        bundle = Bundle(path)
        
        raster_path = bundle.file_dictionary[_IMAGE]
        
        data_array = open_handle(raster_path)
        data_array = numpy.array(data_array)
        
        print data_array, len(data_array)
        
        print len(data_array[data_array!=0])
        
        for i in range(data_array.shape[0]):
            print 'band: %s' % (i + 1)
            band = data_array[i,:,:].ravel()
            band = band[band!=0]
            features_array.append(numpy.nanpercentile(band,10))
            features_array.append(numpy.nanpercentile(band,25))
            features_array.append(numpy.nanpercentile(band,50))
            features_array.append(numpy.nanpercentile(band,75))
            features_array.append(numpy.nanpercentile(band,90))
            features_array.append(numpy.mean(band))
            features_array.append(numpy.min(band) * 1.0)
            features_array.append(numpy.max(band) * 1.0)
        geotransform = get_geotransform(raster_path)
        
        features_array.append(geotransform[0])
        features_array.append(geotransform[3])
        
        
        print features_array
        
        
        features_array.append((bundle.get_aquisition_date() - datetime.datetime(1970, 1, 1)).total_seconds())
        tile_id =  bundle.get_sensor().get_attribute(TILE_ID)
        

        features = RapideyeFeatures(band_1_quant_10=features_array[0],
                                    band_1_quant_25=features_array[1],
                                    band_1_quant_50=features_array[2],
                                    band_1_quant_75=features_array[3],
                                    band_1_quant_90=features_array[4],
                                    band_1_mean=features_array[5],
                                    band_1_min=features_array[6],
                                    band_1_max=features_array[7],
                                    band_2_quant_10=features_array[8],
                                    band_2_quant_25=features_array[9],
                                    band_2_quant_50=features_array[10],
                                    band_2_quant_75=features_array[11],
                                    band_2_quant_90=features_array[12],
                                    band_2_mean=features_array[13],
                                    band_2_min=features_array[14],
                                    band_2_max=features_array[15],
                                    band_3_quant_10=features_array[16],
                                    band_3_quant_25=features_array[17],
                                    band_3_quant_50=features_array[18],
                                    band_3_quant_75=features_array[19],
                                    band_3_quant_90=features_array[20],
                                    band_3_mean=features_array[21],
                                    band_3_min=features_array[22],
                                    band_3_max=features_array[23],
                                    band_4_quant_10=features_array[24],
                                    band_4_quant_25=features_array[25],
                                    band_4_quant_50=features_array[26],
                                    band_4_quant_75=features_array[27],
                                    band_4_quant_90=features_array[28],
                                    band_4_mean=features_array[29],
                                    band_4_min=features_array[30],
                                    band_4_max=features_array[31],
                                    band_5_quant_10=features_array[32],
                                    band_5_quant_25=features_array[33],
                                    band_5_quant_50=features_array[34],
                                    band_5_quant_75=features_array[35],
                                    band_5_quant_90=features_array[36],
                                    band_5_mean=features_array[37],
                                    band_5_min=features_array[38],
                                    band_5_max=features_array[39],
                                    top=features_array[40],
                                    left=features_array[41],
                                    time=features_array[42],
                                    footprint=tile_id,
                                    path=raster_path)
        
        
        klass = sessionmaker(bind=ENGINE, autoflush=False)
        session = klass()
        
        session.add(features)
        session.commit()
        
        print tile_id
        print features_array
        print len(features_array)
        
        print("--- %s seconds ---" % (time.time() - start_time))