Пример #1
0
def singlePartAnalysis(surf, img, pxlen, thres, h_tip, ar_tip, N_part, N_pxl,
                       param_string_list, binwidth_list, bin_min_list,
                       bin_max_list):

    # get single particles
    surf_obj_list, surf_labeled = mf.identObj(surf, thres)
    img_obj_list, img_labeled = mf.identObj(img, thres)
    mf.plotThres(
        surf, surf_labeled, pxlen,
        'surface (found ' + str(len(surf_obj_list)) + ' of ' + str(N_part) +
        ' particles, thres=' + str(thres) + 'nm)')
    mf.plotThres(
        img, img_labeled, pxlen, 'image (found ' + str(len(img_obj_list)) +
        ' of ' + str(N_part) + ' particles, thres=' + str(thres) + 'nm)')

    surf_param_list = [
        calcParams(obj_i, pxlen, thres) for obj_i in surf_obj_list
    ]
    img_param_list = [
        calcParams(obj_i, pxlen, thres) for obj_i in img_obj_list
    ]

    # plot histograms of parameters
    N_param = len(surf_param_list[0])
    for i in range(N_param):  # iterate over all parameters (mean, std, etc.)
        surf_dist = [
            surf_param_list[j][i] for j in range(len(surf_param_list))
        ]
        img_dist = [img_param_list[j][i] for j in range(len(img_param_list))]

        fig, (ax1, ax2) = plt.subplots(nrows=2,
                                       ncols=1,
                                       sharex=True,
                                       sharey=True)
        bins = np.arange(min(surf_dist + img_dist),
                         max(surf_dist + img_dist) + binwidth_list[i],
                         binwidth_list[i])
        ax1.hist(surf_dist,
                 color='b',
                 bins=bins,
                 edgecolor='black',
                 linewidth=2)
        ax2.hist(img_dist,
                 color='r',
                 bins=bins,
                 edgecolor='black',
                 linewidth=2)
        ax1.set_xlim(bin_min_list[i], bin_max_list[i])
        ax2.set_xlim(bin_min_list[i], bin_max_list[i])
        ax2.set_xlabel(param_string_list[i])
        ax1.set_ylabel('frequency')
        ax2.set_ylabel('frequency')
        ax1.set_title('surface (found ' + str(len(surf_obj_list)) + ' of ' +
                      str(N_part) + ' particles, thres=' + str(thres) + 'nm)')
        ax2.set_title('image (found ' + str(len(img_obj_list)) + ' of ' +
                      str(N_part) + ' particles, thres=' + str(thres) + 'nm)')
        fig.suptitle(r'$h_{tip}=$' + str(h_tip) + r'$nm,\ a.r.=$' +
                     str(ar_tip) + r'$,\ N_{pxl}=$' + str(N_pxl) +
                     r'$,\ l_{px}=$' + str(pxlen) + r'$nm,\ thres=$' +
                     str(thres) + r'$nm$')
Пример #2
0
def reconstLogNorm(z, pxlen, thres, N_part, R_mu_real, R_sigma_real):
    z_obj_list, z_labeled = mf.identObj(z, thres)
    mf.plotThres(z, z_labeled, pxlen, 'found ' + str(len(z_obj_list)) + ' of ' + str(N_part) + ' particles, thres=' + str(thres)+'nm')
    
    R_list = [(np.max(np.shape(obj_i)))*pxlen/2 for obj_i in z_obj_list]
    
    R_mean = np.mean(R_list)
    R_std = np.std(R_list)
    
    R_mu = np.log(R_mean / np.sqrt(1 + R_std**2 / R_mean**2)) # recalculated gaussian
    R_sigma = np.sqrt(np.log(1 + (R_std/R_mean)**2)) # reculaculated gaussian
    
    x = np.linspace(R_mean - 3*R_std, R_mean + 3*R_std, 1000)
    pdf = 1 / (x * R_sigma * np.sqrt(2*np.pi)) * np.exp(-(np.log(x) - R_mu)**2 / (2*R_sigma**2))
    pdf_real = 1 / (x * R_sigma_real * np.sqrt(2*np.pi)) * np.exp(-(np.log(x) - R_mu_real)**2 / (2*R_sigma_real**2))
    
    plt.figure()
    plt.hist(R_list, bins=12, density=True, edgecolor='black', linewidth=2, color='grey', alpha=0.5)
    plt.plot(x, pdf, color='r', linewidth=3.5, label='empiric distribution (R_mu = {0:.3f}, R_sigma = {1:.3f})'.format(R_mu, R_sigma))
    plt.plot(x, pdf_real, color='green', linewidth=3.5, label='real distribution (R_mu = {0:.3f}, R_sigma = {1:.3f})'.format(R_mu_real, R_sigma_real))
    plt.xlabel(r'$R_{part} [nm]$')
    plt.ylabel('frequency')
    plt.title('found ' + str(len(z_obj_list)) + ' of ' + str(N_part) + ' particles, thres=' + str(thres)+'nm')
    plt.legend(loc=1)
    plt.tight_layout()

    return R_mean, R_std, R_mu, R_sigma
