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","."]
code: def _compress_chunk(self, chunk_idx):
      # Retrieve the chunk data as a 2D NumPy array.
      chunk = self.get_chunk(chunk_idx)
      assert chunk.ndim == 2
      assert chunk.shape[1] == self.n_channels
      # Compute the diff along the time and/or spatial axis.
      chunkd = diff_along_axis(
          chunk, axis=0 if self.do_time_diff else None
      )
      chunkd = diff_along_axis(
          chunkd, axis=1 if self.do_spatial_diff else None
      )
      assert chunkd.shape == chunk.shape
      assert chunkd.dtype == chunk.dtype
      # Check first line/column of the diffed chunk.
      assert chunkd[0, 0] == chunk[0, 0]
      if self.do_time_diff and not self.do_spatial_diff:
          assert np.array_equal(chunkd[0, :], chunk[0, :])
      elif not self.do_time_diff and self.do_spatial_diff:
          assert np.array_equal(chunkd[:, 0], chunk[:, 0])
      # Compress the diff.
      logger.log(
          5,
          "Compressing %d MB...",
          (chunkd.size * chunk.itemsize) / 1024.0**2,
      )
      # order=Fortran: Transposing (demultiplexing) the chunk may save a few %.
      chunkdc = zlib.compress(chunkd.tobytes(order=self.chunk_order))
      ratio = 100 - 100 * len(chunkdc) / (chunk.size * chunk.itemsize)
      logger.debug(
          "Chunk %d/%d: -%.3f%%.", chunk_idx + 1, self.n_chunks, ratio
      )
      return chunk_idx, (chunk, chunkdc)
  
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 6 for calling the Writer obj's underlying member method code with example usage: obj._compress_chunk(chunk_idx) and returns: chunk_idx,  chunk,  chunkdc