Skip to content

Commit

Permalink
pt_blockmedian.py: rolled back changes to help with merge of tyler's …
Browse files Browse the repository at this point in the history
…branch
  • Loading branch information
Ben Smith committed Jun 17, 2020
1 parent b4fbc7c commit 779cecd
Showing 1 changed file with 7 additions and 36 deletions.
43 changes: 7 additions & 36 deletions pt_blockmedian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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__()

0 comments on commit 779cecd

Please sign in to comment.