From 779cecd23457f4027cd0eeac439459597170be3d Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Wed, 17 Jun 2020 16:49:02 -0600 Subject: [PATCH] pt_blockmedian.py: rolled back changes to help with merge of tyler's branch --- pt_blockmedian.py | 43 +++++++------------------------------------ 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/pt_blockmedian.py b/pt_blockmedian.py index b4938b8..cc2ffc0 100644 --- a/pt_blockmedian.py +++ b/pt_blockmedian.py @@ -24,11 +24,11 @@ def pt_blockmedian(xx, yy, zz, delta, xy0=[0.,0.], return_index=False, index_onl xr=np.floor((x-xy0[0])/delta) yr=np.floor((y-xy0[1])/delta) xyind=xr*yscale+(yr-np.min(yr)) - sorted_ind=np.argsort(xyind+(z-np.nanmin(z))/zscale) - xs=x[sorted_ind] - ys=y[sorted_ind] - zs=z[sorted_ind] - xyind=xyind[sorted_ind] + ind=np.argsort(xyind+(z-np.nanmin(z))/zscale) + xs=x[ind] + ys=y[ind] + zs=z[ind] + xyind=xyind[ind] ux, ix=np.unique(xyind, return_index=True) if not index_only: xm=np.zeros_like(ux)+np.NaN @@ -51,7 +51,7 @@ def pt_blockmedian(xx, yy, zz, delta, xy0=[0.,0.], return_index=False, index_onl ym[count]=(ys[iM[0]]+ys[iM[1]])/2. zm[count]=(zs[iM[0]]+zs[iM[1]])/2. if return_index: - ind[count,:]=sorted_ind[iM] + ind[count,:]=iM else: # odd case: iM ends in 0.5. if ni=3, iM=3/2-1 = 0.5, want 1 # if ni=1, iM=-0.5, want 0 @@ -61,7 +61,7 @@ def pt_blockmedian(xx, yy, zz, delta, xy0=[0.,0.], return_index=False, index_onl ym[count]=ys[iM] zm[count]=zs[iM] if return_index: - ind[count,:]=sorted_ind[iM] + ind[count,:]=iM #plt.figure(1); plt.clf(); plt.subplot(211); plt.cla(); plt.scatter(xs[ii]-xm[count], ys[ii]-ym[count], c=zs[ii]); plt.axis('equal'); plt.subplot(212); plt.plot(zs[ii]); #plt.pause(1) #print(count) @@ -72,32 +72,3 @@ def pt_blockmedian(xx, yy, zz, delta, xy0=[0.,0.], return_index=False, index_onl else: return xm, ym, zm - -def __main__(): - scale=10 - N=200000 - delta=2 - x=np.random.rand(N)*scale - y=np.random.rand(N)*scale - z=np.random.rand(N)*scale - - xm, ym, zm0, ii=pt_blockmedian(x, y, z, delta, return_index=True) - - zm=0.5*(z[ii[:,0]]+z[ii[:,1]]) - - xi=np.floor(x/delta)*delta - yi=np.floor(y/delta)*delta - if False: - for x0 in np.unique(xi): - for y0 in np.unique(yi): - els=(xi==x0) & (yi==y0) - if ~np.any(els): - continue - zmi=np.median(z[els]) - - this=(np.floor(xm/delta)*delta == x0) & (np.floor(ym/delta)*delta == y0) - print(f"({x0}, {y0}: {zmi-zm[this]}?") - -if __name__=='__main__': - __main__() -