def test_h_and_z(): phases = np.linspace(0, 1, 101) weights = np.zeros(101) weights[:50] = 1 ans = 0.01980198019801975 res = es.hm(phases) assert_allclose(res, ans, atol=1.0e-7) ans = 40.54180942257532 res = es.hmw(phases, weights) assert_allclose(res, ans, atol=1.0e-7) res = es.z2m(phases, m=4) assert len(res) == 4 ans = 0.0792079207920788 assert_allclose(res[3], ans, atol=1.0e-7) ans = 40.54180942257532 res = es.hmw(phases, weights) assert_allclose(res, ans, atol=1.0e-7) res = es.z2mw(phases, weights, m=4) assert len(res) == 4 ans = 45.05833019383544 assert_allclose(res[3], ans, atol=1.0e-7)
def get_Z2(obsid, model, par_file, m): """ Calculates the Z^2 statistic given the ObsID, binary model name (if there's one), and the parameter file. obsid - Observation ID of the object of interest (10-digit str) model - binary model being used (ELL1, BT, DD, or DDK for now) par_file - orbital parameter file for input into PINT's photonphase m - number of harmonics """ filename = Lv0_dirs.NICERSOFT_DATADIR + obsid + '_pipe/cleanfilt_phase' if model == '': filename = filename + '.evt' if model != 'ELL1' and model != 'BT' and model != 'DD' and model != 'DDK': raise ValueError( "The model should be one of ELL1, BT, DD, or DDK! Update if a new model has been added to PINT." ) else: filename = filename + '_' + model + '.evt' event = fits.open(filename) if 'PULSE_PHASE' not in event[1].columns.names: raise ValueError( 'The PULSE_PHASE column is not in the PINT-processed event file! Check your steps again.' ) phases = event[1].data['PULSE_PHASE'] z_vals = z2m(phases, m=m) probs = sf_z2m(z_vals) significances = sig2sigma(probs) return significances
def get_Z2(phases, m): """ Calculate the Z^2 significances given the event file and harmonic number m eventfile - name of event file m - number of harmonics """ z_vals = z2m(phases, m=m) probs = sf_z2m(z_vals) significances = sig2sigma(probs) return significances
def get_Z2(eventfile, m): """ Calculate the Z^2 significances given the event file and harmonic number m eventfile - name of event file m - number of harmonics """ phases = fits.open(eventfile)[1].data['PULSE_PHASE'] z_vals = z2m(phases, m=m) probs = sf_z2m(z_vals) significances = sig2sigma(probs) return significances
print('Ignoring file {0} with good time {1:0.2f}.'.format( fn, good_time)) continue tlist.append(t) log.info('Concatenating files') if len(tlist) == 1: etable = tlist[0] else: etable = vstack(tlist, metadata_conflicts='silent') del tlist m = args.maxharm ts_func = cached_zm if args.ztest else cached_hm phasesinitial = etable['PULSE_PHASE'].astype(np.float32) hbest = z2m(phasesinitial, m=m)[-1] if args.ztest else hm(phasesinitial, m=m) eminbest = 0.0 emaxbest = 100.0 ts_name = "Ztest" if args.ztest else "Htest" if args.ztest: print("Initial {0} = {1}".format(ts_name, np.round(hbest, 3))) else: print("Initial {0} = {1} ({2} sigma)".format(ts_name, np.round(hbest, 3), np.round(h2sig(hbest), 3))) # assemble cache cache = np.empty([m, 2, len(phasesinitial)], dtype=np.float32) for i in xrange(m): cache[i, 0] = np.cos(phasesinitial * (2 * np.pi * (i + 1))) cache[i, 1] = np.sin(phasesinitial * (2 * np.pi * (i + 1))) cached_hm._cache = cached_zm._cache = cache
default=32, type=int) parser.add_argument("--outfile", help="Output file for plot (type determined by extension)", default=None) args = parser.parse_args() hdulist = pyfits.open(args.evtfile) dat = hdulist[1].data hdr = hdulist[1].header ph = dat['PULSE_PHASE'] try: print("Z test = {} ({} sig)".format( z2m(ph)[-1], sig2sigma(sf_z2m(z2m(ph)[-1], lo)))) except: pass print("H test = {} ({} sig)".format(hm(ph), h2sig(hm(ph)))) fig, ax = plt.subplots(figsize=(8, 4.5)) h, edges = np.histogram(ph, bins=np.linspace(0.0, 1.0, args.nbins, endpoint=True)) try: if hdr['EXPOSURE'] > 0: h = np.array(h, dtype=np.float) / (np.float(hdr['EXPOSURE']) / args.nbins) rates = True except: rates = False