class_docstr: Handle compression of a raw data file.
  
  Constructor
  -----------
  
  chunk_duration : float
      Duration of the chunks, in seconds.
  algorithm : str
      Name of the compression algorithm. Only `zlib` is supported at the moment.
  comp_level : int
      Compression level of the chosen algorithm.
  do_time_diff : bool
      Whether to compute the time-wise diff of the array before compressing.
  do_spatial_diff : bool
      Whether to compute the spatial diff of the array before compressing.
  n_threads : int
      Number of CPUs to use for compression. By default, use all of them.
  before_check : function
      A callback method that could be called just before the integrity check.
  check_after_compress : bool
      Whether to perform the automatic check after compression.
class_docstr_tok: ["Handle","compression","of","a","raw","data","file",".","Constructor","--","--","--","--","--","-","chunk_duration",":","float","Duration","of","the","chunks",",","in","seconds",".","algorithm",":","str","Name","of","the","compression","algorithm",".","Only","`","zlib","`","is","supported","at","the","moment",".","comp_level",":","int","Compression","level","of","the","chosen","algorithm",".","do_time_diff",":","bool","Whether","to","compute","the","time-wise","diff","of","the","array","before","compressing",".","do_spatial_diff",":","bool","Whether","to","compute","the","spatial","diff","of","the","array","before","compressing",".","n_threads",":","int","Number","of","CPUs","to","use","for","compression",".","By","default",",","use","all","of","them",".","before_check",":","function","A","callback","method","that","could","be","called","just","before","the","integrity","check",".","check_after_compress",":","bool","Whether","to","perform","the","automatic","check","after","compression","."]
docstr: Open a raw data (memmapped) from disk in order to compress it.
  
  Parameters
  ----------
  
  data_path : str or Path
      Path to the raw binary array.
  sample_rate : float
      Sample rate of the data.
  n_channels : int
      Number of columns (channels) in the data array.
      The shape of the data is `(n_samples, n_channels)`.
  dtype : dtype
      NumPy data type of the data array.
  offset : int
      Offset, in bytes, of the data within the binary file.
  mmap : bool
      Whether the data should be memmapped.
docstr_tok: ["Open","a","raw","data","(","memmapped",")","from","disk","in","order","to","compress","it",".","Parameters","--","--","--","--","--","data_path",":","str","or","Path","Path","to","the","raw","binary","array",".","sample_rate",":","float","Sample","rate","of","the","data",".","n_channels",":","int","Number","of","columns","(","channels",")","in","the","data","array",".","The","shape","of","the","data","is","`","(","n_samples",",","n_channels",")","`",".","dtype",":","dtype","NumPy","data","type","of","the","data","array",".","offset",":","int","Offset",",","in","bytes",",","of","the","data","within","the","binary","file",".","mmap",":","bool","Whether","the","data","should","be","memmapped","."]
code: def open(
      self,
      data_path,
      sample_rate=None,
      n_channels=None,
      dtype=None,
      offset=None,
      mmap=True,
  ):
      """Open a raw data (memmapped) from disk in order to compress it.
  
      Parameters
      ----------
  
      data_path : str or Path
          Path to the raw binary array.
      sample_rate : float
          Sample rate of the data.
      n_channels : int
          Number of columns (channels) in the data array.
          The shape of the data is `(n_samples, n_channels)`.
      dtype : dtype
          NumPy data type of the data array.
      offset : int
          Offset, in bytes, of the data within the binary file.
      mmap : bool
          Whether the data should be memmapped.
  
      """
  
      self.data_path = Path(data_path)
  
      # Get default parameters from the config file, if it exists.
      sample_rate = sample_rate or self.config.get("sample_rate", None)
      if not sample_rate:
          raise ValueError(
              "Please provide a sample rate (-s option in the command-line)."
          )
  
      if str(data_path).endswith(".npy"):
          # NPY files.
          self.data = np.load(data_path, mmap_mode="r")
          self.shape = self.data.shape
          if self.data.ndim >= 3:
              self.data = np.reshape(
                  self.data, (-1, self.data.shape[-1])
              )
          self.dtype = dtype = self.data.dtype
          self.n_channels = n_channels = self.data.shape[1]
      else:
          # Raw binary files.
          n_channels = n_channels or self.config.get("n_channels", None)
          if not n_channels:
              raise ValueError(
                  "Please provide n_channels (-n option in the command-line)."
              )
          dtype = dtype or self.config.get("dtype", None)
          if not dtype:
              raise ValueError(
                  "Please provide a dtype (-d option in the command-line)."
              )
          self.dtype = np.dtype(dtype)
          self.data = load_raw_data(
              data_path, n_channels=n_channels, dtype=self.dtype
          )
          self.shape = self.data.shape
  
      self.sample_rate = float(sample_rate)
      assert sample_rate > 0
      assert n_channels > 0
      self.file_size = self.data.size * self.data.itemsize
      assert self.data.ndim == 2
      self.n_samples, self.n_channels = self.data.shape
      assert self.n_samples > 0
      assert self.n_channels > 0
      assert n_channels == self.n_channels
      duration = self.data.shape[0] / self.sample_rate
      logger.info(
          "Opening %s, duration %.1fs, %d channels.",
          data_path,
          duration,
          self.n_channels,
      )
      self._compute_chunk_bounds()
      self.sha1_compressed = hashlib.sha1()
      self.sha1_uncompressed = hashlib.sha1()
  
imports: import argparse
  import bisect
  from functools import lru_cache
  import hashlib
  import json
  import logging
  import multiprocessing
  from multiprocessing.dummy import Pool
  import os
  import os.path
  from pathlib import Path
  import sys
  from threading import Lock
  import zlib
  from tqdm import tqdm
  import numpy
label_desc: Use image node_id 2 for calling the Writer obj's underlying member method code with example usage: obj.open(data_path, sample_rate, n_channels, dtype, offset, mmap) without return types