def verify_hash(self): """ Computes SHA-1 hash and returns True if it matches metadata, False otherwise :return: boolean """ if self.is_mtscomp: with open(self.file_bin.with_suffix('.ch')) as fid: mtscomp_params = json.load(fid) sm = mtscomp_params.get('sha1_compressed', None) if sm is None: _logger.warning( "SHA1 hash is not implemented for compressed ephys. To check " "the spikeglx acquisition hash, uncompress the file first !" ) return True sm = sm.upper() else: sm = self.meta.fileSHA1 sc = hashfile.sha1(self.file_bin).upper() if sm == sc: log_func = _logger.info else: log_func = _logger.error log_func(f"SHA1 metadata: {sm}") log_func(f"SHA1 computed: {sc}") return sm == sc
def test_check_ephys_file(self): self.tdir = tempfile.TemporaryDirectory(prefix='glx_test') self.addCleanup(self.tdir.cleanup) bin_3b = spikeglx._mock_spikeglx_file( Path(self.tdir.name).joinpath('sample3B_g0_t0.imec1.ap.bin'), self.workdir / 'sample3B_g0_t0.imec1.ap.meta', ns=32, nc=385, sync_depth=16) self.assertEqual(hashfile.md5(bin_3b['bin_file']), "207ba1666b866a091e5bb8b26d19733f") self.assertEqual(hashfile.sha1(bin_3b['bin_file']), '1bf3219c35dea15409576f6764dd9152c3f8a89c') sr = spikeglx.Reader(bin_3b['bin_file']) self.assertTrue(sr.verify_hash())
def verify_hash(self): """ Computes SHA-1 hash and returns True if it matches metadata, False otherwise :return: boolean """ if self.is_mtscomp: _logger.warning( "SHA1 hash is not implemented for compressed ephys. To check " "the spikeglx acquisition hash, uncompress the file first !") return True else: sm = self.meta.fileSHA1 sc = hashfile.sha1(self.file_bin).upper() if sm == sc: log_func = _logger.info else: log_func = _logger.error log_func(f"SHA1 metadata: {sm}") log_func(f"SHA1 computed: {sc}") return sm == sc