def get_shifts(dist, ref_dist, max_shift=DEFAULT_MAX_SHIFT, pixsize=DEFAULT_PIXSIZE): '''try to return shifts between two distributions, not really working for now ''' imgs = [ci(ff) for ff in dist.filelist] cdimgs = [im.get_od_image() / im.s_lambda for im in imgs] ldimgs = [bp.line_density(cdim, pixsize) for cdim in cdimgs] ldsnorm = [ld / np.sum(ld) for ld in ldimgs] ref_img = ci(ref_dist.filelist[-1]) ref_cdimg = ref_img.get_od_image() / ref_img.s_lambda ref_ldimg = bp.line_density(ref_cdimg, pixsize) ref_ldnorm = ref_ldimg / np.sum(ref_ldimg) shifts = [] for nn, ld in enumerate(ldimgs): shift = ia.optimal_shift(ref_ldnorm, ldsnorm[nn]) if abs(shift) > max_shift: pass else: #aligned.append(np.roll(ld, -shift)) shifts.append(shift) return shifts
def get_line_densities(dist, pixsize=DEFAULT_PIXSIZE): '''returns the integrated line densities (lds) and the normalized lds dist - a cloud distribution object ''' imgs = [ci(ff) for ff in dist.filelist] cdimgs = [im.get_od_image() / im.s_lambda for im in imgs] ldimgs = [bp.line_density(cdim, pixsize) for cdim in cdimgs] ldsnorm = [ld / np.sum(ld) for ld in ldimgs] return ldsnorm, ldimgs
def field_dist(dist, unbias=False, **kwargs): '''Return a list of magnetic field profiles calculated from data in distribution. Args: dist: a CloudDistribution unbias: if True, subtract the mean magnetic field from each field profile ''' imgs = [ci(ff) for ff in dist.filelist] cdimgs = [img.get_od_image() / img.s_lambda for img in imgs] lds = [bp.line_density(cd) for cd in cdimgs] fas = [bp.field_array(ld, **kwargs) for ld in lds] if unbias: fas = [fa - np.mean(fa) for fa in fas] return fas
def field_dist(dist, unbias=False, **kwargs): '''Return a list of magnetic field profiles calculated from data in distribution. Args: dist: a CloudDistribution unbias: if True, subtract the mean magnetic field from each field profile ''' imgs = [ci(ff) for ff in dist.filelist] cdimgs = [img.get_od_image()/ img.s_lambda for img in imgs] lds = [bp.line_density(cd) for cd in cdimgs] fas = [bp.field_array(ld, **kwargs) for ld in lds] if unbias: fas = [fa - np.mean(fa) for fa in fas] return fas
import matplotlib.pyplot as plt gamma = 8.63e-29 # T/m**3, from Wildermuth thesis p 85 rho0 = 2e-6 z0 = 2e-6 # dnoise = CD(r'C:\Users\Levlab\Documents\becy_stats_data\dragonfly_noise\2014-10-16\small_sample') dnoise = CD(r'Z:\Data\ACM Data\dragonfly_noise\2014-10-20') cts_per_px = [] ln_per_px = [] dn_per_px = [] for imgfile in dnoise.filelist: img = ci(imgfile) # img.truncate_image(600, 1000, 500, 600) odimg = img.get_od_image() # light_noise = img.atom_image_trunc - img.light_image_trunc*img.fluc_cor light_noise = img.atom_image_trunc - img.light_image_trunc dark_noise = img.dark_image_trunc ln_sum = np.sum(light_noise, axis = 0) dn_sum = np.sum(dark_noise, axis = 0) odsum = np.sum(odimg, axis = 0) * (img.pixel_size / img.magnification)**2 / img.s_lambda # plt.plot(odsum); plt.show() cts_per_px.append(odsum) ln_per_px.append(ln_sum) dn_per_px.append(dn_sum) ct_mu = np.mean(cts_per_px) delB = gamma * ct_mu / (rho0**2 * z0) print 'Delta N = %2.2f\n'%ct_mu
import numpy as np import matplotlib.pyplot as plt gamma = 8.63e-29 # T/m**3, from Wildermuth thesis p 85 rho0 = 2e-6 z0 = 2e-6 # dnoise = CD(r'C:\Users\Levlab\Documents\becy_stats_data\dragonfly_noise\2014-10-16\small_sample') dnoise = CD(r'Z:\Data\ACM Data\dragonfly_noise\2014-10-20') cts_per_px = [] ln_per_px = [] dn_per_px = [] for imgfile in dnoise.filelist: img = ci(imgfile) # img.truncate_image(600, 1000, 500, 600) odimg = img.get_od_image() # light_noise = img.atom_image_trunc - img.light_image_trunc*img.fluc_cor light_noise = img.atom_image_trunc - img.light_image_trunc dark_noise = img.dark_image_trunc ln_sum = np.sum(light_noise, axis=0) dn_sum = np.sum(dark_noise, axis=0) odsum = np.sum( odimg, axis=0) * (img.pixel_size / img.magnification)**2 / img.s_lambda # plt.plot(odsum); plt.show() cts_per_px.append(odsum) ln_per_px.append(ln_sum) dn_per_px.append(dn_sum) ct_mu = np.mean(cts_per_px) delB = gamma * ct_mu / (rho0**2 * z0)
A_guess = np.max(image) theta_guess = 2*pi/180 k_guess = 4*pi*np.sin(theta_guess) / WAVELENGTH p_0 = [A_guess, k_guess, 0, 0] #fit guess for k, phi, offset coef, covar = curve_fit(sinusoid_1d, xdata, image, p0=p_0) return coef, covar if __name__ == "__main__": # img = ci(r'Z:\Data\ACM Data\MoveMicro_h_from_sample\2014-10-15\40.5\2014-10-15_192124.mat') dir = r'D:\ACMData\Imaging System\expose_time\2014-10-16\MoveMicro40.5\fringes_fits' imgs = CD(dir, False).filelist thetas = [] for f in imgs: img = ci(f) limg = img.light_image plt.imshow(limg) plt.show() limg_trunc = limg[:200, :] plt.imshow(limg_trunc) plt.show() light_pattern = np.sum(limg_trunc, axis = 1) distances = np.cumsum(np.ones(len(light_pattern))*(PIXELSIZE / MAGNIFICATION)) coef, covar = fit_sinusoid_1d(light_pattern, distances) plt.plot(distances, sinusoid_1d(distances, *coef)) plt.plot(distances, light_pattern) plt.show()
from cloud_distribution import * from cloud_image import CloudImage as ci import BECphysics as bp import matplotlib.pyplot as plt import numpy as np cdist = CD(r'C:\Users\Levlab\Documents\becy_stats_data\statistics\5umMap\2014-10-17') imgs = [ci(ff) for ff in cdist.filelist] cdimgs = [img.get_od_image / img.s_lambda for img in imgs] lds = [bp.line_density(cd) for cd in cdimgs] plt.plot(lds[0]) plt.show() fas = [bp.field_array(ld) for ld in lds] fasarr = np.array(fas) xaxis = np.cumsum(np.ones(len(fas)) * (3.75 / 6.4)) ylocs = np.cumsum(np.ones(fasarr.shape[1])*2) X, Y = np.meshgrid(xaxis, ylocs) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') plt.contourf(X, Y, fasarr) plt.show()
from cloud_distribution import * from cloud_image import CloudImage as ci import BECphysics as bp import matplotlib.pyplot as plt import numpy as np cdist = CD( r'C:\Users\Levlab\Documents\becy_stats_data\statistics\5umMap\2014-10-17') imgs = [ci(ff) for ff in cdist.filelist] cdimgs = [img.get_od_image / img.s_lambda for img in imgs] lds = [bp.line_density(cd) for cd in cdimgs] plt.plot(lds[0]) plt.show() fas = [bp.field_array(ld) for ld in lds] fasarr = np.array(fas) xaxis = np.cumsum(np.ones(len(fas)) * (3.75 / 6.4)) ylocs = np.cumsum(np.ones(fasarr.shape[1]) * 2) X, Y = np.meshgrid(xaxis, ylocs) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') plt.contourf(X, Y, fasarr) plt.show()
from cloud_distribution import CD from cloud_image import CloudImage as ci import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from scipy import ndimage img = ci( r'Z:\Data\ACM Data\MoveMicro_h_from_sample\2014-10-15\40.5\2014-10-15_192124.mat' ) # img = ci(r'Z:\Data\ACM Data\Statistics\loadmot_number\2014-08-11\2014-08-11_104746.mat') dimg = img.dark_image # plt.imshow(dimg) # plt.show() # noise_floor = np.mean(dimg) + 50*np.std(dimg) noise_floor = 2000 print 'mean: %2.2f' % np.mean(dimg) print 'std: %2.2f' % np.std(dimg) light_masked = np.ma.masked_less_equal(img.light_image, noise_floor) od_img = img.get_od_image(trunc_switch=False) struct = ndimage.generate_binary_structure(2, 10) Zmask1 = ndimage.morphology.binary_erosion(light_masked.mask, struct) Zmask2 = light_masked.mask Zmask3 = np.ma.masked_less_equal(img.atom_image, noise_floor).mask Zmask = np.logical_or(Zmask1, Zmask2) Zmask = np.logical_or(Zmask, Zmask3)