KitwareMedical / HASI

High-throughput Applications for Skeletal Imaging
Apache License 2.0
6 stars 8 forks source link

ENH: Add test_integration.py data to IPFS #63

Closed thewtex closed 3 years ago

thewtex commented 3 years ago

Data created with script:

!/usr/bin/env python

from pathlib import Path import os import subprocess import itk import zarr from numcodecs import Blosc import json

femur_root = Path('/home/matt/data/hasi-femur-nrrd') ipfs_data_repo = Path('/home/matt/data/hasi-testing-data/femur') os.chdir(ipfs_data_repo)

images = {} for image_nrrd in femur_root.iterdir(): if image_nrrd.is_file(): image = itk.imread(str(image_nrrd)) image_da = itk.xarray_from_image(image) name = image_nrrd.stem print(name) image_ds = image_da.to_dataset(name=name) output_dir = ipfs_data_repo store = zarr.DirectoryStore(output_dir / (name + '.zarr')) chunk_size = 64 compressor = Blosc(cname='zstd', clevel=5, shuffle=Blosc.SHUFFLE) image_ds.to_zarr(store, mode='w', compute=True, encoding={name: {'chunks': [chunk_size]*image.GetImageDimension(), 'compressor': compressor}}) cid = subprocess.check_output(['ipfs', 'add', '-r', '--hidden', '-s', 'size-1000000', '--raw-leaves', '--cid-version', '1', '-Q', str(name + '.zarr')]).decode().strip() images[str(name)] = cid

index_json = ipfs_data_repo / 'index.json' with open(index_json, 'w') as fp: json.dump(images, fp) index_cid = subprocess.check_output(['ipfs', 'add', '-r', '--hidden', '-s', 'size-1000000', '--raw-leaves', '--cid-version', '1', '-Q', '-w', str(index_json)]).decode().strip() print('index_cid', index_cid)