def test_ohdev_ci(self): s32rows = testutils.read_stable32(resultfile='ohdev_decade.txt', datarate=1.0) for row in s32rows: data = testutils.read_datafile(data_file) (taus, devs, errs, ns) = allan.ohdev(data, rate=rate, taus=[row['tau']]) edf = allan.edf_greenhall(alpha=row['alpha'], d=3, m=row['m'], N=len(data), overlapping=True, modified=False, verbose=True) (lo, hi) = allan.confidence_intervals(devs[0], ci=0.68268949213708585, edf=edf) print("n check: ", testutils.check_equal(ns[0], row['n'])) print("dev check: ", testutils.check_approx_equal(devs[0], row['dev'])) print( "min dev check: ", lo, row['dev_min'], testutils.check_approx_equal(lo, row['dev_min'], tolerance=1e-3)) print( "max dev check: ", hi, row['dev_max'], testutils.check_approx_equal(hi, row['dev_max'], tolerance=1e-3))
def test_ohdev_ci(self): s32rows = testutils.read_stable32(resultfile='ohdev_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.ohdev(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=3, m=row['m'], N=len(data), overlapping=True, modified=False, 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=5e-3))
def test_phasedat_ohdev(self): s32_rows = testutils.read_stable32( 'phase_dat_ohdev_octave.txt' , 1.0 ) phase = testutils.read_datafile('PHASE.DAT') (taus,devs,errs,ns) = allan.ohdev(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 # F filter factor, 1 modified variance, m unmodified variance # S stride factor, 1 nonoverlapped estimator, m overlapped estimator (estimator stride = tau/S ) # N number of phase obs los=[] his=[] for (d,t, n) in zip(devs, taus, ns): #edf = greenhall_simple_edf( alpha=0, d=3, m=t, S=1, F=t, N=len(phase) ) edf2 = allan.edf_greenhall( alpha=0, d=3, m=int(t), N=len(phase), overlapping = True, modified=False ) #print(edf,edf2,edf2/edf) (lo,hi) = allan.confidence_interval( dev=d, edf=edf2 ) #allan.uncertainty_estimate(len(phase), t, d,ci=0.683,noisetype='wf') los.append(lo) his.append(hi) print("ohdev()") 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_ohdev_ci_and_noiseID(self): """ ADEV with confidence intervals, including noise-ID """ change_to_test_dir() s32rows = testutils.read_stable32( resultfile='stable32_OHDEV_octave.txt', datarate=1.0) for row in s32rows: phase = testutils.read_datafile('gps_1pps_phase_data.txt.gz') (taus, devs, errs, ns) = allan.ohdev(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="ohdev", 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_ohdev_ci(self): s32rows = testutils.read_stable32(resultfile='ohdev_decade.txt', datarate=1.0) for row in s32rows: data = testutils.read_datafile(data_file) (taus, devs, errs, ns) = allan.ohdev(data, rate=rate, taus=[ row['tau'] ]) edf = allan.edf_greenhall(alpha=row['alpha'],d=3,m=row['m'],N=len(data),overlapping=True, modified = False, verbose=True) (lo,hi) =allan.confidence_intervals(devs[0],ci=0.68268949213708585, edf=edf) print("n check: ", testutils.check_equal( ns[0], row['n'] ) ) print("dev check: ", testutils.check_approx_equal( devs[0], row['dev'] ) ) print("min dev check: ", lo, row['dev_min'], testutils.check_approx_equal( lo, row['dev_min'], tolerance=1e-3 ) ) print("max dev check: ", hi, row['dev_max'], testutils.check_approx_equal( hi, row['dev_max'], tolerance=1e-3 ) )
def test_ohdev_ci(self): """ Overlapping Hadamard deviation with confidence intervals """ s32rows = testutils.read_stable32(resultfile='ohdev_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.ohdev(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=3,m=row['m'],N=len(data),overlapping=True, modified = False, 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=5e-3 ) )
def test_ohdev_ci(self): s32rows = testutils.read_stable32(resultfile="ohdev_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.ohdev(data, rate=rate, data_type="freq", taus=[row["tau"]]) edf = allan.edf_greenhall( alpha=row["alpha"], d=3, m=row["m"], N=len(data), overlapping=True, modified=False, verbose=True ) (lo, hi) = allan.confidence_intervals(devs[0], ci=0.68268949213708585, 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=5e-3) )
def test_phasedat_ohdev(self): s32_rows = testutils.read_stable32('phase_dat_ohdev_octave.txt', 1.0) phase = testutils.read_datafile('PHASE.DAT') (taus, devs, errs, ns) = allan.ohdev(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 # F filter factor, 1 modified variance, m unmodified variance # S stride factor, 1 nonoverlapped estimator, m overlapped estimator (estimator stride = tau/S ) # N number of phase obs los = [] his = [] for (d, t, n) in zip(devs, taus, ns): #edf = greenhall_simple_edf( alpha=0, d=3, m=t, S=1, F=t, N=len(phase) ) edf2 = allan.edf_greenhall(alpha=0, d=3, m=int(t), N=len(phase), overlapping=True, modified=False) #print(edf,edf2,edf2/edf) (lo, hi) = allan.confidence_intervals(dev=d, ci=0.68268949213708585, edf=edf2) # 0.68268949213708585 #allan.uncertainty_estimate(len(phase), t, d,ci=0.683,noisetype='wf') 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_ohdev_ci_and_noiseID(self): """ ADEV with confidence intervals, including noise-ID """ change_to_test_dir() s32rows = testutils.read_stable32(resultfile='stable32_OHDEV_octave.txt', datarate=1.0) for row in s32rows: phase = testutils.read_datafile('gps_1pps_phase_data.txt.gz') (taus, devs, errs, ns) = allan.ohdev(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="ohdev", 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"
60) # log-spaced tau values from 10s and upwards rate = 1 / float(1.0) (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)
return out fname = "gps_1pps_phase_data.txt.gz" phase = read_datafile(fname,column=0) print len(phase), " values read: ", len(phase)/3600.0 , " hours" #f = to_fractional(f10MHz, 10e6 ) # convert to fractional frequency my_taus = numpy.logspace(1,6,60) # log-spaced tau values from 10s and upwards rate = 1/float(1.0) (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')
fname = "ocxo_frequency.txt" f10MHz = read_datafile(fname, column=0) f = to_fractional(f10MHz, 10e6) # convert to fractional frequency # log-spaced tau values from 10s and upwards my_taus = numpy.logspace(1, 5, 40) rate = 1/float(10) # data collected with 10s gate time (oadev_taus, oadev_devs, oadev_errs, ns) = allan.oadev( f, data_type='freq', rate=rate, taus=my_taus) (mdev_taus, mdev_devs, mdev_errs, ns) = allan.mdev( f, data_type='freq', rate=rate, taus=my_taus) (hdev_taus, hdev_devs, hdev_errs, ns) = allan.hdev( f, data_type='freq', rate=rate, taus=my_taus) (ohdev_taus, ohdev_devs, ohdev_errs, ns) = allan.ohdev( f, data_type='freq', rate=rate, taus=my_taus) plt.subplot(111, xscale="log", yscale="log") 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.xlabel('Taus (s)') plt.ylabel('ADEV') plt.legend() plt.grid() plt.show()
f = to_fractional(f10MHz, 10e6) # convert to fractional frequency my_taus = numpy.logspace(1, 5, 40) # log-spaced tau values from 10s and upwards rate = 1 / float(10) # data collected with 10s gate time (oadev_taus, oadev_devs, oadev_errs, ns) = allan.oadev(frequency=f, rate=rate, taus=my_taus) (mdev_taus, mdev_devs, mdev_errs, ns) = allan.mdev(frequency=f, rate=rate, taus=my_taus) (hdev_taus, hdev_devs, hdev_errs, ns) = allan.hdev(frequency=f, rate=rate, taus=my_taus) (ohdev_taus, ohdev_devs, ohdev_errs, ns) = allan.ohdev(frequency=f, rate=rate, taus=my_taus) plt.subplot(111, xscale="log", yscale="log") 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.xlabel('Taus (s)') plt.ylabel('ADEV') plt.legend() plt.grid() plt.show()
out=[] for f in flist: out.append( f/float(f0) - 1.0 ) return out fname = "ocxo_frequency.txt" f10MHz = read_datafile(fname,column=0) f = to_fractional(f10MHz, 10e6 ) # convert to fractional frequency my_taus = numpy.logspace(1,5,40) # log-spaced tau values from 10s and upwards rate = 1/float(10) # data collected with 10s gate time (oadev_taus,oadev_devs,oadev_errs,ns) = allan.oadev(frequency=f, rate=rate, taus=my_taus) (mdev_taus,mdev_devs,mdev_errs,ns) = allan.mdev(frequency=f, rate=rate, taus=my_taus) (hdev_taus,hdev_devs,hdev_errs,ns) = allan.hdev(frequency=f, rate=rate, taus=my_taus) (ohdev_taus,ohdev_devs,ohdev_errs,ns) = allan.ohdev(frequency=f, rate=rate, taus=my_taus) plt.subplot(111, xscale="log", yscale="log") 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.xlabel('Taus (s)') plt.ylabel('ADEV') plt.legend() plt.grid() plt.show()