def find_transit_file(dir_nm, unix_time=None, src=None, trans=True, verbose=True): flist = glob.glob(dir_nm) tdel = [] print "Looking at %d files" % len(flist) for ii in range(len(flist)): if trans is True: try: r = andata.Reader(flist[ii]) if ii == 0 and src != None: time_trans = eph.transit_times(src, r.time[0]) elif unix_time != None: time_trans = unix_time else: continue tdel.append(np.min(abs(time_trans - r.time))) if verbose is True: print flist[ii] print "%f hours away \n" % np.min( abs(time_trans - r.time)) / 3600.0 except (KeyError, IOError): print "That one didn't work" elif trans is False: try: f = h5py.File(flist[ii], 'r') times = f['index_map']['time'].value['ctime'][0] f.close() time_trans = unix_time tdel.append(np.min(abs(time_trans - times))) except (ValueError, IOError): pass tdel = np.array(tdel) return flist[np.argmin(tdel)], tdel.min()
def find_transit(time0='Now', src=eph.CasA): import time if time0 == 'Now': time0 = time.time() # Get reference datetime from unixtime dt_now = eph.unix_to_datetime(time0) dt_now = dt_now.isoformat() # Only use relevant characters in datetime string dt_str = dt_now.replace("-", "")[:7] dirnm = '/mnt/gong/archive/' + dt_str filelist = glob.glob(dirnm + '*/*h5') # Step through each file and find that day's transit for ff in filelist: try: andataReader = andata.Reader(ff) acqtimes = andataReader.time trans_time = eph.transit_times(src, time0) #print ff # print eph.transit_RA(trans_time), eph.transit_RA(acqtimes[0]) del andataReader if np.abs(acqtimes - trans_time[0]).min() < 1000.0: # print "On ", eph.unix_to_datetime(trans_time[0]) # print "foundit in %s \n" % ff return ff break except (KeyError, ValueError, IOError): pass return None
def fringestop_and_sum(fn, feeds, freq, src, transposed=True, return_unfs=True, meridian=False, del_t=1500, frick=None): """ Take an input file fn and a set of feeds and return a formed beam on src. """ if transposed is True: r = andata.Reader(fn) r.freq_sel = freq X = r.read() times = r.time else: f = h5py.File(fn, 'r') times = f['index_map']['time'].value['ctime'] print "Read in data" # Get transit time for source src_trans = eph.transit_times(src, times[0]) del_phi = 1.30 * (src._dec - np.radians(eph.CHIMELATITUDE)) * np.sin( np.radians(1.988)) del_phi *= (24 * 3600.0) / (2 * np.pi) # Adjust the transit time accordingly src_trans += del_phi # Select +- del_t of transit, accounting for the mispointing t_range = np.where((times < src_trans + del_t) & (times > src_trans - del_t))[0] times = times[t_range[0]:t_range[-1]] #[offp::2] test print "Time range:", times[0], times[-1] # Generate correctly ordered corrinputs corrinput_real = gen_inp()[0] inp = np.array(corrinput_real) # Ensure vis array is in correct order (freq, prod, time) if transposed is True: data = X.vis[:, :, t_range[0]:t_range[-1]] freq = X.freq else: v = f['vis'][t_range[0]:t_range[-1], freq, :] vis = v['r'] + 1j * v['i'] data = vis.transpose()[np.newaxis] del vis freq = 800 - 400.0 / 1024 * freq freq = np.array([freq]) # autos = auto_corrs(256) # offp = (abs(data[:, autos, 0::2]).mean() > (abs(data[:, autos, 1::2]).mean())).astype(int) # data = data[..., offp::2] test data_unfs = sum_corrs(data.copy(), feeds) ra_ = eph.transit_RA(times) ra_2 = nolan_ra(times) #ra_ = ra_2.copy() if meridian is True: ra = np.ones_like(ra_) * np.degrees(src._ra) else: ra = ra_ print len(inp) dfs = tools.fringestop_pathfinder(data.copy(), ra, freq, inp, src) #dfs = fringestop_pathfinder(data.copy(), ra_2, freq, inp, src, frick=frick) # dfs = fringestop_pathfinder(data.copy(), ra_1, freq, inp, src, frick=frick) # fp = np.loadtxt('/home/connor/feed_layout_decrease.txt') # PH = fill_nolan(times, src._ra * 180.0 / np.pi, src._dec * 180.0 / np.pi, fp) dfs_sum = sum_corrs(dfs, feeds) if return_unfs is True: return dfs_sum, ra_, dfs, data else: return dfs_sum, ra_
def reader(): with warnings.catch_warnings(): warnings.simplefilter("ignore", category=UserWarning) yield andata.Reader(acq_fname_list)