<jupyter_start><jupyter_text>So here are the distributions pre filtering, same as before.<jupyter_code>mean_x, mean_y = [],[]
fig = plt.figure(figsize=(14,8))
ax1 = fig.add_subplot(221)  
ax2 = fig.add_subplot(222)  
for im in test.image_stack():
    xdist,ydist = al.get_offset_distribution(im)
    mean_x.append(np.mean(xdist))
    mean_y.append(np.mean(ydist))
    ax1.hist(xdist,50)
    ax2.hist(ydist,50)

ax3 = fig.add_subplot(223)  
ax3.plot(mean_x,"ro")
ax3.set_ylabel("average x-offset")
ax3.set_xlabel("individual test images")
ax4 = fig.add_subplot(224)
ax4.plot(mean_y,"go")
ax4.set_ylabel("average y-offset")
ax4.set_xlabel("individual test images")<jupyter_output><empty_output><jupyter_text>Okay heres the new filter in action. I havent yet figured out the best way to visualize user optimization of parameters yet, but for now it spits out histograms.<jupyter_code>for im in test.image_stack():
    fig = al.show_filtering(im,.4,.25,5)<jupyter_output><empty_output><jupyter_text>Okay, the next two plots are from the original notebook, but using this new filter and the settings I picked above.<jupyter_code>mean_x, mean_y = [],[]
fig = plt.figure(figsize=(14,8))
ax1 = fig.add_subplot(221)  
ax2 = fig.add_subplot(222)  
for im in test.image_stack():
    xdist,ydist = al.get_offset_distribution(im)
    
    
    scrubbed_x = al.pinhole_filter(xdist,.4,.25)
    scrubbed_y = al.pinhole_filter(ydist,.4,.25)
    
    
    print("percent change in x and y distributions post-scrub: ",
          int((len(scrubbed_x)/len(xdist))*100),
          int((len(scrubbed_y)/len(ydist))*100))
    mean_x.append(np.mean(scrubbed_x))
    mean_y.append(np.mean(scrubbed_y))
    
    ax1.hist(scrubbed_x,al.make_bins(scrubbed_x,.1),ec = 'k',alpha = .5)
    ax2.hist(scrubbed_y,al.make_bins(scrubbed_y,.1),ec = 'k',alpha = .5)

ax3 = fig.add_subplot(223)  
ax3.plot(mean_x,"ro")
ax3.set_ylim(np.mean(mean_x)-.5,np.mean(mean_x)+.5)
ax3.set_ylabel("average x-offset")
ax3.set_xlabel("individual test images")
ax4 = fig.add_subplot(224)
ax4.plot(mean_y,"go") 
ax4.set_ylim(np.mean(mean_y)-.5,np.mean(mean_y)+.5)
ax4.set_ylabel("average y-offset")
ax4.set_xlabel("individual test images")<jupyter_output>percent change in x and y distributions post-scrub:  27 40
percent change in x and y distributions post-scrub:  38 44
percent change in x and y distributions post-scrub:  31 42
percent change in x and y distributions post-scrub:  41 60
percent change in x and y distributions post-scrub:  28 42
percent change in x and y distributions post-scrub:  45 46
percent change in x and y distributions post-scrub:  49 54
percent change in x and y distributions post-scrub:  39 37
percent change in x and y distributions post-scrub:  44 52
percent change in x and y distributions post-scrub:  51 47
percent change in x and y distributions post-scrub:  45 39<jupyter_text>So here's the global distribution, same parameters.<jupyter_code>from scipy.stats import norm,skewnorm
import matplotlib.mlab as mlab
pooled_x, pooled_y = [],[]
fig = plt.figure(figsize=(14,4))
ax1 = fig.add_subplot(121)  
ax2 = fig.add_subplot(122)  

for im in test.image_stack():
    xdist,ydist = al.get_offset_distribution(im)
    pooled_x+=al.pinhole_filter(xdist,.4,.25)   
    pooled_y+=al.pinhole_filter(ydist,.4,.25)   

n1,bins1,patches1 = ax1.hist(pooled_x,al.FD_rule_bins(pooled_x), density=1, fc = "g",ec = "k",alpha = .5)
n2,bins2,patches2 = ax2.hist(pooled_y,al.FD_rule_bins(pooled_y), density=1, fc = "g",ec = "k",alpha = .5)

moments_norm = norm.fit(pooled_x)
moments_skew = skewnorm.fit(pooled_x)
ax1.plot(bins1, norm.pdf(bins1,*moments_norm), 'c--', linewidth=2)
ax1.plot(bins1, skewnorm.pdf(bins1,*moments_skew), 'm--', linewidth=2)
ax1.set_title("displacements in x")
print("displacements in x")
print("norm fit moments: ",moments_norm)
print("skewnorm fit moments: ",moments_skew)
moments_norm = norm.fit(pooled_y)
moments_skew = skewnorm.fit(pooled_y)
ax2.plot(bins2, norm.pdf(bins2,*moments_norm), 'c--', linewidth=2)
ax2.plot(bins2, skewnorm.pdf(bins2,*moments_skew), 'm--', linewidth=2)
ax2.set_title("displacements in y")
print("displacements in y")
print("norm fit moments: ",moments_norm)
print("skewnorm fit moments: ",moments_skew)
global_dx,global_dy = al.find_global_offset(test.image_stack())
print(global_dx,global_dy)
im = test.image_stack()[3]
adj_image = al.align_by_offset(im,global_dx,global_dy)
im_old = al.overlay(im)
im_new = al.overlay(adj_image)
    
fig = plt.figure(figsize=(12,12))
ax1 = fig.add_subplot(211)  
ax2 = fig.add_subplot(212,sharex=ax1)
ax1.set_title('Before', fontsize = "18")
ax2.set_title('After', fontsize = "18")
ax1.imshow(im_old)
ax2.imshow(im_new)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.139307708643024, 'fraction_numerical': 0.04183478445529836, 'mean_word_length': 5.434426229508197, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '444960', 'license': 'MIT', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1854, 'n_words': 378, 'path': 'Alignment_tests.ipynb', 'repo_name': 'livjensen7/toolbox', 'size': '4709'}