Пример #3
0
                 dist,
                 r_part_min,
                 r_part_max,
                 xmin=dist / 2,
                 xmax=len(z) * pxlen - dist / 2,
                 ymin=dist / 2,
                 ymax=len(z) * pxlen - dist / 2)

mf.plotfalsecol(z, pxlen)

tip = mf.genSemisphTip(pxlen, htip, r=rtip)
img = mph.grey_dilation(z, structure=-tip)
mf.plotfalsecol(img, pxlen)
mf.plotfalsecol(tip, pxlen)
if r_part_max > htip:
    print('Warning: possible spikes higher than semisphere tip')
obj = mf.identObj(img, thres)[0]
for o in obj:
    #    mf.plotfalsecol(o,pxlen)
    h, r, A, V, e = par.capPar(o, pxlen, thres)
    h_arr = np.append(h_arr, h)
    r_arr = np.append(r_arr, r)
    A_arr = np.append(A_arr, A)
    V_arr = np.append(V_arr, V)
    dV_arr = np.append(dV_arr, 1 - 6 * V / (np.pi * h**3 + 3 * h * A))

np.savetxt('capOnsph5.dat',
           np.array([h_arr, r_arr, A_arr, V_arr, dV_arr]),
           header='R_tip=' + str(rtip) + '; Npx=' + str(Npx) + '; pxlen=' +
           str(pxlen) + '\n on rows: h, r, A, V, dV')
Пример #4
0
rtip = s * 300
#rtip=s*500

htip = hspikemax * 1.02
spikedist = 2 * np.sqrt(rtip**2 - (rtip - hspikemax)**2) + 2
#MAP-------------------------------------------------
# z=mf.genFlat(Npx)
# #z=mf.genNormNoise(z,pxlen, 2, 2)
# z=mf.genHexSpikes(z,pxlen,hspikemin,hspikemax,spikedist,rspikemin,rspikemax,
#                   0.9,0.2,par='r', xmin=spikedist/2, xmax=len(z)*pxlen-spikedist/2,
#                   ymin=spikedist/2, ymax=len(z)*pxlen-spikedist/2)

# mf.plotfalsecol(z,pxlen)
# np.savetxt('map1.dat',z, header=str(pxlen)+' '+str(Npx)+' '+str(rtip)+' '+str(s)+' \n pxlen, Npx, Rtip, s')
# #Tip------------------------------------------------
# #occhio che h/a>>pxlen
# if hspikemax>rtip: print('Warning: possible spikes higher than semisphere tip')
# tip=mf.genSemisphTip(pxlen,htip,r=rtip)
# np.savetxt('tip1.dat',tip, header=str(pxlen)+' '+str(Npx)+' '+str(rtip)+' '+str(s)+' \n pxlen, Npx, Rtip, s')
# mf.plotfalsecol(tip,pxlen)
# # #IMG------------------------------------------------
# img = mph.grey_dilation(z, structure=-tip)
# img = mf.genNormNoise(img,pxlen, 4, 2)
# np.savetxt('img1.dat',img, header=str(pxlen)+' '+str(Npx)+' '+str(rtip)+' '+str(s)+' \n pxlen, Npx, Rtip, s')
# mf.plotfalsecol(img,pxlen)
# #---------------------------------------------------

img = np.loadtxt('img1.dat')
img = mph.filters.median_filter(img, 5)
img_obj_list, img_labeled, img_obj_ind = mf.identObj(img, thres, Npx_min=5)
mf.plotThres(img, img_labeled, pxlen)
Пример #5
0
pxlen=L/Npx
thres=0 #soglia
#-----------------------------------------------
R=q*L
htip=2*R*1.02
R_tip=np.linspace(R/5,3*R, 8)

V_red_dil = []
height = []
profiles = []
posmax = []

z=mf.genFlat(int(Npx[-1]))
z=mf.genSphere(z,pxlen[-1],np.array([L/2, L/2]),np.array([R]))
obj = mf.identObj(z,thres)[0]
V_red_calc= par.V(obj, pxlen[-1]) / volsphere(R)

maxh=0
posmax.append(0)
for x in range(np.shape(obj)[0]):
    height.append(np.amax(obj[0:,x])/R)
    if maxh<height[-1]:
        maxh=height[-1]
        posmax[-1]=x
profiles.append(np.array(height))
height.clear()

for rtip in R_tip:
    for i in range(len(Npx)): #iterazione su risoluzione
        print('R_tip=', rtip , ' Npx=', int(Npx[i]))