import json import numpy as np import zarr meta = json.load(open("PHerc0172.lasagna.json")) cos = zarr.open(meta["groups"]["cos"]["zarr"], mode="r") # cos, 2x down from the CT level read nx = zarr.open(meta["groups"]["nx"]["zarr"], mode="r") # normals, 4x down; stored as v * 127 + 128 ny = zarr.open(meta["groups"]["ny"]["zarr"], mode="r") z, y, x = 5176, 725, 1125 # a voxel on the normals' grid that holds data a, b = (float(nx[z, y, x]) - 128) / 127, (float(ny[z, y, x]) - 128) / 127 c = np.sqrt(max(0.0, 1 - a * a - b * b)) # nz is not stored patch = cos[2 * z, 2 * y:2 * y + 64, 2 * x:2 * x + 64] # the same place on the cos grid print("normal", round(a, 3), round(b, 3), round(c, 3), "cos patch mean", float(np.mean(patch)))