def mapallvis(uvo, uvc, so, mapdir, lines=[]): """ Similar to mapvis but doesn't do multiple frequency synthesis. The frequency axis is preserved so you can get spectra from the image. """ calibrator = 'cnt.usb' tall = 0.50 # remove continuum, its already been mapped lines.remove(calibrator) lines.remove('usb') for i, lin in enumerate(lines): vis = '{}/{}.{}.corrected.slfc'.format(uvc, so, lin) for src in [ '{}/{}.{}'.format(mapdir, so, lin), '{}/{}.{}.uncorrected'.format(mapdir, so, lin) ]: line = miriad.averageVelocityLine(vis, 2) for path in glob.glob('{}.full.*'.format(src)): if os.path.exists(path): shutil.rmtree(path) invertOptions = { 'vis': vis, 'stokes': 'i,v', 'beam': '{}.full.bm'.format(src), 'map': '{0}.i.full.mp,{0}.v.full.mp'.format(src), 'imsize': 128, 'cell': 0.3, 'options': 'systemp,double', 'sup': 0, } miriad.invert(invertOptions) for stk in ['i', 'v']: miriad.clean({ 'map': '{}.{}.full.mp'.format(src, stk), 'beam': '{}.full.bm'.format(src), 'out': '{}.{}.full.cc'.format(src, stk), 'niters': 3000, 'cutoff': tall }) miriad.restor({ 'map': '{}.{}.full.mp'.format(src, stk), 'beam': '{}.full.bm'.format(src), 'model': '{}.{}.full.cc'.format(src, stk), 'out': '{}.{}.full.cm'.format(src, stk), }) vis = '{}/{}.{}'.format(uvo, so, lin)
#!/usr/bin/python3 import shutil, glob, os import miriad """ Separate the continuum from molecular lines """ so = 'NGC7538S-s4' dd = 'UVDATA' vis = '{}/{}'.format(dd, so) sb = 'usb' numChannels = miriad.getNumChannels('{}.{}'.format(vis, sb)) ch = miriad.averageVelocityLine('{}.{}'.format(vis, sb), 5) freq = 345.8 lab = 'cnt.usb' free = '6,107,275,478,500,725,762,815,833,1096,1109,1351,1366,1531' path = '{}.{}'.format(vis, lab) if os.path.exists(path): shutil.rmtree(path) for path in glob.glob('tmp.*'): if os.path.exists(path): shutil.rmtree(path) print("Starting with:", vis + '.' + sb) miriad.uvaver({'vis': '{}.{}'.format(vis, sb), 'out': 'tmp.1'}) miriad.uvputhd({ 'vis': 'tmp.1', 'out': 'tmp.2',
def compareSpectra(visUncorrected, visCorrected, combineI=1, combineV=10, plotOptions={}, stokesVylim=None, stokesIylim=None, legendloc=1, filterMaxPeak=False): """ Compare spectra utility. Three panel plot with Stokes I, stokes V uncorrected and Stokes V corrected combine: the number of velocity channels to average together """ miriadDefaults = { 'options': 'avall,nobase', 'axis': 'freq,amp', 'interval': 9999, } optionsI = { **miriadDefaults, **{ 'stokes': 'i', 'line': miriad.averageVelocityLine(visUncorrected, factor=combineI) } } optionsV = { **miriadDefaults, **{ 'stokes': 'v', 'line': miriad.averageVelocityLine(visCorrected, factor=combineV) } } freq1, amps1 = miriad.dumpSpec(visCorrected, optionsI) freq2, amps2 = miriad.dumpSpec(visUncorrected, optionsV) freq3, amps3 = miriad.dumpSpec(visCorrected, optionsV) # hack for a bad channel if filterMaxPeak: amps1[amps1.index(max(amps1))] = 0 amps2[amps2.index(max(amps2))] = 0 amps3[amps3.index(max(amps3))] = 0 fontsize = 8 subtitledict = {'verticalalignment': 'center'} pad = 0.05 # 5% if stokesVylim is None: upperlim = max(max(amps2), max(amps3)) lowerlim = min(min(amps2), min(amps3)) upperlim = upperlim + pad * upperlim stokesVylim = [(lowerlim, upperlim), (lowerlim, upperlim)] elif stokesVylim is 'separate': upperlim = max(max(amps2), max(amps3)) lowerlim = min(min(amps2), min(amps3)) upperlim = upperlim + pad * upperlim stokesVylim = [(lowerlim, max(amps2) + pad * max(amps2)), (lowerlim, max(amps3) + pad * max(amps3))] # xlim = (345.65,347.65) xlim = (min(freq2), max(freq2)) defaults = { 0: { 'x': freq1, 'y': amps1, 'draw': 'steps-mid', 'line': 'k-', 'label': 'Stokes I' }, 'legend': { 'loc': legendloc, 'fontsize': fontsize }, 'title': '', 'xlabel': 'Frequency (GHz)', 'ylabel': 'Visibility Amplitude', 'sharex': True, 'sharey': 'row', 'hspace': 0.0, 'ylim': stokesIylim, 'xlim': xlim, 'minorticks': True, } fig = plawt.plot({ **defaults, **plotOptions }, { 0: { 'x': freq2, 'y': amps2, 'draw': 'steps-mid', 'line': 'k-', 'label': 'Stokes V before squint correction' }, 'legend': { 'loc': legendloc, 'fontsize': fontsize }, 'ylim': stokesVylim[0], }, { 0: { 'x': freq3, 'y': amps3, 'draw': 'steps-mid', 'line': 'k-', 'label': 'Stokes V after squint correction' }, 'legend': { 'loc': legendloc, 'fontsize': fontsize }, 'ylim': stokesVylim[1], })
dd = 'UVDATA' molecules = ['CO'] for molecule in molecules: if molecule == 'CO': freq = 345.7959 lab = 'co3-2' rms = 0.15 rng = '0,30' vis = 'UVDATA/{}.{}'.format(so, lab) src = 'MAPS/{}.{}'.format(so, lab) tall = rms * 3 # line selection line = miriad.averageVelocityLine(vis, 2) # MAPS: for path in glob.glob('{}.*'.format(src)): if os.path.exists(path): if os.path.isdir(path): shutil.rmtree(path) else: os.remove(path) miriad.invert({ 'vis': vis, 'line': line, 'beam': '{}.bm'.format(src), 'map': '{0}.i.mp,{0}.q.mp,{0}.u.mp,{0}.v.mp'.format(src), 'imsize': 128, 'cell': 0.3, 'options': 'systemp,double',
if __name__ == '__main__': so = 'irc+10216' uvo = 'UVDATA' uvc = 'UVOffsetCorrect' mapdir = 'MAPSCorrect' lines = ['cs7-6', 'sis19-18', 'h13cn4-3', 'co3-2', 'cnt.usb', 'usb'] # input("Press return to split") # squint.split(uvo, uvc, so, lines) # input("Press return to selfcal") # squint.selfcal(so, uvc, lines) # input("Press return to map visibilities") # squint.mapvis(uvo, uvc, so, mapdir, lines[:], # lineSelection=[None, None, None, None] # ) input("Press return to map visibilities with frequency axis") lsels = ['vel,8,-40,4,4' for l in lines] selects = ['uvrange(0,80)' if l == 'co3-2' else None for l in lines] lsels[lines.index('usb')] = miriad.averageVelocityLine('UVOffsetCorrect/irc+10216.usb.corrected.slfc', 17) squint.mapallvis(uvo, uvc, so, mapdir, lines[:], lineSelection=lsels, selects=selects ) # input("Press return to save plots") # vrms = 0.13 # squint.disp(uvo, uvc, so, mapdir, # lines=['cs7-6', 'sis19-18', 'h13cn4-3', 'co3-2', 'cnt'], # stokesVrms=[vrms for l in lines] # )
def mapvis(uvo, uvc, so, mapdir, lines=[], lineSelection=[]): """ Make a map from visibilities 1. Continuum Stokes I,V Uncorrected & Corrected data 2. Map All lines. Corrected 3. Map All lines. Uncorrected 4. Continuum LL and RR independently, for non-selfcal and selfcal cases """ calibrator = 'cnt.usb' if len(lines) != len(lineSelection): lineSelection = [None for l in lines] # 1. src = '{}/{}.cnt'.format(mapdir, so) tall = 0.03 for path in glob.glob('{}.*'.format(src)): if os.path.exists(path): shutil.rmtree(path) vis = '{}/{}.cnt.usb.corrected.slfc'.format(uvc, so) for src in [ '{}/{}.cnt'.format(mapdir, so), '{}/{}.cnt.uncorrected'.format(mapdir, so) ]: miriad.invert({ 'vis': vis, 'stokes': 'i,v', 'beam': '{}.bm'.format(src), 'map': '{0}.i.mp,{0}.v.mp'.format(src), 'imsize': 128, 'cell': 0.3, 'options': 'systemp,double,mfs', 'sup': 0 }) for stk in ['i', 'v']: miriad.clean({ 'map': '{}.{}.mp'.format(src, stk), 'beam': '{}.bm'.format(src), 'out': '{}.{}.cc'.format(src, stk), 'niters': 3000, 'cutoff': tall }) miriad.restor({ 'map': '{}.{}.mp'.format(src, stk), 'beam': '{}.bm'.format(src), 'model': '{}.{}.cc'.format(src, stk), 'out': '{}.{}.cm'.format(src, stk), }) vis = '{}/{}.cnt.usb'.format(uvo, so) # 2. Map corrected line data # 3. Map uncorrected line data with same paramenters as in 2 tall = 0.50 # remove continuum, its already been mapped lines.remove(calibrator) lines.remove('usb') for i, lin in enumerate(lines): vis = '{}/{}.{}.corrected.slfc'.format(uvc, so, lin) for src in [ '{}/{}.{}'.format(mapdir, so, lin), '{}/{}.{}.uncorrected'.format(mapdir, so, lin) ]: line = miriad.averageVelocityLine(vis, 2) for path in glob.glob('{}.*'.format(src)): if os.path.exists(path): shutil.rmtree(path) invertOptions = { 'vis': vis, 'stokes': 'i,v', 'beam': '{}.bm'.format(src), 'map': '{0}.i.mp,{0}.v.mp'.format(src), 'imsize': 128, 'cell': 0.3, 'options': 'systemp,double,mfs', 'sup': 0, } if lineSelection[i] is not None: invertOptions['line'] = lineSelection[i] miriad.invert(invertOptions) for stk in ['i', 'v']: miriad.clean({ 'map': '{}.{}.mp'.format(src, stk), 'beam': '{}.bm'.format(src), 'out': '{}.{}.cc'.format(src, stk), 'niters': 3000, 'cutoff': tall }) miriad.restor({ 'map': '{}.{}.mp'.format(src, stk), 'beam': '{}.bm'.format(src), 'model': '{}.{}.cc'.format(src, stk), 'out': '{}.{}.cm'.format(src, stk), }) vis = '{}/{}.{}'.format(uvo, so, lin) # 4. nopol is for selfcal case (this option is not used!) tall = 0.03 for stk in ['ll', 'rr']: src = '{}/{}.cnt.{}'.format(mapdir, so, stk) for path in glob.glob('{}.*'.format(src)): if os.path.exists(path): shutil.rmtree(path) for pol in ['nopol', 'nocal']: path = '{}.bm'.format(src) if os.path.exists(path): shutil.rmtree(path) miriad.invert({ 'vis': '{}/{}.cnt.usb.{}'.format(uvc, so, stk), 'beam': '{}.bm'.format(src), 'map': '{}.{}.mp'.format(src, pol), 'imsize': 128, 'cell': 0.3, 'options': 'systemp,double,mfs,{}'.format(pol), 'sup': 0 }) miriad.clean({ 'map': '{}.{}.mp'.format(src, pol), 'beam': '{}.bm'.format(src), 'out': '{}.{}.cc'.format(src, pol), 'niters': 3000, 'cutoff': tall }) miriad.restor({ 'map': '{}.{}.mp'.format(src, pol), 'beam': '{}.bm'.format(src), 'model': '{}.{}.cc'.format(src, pol), 'out': '{}.{}.cm'.format(src, pol), })
def plotPhase(vis, device='2/xs'): miriad.smauvplt({ 'vis': vis, 'device': device, 'interval': '1e3', 'stokes': 'i,v', 'axis': 'time,pha', 'nxy': '2,2' }) # vis = 'UVDATA/NGC7538S-s4.usb' vis = 'UVOffsetCorrect/NGC7538S-s4.usb.corrected.slfc' numChannels = miriad.getNumChannels(vis) velrange = miriad.getVelocityRange(vis) miriad.uvspec({ 'vis': 'UVDATA/NGC7538S-s4.usb,UVOffsetCorrect/NGC7538S-s4.usb.corrected.slfc', 'device': '1/xs', 'interval': 9999, 'options': 'avall,nobase', 'nxy': '1,2', 'stokes': 'v', 'axis': 'freq,phase', # 'yrange': '0,0.5', 'line': miriad.averageVelocityLine(vis, factor=20), })
def mapallvis(uvo, uvc, so, mapdir, lines=[], lineSelection=[], selects=[]): """ Similar to mapvis but doesn't do multiple frequency synthesis. The frequency axis is preserved so you can get spectra from the image. """ from subprocess import CalledProcessError if len(lines) != len(lineSelection): lineSelection = [None for l in lines] if len(lines) != len(selects): selects = [None for l in lines] calibrator = 'cnt.usb' tall = 0.50 # remove continuum, its already been mapped lineSelection.pop(lines.index(calibrator)) lines.remove(calibrator) for i, lin in enumerate(lines): vis = '{}/{}.{}.corrected.slfc'.format(uvc, so, lin) for src in [ '{}/{}.{}'.format(mapdir, so, lin), '{}/{}.{}.uncorrected'.format(mapdir, so, lin) ]: for path in glob.glob('{}*.full.*'.format(src)): if os.path.exists(path): shutil.rmtree(path) invertOptions = { 'vis': vis, 'stokes': 'i,v', 'beam': '{}.full.bm'.format(src), 'map': '{0}.i.full.mp,{0}.v.full.mp'.format(src), 'imsize': 128, 'cell': 0.3, 'options': 'systemp,double', 'sup': 0, } if selects[i]: invertOptions['select'] = selects[i] try: miriad.invert(invertOptions) except CalledProcessError: print("### Retrying invert with line selection") line = miriad.averageVelocityLine(vis, 2) sel = lineSelection[i] if lineSelection[i] is not None else line invertOptions['line'] = sel miriad.invert(invertOptions) for stk in ['i', 'v']: miriad.clean({ 'map': '{}.{}.full.mp'.format(src, stk), 'beam': '{}.full.bm'.format(src), 'out': '{}.{}.full.cc'.format(src, stk), 'niters': 3000, 'cutoff': tall }) miriad.restor({ 'map': '{}.{}.full.mp'.format(src, stk), 'beam': '{}.full.bm'.format(src), 'model': '{}.{}.full.cc'.format(src, stk), 'out': '{}.{}.full.cm'.format(src, stk), }) vis = '{}/{}.{}'.format(uvo, so, lin)
so = 'orkl_080106' uvo = 'UVDATA' uvc = 'UVOffsetCorrect' mapdir = 'MAPSCorrect' lines = ['co3-2', 'sio8-7', 'cnt.usb', 'usb'] input("Press return to split") squint.split(uvo, uvc, so, lines) input("Press return to selfcal") squint.selfcal(so, uvc, lines) input("Press return to map visibilities") squint.mapvis(uvo, uvc, so, mapdir, lines[:], lineSelection=[None, None, None, None] ) input("Press return to map visibilities with frequency axis") usbLine = miriad.averageVelocityLine('UVOffsetCorrect/orkl_080106.usb.corrected.slfc/', 8) selects = [None if l == 'co3-2' else None for l in lines] squint.mapallvis(uvo, uvc, so, mapdir, lines[:], lineSelection=['vel,43,-31,2,2', 'vel,27,-20,2,2', None, usbLine], # selects=selects ) input("Press return to save plots") squint.disp(uvo, uvc, so, mapdir, lines=['co3-2', 'sio8-7', 'cnt'], stokesVrms=[0.13, 0.06, 0.038] ) # input("Press return to map continuum visibilities with frequency axis") # # usbLine = miriad.averageVelocityLine('UVOffsetCorrect/orkl_080106.usb.corrected.slfc/', 8) # squint.mapallvis(uvo, uvc, so, mapdir, ['cnt.usb'], # lineSelection=[None]