Example #1
0
def test_fit():
    data_string = """
    time   velocity   uncertainty
    2.23          139               16
    9.37           96                9
    11.64           62               17
    16              20               25
    23.21          -55               10
    """

    df_data = read_data(data_string)
    time = df_data['time'].values
    velocity = df_data['velocity'].values
    dy = df_data['uncertainty'].values
    slope_w, yint_w, var_slope, var_inter = LineFitWt(time, velocity, dy)
    ntest.assert_almost_equal(
        [slope_w, yint_w, var_slope, var_inter],
        [-9.9656001, 179.924646, 0.5982539, 140.7892905])
Example #2
0
get_ipython().magic('matplotlib inline')

plt.close('all')
from a212libs.utils import read_data
from a212libs.linfit import LineFitWt

data_string = """
time   velocity   uncertainty
   2.23          139               16
   9.37           96                9
  11.64           62               17
  16              20               25
  23.21          -55               10
"""
df_data = read_data(data_string)
time = df_data['time'].values
velocity = df_data['velocity'].values
dy = df_data['uncertainty'].values

fig,ax = plt.subplots(1,1,figsize=(10,8))
out=ax.errorbar('time','velocity',yerr='uncertainty',data=df_data,
                fmt='bo',ecolor='r',marker='d',mec='r',mfc='y',ms=12,zorder=10,
               label='data')
limits=ax.axis()
xvals=np.array(limits[:2])
slope_w,yint_w, var_slope, var_inter = LineFitWt(time,velocity,dy)
yvals = yint_w + slope_w*xvals
ax.plot(xvals,yvals,'g-',label = 'weights')
sigma_slope = np.sqrt(var_slope)
sigma_intercept = np.sqrt(var_inter)
Example #3
0
    return chisquare

data_string = """
time   velocity   uncertainty
  2.23          139               16
  4.78          123               16
  7.21          115                4
  9.37           96                9
 11.64           62               17
 14.23           54               17
 16.55           10               12
 18.70           -3               15
 21.05          -13               18
 23.21          -55               10
"""
df_data = read_data(data_string)
time = df_data['time'].values
velocity = df_data['velocity'].values
dy = df_data['uncertainty'].values

fig,ax = plt.subplots(1,1)
out=ax.errorbar('time','velocity',yerr='uncertainty',data=df_data,
                fmt='bo',ecolor='r',marker='d',mec='r',mfc='y',ms=12,zorder=10,
               label='data')
limits=ax.axis()
slope_nw,yint_nw = LineFit(time,velocity)
xvals=np.array(limits[:2])
yvals = yint_nw + slope_nw*xvals
chir_nw = reduced_chi(time,velocity,slope_nw,yint_nw)
ax.plot(xvals,yvals,'b-',label = 'noweights')
ax.text(0.2,0,'unwght slope, int = {:5.2f}, {:5.2f}'.format(slope_nw,yint_nw))