def test_tdev_ci_and_noiseID(self): """ ADEV with confidence intervals, including noise-ID """ change_to_test_dir() s32rows = testutils.read_stable32( resultfile='stable32_TDEV_octave.txt', datarate=1.0) for row in s32rows: phase = testutils.read_datafile('gps_1pps_phase_data.txt.gz') (taus, devs, errs, ns) = allan.tdev(phase, rate=rate, data_type="phase", taus=[row['tau']]) dev = devs[0] #print(dev/row['dev']) assert np.isclose(dev, row['dev'], rtol=1e-2, atol=0) try: # CI including noise-ID (lo2, hi2) = allan.confidence_interval_noiseID(phase, dev, af=int(row['m']), dev_type="tdev", data_type="phase") print(" tau= %f lo/s32_lo = %f hi/s32_hi = %f " % (row['tau'], lo2 / row['dev_min'], hi2 / row['dev_max'])) assert np.isclose(lo2, row['dev_min'], rtol=1e-2, atol=0) assert np.isclose(hi2, row['dev_max'], rtol=1e-2, atol=0) except NotImplementedError: print("can't do CI for tau= %f" % row['tau']) pass
def test_phasedat_tdev(self): s32_rows = testutils.read_stable32( 'phase_dat_tdev_octave.txt' , 1.0 ) phase = testutils.read_datafile('PHASE.DAT') (taus,devs,errs,ns) = allan.tdev(phase, taus=[s32['tau'] for s32 in s32_rows]) # CI computation # alhpa= +2,...,-4 noise power # d= 1 first-difference variance, 2 allan variance, 3 hadamard variance # alpha+2*d >1 # m = tau/tau0 averaging factor # N number of phase obs los=[] his=[] for (d,t, n) in zip(devs, taus, ns): edf2 = allan.edf_greenhall( alpha=0, d=2, m=int(t), N=len(phase), overlapping = True, modified=True ) # covert to mdev # tdev = taus * mdev / np.sqrt(3.0) mdev = d/t*np.sqrt(3.0) (lo,hi) = allan.confidence_interval( dev=mdev, edf=edf2 ) # convert back to tdev lo = t*lo/np.sqrt(3.0) hi = t*hi/np.sqrt(3.0) los.append(lo) his.append(hi) print("tdev()") for (s32, t2, d2, lo2, hi2, n2) in zip(s32_rows, taus, devs, los, his, ns): print("s32 %03d %03f %1.6f %1.6f %1.6f" % (s32['n'], s32['tau'], s32['dev_min'], s32['dev'], s32['dev_max'])) print("at %03d %03f %1.6f %1.6f %1.6f" % (n2, t2, round(lo2,5), round(d2,5), round(hi2,5) )) testutils.check_approx_equal(s32['dev_min'], lo2, tolerance=1e-3) testutils.check_approx_equal(s32['dev_max'], hi2, tolerance=1e-3) print("----")
def test_phasedat_tdev(self): s32_rows = testutils.read_stable32('phase_dat_tdev_octave.txt', 1.0) phase = testutils.read_datafile('PHASE.DAT') (taus, devs, errs, ns) = allan.tdev(phase, taus=[s32['tau'] for s32 in s32_rows]) # CI computation # alhpa= +2,...,-4 noise power # d= 1 first-difference variance, 2 allan variance, 3 hadamard variance # alpha+2*d >1 # m = tau/tau0 averaging factor # N number of phase obs los = [] his = [] for (d, t, n) in zip(devs, taus, ns): #edf = greenhall_simple_edf( alpha=0, d=2, m=t, S=1, F=t, N=len(phase) ) edf2 = allan.edf_greenhall(alpha=0, d=2, m=int(t), N=len(phase), overlapping=True, modified=True) # covert to mdev # taus * md / np.sqrt(3.0) mdev = d / t * np.sqrt(3.0) (lo, hi) = allan.confidence_intervals(dev=mdev, ci=0.68268949213708585, edf=edf2) # 0.68268949213708585 # convert back to tdev lo = t * lo / np.sqrt(3.0) hi = t * hi / np.sqrt(3.0) los.append(lo) his.append(hi) for (s32, t2, d2, lo2, hi2, n2) in zip(s32_rows, taus, devs, los, his, ns): print("s32 %03d %03f %1.6f %1.6f %1.6f" % (s32['n'], s32['tau'], s32['dev_min'], s32['dev'], s32['dev_max'])) print("at %03d %03f %1.6f %1.6f %1.6f" % (n2, t2, round(lo2, 5), round(d2, 5), round(hi2, 5))) testutils.check_approx_equal(s32['dev_min'], lo2, tolerance=1e-3) testutils.check_approx_equal(s32['dev_max'], hi2, tolerance=1e-3) print("----")
def test_tdev_ci(self): """ Time Deviation with confidence intervals """ s32rows = testutils.read_stable32(resultfile='tdev_octave.txt', datarate=1.0) for row in s32rows: data = testutils.read_datafile(data_file) data = allan.frequency2fractional(data, mean_frequency=1.0e7) (taus, devs, errs, ns) = allan.tdev(data, rate=rate, data_type="freq", taus=[ row['tau'] ]) # NOTE! Here we use alhpa from Stable32-results for the allantools edf computation! edf = allan.edf_greenhall(alpha=row['alpha'],d=2,m=row['m'],N=len(data),overlapping=True, modified = True, verbose=True) (lo,hi) =allan.confidence_interval(devs[0], edf=edf) print("n check: ", testutils.check_equal( ns[0], row['n'] ) ) print("dev check: ", devs[0], row['dev'], testutils.check_approx_equal( devs[0], row['dev'], tolerance=2e-3 ) ) print("min dev check: ", lo, row['dev_min'], testutils.check_approx_equal( lo, row['dev_min'], tolerance=2e-3 ) ) print("max dev check: ", hi, row['dev_max'], testutils.check_approx_equal( hi, row['dev_max'], tolerance=2e-3 ) )
def test_tdev_ci_and_noiseID(self): """ ADEV with confidence intervals, including noise-ID """ change_to_test_dir() s32rows = testutils.read_stable32(resultfile='stable32_TDEV_octave.txt', datarate=1.0) for row in s32rows: phase = testutils.read_datafile('gps_1pps_phase_data.txt.gz') (taus, devs, errs, ns) = allan.tdev(phase, rate=rate, data_type="phase", taus=[row['tau']]) dev = devs[0] #print(dev/row['dev']) assert np.isclose(dev, row['dev'], rtol=1e-2, atol=0) try: # CI including noise-ID (lo2, hi2) = allan.confidence_interval_noiseID(phase, dev, af=int(row['m']), dev_type="tdev", data_type="phase") print(" tau= %f lo/s32_lo = %f hi/s32_hi = %f "% (row['tau'], lo2/row['dev_min'], hi2/row['dev_max'])) assert np.isclose(lo2, row['dev_min'], rtol=1e-2, atol=0) assert np.isclose(hi2, row['dev_max'], rtol=1e-2, atol=0) except NotImplementedError: print("can't do CI for tau= %f"%row['tau']) pass
def nbs14_test(): taus = [1, 2] devs = [] tol = 1e-4 # first tests that call the _phase functions print "nbs14 tests for phase data:" (taus2,adevs2,aerrs2,ns2) = allan.adev_phase( nbs14_phase, 1.0, taus) adevs = nbs14_devs[0] assert( check_devs( adevs2[0], adevs[0] ) ) assert( check_devs( adevs2[1], adevs[1] ) ) print "nbs14 adev OK" (taus2,adevs2,aerrs2,ns2) = allan.oadev_phase( nbs14_phase, 1.0, taus) oadevs = nbs14_devs[1] assert( check_devs( adevs2[0], oadevs[0] ) ) assert( check_devs( adevs2[1], oadevs[1] ) ) print "nbs14 oadev OK" (taus2,adevs2,aerrs2,ns2) = allan.mdev_phase( nbs14_phase, 1.0, taus) mdevs = nbs14_devs[2] assert( check_devs( adevs2[0], mdevs[0] ) ) assert( check_devs( adevs2[1], mdevs[1] ) ) print "nbs14 mdev OK" (taus2,adevs2,aerrs2,ns2) = allan.totdev_phase( nbs14_phase, 1.0, taus) totdevs = nbs14_devs[3] assert( check_devs( adevs2[0], totdevs[0] ) ) assert( check_devs( adevs2[1], totdevs[1] ) ) print "nbs14 totdev OK" (taus2,adevs2,aerrs2,ns2) = allan.hdev_phase( nbs14_phase, 1.0, taus) hdevs = nbs14_devs[4] assert( check_devs( adevs2[0], hdevs[0] ) ) assert( check_devs( adevs2[1], hdevs[1] ) ) print "nbs14 hdev OK" (taus2,adevs2,aerrs2,ns2) = allan.tdev_phase( nbs14_phase, 1.0, taus) tdevs = nbs14_devs[5] assert( check_devs( adevs2[0], tdevs[0] ) ) assert( check_devs( adevs2[1], tdevs[1] ) ) print "nbs14 tdev OK" (taus2,adevs2,aerrs2,ns2) = allan.ohdev_phase( nbs14_phase, 1.0, taus) ohdevs = nbs14_devs[6] assert( check_devs( adevs2[0], ohdevs[0] ) ) assert( check_devs( adevs2[1], ohdevs[1] ) ) print "nbs14 ohdev OK" # then the same tests for frequency data print "nbs14 tests for frequency data:" f_fract = [ float(f) for f in nbs14_f] (taus2,adevs2,aerrs2,ns2) = allan.adev( f_fract, 1.0, taus) adevs = nbs14_devs[0] assert( check_devs( adevs2[0], adevs[0] ) ) assert( check_devs( adevs2[1], adevs[1] ) ) print "nbs14 freqdata adev OK" (taus2,adevs2,aerrs2,ns2) = allan.oadev( f_fract, 1.0, taus) oadevs = nbs14_devs[1] assert( check_devs( adevs2[0], oadevs[0] ) ) assert( check_devs( adevs2[1], oadevs[1] ) ) print "nbs14 freqdata oadev OK" (taus2,adevs2,aerrs2,ns2) = allan.mdev( f_fract, 1.0, taus) mdevs = nbs14_devs[2] assert( check_devs( adevs2[0], mdevs[0] ) ) assert( check_devs( adevs2[1], mdevs[1] ) ) print "nbs14 freqdata mdev OK" (taus2,adevs2,aerrs2,ns2) = allan.totdev( f_fract, 1.0, taus) totdevs = nbs14_devs[3] assert( check_devs( adevs2[0], totdevs[0] ) ) assert( check_devs( adevs2[1], totdevs[1] ) ) print "nbs14 freqdata totdev OK" (taus2,adevs2,aerrs2,ns2) = allan.hdev( f_fract, 1.0, taus) hdevs = nbs14_devs[4] assert( check_devs( adevs2[0], hdevs[0] ) ) assert( check_devs( adevs2[1], hdevs[1] ) ) print "nbs14 freqdata hdev OK" (taus2,adevs2,aerrs2,ns2) = allan.tdev( f_fract, 1.0, taus) tdevs = nbs14_devs[5] assert( check_devs( adevs2[0], tdevs[0] ) ) assert( check_devs( adevs2[1], tdevs[1] ) ) print "nbs14 freqdata tdev OK" (taus2,adevs2,aerrs2,ns2) = allan.ohdev( f_fract, 1.0, taus) ohdevs = nbs14_devs[6] assert( check_devs( adevs2[0], ohdevs[0] ) ) assert( check_devs( adevs2[1], ohdevs[1] ) ) print "nbs14 freqdata ohdev OK" print "nbs14 all test OK"
""" ########################## # test stable32plot.py # ########################## """ import allantools from pylab import figure, show, plot from stable32plot import sigmaplot, dataplot #import 2 functions: sigmaplot,dataplot """#------------generate random data and cal adev-----------------""" x1 = allantools.noise.white(1000) (taus, adevs, errors, ns) = allantools.adev(x1) (taust, adevst, errorst, nst) = allantools.tdev(x1) (tauso, adevso, errorso, nso) = allantools.oadev(x1) x2 = allantools.noise.white(1000, 0.6) (taus2, adevs2, errors2, ns2) = allantools.oadev(x2) x3 = allantools.noise.white(1000, 0.5) (taus3, adevs3, errors3, ns3) = allantools.oadev(x3) x4 = allantools.noise.white(1000, 0.4) (taus4, adevs4, errors4, ns4) = allantools.oadev(x4) x5 = allantools.noise.white(1000, 0.3) (taus5, adevs5, errors5, ns5) = allantools.oadev(x5) x6 = allantools.noise.white(1000, 0.2) (taus6, adevs6, errors6, ns6) = allantools.oadev(x6)
(mdev_taus, mdev_devs, mdev_errs, ns) = allan.mdev(phase=phase, rate=rate, taus=my_taus) (totdev_taus, totdev_devs, totdev_errs, ns) = allan.totdev(phase=phase, rate=rate, taus=my_taus) (tie_taus, tie_devs, tie_errs, ns) = allan.tierms(phase=phase, rate=rate, taus=my_taus) #(mtie_taus,mtie_devs,mtie_errs,ns) = allan.mtie(phase=phase, rate=rate, taus=my_taus) (tdev_taus, tdev_devs, tdev_errs, ns) = allan.tdev(phase=phase, rate=rate, taus=my_taus) (tdev2_taus, tdev2_devs, tdev2_errs, ns2) = allan.tdev(frequency=allan.phase2frequency(phase, 1.0), rate=rate, taus=my_taus) plt.subplot(111, xscale="log", yscale="log") plt.errorbar(adev_taus, adev_devs, yerr=adev_errs, label='ADEV') plt.errorbar(oadev_taus, oadev_devs, yerr=oadev_errs, label='OADEV') plt.errorbar(mdev_taus, mdev_devs, yerr=mdev_errs, label='MDEV') plt.errorbar(hdev_taus, hdev_devs, yerr=hdev_errs, label='HDEV') plt.errorbar(ohdev_taus, ohdev_devs, yerr=ohdev_errs, label='OHDEV') plt.errorbar(tdev_taus, tdev_devs, yerr=tdev_errs, label='TDEV(phase)') plt.errorbar(tdev2_taus, tdev2_devs, yerr=tdev2_errs, label='TDEV(frequency)')
(mdev_taus, mdev_devs, mdev_errs, ns) = allan.mdev(phase, rate=rate, taus=my_taus) (totdev_taus, totdev_devs, totdev_errs, ns) = allan.totdev(phase, rate=rate, taus=my_taus) (tie_taus, tie_devs, tie_errs, ns) = allan.tierms(phase, rate=rate, taus=my_taus) #(mtie_taus,mtie_devs,mtie_errs,ns) = allan.mtie(phase=phase, rate=rate, taus=my_taus) (tdev_taus, tdev_devs, tdev_errs, ns) = allan.tdev(phase, rate=rate, taus=my_taus) (tdev2_taus, tdev2_devs, tdev2_errs, ns2) = allan.tdev(allan.phase2frequency(phase, 1.0), data_type='freq', rate=rate, taus=my_taus) plt.subplot(111, xscale="log", yscale="log") plt.errorbar(adev_taus, adev_devs, yerr=adev_errs, label='ADEV') plt.errorbar(oadev_taus, oadev_devs, yerr=oadev_errs, label='OADEV') plt.errorbar(mdev_taus, mdev_devs, yerr=mdev_errs, label='MDEV') plt.errorbar(hdev_taus, hdev_devs, yerr=hdev_errs, label='HDEV') plt.errorbar(ohdev_taus, ohdev_devs, yerr=ohdev_errs, label='OHDEV') plt.errorbar(tdev_taus, tdev_devs, yerr=tdev_errs, label='TDEV(phase)')
(adev_taus,adev_devs,adev_errs,ns) = allan.adev(phase=phase, rate=rate, taus=my_taus) (oadev_taus,oadev_devs,oadev_errs,ns) = allan.oadev(phase=phase, rate=rate, taus=my_taus) (hdev_taus,hdev_devs,hdev_errs,ns) = allan.hdev(phase=phase, rate=rate, taus=my_taus) (ohdev_taus,ohdev_devs,ohdev_errs,ns) = allan.ohdev(phase=phase, rate=rate, taus=my_taus) (mdev_taus,mdev_devs,mdev_errs,ns) = allan.mdev(phase=phase, rate=rate, taus=my_taus) (totdev_taus,totdev_devs,totdev_errs,ns) = allan.totdev(phase=phase, rate=rate, taus=my_taus) (tie_taus,tie_devs,tie_errs,ns) = allan.tierms(phase=phase, rate=rate, taus=my_taus) #(mtie_taus,mtie_devs,mtie_errs,ns) = allan.mtie(phase=phase, rate=rate, taus=my_taus) (tdev_taus,tdev_devs,tdev_errs,ns) = allan.tdev(phase=phase, rate=rate, taus=my_taus) (tdev2_taus,tdev2_devs,tdev2_errs,ns2) = allan.tdev(frequency=allan.phase2frequency(phase,1.0), rate=rate, taus=my_taus) plt.subplot(111, xscale="log", yscale="log") plt.errorbar(adev_taus, adev_devs, yerr=adev_errs, label='ADEV') plt.errorbar(oadev_taus, oadev_devs, yerr=oadev_errs, label='OADEV') plt.errorbar(mdev_taus, mdev_devs, yerr=mdev_errs, label='MDEV') plt.errorbar(hdev_taus, hdev_devs, yerr=hdev_errs, label='HDEV') plt.errorbar(ohdev_taus, ohdev_devs, yerr=ohdev_errs, label='OHDEV') plt.errorbar(tdev_taus, tdev_devs, yerr=tdev_errs, label='TDEV(phase)') plt.errorbar(tdev2_taus, tdev2_devs, yerr=tdev2_errs, label='TDEV(frequency)') plt.errorbar(totdev_taus, totdev_devs, yerr=totdev_errs, label='TOTDEV') plt.errorbar(tie_taus, tie_devs, yerr=tie_errs, label='TIERMS')
""" ########################## # test stable32plot.py # ########################## """ import allantools from pylab import figure,show,plot from stable32plot import sigmaplot,dataplot#import 2 functions: sigmaplot,dataplot """#------------generate random data and cal adev-----------------""" x1 = allantools.noise.white(1000) (taus, adevs, errors, ns) = allantools.adev(x1) (taust, adevst, errorst, nst) = allantools.tdev(x1) (tauso, adevso, errorso, nso) = allantools.oadev(x1) x2=allantools.noise.white(1000,0.6) (taus2,adevs2,errors2,ns2)=allantools.oadev(x2) x3=allantools.noise.white(1000,0.5) (taus3,adevs3,errors3,ns3)=allantools.oadev(x3) x4=allantools.noise.white(1000,0.4) (taus4,adevs4,errors4,ns4)=allantools.oadev(x4) x5=allantools.noise.white(1000,0.3) (taus5,adevs5,errors5,ns5)=allantools.oadev(x5) x6=allantools.noise.white(1000,0.2)