Exemplo n.º 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
Exemplo n.º 2
0
    sz_options = pressio.compressor_get_options(compressor)
    metric_ids = pressio.vector_string([b'time', b'size'])
    metrics = pressio.new_metrics(library, metric_ids)

    pressio.options_set_integer(sz_options, b"sz:error_bound_mode", sz.PSNR)
    pressio.options_set_double(sz_options, b"sz:psnr_err_bound",
                               float(sys.argv[1]))

    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()
Exemplo n.º 3
0
metrics_ids = pressio.vector_string([b'time', b'size'])
metrics = pressio.new_metrics(library, metrics_ids)

pressio.options_set_integer(sz_options, b"sz:error_bound_mode", sz.ABS)
pressio.options_set_double(sz_options, b"sz:abs_err_bound", 0.5)

pressio.compressor_check_options(compressor, sz_options)
pressio.compressor_set_options(compressor, sz_options)
pressio.compressor_set_metrics(compressor, metrics)

data = np.random.rand(300, 300, 300)

input_data = pressio.io_data_from_numpy(data)

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

dims = pressio.vector_uint64_t([300, 300, 300])
decompressed_data = pressio.data_new_empty(pressio.double_dtype, dims)

pressio.compressor_compress(compressor, input_data, compressed_data)

pressio.compressor_decompress(compressor, compressed_data, decompressed_data)

metric_results = pressio.compressor_get_metrics_results(compressor)
compression_ratio = pressio.new_double()
pressio.options_get_double(metric_results, b"size:compression_ratio",
                           compression_ratio)
print("compression ratio", pressio.double_value(compression_ratio))

result = pressio.io_data_to_numpy(decompressed_data)