Commit dc2945e5 authored by csongor's avatar csongor

remove unnecessary files

parent a8e3b269
import numpy as np
def smooth_power_2s(power, k, exclude=1, smooth_length=None):
if smooth_length == 0:
# No smoothing requested, just return the input array.
return power
if (exclude > 0):
k = k[exclude:]
excluded_power = np.copy(power[:exclude])
power = power[exclude:]
if (smooth_length is None) or (smooth_length < 0):
smooth_length = k[1]-k[0]
nmirror = int(5*smooth_length/(k[1]-k[0]))+2
print "nmirror", nmirror
mpower = np.r_[np.exp(2*np.log(power[0])-np.log(power[1:nmirror][::-1])),power,np.exp(2*np.log(power[-1])-np.log(power[-nmirror:-1][::-1]))]
print "mpower", mpower
mk = np.r_[(2*k[0]-k[1:nmirror][::-1]),k,(2*k[-1]-k[-nmirror:-1][::-1])]
mdk = np.r_[0.5*(mk[1]-mk[0]),0.5*(mk[2:]-mk[:-2]),0.5*(mk[-1]-mk[-2])]
p_smooth = np.empty(mpower.shape)
for i in xrange(len(p_smooth)):
l = i-int(2*smooth_length/mdk[i])-1
l = max(l,0)
u = i+int(2*smooth_length/mdk[i])+2
u = min(u,len(p_smooth))
C = np.exp(-(mk[l:u]-mk[i])**2/(2.*smooth_length**2))*mdk[l:u]
p_smooth[i] = np.sum(C*mpower[l:u])/np.sum(C)
p_smooth = p_smooth[nmirror - 1:-nmirror + 1]
# dk = 0.5*(k[2:] - k[:-2])
# dk = np.r_[0.5*(k[1]-k[0]),dk]
# dk = np.r_[dk,0.5*(k[-1]-k[-2])]
# if (smooth_length is None) or (smooth_length < 0):
# smooth_length = k[1]-k[0]
#
# p_smooth = np.empty(power.shape)
# for i in xrange(len(p_smooth)):
# l = i-int(2*smooth_length/dk[i])-1
# l = max(l,0)
# u = i+int(2*smooth_length/dk[i])+2
# u = min(u,len(p_smooth))
# C = np.exp(-(k[l:u]-k[i])**2/(2.*smooth_length**2))*dk[l:u]
# p_smooth[i] = np.sum(C*power[l:u])/np.sum(C)
if (exclude > 0):
p_smooth = np.r_[excluded_power,p_smooth]
return p_smooth
\ No newline at end of file
import pyximport; pyximport.install()
import extended
import numpy as np
print "///////////////////////////////////////First thing ////////////////////////"
k=np.sqrt(np.arange(600))
power = np.ones(600)
power[300]=1000
print power, k
smooth = extended.smooth_power_2s(power, k)
print "Smoooooth", smooth
print "///////////////////////////////////////Final thing ////////////////////////"
print "smooth.len == power.len" , len(smooth), len(power), len(power)==len(smooth)
\ No newline at end of file
import pyximport; pyximport.install()
import extended
import util
import numpy as np
print "///////////////////////////////////////First thing ////////////////////////"
n=8
ksq=np.sqrt(np.arange(n))
kk=np.arange(n)
power = np.ones(n**3).reshape((n,n,n))
# power[0][4][4]=1000
# power[1][4][4]=1000
# power[2][4][4]=1000
# power[3][4][4]=1000
power[n/2][n/2][n/2]=10000
# power[5][4][4]=1000
# power[6][4][4]=1000
# power[7][4][4]=1000
k = kk
sigma=k[1]-k[0]
mirrorsize=7
startindex=mirrorsize/2
endindex=n-mirrorsize/2
print power, k, power.shape
# smooth = extended.smooth_something(datablock=power, axis=(2),
# startindex=startindex, endindex=endindex,
# kernelfunction=extended.GaussianKernel, k=k,
# sigma=sigma)
smooth = util.apply_along_axis(extended.smoothie, (2), power,
startindex=startindex, endindex=endindex, k=k,
smooth_length=sigma)
print "Smoooooth", smooth
# doublesmooth = extended.smooth_something(datablock=smooth, axis=(1),
# startindex=startindex, endindex=endindex,
# kernelfunction=extended.GaussianKernel,
# k=k, sigma=sigma)
doublesmooth = util.apply_along_axis(extended.smoothie, (1), smooth,
startindex=startindex, endindex=endindex, k=k,
smooth_length=sigma)
print "DoubleSmooth", doublesmooth
# tripplesmooth = extended.smooth_something(datablock=doublesmooth, axis=(0),
# startindex=startindex, endindex=endindex,
# kernelfunction=extended.GaussianKernel,
# k=k, sigma=sigma)
tripplesmooth = util.apply_along_axis(extended.smoothie, (0), doublesmooth,
startindex=startindex, endindex=endindex, k=k,
smooth_length=sigma)
print "TrippleSmooth", tripplesmooth
print "///////////////////////////////////////Final thing ////////////////////////"
print "smooth.len == power.len" , tripplesmooth.shape, power.shape, power.shape==smooth.shape
\ No newline at end of file
import pyximport; pyximport.install()
import extended
import numpy as np
print "///////////////////////////////////////First thing ////////////////////////"
arr = np.ones(5, dtype=np.float)
arr[2] = 10.0
mk = np.arange(5, dtype=np.float)
mi = 3.0
smooth = 1.0
a = extended.GaussianKernel(arr,mk,mi,smooth)
print a
print "///////////////////////////////////////Second thing ////////////////////////"
n=12
ksq=np.sqrt(np.arange(n), dtype=np.float)
kk=np.arange(n, dtype=np.float)
power = np.ones(n, dtype=np.float)
# power[0][4][4]=1000
# power[1][4][4]=1000
# power[2][4][4]=1000
# power[3][4][4]=1000
power[n/2]=100
# power[5][4][4]=1000
# power[6][4][4]=1000
# power[7][4][4]=1000
k = kk
sigma=k[1]-k[0]
mirrorsize=7
startindex=mirrorsize/2
endindex=n-mirrorsize/2
print power, k, power.shape
smooth = extended.apply_kernel_along_array(power, startindex, endindex, k, sigma)
print smooth
print "///////////////////////////////////////Third thing ////////////////////////"
n=10
ksq=np.sqrt(np.arange(n))
kk=[np.arange(0,1,1.0/n)]*n**2
power = np.ones(n**3).reshape((n,n,n))
# power[0][4][4]=1000
# power[1][4][4]=1000
# power[2][4][4]=1000
# power[3][4][4]=1000
power[n/2][n/2][n/2]=10000
# power[5][4][4]=1000
# power[6][4][4]=1000
# power[7][4][4]=1000
distances = np.asarray(kk,dtype=np.float64)
sigma=k[1]-k[0]
mirrorsize=5
startindex=mirrorsize/2
endindex=n-mirrorsize/2
print k, power, power.shape
# smooth = extended.smooth_something(datablock=power, axis=(2),
# startindex=startindex, endindex=endindex,
# kernelfunction=extended.GaussianKernel, k=k,
# sigma=sigma)
smooth = extended.apply_along_axis(2, power,
startindex, endindex, distances,
sigma)
print "Smoooooth", smooth
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment