def get_phs_center(msfile): """ get the phase center of the MS file using CASA taskinit.ms Parameters ---------- msfile: str measurement set filename Returns ------- pcd: phase center Note ---- may need further modification if nField > 1 unless it is the same for all fields (need further investigation) """ from taskinit import ms ms.open(msfile) pc = ms.getfielddirmeas() if not isinstance(pc, dict) is True: pc() epoch = pc['refer'] pcd_dec = pc['m1']['value'] * 180 / np.pi pcd_ra = pc['m0']['value'] * 180 / np.pi if pcd_ra < 0: pcd_ra += 360 ms.done() pcd = [pcd_ra, pcd_dec] return pcd
def MSpcd2(msFile): """using CASA taskinit.ms Parameters ---------- msFile: string measurement set filename Returns ------- pcd: phase center Note ---- may need further modification if nField > 1 unless it is the same for all fields (need further investigation) """ from taskinit import ms ms.open(msFile) pc = ms.getfielddirmeas() if not isinstance(pc, dict) is True: pc() epoch = pc['refer'] pcd_dec = pc['m1']['value'] * 180 / numpy.pi pcd_ra = pc['m0']['value'] * 180 / numpy.pi if pcd_ra < 0: pcd_ra += 360 ms.done() pcd = [pcd_ra, pcd_dec] return pcd
def read_msinfo(vis=None, msinfofile=None): # read MS information # msinfo = dict.fromkeys(['vis', 'scans', 'fieldids', 'btimes', 'btimestr', \ 'inttimes', 'ras', 'decs']) ms.open(vis) scans = ms.getscansummary() scanids = sorted(scans.keys(), key=lambda x: int(x)) nscanid = len(scanids) btimes = [] btimestr = [] etimes = [] fieldids = [] inttimes = [] dirs = [] ras = [] decs = [] for i in range(nscanid): btimes.append(scans[scanids[i]]['0']['BeginTime']) etimes.append(scans[scanids[i]]['0']['EndTime']) fieldid = scans[scanids[i]]['0']['FieldId'] fieldids.append(fieldid) dir = ms.getfielddirmeas('PHASE_DIR', fieldid) dirs.append(dir) ras.append(dir['m0']) decs.append(dir['m1']) inttimes.append(scans[scanids[i]]['0']['IntegrationTime']) ms.close() btimestr = [qa.time(qa.quantity(btimes[i], 'd'), form='fits', prec=10)[0] \ for i in range(nscanid)] msinfo['vis'] = vis msinfo['scans'] = scans msinfo['fieldids'] = fieldids msinfo['btimes'] = btimes msinfo['btimestr'] = btimestr msinfo['inttimes'] = inttimes msinfo['ras'] = ras msinfo['decs'] = decs if msinfofile: np.savez(msinfofile, vis=vis, scans=scans, fieldids=fieldids, \ btimes=btimes, btimestr=btimestr, inttimes=inttimes, \ ras=ras, decs=decs) return msinfo
def read_msinfo(vis=None, msinfofile=None, use_scan_time=True): import glob # read MS information # msinfo = dict.fromkeys([ 'vis', 'scans', 'fieldids', 'btimes', 'btimestr', 'inttimes', 'ras', 'decs', 'observatory' ]) ms.open(vis) metadata = ms.metadata() observatory = metadata.observatorynames()[0] scans = ms.getscansummary() scanids = sorted(scans.keys(), key=lambda x: int(x)) nscanid = len(scanids) btimes = [] btimestr = [] etimes = [] fieldids = [] inttimes = [] dirs = [] ras = [] decs = [] ephem_file = glob.glob(vis + '/FIELD/EPHEM*SUN.tab') if ephem_file: print('Loading ephemeris info from {}'.format(ephem_file[0])) tb.open(ephem_file[0]) col_ra = tb.getcol('RA') col_dec = tb.getcol('DEC') col_mjd = tb.getcol('MJD') if use_scan_time: from scipy.interpolate import interp1d f_ra = interp1d(col_mjd, col_ra) f_dec = interp1d(col_mjd, col_dec) for idx, scanid in enumerate(scanids): btimes.append(scans[scanid]['0']['BeginTime']) etimes.append(scans[scanid]['0']['EndTime']) fieldid = scans[scanid]['0']['FieldId'] fieldids.append(fieldid) inttimes.append(scans[scanid]['0']['IntegrationTime']) ras = f_ra(np.array(btimes)) decs = f_dec(np.array(btimes)) ras = qa.convert(qa.quantity(ras, 'deg'), 'rad') decs = qa.convert(qa.quantity(decs, 'deg'), 'rad') else: ras = qa.convert(qa.quantity(col_ra, 'deg'), 'rad') decs = qa.convert(qa.quantity(col_dec, 'deg'), 'rad') else: for idx, scanid in enumerate(scanids): btimes.append(scans[scanid]['0']['BeginTime']) etimes.append(scans[scanid]['0']['EndTime']) fieldid = scans[scanid]['0']['FieldId'] fieldids.append(fieldid) inttimes.append(scans[scanid]['0']['IntegrationTime']) dir = ms.getfielddirmeas('PHASE_DIR', fieldid) dirs.append(dir) ras.append(dir['m0']) decs.append(dir['m1']) ms.close() btimestr = [ qa.time(qa.quantity(btimes[idx], 'd'), form='fits', prec=10)[0] for idx in range(nscanid) ] msinfo['vis'] = vis msinfo['scans'] = scans msinfo['fieldids'] = fieldids msinfo['btimes'] = btimes msinfo['btimestr'] = btimestr msinfo['inttimes'] = inttimes msinfo['ras'] = ras msinfo['decs'] = decs msinfo['observatory'] = observatory if msinfofile: np.savez(msinfofile, vis=vis, scans=scans, fieldids=fieldids, btimes=btimes, btimestr=btimestr, inttimes=inttimes, ras=ras, decs=decs, observatory=observatory) return msinfo