コード例 #1
0
ファイル: zarr_jpeg.py プロジェクト: d-v-b/zarr-jpeg
                f'Invalid dimensionality of input array.\n Input must have dimensionality of at least 2; got {buf.ndim}'
            )
        if len(self.input_shape) != len(bufa.shape):
            raise ValueError(
                f'Invalid input size.\n Input must have dimensionality matching the input_shape parameter of this compressor, i.e. {self.input_shape}, which has a dimensionality of {len(self.input_shape)}.\n Got input with shape {bufa.shape} instead, which has a dimensionality of {len(bufa.shape)}.'
            )
        if not all(chnk >= shpe
                   for chnk, shpe in zip(self.input_shape, bufa.shape)):
            raise ValueError(
                f'Invalid input size. Input must be less than or equal to the input_shape parameter of this compressor, i.e. {self.input_shape}. Got input with shape {bufa.shape} instead'
            )
        new_shape = [
            np.prod([bufa.shape[dim] for dim in axis], dtype='int')
            for axis in axis_reduction
        ]
        tiled = bufa.reshape(new_shape)

        return jpeg_encode(tiled, level=self.quality)

    def decode(self, buf, out=None):
        buf = ensure_contiguous_ndarray(buf)

        if out is not None:
            out = ensure_contiguous_ndarray(out)

        tiled = jpeg_decode(buf)
        return ndarray_copy(tiled, out)


register_codec(jpeg)
コード例 #2
0
ファイル: codecs.py プロジェクト: tomwhite/gwas-analysis
        # broadcast to 3rd dimension having 2 elements, least significant
        # bit then second least, in that order; results in nxmx2 array
        # containing individual bits as bools
        # see: https://stackoverflow.com/questions/22227595/convert-integer-to-binary-array-with-suitable-padding
        arr = arr[:, :, None] & self.__bit_mask
        bool_arr = arr > 0
        # NOTE: -1 codes as [True, True] which equals to 3 in uint8 bit encoding

        return super().encode(bool_arr)

    def decode(self,
               buf: np.ndarray,
               out: Optional[np.ndarray] = None) -> np.ndarray:
        dec = super().decode(buf, out=None)

        # given a flattened version of what was originally an nxmx2 array,
        # reshape to group adjacent bits in second dimension and
        # convert back to int based on each little-endian bit pair
        dec = np.packbits(dec.reshape((-1, 2)), bitorder="little", axis=1)
        dec = dec.squeeze(axis=1)

        # -1 which codes for missing data got encoded as 11000000 which codes for 3 in uint8,
        # we revert that here
        dec[dec == 3] = -1

        # handle destination
        return ndarray_copy(dec, out)


register_codec(PackGeneticBits)
コード例 #3
0
ファイル: __init__.py プロジェクト: tacaswell/numcodecs
pipelines in a variety of ways.

If you have a question, find a bug, would like to make a suggestion or
contribute code, please `raise an issue on GitHub
<https://github.com/alimanfoo/numcodecs/issues>`_.

"""

import multiprocessing
import atexit

from numcodecs.version import version as __version__
from numcodecs.registry import get_codec, register_codec

from numcodecs.zlib import Zlib
register_codec(Zlib)

from numcodecs.gzip import GZip
register_codec(GZip)

from numcodecs.bz2 import BZ2
register_codec(BZ2)

try:
    from numcodecs.lzma import LZMA
    register_codec(LZMA)
except ImportError:  # pragma: no cover
    pass

try:
    from numcodecs import blosc
コード例 #4
0
contribute code, please `raise an issue on GitHub
<https://github.com/alimanfoo/numcodecs/issues>`_.

"""

from __future__ import absolute_import, print_function, division
import multiprocessing
import atexit


from numcodecs.version import version as __version__
from numcodecs.registry import get_codec, register_codec
from numcodecs.compat import PY2

from numcodecs.zlib import Zlib
register_codec(Zlib)

from numcodecs.bz2 import BZ2
register_codec(BZ2)

if not PY2:
    from numcodecs.lzma import LZMA
    register_codec(LZMA)

try:
    from numcodecs import blosc as _blosc
    from numcodecs.blosc import Blosc
    register_codec(Blosc)
    # initialize blosc
    ncores = multiprocessing.cpu_count()
    _blosc.init()
コード例 #5
0
ファイル: plugins.py プロジェクト: tomwhite/gwas-analysis
 def setup(self, worker):
     from numcodecs.registry import register_codec
     register_codec(PackGeneticBits)
コード例 #6
0
If you have a question, find a bug, would like to make a suggestion or
contribute code, please `raise an issue on GitHub
<https://github.com/alimanfoo/numcodecs/issues>`_.

"""

from __future__ import absolute_import, print_function, division
import multiprocessing
import atexit

from numcodecs.version import version as __version__
from numcodecs.registry import get_codec, register_codec

from numcodecs.zlib import Zlib

register_codec(Zlib)
register_codec(Zlib, 'gzip')  # alias

from numcodecs.bz2 import BZ2

register_codec(BZ2)

try:
    from numcodecs.lzma import LZMA
    register_codec(LZMA)
except ImportError:  # pragma: no cover
    pass

try:
    from numcodecs import blosc
    from numcodecs.blosc import Blosc
コード例 #7
0
    def _read_header(self, chunk):

        num_dims = struct.unpack('>H', chunk[2:4])[0]
        shape = tuple(
            struct.unpack('>I', chunk[i:i + 4])[0]
            for i in range(4, num_dims * 4 + 4, 4))[::-1]

        len_header = 4 + num_dims * 4

        return len_header, shape

    def _to_big_endian(self, data):
        # assumes data is ndarray

        if self._little_endian:
            return data.byteswap()
        return data

    def _from_big_endian(self, data):
        # assumes data is byte array in big endian

        if not self._little_endian:
            return data

        a = np.frombuffer(data, self.dtype.newbyteorder('>'))
        return a.astype(self.dtype)


register_codec(N5ChunkWrapper, N5ChunkWrapper.codec_id)
コード例 #8
0
def register_codec(cls=Tiff, codec_id=None):
    """Register Tiff codec with numcodecs."""
    registry.register_codec(cls, codec_id=codec_id)