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
    compressor = pressio.get_compressor(library, b"sz")
    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()