Beispiel #1
0
def test():
    from matplotlib import pyplot
    # make some dat
    import _test_dat as test_dat
    chans = num.arange(2048)
    offset = 1.0
    slope = .01
    en = offset + slope*chans
    data = test_dat.data1(en)
    pyplot.plot(en,data,'ko')
    #
    bgr = Background(bottom_width=4.,compress=4)
    bgr.calc(data,slope=slope)
    print bgr
    pyplot.plot(en,bgr.bgr,'r')
    #
    pyplot.show()
Beispiel #2
0
def test_fit():
    from matplotlib import pyplot
    import _test_dat as test_dat
    from xrf_bgr import Background
    #############################
    # Data
    #############################
    chans = num.arange(2048)
    offset = 1.0
    slope = .01
    en = offset + slope * chans
    data = test_dat.data1(en)
    pyplot.subplot(211)
    pyplot.plot(en, data, 'ko')

    #############################
    # fit
    #############################
    p1 = XrfPeak(label='p1', energy=4.)
    p2 = XrfPeak(label='p2', energy=7.)
    bgr = Background(bottom_width=4, compress=4)
    xspec = XrfSpectrum(data=data,
                        chans=chans,
                        peaks=[p1, p2],
                        bgr=bgr,
                        energy_offset=1.,
                        energy_slope=0.01,
                        chi_exp=0.5,
                        guess=True)

    # lets see how good the initial guess is
    pyplot.plot(en, xspec.peaks[0].calc(en), 'r')
    pyplot.plot(en, xspec.peaks[1].calc(en), 'r')

    # Now do the fit
    xspec.fit(opt_bgr=False, quiet=0)
    print xspec
    pyplot.subplot(212)
    en = xspec.energy_offset + xspec.energy_slope * chans
    pyplot.plot(en, data, 'ko')
    pyplot.plot(en, xspec.predicted, 'g')
    pyplot.plot(en, xspec.bgr.bgr, 'k-')

    #############################
    pyplot.show()
Beispiel #3
0
def test_fit():
    from matplotlib import pyplot
    import _test_dat as test_dat
    from   xrf_bgr import Background
    #############################
    # Data
    #############################
    chans = num.arange(2048)
    offset = 1.0
    slope = .01
    en = offset + slope*chans
    data = test_dat.data1(en)
    pyplot.subplot(211)
    pyplot.plot(en,data,'ko')

    #############################
    # fit
    #############################
    p1    = XrfPeak(label='p1',energy=4.)
    p2    = XrfPeak(label='p2',energy=7.)
    bgr   = Background(bottom_width=4,compress=4)
    xspec = XrfSpectrum(data=data,chans=chans,peaks=[p1,p2],bgr=bgr,
                        energy_offset=1.,energy_slope=0.01,chi_exp=0.5,
                        guess=True)

    # lets see how good the initial guess is
    pyplot.plot(en,xspec.peaks[0].calc(en),'r')
    pyplot.plot(en,xspec.peaks[1].calc(en),'r')
    
    # Now do the fit
    xspec.fit(opt_bgr=False,quiet=0)
    print xspec
    pyplot.subplot(212)
    en = xspec.energy_offset + xspec.energy_slope*chans
    pyplot.plot(en,data,'ko')
    pyplot.plot(en,xspec.predicted,'g')
    pyplot.plot(en,xspec.bgr.bgr,'k-')

    #############################
    pyplot.show()
Beispiel #4
0
def test_peak():
    from matplotlib import pyplot
    # make some dat
    import _test_dat as test_dat
    chans = num.arange(2048)
    offset = 1.0
    slope = .01
    en = offset + slope*chans
    data = test_dat.data1(en)
    pyplot.plot(en,data,'ko')
    #
    p1 = XrfPeak(label='1',energy=4.,ampl=550,fwhm=.5)
    print p1.get_params()
    p2 = XrfPeak(label='1',energy=7.,ampl=850,fwhm=.6)
    print p2.get_params()
    pyplot.plot(en,p1.calc(en),'r')
    pyplot.plot(en,p2.calc(en),'r')
    #
    (y,(mi,ma)) = p1._calc_range(en)
    print mi,ma
    pyplot.plot(en[mi:ma],y,'g')
    #
    pyplot.show()
Beispiel #5
0
def test_peak():
    from matplotlib import pyplot
    # make some dat
    import _test_dat as test_dat
    chans = num.arange(2048)
    offset = 1.0
    slope = .01
    en = offset + slope * chans
    data = test_dat.data1(en)
    pyplot.plot(en, data, 'ko')
    #
    p1 = XrfPeak(label='1', energy=4., ampl=550, fwhm=.5)
    print p1.get_params()
    p2 = XrfPeak(label='1', energy=7., ampl=850, fwhm=.6)
    print p2.get_params()
    pyplot.plot(en, p1.calc(en), 'r')
    pyplot.plot(en, p2.calc(en), 'r')
    #
    (y, (mi, ma)) = p1._calc_range(en)
    print mi, ma
    pyplot.plot(en[mi:ma], y, 'g')
    #
    pyplot.show()