コード例 #1
0
def test_fpzip():
    for N in range(0, 100):
        flts = np.array(range(N), dtype=np.float32).reshape((N, 1, 1, 1))
        compressed = encode(flts, 'fpzip')
        assert compressed != flts
        decompressed = decode(compressed, 'fpzip')
        assert np.all(decompressed == flts)

    for N in range(0, 200, 2):
        flts = np.array(range(N), dtype=np.float32).reshape((N // 2, 2, 1, 1))
        compressed = encode(flts, 'fpzip')
        assert compressed != flts
        decompressed = decode(compressed, 'fpzip')
        assert np.all(decompressed == flts)
コード例 #2
0
ファイル: tx.py プロジェクト: ntabris/cloud-volume
    def do_upload(imgchunk, cloudpath):
        encoded = chunks.encode(imgchunk, meta.encoding(mip),
                                meta.compressed_segmentation_block_size(mip))

        remote_compress = should_compress(meta.encoding(mip), compress, cache)
        cache_compress = should_compress(meta.encoding(mip),
                                         compress,
                                         cache,
                                         iscache=True)
        remote_compress = compression.normalize_encoding(remote_compress)
        cache_compress = compression.normalize_encoding(cache_compress)

        encoded = compression.compress(encoded, remote_compress)
        cache_encoded = encoded
        if remote_compress != cache_compress:
            cache_encoded = compression.compress(encoded, cache_compress)

        remote.put(
            path=cloudpath,
            content=encoded,
            content_type=content_type(meta.encoding(mip)),
            compress=remote_compress,
            compression_level=compress_level,
            cache_control=cdn_cache_control(cdn_cache),
            raw=True,
        )

        if cache.enabled:
            local.put(
                path=cloudpath,
                content=cache_encoded,
                content_type=content_type(meta.encoding(mip)),
                compress=cache_compress,
                raw=True,
            )
コード例 #3
0
def encode_decode(data, format, num_chan=1):
    encoded = encode(data, format)
    result = decode(encoded,
                    format,
                    shape=(64, 64, 64, num_chan),
                    dtype=np.uint8)

    assert np.all(result.shape == data.shape)
    assert np.all(data == result)
コード例 #4
0
def test_kempression():
    data = np.random.random_sample(size=1024 * 3).reshape(
        (64, 4, 4, 3)).astype(np.float32)
    encoded = encode(data, 'kempressed')
    result = decode(encoded,
                    'kempressed',
                    shape=(64, 4, 4, 3),
                    dtype=np.float32)
    assert np.all(result.shape == data.shape)
    assert np.all(np.abs(data - result) <= np.finfo(np.float32).eps)
コード例 #5
0
def test_jpeg():
    data = np.zeros(shape=(64, 64, 64, 1), dtype=np.uint8)
    encode_decode(data, 'jpeg')
    encode_decode(data + 255, 'jpeg')

    # Random jpeg won't decompress to exactly the same image
    # but it should have nearly the same average power
    random_data = np.random.randint(255, size=(64, 64, 64, 1), dtype=np.uint8)
    pre_avg = random_data.copy().flatten().mean()
    encoded = encode(random_data, 'jpeg')
    decoded = decode(encoded, 'jpeg', shape=(64, 64, 64, 1), dtype=np.uint8)
    post_avg = decoded.copy().flatten().mean()

    assert abs(pre_avg - post_avg) < 1
コード例 #6
0
def test_jpeg(shape, num_channels):
  import simplejpeg

  xshape = list(shape) + [ num_channels ]
  data = np.zeros(shape=xshape, dtype=np.uint8)
  encode_decode(data, 'jpeg', shape, num_channels)
  encode_decode(data + 255, 'jpeg', shape, num_channels)

  jpg = simplejpeg.decode_jpeg(
    encode(data, 'jpeg'), 
    colorspace="GRAY",
  )
  assert jpg.shape[0] == shape[1] * shape[2]
  assert jpg.shape[1] == shape[0]

  # Random jpeg won't decompress to exactly the same image
  # but it should have nearly the same average power
  random_data = np.random.randint(255, size=xshape, dtype=np.uint8)
  pre_avg = random_data.copy().flatten().mean()
  encoded = encode(random_data, 'jpeg')
  decoded = decode(encoded, 'jpeg', shape=xshape, dtype=np.uint8)
  post_avg = decoded.copy().flatten().mean()

  assert abs(pre_avg - post_avg) < 1
コード例 #7
0
ファイル: tx.py プロジェクト: Pedro-cramos/cloud-volume
    def do_upload(imgchunk, cloudpath):
        encoded = chunks.encode(imgchunk, meta.encoding(mip),
                                meta.compressed_segmentation_block_size(mip))

        remote.put(
            path=cloudpath,
            content=encoded,
            content_type=content_type(meta.encoding(mip)),
            compress=should_compress(meta.encoding(mip), compress, cache),
            compression_level=compress_level,
            cache_control=cdn_cache_control(cdn_cache),
        )

        if cache.enabled:
            local.put(path=cloudpath,
                      content=encoded,
                      content_type=content_type(meta.encoding(mip)),
                      compress=should_compress(meta.encoding(mip),
                                               compress,
                                               cache,
                                               iscache=True))
コード例 #8
0
  def do_upload(imgchunk, cloudpath):
    encoded = chunks.encode(imgchunk, meta.encoding(mip), meta.compressed_segmentation_block_size(mip))

    with remotestor() as cloudstorage:
      cloudstorage.put_file(
        file_path=cloudpath, 
        content=encoded,
        content_type=content_type(meta.encoding(mip)), 
        compress=should_compress(meta.encoding(mip), compress, cache),
        compress_level=compress_level,
        cache_control=cdn_cache_control(cdn_cache),
      )

    if cache.enabled:
      with localstor() as cachestorage:
        cachestorage.put_file(
          file_path=cloudpath,
          content=encoded, 
          content_type=content_type(meta.encoding(mip)), 
          compress=should_compress(meta.encoding(mip), compress, cache, iscache=True)
        )