Merge branch 'master' of https://git.ipr.univ-rennes1.fr/mcammara/mcutils
This commit is contained in:
commit
585c57c33a
24
mcutils.py
24
mcutils.py
|
@ -14,8 +14,11 @@ import collections
|
||||||
import os
|
import os
|
||||||
import pylab as plt
|
import pylab as plt
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
sqrt2=np.sqrt(2)
|
sqrt2=np.sqrt(2)
|
||||||
|
|
||||||
|
_svd_ret = collections.namedtuple("svd_return",["basis","s",\
|
||||||
|
"population","data"])
|
||||||
|
|
||||||
### COLORS, ETC ###
|
### COLORS, ETC ###
|
||||||
colors = None
|
colors = None
|
||||||
|
@ -136,6 +139,27 @@ def poly_approximant(x,y,order=10,allowExtrapolation=False,fill_value=0):
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
def svd(data,ncomp=None,truncate=True):
|
||||||
|
""" do SVD based cleaning
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
ncomp : int
|
||||||
|
number of components to keep
|
||||||
|
truncate : bool
|
||||||
|
if True, returns only basis and populations of up to ncomp
|
||||||
|
"""
|
||||||
|
# first index is time/T/P
|
||||||
|
u,s,v = np.linalg.svd(data,full_matrices=False)
|
||||||
|
if ncomp is not None:
|
||||||
|
s[ncomp:]=0
|
||||||
|
data = np.dot(u,np.dot(np.diag(s),v))
|
||||||
|
if truncate:
|
||||||
|
v = v[:ncomp]
|
||||||
|
u = u[:,:ncomp]
|
||||||
|
return _svd_ret(basis=v,s=s,population=u.T,data=data)
|
||||||
|
|
||||||
|
|
||||||
def smoothing(x,y,err=None,k=5,s=None,newx=None,derivative_order=0):
|
def smoothing(x,y,err=None,k=5,s=None,newx=None,derivative_order=0):
|
||||||
idx = np.isnan(x)|np.isnan(y)
|
idx = np.isnan(x)|np.isnan(y)
|
||||||
idx = ~ idx
|
idx = ~ idx
|
||||||
|
|
Loading…
Reference in New Issue