<jupyter_start><jupyter_text>MHW Systems<jupyter_code>#imports
from importlib import reload
from pkg_resources import resource_filename

import numpy as np
import h5py
import os
from matplotlib import pyplot as plt

from mhw_analysis.systems import build
%matplotlib notebook<jupyter_output><empty_output><jupyter_text>Load (this cube was built by MWH_3D)<jupyter_code>#cube = np.load('tst_cube.npy')
cube = np.load('tst_cube_pacific.npy')
cube.shape<jupyter_output><empty_output><jupyter_text>Explore<jupyter_code>ch = 80
plt.clf()
plt.imshow(cube[ch, :, :])
plt.show()<jupyter_output><empty_output><jupyter_text>Build one  Convert cube to bool<jupyter_code>cube = cube.astype(bool)<jupyter_output><empty_output><jupyter_text>Run it<jupyter_code>reload(build)
mask, parent = build.make_labels(cube)
np.max(mask)
for ii in range(1,np.max(mask)):
    print(ii,np.sum(mask==ii))
cube.size<jupyter_output><empty_output><jupyter_text>----  Fussing with h5py  Load numpy array<jupyter_code>tst_mask = np.load(os.path.join(resource_filename('mhw_analysis', 'systems'),  'tst.npz'))['mask']
tst_mask.shape
tst_mask.dtype<jupyter_output><empty_output><jupyter_text>h5py<jupyter_code>f.close()
f = h5py.File(os.path.join(resource_filename('mhw_analysis', 'systems'),  'tst_mask.hdf'), mode='w')
dset = f.create_dataset("mask", tst_mask.shape, dtype='int32', chunks=True, compression='gzip', data=tst_mask)
dset.chunks
f.close()<jupyter_output><empty_output><jupyter_text>Read<jupyter_code>f2 = h5py.File(os.path.join(resource_filename('mhw_analysis', 'systems'),  'tst_mask.hdf'), mode='r')
f2['mask'].shape
f2['mask'].chunks
%time  tmp = f2['mask'][100:200,100:200, 100:205]
%time  tmp = f2['mask'][:, :, 100:205]
tmp.nbytes / 1e6
tmp.shape
tmp<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup