def main(scan_no): # scan_no = int(sys.argv[1]) if rank == 0 and not os.path.exists('No%04d' % (scan_no)): os.mkdir('No%04d' % (scan_no)) cfg = utils.gen_cfg(scan_no, dms = dms) cfg.rank = rank cfg.psize = psize cfg.use_dev = 'numpy' if psize == 1: combine_seg(cfg) return # cfg.use_dev = 'cupy' # cfg.use_dev = 'torch' # cfg.bm = True if cfg.use_dev == 'cupy': open_cupy(cfg) if cfg.use_dev == 'torch': open_torch(cfg) comm.Barrier() if psize < 2: if rank == 0: print('procfit.py: at least 2 procs are required!') sys.exit(0) if rank == 0: assign(cfg) else: calc(cfg) comm.Barrier()
def main_batch(scan_no): cfg = utils.gen_cfg(scan_no) din = prep_din(cfg) names = utils.gen_file_list('nsums', scan_no, 'npy') for name in names: make_fit_calc(cfg, din, name)
def main_single(): if len(sys.argv) < 2: print('./sp_fit.py sp_file') return fname = sys.argv[1] scan_no, dm, time = utils.parse_name(fname) cfg = utils.gen_cfg(scan_no) make_fit_sp(cfg, fname)
def main_single(): if len(sys.argv) < 2: print('./sp_calc.py .sp.npy') return name = sys.argv[1] scan_no, dm, time = utils.parse_name(name) cfg = utils.gen_cfg(scan_no) din = prep_din(cfg) make_fit_calc(cfg, din, name)
def main(): if len(sys.argv) < 4: print('./showspec_all.py: scan_no t0 t1') sys.exit(0) # sp_file = sys.argv[-1] # scan_no, dm, time = utils.parse_name(sp_file) scan_no = int(sys.argv[1]) cfg = utils.gen_cfg(scan_no) # cfg.dm = dm t0 = float(sys.argv[2]) t1 = float(sys.argv[3]) stns = [] bl_nos = [] # if True: if False: print('Reading sp file %s ...' % (sp_file)) # arr = np.loadtxt(sp_file, dtype = dtype_sp) arr = utils.read_sp(sp_file) for a in arr: blid = a['blid'] s1, s2 = cfg.blid2name[blid] bl_nos.append(cfg.bls[blid]) if not s1 in stns: stns.append(s1) if not s2 in stns: stns.append(s2) # Always calculate SP for all baselines else: bl_nos = cfg.bls stns = cfg.stns for i in range(cfg.nstn): for j in range(i + 1, cfg.nstn): bl_no = (i + 1) * 256 + (j + 1) if not bl_no in bl_nos: continue stn0 = cfg.stns[i] stn1 = cfg.stns[j] print('%s-%s...' % (stn0, stn1)) gen_cross_spec(cfg, scan_no, t0, t1, stn0, stn1) for stn in stns: print('%s-%s...' % (stn, stn)) gen_auto_spec(cfg, scan_no, t0, t1, stn, stn)
def main_single(): if len(sys.argv) < 2: print('./sp_calc.py .sp.npy') return name = sys.argv[1] scan_no, dm, time = utils.parse_name(name) cfg = utils.gen_cfg(scan_no) cfg.pols = [b'LL', b'RR'] cal = np.load('cal_fine_No%04d.npy' % (scan_no + 1), allow_pickle=True).item() x, xe = make_sp_solve(cfg, cal, name) print(x)
def main(scan_no): cfg = utils.gen_cfg(scan_no) t0 = cfg.dt(cfg.read_rec(0, count = 1)[0]) - cfg.ap/2 t1 = cfg.dt(cfg.read_rec(cfg.nrec - 1, count = 1)[0]) - cfg.ap/2 # t0, t1 = 25., 55. # t0 = int(t0/cfg.ap)*cfg.ap # t1 = int(t1/cfg.ap)*cfg.ap d = {} for bl_no in cfg.bl_nos: bl_name = cfg.bl_no2name[bl_no] print('ref fit %s...' % (bl_name)) d[bl_name] = gen_fine_bl(cfg, bl_no, t0, t1) print(d) np.save('cal_fine_No%04d.npy' % (scan_no), d)
def main(): if len(sys.argv) < 2: print('../crossmatch.py scan_no') sys.exit(0) global scan_no, nbl scan_no = int(sys.argv[1]) cfg = utils.gen_cfg(scan_no) # cfg = utils.gen_cfg_aov025(scan_no) for dm in cfg.dms: cms = [] for blid in range(cfg.nbl): cands = load_cand_file(dm, blid) if len(cands) == 0: continue match_cand(cands, cms) output_cms(cfg, dm, cms)
def bm_load_seg(t_seg): scan_no = 50 cfg = utils.gen_cfg(scan_no, t_seg = t_seg) s1 = cfg.stn2id['IR'] s2 = cfg.stn2id['MC'] bl_no = (s1+1) * 256 + (s2+1) t0 = 25. t0 = int(t0 / cfg.tsum) * cfg.tsum t1 = t0 + cfg.t_seg t11 = t1 + cfg.t_extra if t11 > cfg.dur: t11 = cfg.dur t11 = int(t11 / cfg.tsum) * cfg.tsum cfg.bm_load_seg = True arr = cfg.load_seg(bl_no, t0, t11) return arr
def run_compare(): scan_no = 50 # dms = np.arange(0, 1000.0, 50.0) # cfg = utils.gen_cfg_el060(scan_no, dms = dms) cfg = utils.gen_cfg(scan_no, t_seg = 2.0) cfg.bm = True cfg.nsums = [16] s1 = cfg.stn2id['IR'] s2 = cfg.stn2id['SV'] bl_no = (s1+1) * 256 + (s2+1) t0 = 25. t0 = int(t0 / cfg.tsum) * cfg.tsum t1 = t0 + cfg.t_seg ds = {} d = fit(cfg, t0, t1, bl_no) open_torch(cfg) d_d = fit_torch(cfg, t0, t1, bl_no) # open_cupy(cfg) # d_d = fit_cupy(cfg, t0, t1, bl_no) compare_result(cfg, d, d_d) return if psize < 2: if rank == 0: print('procfit.py: at least 2 procs are required!') sys.exit(0) if rank == 0: assign(cfg) else: calc(cfg)
def main_cal(): # el060: scan_no = 36 t0, t1 = 180, 210 cfg = utils.gen_cfg(scan_no) # scan_no = 1 # t0, t1 = 10, 40. # cfg = utils.gen_cfg_aov025(scan_no) tu = cfg.ap t0 = int(t0 / tu) * tu t1 = int(t1 / tu) * tu d = {} for i in range(cfg.nbl): bl_no = cfg.bls[i] name = cfg.bl_no2name[bl_no] print('%s (%d) ...' % (name, bl_no)) d[name] = gen_cal_bl(cfg, bl_no, t0, t1) np.save('cal_initial.npy', d)
def benchmark(dev, t_seg): scan_no = 50 cfg = utils.gen_cfg(scan_no, t_seg = t_seg) cfg.bm = True s1 = cfg.stn2id['IR'] s2 = cfg.stn2id['MC'] bl_no = (s1+1) * 256 + (s2+1) t0 = 25. t0 = int(t0 / cfg.tsum) * cfg.tsum t1 = t0 + cfg.t_seg if dev == 'numpy': def f(): return fit(cfg, t0, t1, bl_no) elif dev == 'torch': open_torch(cfg) def f(): return fit_torch(cfg, t0, t1, bl_no) elif dev == 'cupy': open_cupy(cfg) def f(): return fit_cupy(cfg, t0, t1, bl_no) arr = [] for i in range(11): res = f() arr.append(res) arr = np.array(arr) print(arr) arr = np.average(arr[1:, :], axis = 0) print(arr) return arr
for nsum in m.nsum_list: es = m.load_fitdump(dm, m.blid, nsum) t_arr = [] for e in es: t_arr.append(e.time) ids = np.argsort(t_arr) for id in ids: m.insert_to_cl(es[id]) # m.trim_cl() m.print_cl() m.sum_cl() if __name__ == '__main__': global scan_no scan_no = int(sys.argv[1]) cfg = utils.gen_cfg(scan_no) # with open('No%04d/blinfo.txt' % (scan_no), 'r') as f: # nbl = len(f.readlines()) for dm in cfg.dms: path = 'No%04d/dm%.3f' % (scan_no, dm) if not os.path.exists(path): os.mkdir(path) for blid in range(cfg.nbl): match(cfg, dm, blid)