Commit 0737d4d8 authored by Marco Selig's avatar Marco Selig

smooth_power adjusted to 'new standard'.

parent c3822414
...@@ -134,50 +134,83 @@ def weight_power(domain,spec,power=1,pindex=None,pundex=None,**kwargs): ...@@ -134,50 +134,83 @@ def weight_power(domain,spec,power=1,pindex=None,pundex=None,**kwargs):
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
def smooth_power(power,kindex,mode="2s",exclude=1,sigma=-1): def smooth_power(spec,domain=None,kindex=None,mode="2s",exclude=1,sigma=-1,**kwargs):
""" """
Smoothes a power spectrum via convolution with a Gaussian kernel. Smoothes a power spectrum via convolution with a Gaussian kernel.
Parameters Parameters
---------- ----------
power : ndarray spec : ndarray
The power spectrum to be smoothed. The power spectrum to be smoothed.
domain : space, *optional*
kindex : ndarray The space wherein the power spectrum is defined (default: None).
The array specifying the coordinate indices in conjugate space. kindex : ndarray, *optional*
The array specifying the coordinate indices in conjugate space
mode : string (default: None).
Specifies the smoothing mode (default: "2s") : mode : string, *optional*
Specifies the smoothing mode (default: "2s") :
- "ff" (smoothing in the harmonic basis using fast Fourier transformations) - "ff" (smoothing in the harmonic basis using fast Fourier transformations)
- "bf" (smoothing in the position basis by brute force) - "bf" (smoothing in the position basis by brute force)
- "2s" (smoothing in the position basis restricted to a 2-`sigma` interval) - "2s" (smoothing in the position basis restricted to a 2-`sigma` interval)
exclude : scalar exclude : scalar, *optional*
Excludes the first power spectrum entries from smoothing, indicated by Excludes the first power spectrum entries from smoothing, indicated by
the given integer scalar (default = 1, the monopol is not smoothed). the given integer scalar (default = 1, the monopol is not smoothed).
sigma : scalar, *optional*
FWHM of Gaussian convolution kernel (default = -1, `sigma` is set
automatically).
sigma : scalar Returns
FWHM of Gaussian convolution kernel (default = -1, `sigma` is set -------
automatically). smoothspec : ndarray
The smoothed power spectrum.
Returns Other Parameters
------- ----------------
smoothpower : ndarray log : bool, *optional*
The smoothed power spectrum. Flag specifying if the spectral binning is performed on logarithmic
scale or not; if set, the number of used bins is set
automatically (if not given otherwise); by default no binning
is done (default: None).
nbin : integer, *optional*
Number of used spectral bins; if given `log` is set to ``False``;
integers below the minimum of 3 induce an automatic setting;
by default no binning is done (default: None).
binbounds : {list, array}, *optional*
User specific inner boundaries of the bins, which are preferred
over the above parameters; by default no binning is done
(default: None). vmin : {scalar, list, ndarray, field}, *optional*
Lower limit of the uniform distribution if ``random == "uni"``
(default: 0).
Raises Raises
------ ------
KeyError KeyError
If `mode` is unsupported. If `mode` is unsupported.
""" """
## check implicit kindex
if(kindex is None):
if(isinstance(domain,space)):
try:
domain.set_power_indices(**kwargs)
except:
raise ValueError(about._errors.cstring("ERROR: invalid input."))
else:
kindex = domain.power_indices.get("kindex")
else:
raise TypeError(about._errors.cstring("ERROR: insufficient input."))
## check explicit power indices
else:
kindex = np.array(kindex,dtype=domain.vol.dtype)
## smoothing
if(mode=="2s"): if(mode=="2s"):
return gs.smooth_power_2s(power,kindex,exclude=exclude,smooth_length=sigma) return gs.smooth_power_2s(spec,kindex,exclude=exclude,smooth_length=sigma)
elif(mode=="ff"): elif(mode=="ff"):
return gs.smooth_power(power,kindex,exclude=exclude,smooth_length=sigma) return gs.smooth_power(spec,kindex,exclude=exclude,smooth_length=sigma)
elif(mode=="bf"): elif(mode=="bf"):
return gs.smooth_power_bf(power,kindex,exclude=exclude,smooth_length=sigma) return gs.smooth_power_bf(spec,kindex,exclude=exclude,smooth_length=sigma)
else: else:
raise KeyError(about._errors.cstring("ERROR: unsupported mode '"+str(mode)+"'.")) raise KeyError(about._errors.cstring("ERROR: unsupported mode '"+str(mode)+"'."))
...@@ -359,7 +392,7 @@ def infer_power(m,domain=None,Sk=None,D=None,pindex=None,pundex=None,kindex=None ...@@ -359,7 +392,7 @@ def infer_power(m,domain=None,Sk=None,D=None,pindex=None,pundex=None,kindex=None
## check domain ## check domain
if(domain is None): if(domain is None):
if(Sk is None): if(Sk is None):
raise TypeError(about._errors.cstring("ERROR: invalid input.")) raise TypeError(about._errors.cstring("ERROR: insufficient input."))
else: else:
domain = Sk.domain domain = Sk.domain
elif(not isinstance(domain,space)): elif(not isinstance(domain,space)):
...@@ -367,24 +400,24 @@ def infer_power(m,domain=None,Sk=None,D=None,pindex=None,pundex=None,kindex=None ...@@ -367,24 +400,24 @@ def infer_power(m,domain=None,Sk=None,D=None,pindex=None,pundex=None,kindex=None
## check implicit power indices ## check implicit power indices
if(pindex is None)or(kindex is None)or(rho is None): if(pindex is None)or(kindex is None)or(rho is None):
try: try:
self.domain.set_power_indices(**kwargs) domain.set_power_indices(**kwargs)
except: except:
raise ValueError(about._errors.cstring("ERROR: invalid input.")) raise ValueError(about._errors.cstring("ERROR: invalid input."))
else: else:
pindex = self.domain.power_indices.get("pindex") pindex = domain.power_indices.get("pindex")
kindex = self.domain.power_indices.get("kindex") kindex = domain.power_indices.get("kindex")
rho = self.domain.power_indices.get("rho") rho = domain.power_indices.get("rho")
if(pundex is None): if(pundex is None):
pundex = self.domain.power_indices.get("pundex") pundex = domain.power_indices.get("pundex")
elif(not isinstance(pundex,list)): elif(not isinstance(pundex,list)):
raise TypeError(about._errors.cstring("ERROR: invalid input.")) raise TypeError(about._errors.cstring("ERROR: invalid input."))
elif(len(pundex)!=np.size(self.domain.dim(split=True))): elif(len(pundex)!=np.size(domain.dim(split=True))):
raise ValueError(about._errors.cstring("ERROR: dimension mismatch ( "+str(len(pundex))+" <> "+str(np.size(self.domain.dim(split=True)))+" ).")) raise ValueError(about._errors.cstring("ERROR: dimension mismatch ( "+str(len(pundex))+" <> "+str(np.size(domain.dim(split=True)))+" )."))
## check explicit power indices ## check explicit power indices
else: else:
pindex = np.array(pindex,dtype=np.int) pindex = np.array(pindex,dtype=np.int)
if(not np.all(np.array(np.shape(pindex))==self.domain.dim(split=True))): if(not np.all(np.array(np.shape(pindex))==domain.dim(split=True))):
raise ValueError(about._errors.cstring("ERROR: shape mismatch ( "+str(np.array(np.shape(pindex)))+" <> "+str(self.domain.dim(split=True))+" ).")) raise ValueError(about._errors.cstring("ERROR: shape mismatch ( "+str(np.array(np.shape(pindex)))+" <> "+str(domain.dim(split=True))+" )."))
kindex = np.array(kindex,dtype=domain.vol.dtype) kindex = np.array(kindex,dtype=domain.vol.dtype)
rho = np.array(rho,dtype=np.int) rho = np.array(rho,dtype=np.int)
if(pundex is None): if(pundex is None):
...@@ -392,8 +425,8 @@ def infer_power(m,domain=None,Sk=None,D=None,pindex=None,pundex=None,kindex=None ...@@ -392,8 +425,8 @@ def infer_power(m,domain=None,Sk=None,D=None,pindex=None,pundex=None,kindex=None
pundex = list(np.unravel_index(np.unique(pindex,return_index=True,return_inverse=False)[1],pindex.shape,order='C')) pundex = list(np.unravel_index(np.unique(pindex,return_index=True,return_inverse=False)[1],pindex.shape,order='C'))
elif(not isinstance(pundex,list)): elif(not isinstance(pundex,list)):
raise TypeError(about._errors.cstring("ERROR: invalid input.")) raise TypeError(about._errors.cstring("ERROR: invalid input."))
elif(len(pundex)!=np.size(self.domain.dim(split=True))): elif(len(pundex)!=np.size(domain.dim(split=True))):
raise ValueError(about._errors.cstring("ERROR: dimension mismatch ( "+str(len(pundex))+" <> "+str(np.size(self.domain.dim(split=True)))+" ).")) raise ValueError(about._errors.cstring("ERROR: dimension mismatch ( "+str(len(pundex))+" <> "+str(np.size(domain.dim(split=True)))+" )."))
## check projection operator ## check projection operator
if(Sk is None): if(Sk is None):
Sk = projection_operator(domain,assign=pindex) Sk = projection_operator(domain,assign=pindex)
......
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