From b91238d9881e0bfec3082437089ba0d87694721e Mon Sep 17 00:00:00 2001 From: DanielVillarreal09 Date: Mon, 20 Jul 2020 14:24:36 -0700 Subject: [PATCH 1/2] Adapting the code to Python3 --- analysis/analysis.py | 87 +++++------ analysis/analysis_overlays.py | 206 ++++++++++--------------- analysis/analysis_queen.py | 14 +- image_processing/acquisitionlib.py | 36 ++--- image_processing/collection_cells.py | 68 ++++---- image_processing/preprocess_images.py | 154 +++--------------- image_processing/process_collection.py | 24 +-- image_processing/process_nd2.py | 11 +- image_processing/segmentation_cells.py | 52 +++---- image_processing/utils.py | 14 +- 10 files changed, 249 insertions(+), 417 deletions(-) diff --git a/analysis/analysis.py b/analysis/analysis.py index bba0edd..30b495a 100755 --- a/analysis/analysis.py +++ b/analysis/analysis.py @@ -23,12 +23,12 @@ # yaml formats npfloat_representer = lambda dumper,value: dumper.represent_float(float(value)) nparray_representer = lambda dumper,value: dumper.represent_list(value.tolist()) -float_representer = lambda dumper,value: dumper.represent_scalar(u'tag:yaml.org,2002:float', "{:<.8e}".format(value)) +float_representer = lambda dumper,value: dumper.represent_scalar('tag:yaml.org,2002:float', "{:<.8e}".format(value)) unicode_representer = lambda dumper,value: dumper.represent_unicode(value.encode('utf-8')) yaml.add_representer(float,float_representer) yaml.add_representer(np.float_,npfloat_representer) yaml.add_representer(np.ndarray,nparray_representer) -yaml.add_representer(unicode,unicode_representer) +yaml.add_representer(str,unicode_representer) # matplotlib controls plt.rcParams['svg.fonttype'] = 'none' # to embed fonts in output ('path' is to convert as text as paths) @@ -39,7 +39,7 @@ def default_parameters(): """Generate a default parameter dictionary.""" - print "Loading default parameters" + print("Loading default parameters") params={} # dimensions params['dimensions']={} @@ -66,20 +66,16 @@ def hist_dimensions(cells, outputdir='.', bins=['auto','auto','auto','auto'], un # initialization if mode == 'um': - titles = [u'length (\u03BCm)', u'width (\u03BCm)', u'area (\u03BCm\u00B2)', u'volume (\u03BCm\u00B3)'] + titles = ['length (\u03BCm)', 'width (\u03BCm)', 'area (\u03BCm\u00B2)', 'volume (\u03BCm\u00B3)'] attrs = ['height_um','width_um','area_um2', 'volume_um3'] else: - titles = [u'length (px)', u'width (px)', u'area (px\u00B2)', u'volume (px\u00B3)'] + titles = ['length (px)', 'width (px)', 'area (px\u00B2)', 'volume (px\u00B3)'] attrs = ['height','width','area', 'volume'] nattrs = len(attrs) - if bins is None: - bins = ['auto' for i in range(nattrs)] - elif len(bins) != nattrs: + if len(bins) != nattrs: raise ValueError("bins has the wrong dimensions!") - if units_dx is None: - units_dx = [None for i in range(nattrs)] - elif len(units_dx) != nattrs: + if len(units_dx) != nattrs: raise ValueError("units_dx has the wrong dimensions!") ncells = len(cells) @@ -90,7 +86,7 @@ def hist_dimensions(cells, outputdir='.', bins=['auto','auto','auto','auto'], un # make lists data = [ [] for i in range(nattrs)] - keys = cells.keys() + keys = list(cells.keys()) for n in range(ncells): key = keys[n] cell = cells[key] @@ -118,13 +114,13 @@ def hist_dimensions(cells, outputdir='.', bins=['auto','auto','auto','auto'], un for i in range(nattrs): attr = attrs[i] - print "attr = {}".format(attr) + print("attr = {}".format(attr)) ax = axes[i] # compute histogram hist,edges = np.histogram(data[i], bins=bins[i], density=False) nbins = len(edges)-1 - print "nbins = {:d}".format(nbins) + print("nbins = {:d}".format(nbins)) # plot histogram color = 'grey' @@ -165,7 +161,7 @@ def hist_dimensions(cells, outputdir='.', bins=['auto','auto','auto','auto'], un for ext in exts: fileout = os.path.join(outputdir,filename+ext) fig.savefig(fileout, bbox_inches='tight', pad_inches=0) - print "Fileout: {: h: @@ -359,15 +359,15 @@ def write_crop(img, mask, points, bname, tiff_dir='.', mask_dir='.', pad_x=5, pa cells.append(cell) # write tiff - if params['write_cropped']: + if not namespace.lean: write_crop(img, mask, points, bname=cell_id, tiff_dir=tiff_dir, mask_dir=mask_dir,debug=namespace.debug, **params['crops']) ncells = len(cells) - print "ncells = {:d} collected".format(ncells) + print("ncells = {:d} collected".format(ncells)) # write down the cell dictionary celldict = {cell['id']: cell for cell in cells} celldict = make_dict_serializable(celldict) pathtocells = os.path.join(outputdir, 'collection.js') write_dict2json(pathtocells,celldict) - print "{:<20s}{: 0): - X[l:-l,l:-l] = np.copy(myimg) - Xpad = X[l:2*l,l:-l] - X[:l,l:-l] = Xpad[::-1,:] - Xpad = X[-2*l:-l,l:-l] - X[-l:,l:-l] = Xpad[::-1,:] - - Xpad = X[:,l:2*l] - X[:,:l] = Xpad[:,::-1] - Xpad = X[:,-2*l:-l] - X[:,-l:] = Xpad[:,::-1] - else: - X = np.copy(myimg) - - # make footprint for average - footprint_func = lambda n,m : (n**2 + m**2 <= l**2) | ((hnew-n)**2 + m**2 <= l**2) | ((hnew-n)**2 + (wnew-m)**2 <= l**2) | (n**2 + (wnew-m)**2 <= l**2) - hh,ww = np.meshgrid(hrange,wrange,indexing='ij') - F = np.float_(footprint_func(hh,ww)) - fsum = np.sum(F) # normalization so that it is a mean - F /= fsum - #print("fsum = {:.6f}".format(fsum)) - # important to check than without lognorm, with l=0, it reproduces the input after fft and ifft. - - Xcpy = np.copy(X) - # log transform - if (logtransform): - X = np.log(X) - - # fourier transform - Xtilde = np.fft.fftn(X) - Ftilde = np.fft.fftn(F) - X = np.real(np.fft.ifftn(Xtilde*Ftilde)) - #print(np.max(X-Xcpy), np.median(X-Xcpy)) - - # log detransform - if (logtransform): - X = np.exp(X) - bg = X[l:-l,l:-l] - -# # test -# import matplotlib.pyplot as plt -# xmin = np.min(myimg) -# xmax = np.max(myimg) -# fig=plt.figure() -# ax = fig.add_subplot(1,2,1) -# #im = ax.imshow(F) -# im = ax.imshow(Xcpy, vmin=xmin,vmax=xmax) -# fig.colorbar(im,ax=ax) -# -# ax = fig.add_subplot(1,2,2) -# #ax.imshow(np.real(Ftilde)) -# im = ax.imshow(X, vmin=xmin,vmax=xmax) -# -# fig.colorbar(im,ax=ax) -# -# fig.savefig('footprint.png') -# plt.close() -# sys.exit() -# # test - - # restore scaling - bg = cv2.blur(bg,ksize=(size,size)) # maybe not essential, to smooth background values - #bg = np.array(bg, dtype=np.float32)/255 - bg = scale* bg - offset - bg = np.array(bg, dtype=img.dtype) - return bg - - def preprocess_image(tiff_file, outputdir='.', invert=None, bg_subtract=True, bg_size=200, debug=False): """ INPUT: @@ -296,9 +184,8 @@ def preprocess_image(tiff_file, outputdir='.', invert=None, bg_subtract=True, bg """ # method for background subtraction - #get_background = get_background_medianblur + get_background = get_background_medianblur #get_background = get_background_checkerboard - get_background = lambda arr, size: get_background_logmean_fft(arr, size=size, logtransform=True) # pre-processing bname = os.path.splitext(os.path.basename(tiff_file))[0] @@ -324,11 +211,11 @@ def preprocess_image(tiff_file, outputdir='.', invert=None, bg_subtract=True, bg if invert == None: invert = [] elif invert == 'all': - invert = range(nchannels) + invert = list(range(nchannels)) # adjust background sliding window size bg_size = 2*int(bg_size/2) + 1 # make odd - print "bg_size = {:d}".format(bg_size) + print("bg_size = {:d}".format(bg_size)) img0 = np.copy(img) # process channels @@ -348,7 +235,7 @@ def preprocess_image(tiff_file, outputdir='.', invert=None, bg_subtract=True, bg if bg_subtract: # print "Background subtraction..." # method for background subtraction using sliding window - img_bg[c] = get_background(arr, bg_size) + img_bg[c] = get_background(arr, size=bg_size) idx = arr > img_bg[c] # print np.unique(arr) # print np.unique(img_bg[c]) @@ -375,15 +262,15 @@ def preprocess_image(tiff_file, outputdir='.', invert=None, bg_subtract=True, bg fname = os.path.basename(tiff_file) fileout = os.path.join(outputdir,fname) ti.imwrite(fileout, img, imagej=True, photometric='minisblack', metadata=meta) - print "{:<20s}{: 0.) ntot = len(np.ravel(eimg)) - print "nz = {:d} / {:d} sparcity index = {:.2e}".format(nz, ntot, float(nz)/float(ntot)) + print("nz = {:d} / {:d} sparcity index = {:.2e}".format(nz, ntot, float(nz)/float(ntot))) efname = bname #efile = os.path.join(outputdir,efname+'.txt') #efile = os.path.join(outputdir,efname+'.pkl') @@ -287,7 +287,7 @@ def get_estimator_boundingbox(tiff_file, channel=0, outputdir='.', w0=1, w1=100, #np.savetxt(fout, eimg) #pkl.dump(eimg,fout) ssp.save_npz(efile, ssp.coo_matrix(eimg), compressed=False) - print "{:<20s}{: 0): - print "Computing OTSU thresholds..." + print("Computing OTSU thresholds...") thresholds = get_OTSU(tiff_files, outputdir=outputdir) From 7154aedffa88fe6837fbcc312a7708a739a75f77 Mon Sep 17 00:00:00 2001 From: renziyuan1997 Date: Tue, 21 Jul 2020 12:20:15 -0700 Subject: [PATCH 2/2] py3 agarpad --- .DS_Store | Bin 0 -> 6148 bytes dockerfile/.DS_Store | Bin 0 -> 6148 bytes .../__pycache__/acquisitionlib.cpython-36.pyc | Bin 0 -> 3369 bytes .../__pycache__/utils.cpython-36.pyc | Bin 0 -> 6983 bytes roles/params.yml | 56 ++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 .DS_Store create mode 100644 dockerfile/.DS_Store create mode 100644 image_processing/__pycache__/acquisitionlib.cpython-36.pyc create mode 100644 image_processing/__pycache__/utils.cpython-36.pyc create mode 100755 roles/params.yml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b3ada6acf44236b24a4ae91e1f8a5606a8c5adef GIT binary patch literal 6148 zcmeHK&2AGh5FV!~^->}BfYcs+;g&=Cqvlj;71~2@NI`G_l5A<-%5I2CnrdGI z-iRmQb@;}%qLh>?ijYSdf3xz78hknzygmL zq3~e-u@r3_>&O7UJBx%wz!lHGKks4aM{%k2Ni$h%YkP+=mSel@wmlHzcI?KZsOg5+ za_0B?p0+Q97|v|hyY&0xPJaJH1hMM}{ctY)=E@IxV%!v?pclz?&fRzbxwdUHyOS>@ zNv&Eb@=CoiDe|PzC>43FTAxg8c5qleKI`5;Jtr@d*Ehu~g%425p2jJ>gE1@cu^k3O z5!`_f<1I2G5$Tg~%?dBqYEbx5=@$yu1%4}hN{&IpfMH-$8PHoM%WWzFrf$Q4VPGW# zxIb`EL`P$)P;MPC$QA$)eF6k%6q5=JEVLUETjLCYhOGz%cNy7@$_G-D*Nf z`fOb)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>dCEDif%SB5+{a@L(JcBj+s zwaKLZ?r9LmVgGBYY?QO{#M>F~=;Z8-cD%twD!rqSaz{xD5a2dG-wv1KVK{m4p-7JU z;lTSmlBeGIZdWA3VHBV2d*gm`9f0SJPow$jrAgU)-EMTlZuFYn=-SS=y5rHL`Ghh9 z0B;zIyA8Vx9-DD{vH z-Y2(I>1Z%SNMVfRdE-#tn>f>~GtCgS1@no058d_DFAt(PN{{+M_iWel3%c2Q{=)Dy zkqKH!MBUt_mZFZzi_~z*h0IxJmkIhcwRYnkje2`cb4enn%K~z_vrEflP#02b9>L!KT3>WGmt$zj!>5JnB-c;Ee?)gPcXa z8Fw)q`xY7$!)b)o$hXjT7)~QmB^Qp4#YYXOTl^A%cc_@Y6%9_XO}P{+1WC30qahyQ z@vo2fK2AfC?(raw!v3EB(cYtzKnw%E7tEfWp-8%6nxfP04gxf&*wcM;L%tVu&o81B zO`XL3=;+>XoLA>o9SWVO`~YC-mlzDE!m5_b3izwBHmjOt=CU$tTQoTg+dv8T;MEWByO7Yqtgs4OA=dCq8f4)@w#1g^8g1-0SlN8FwzYoM6!f3LZt+lG!lFf4tl=SQ7;-1R z7!1eaP0W3F7!6X&o1kMyw6%;3{^4%DI3|a0TpxrO};Sb3)En^^pu30hN Gx4#0$M|7qD literal 0 HcmV?d00001 diff --git a/image_processing/__pycache__/utils.cpython-36.pyc b/image_processing/__pycache__/utils.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..804fc9c5a11b895dcdc6923a205c01a28990b9e2 GIT binary patch literal 6983 zcmcIo-ESLLcAq;l91baok|kOnwrr2Ru~&5Ton6P9Rns_*ouo~a)K=Cpku5Xky_9A| z4yij=mc$))fn@?aDU5Z20t+nqUi6>nAFx1Q`qE-v`?3c52NZcpf9DQG+u9f?3M`4a z=iGC@&pluFyfHRbto`wHZSs;~{Fm{rm6ov2%zrejG zta?_Q4d?kqeo36;)BH#LwI?}dXxe3dMV#k926bWE;FTx&0sSg}9kfNh^u!)emiY>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