Examples with fit routines


In [4]:
%matplotlib inline

In [1]:
from xastropy.xutils import afits as xafits

Dummy function


In [44]:
x = np.linspace(0.,np.pi,100)
y = np.sin(x)

Polynomial fit


In [46]:
reload(xafits)
fdict = xafits.func_fit(x,y,'polynomial',4)

In [16]:
xdb.xplot(x,y,xafits.func_val(x,fdict))


B-spline fit


In [40]:
reload(xafits)
bfdict = xafits.func_fit(x,y,'bspline',3,everyn=25)

In [42]:
xdb.xplot(x,y,xafits.func_val(x,bfdict))


Iterative fit


In [49]:
y[50] = 3.
# Fit
dfit, mask = xafits.iter_fit(x, y, 'bspline', 3, everyn=25)
assert np.sum(mask) == 1
x2 = np.linspace(0,np.pi,100)
y2 = xafits.func_val(x2,dfit)
np.testing.assert_allclose(y2[50], 1.000155331836333)

In [50]:
xdb.xplot(x,y,xafits.func_val(x,dfit))



In [51]:
dfit


Out[51]:
{'everyn': 20,
 'func': u'bspline',
 'knots': array([-0.7979798 , -0.39393939,  0.03030303,  0.43434343]),
 'order': 3,
 'tck': (array([-1.        , -1.        , -1.        , -1.        , -0.7979798 ,
         -0.39393939,  0.03030303,  0.43434343,  1.        ,  1.        ,
          1.        ,  1.        ]),
  array([  3.71017206e-06,   1.05740956e-01,   4.23334865e-01,
           8.80504494e-01,   1.07268597e+00,   7.98292381e-01,
           2.97523416e-01,  -2.63739149e-04,   0.00000000e+00,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00]),
  3),
 'xmax': 3.1415926535897931,
 'xmin': 0.0}

In [ ]: