def test_n5_to_h5(self): from z5py.converter import convert_to_h5 n5_file = os.path.join(self.tmp_dir, 'tmp.n5') h5_file = os.path.join(self.tmp_dir, 'tmp.h5') f = z5py.File(n5_file, use_zarr_format=False) # test conversion for 4 different compression pairs for pair in self.compressor_pairs: key = 'data_%s_%s' % pair compression_a, compression_b = pair ds = f.create_dataset(key, dtype='float32', compression=compression_a, shape=self.shape, chunks=self.chunks) data = np.arange(ds.size).reshape(ds.shape).astype(ds.dtype) ds[:] = data compression_b = None if compression_b == 'raw' else compression_b convert_to_h5(n5_file, h5_file, key, key, chunks=self.chunks, n_threads=1, compression=compression_b) with h5py.File(h5_file, 'r') as fh5: data_h5 = fh5[key][:] self.assertTrue(np.allclose(data, data_h5))
def test_n5_to_h5_with_roi(self): from z5py.converter import convert_to_h5 h5_file = os.path.join(self.tmp_dir, 'tmp.h5') n5_file = os.path.join(self.tmp_dir, 'tmp.n5') n5_key = 'data' with z5py.File(n5_file, 'w') as f: ds = f.create_dataset(n5_key, shape=self.shape, chunks=self.chunks, dtype='float64') data = np.arange(ds.size).reshape(ds.shape).astype(ds.dtype) ds[:] = data # define roi roi = np.s_[5:45, 9:83, 10:60] out_of_roi_mask = np.ones(self.shape, dtype='bool') out_of_roi_mask[roi] = False roi_shape = tuple(rr.stop - rr.start for rr in roi) # convert dataset with roi h5_key = 'data_roi' convert_to_h5(n5_file, h5_file, n5_key, h5_key, n_threads=8, roi=roi, fit_to_roi=False) with h5py.File(h5_file, 'r') as f: data_h5 = f[h5_key][:] self.assertEqual(data.shape, data_h5.shape) self.assertTrue(np.allclose(data[roi], data_h5[roi])) self.assertTrue(np.allclose(data_h5[out_of_roi_mask], 0)) # convert dataset with roi and fit_to_roi h5_key = 'data_roi_fit' convert_to_h5(n5_file, h5_file, n5_key, h5_key, n_threads=8, roi=roi, fit_to_roi=True) with h5py.File(h5_file, 'r') as f: data_h5 = f[h5_key][:] self.assertEqual(roi_shape, data_h5.shape) self.assertTrue(np.allclose(data[roi], data_h5))
import argparse from z5py.converter import convert_to_h5 if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("n5_in_path") parser.add_argument("h5_out_path") parser.add_argument("in_path_in_file") parser.add_argument("out_path_in_file") parser.add_argument("--n_threads", type=int, default=16) args = parser.parse_args() convert_to_h5(args.n5_in_path, args.h5_out_path, args.in_path_in_file, args.out_path_in_file, n_threads=args.n_threads) """ /scratch/beuttenm/hylfm/cache/b01highc_2_ls_reg_8743bf3e67c30c171928d3cc30e75a895047dae013848c7585034fa0.n5 /g/kreshuk/LF_computed/zenodo_upload/small_2.h5 ls_reg ls_reg """