Beispiel #1
0
    def encode(self, uncompressed):
        """perform compression

        params:
            uncompressed: np.ndarray - the data to be compressed
        """
        uncompressed_lp = None
        compressed_lp = None
        try:
            uncompressed_lp = pressio.io_data_from_numpy(uncompressed)
            compressed_lp = pressio.data_new_empty(pressio.byte_dtype,
                                                   pressio.vector_uint64_t())

            rc = pressio.compressor_compress(self._compressor, uncompressed_lp,
                                             compressed_lp)
            if rc:
                raise PressioException.from_compressor(self._compressor)

            comp = pressio.io_data_to_bytes(compressed_lp)
        finally:
            pressio.data_free(uncompressed_lp)
            pressio.data_free(compressed_lp)
        return comp
Beispiel #2
0
    pressio.compressor_check_options(compressor, sz_options)
    pressio.compressor_set_options(compressor, sz_options)
    pressio.compressor_set_metrics(compressor, metrics)

    input_data = pressio.io_data_from_numpy(floatArray)

    compressed_data = pressio.data_new_empty(pressio.byte_dtype,
                                             pressio.vector_uint64_t())

    dims = pressio.vector_uint64_t([height, width, 3])

    decompressed_data = pressio.data_new_empty(pressio.double_dtype, dims)

    #compress data with selected compressor
    pressio.compressor_compress(compressor, input_data, compressed_data)
    #decompress data with selected compressor
    pressio.compressor_decompress(compressor, compressed_data,
                                  decompressed_data)
    #get metric results for compression
    metric_results = pressio.compressor_get_metrics_results(compressor)

    #Grab relevant compression metrics
    compression_ratio = pressio.new_double()
    compressed_size = pressio.new_uint32()
    uncompressed_size = pressio.new_uint32()
    decompressed_size = pressio.new_uint32()
    pressio.options_get_double(metric_results, b"size:compression_ratio",
                               compression_ratio)
    pressio.options_get_uinteger(metric_results, b"size:compressed_size",
                                 compressed_size)