<jupyter_start><jupyter_text>Data Preparation<jupyter_code>hst = img_as_float(ut.read_hyperstack('../data/wt_gbe_20180110.h5'))
center_x,center_y = 500,530
radius_x,radius_y = 550,250
ellipse = ut.calc_ellipse(center_x,center_y,radius_x,radius_y)
# Loop through each timepoint in hyperstack to create mask
for t in range(hst.shape[0]):
    hst[t] = ut.contour_embryo(hst[t],ellipse)
fig,ax = plt.subplots(1,2,figsize=(10,8))
ax[0].imshow(hst[0])
ax[1].imshow(hst[-1])
import h5py
# Open new h5py file to add data to
f = h5py.File('../data/wt_gbe_20180110_mask.h5','w')

# Save each timepoint to a group/dataset in h5 file
for t in range(hst.shape[0]):
    f.create_dataset('t'+str(t)+'/channel1', data=hst[t])
    
# close file
f.close()
mhst = hst.copy()<jupyter_output><empty_output><jupyter_text>Use contour to create bins?<jupyter_code># single time point for testing
img = hst[0]<jupyter_output><empty_output><jupyter_text>Calculate contour based on unmasked image<jupyter_code>snake = active_contour(gaussian(img, 3),
                       ellipse, alpha=0.015, beta=10, gamma=0.001)
snake.shape<jupyter_output><empty_output><jupyter_text>Divide contour into 20pt segments. Could these segments be used to assign bins to the embryo?<jupyter_code>fig,ax = plt.subplots(figsize=(10,8))
ax.imshow(img,cmap='Greys')
ax.plot(ellipse[:,0],ellipse[:,1])
for i in range(20,401,20):
    ax.plot(snake[i-20:i,0],snake[i-20:i,1],lw=5)
ax.plot([100,900],[550,500])<jupyter_output><empty_output><jupyter_text>Reassign `img` as masked image for calculates and assign background points (=0) to be `np.nan`.<jupyter_code>img = mhst[0]
img[img==0] = np.nan
# Crop image to reduce the number of points for processing
imgc = img[int(snake[:,1].min()*0.9) : int(snake[:,1].max()*1.1),
          int(snake[:,0].min()*0.9) : int(snake[:,0].max()*1.1)]

plt.imshow(imgc)<jupyter_output><empty_output><jupyter_text>Divide x axis into 20 segments<jupyter_code>xgrid = np.linspace(0,1024,20).astype(int)
xgrid
ygrid = np.array([0,180,500])
ygrid<jupyter_output><empty_output><jupyter_text>Create an roi mask that assigns each chunk of the grid a unqiue integer<jupyter_code># Split image into a grid
rois = np.zeros_like(imgc)

n=1
for j in range(len(ygrid)-1):
    y = ygrid[j]
    ydt = ygrid[j+1]
    for i in range(len(xgrid)-1):
        x = xgrid[i]
        xdt = xgrid[i+1]
        
        if j > 0:
            xdt = xgrid[-i-1]
            x = xgrid[-i-2]
            
        print(n,x,xdt,y,ydt)
#         print(n)
        rois[y:ydt,x:xdt] = n
        n = n+1
ut.imshow(rois)
nroi = np.unique(rois).shape
nroi<jupyter_output><empty_output><jupyter_text>Calculate the average intensity value in each roi bin<jupyter_code>avgs = []
for n in range(1,nroi[0]+1):
    avgs.append(np.nanmean(imgc[rois==n]))
avgs
plt.plot(avgs)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15611814345991562, 'fraction_numerical': 0.047116736990154715, 'mean_word_length': 4.794297352342159, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '134754', 'license': 'MIT', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1184, 'n_words': 219, 'path': 'notebooks/20181018-test_binning_methods.ipynb', 'repo_name': 'msschwartz21/germband-extension', 'size': '2844'}