def check_polgain(obs_apint_pcal, polcal_field='',): """check the solution of amp of polarisation calibrator This function should be used to for two gain solutions, one with unpolarized source model another one with polarised model. The first solution should absorb the polarised single (amp change with parallactic angle or time) The second solution should have no such signal if the correct model is used """ if isinstance(obs_apint_pcal, (list, tuple)): # ToDo: generate the comparsion bettween this two solutions pass plotms(vis=obs_apint_pcal, xaxis='time', yaxis='amp', field=polcal_field, correlation='/', coloraxis='antenna1', showgui=True)
def check_pol_kcross(vis): """ check the correction for linear phase variation and select suitable scan """ plotms(vis=vis, ydatacolumn='corrected', xaxis='freq', yaxis='phase', field= polcal_field, avgtime='1e9', correlation='XY,YX', spw='', antenna='DA48', iteraxis='baseline',coloraxis='corr', showgui=True, plotrange=[0,0,-180,180])
def check_Dterm(Dtermtable, spw='', showgui=False, plotdir='./plots', basename=None, overwrite=True, gridrows=2, gridcols=3, dpi=600, **kwargs): if basename is None: basename = os.path.basename(Dtermtable) outdir = os.path.join(plotdir, "Dterm-"+basename) os.system('mkdir -p {}'.format(outdir)) for yaxis in ['amp', 'real', 'imag']: subgroups = group_antenna(Dtermtable, subgroup_member=gridrows*gridcols) for page, subgroup in enumerate(subgroups): plotms(vis=Dtermtable, xaxis='frequency', yaxis=yaxis, antenna=subgroup, spw=spw, iteraxis='antenna', coloraxis='corr', plotfile='{}/freq_{}.page{}.png'.format(outdir, yaxis, page), showgui=showgui, highres=True, **kwargs)
def check_XYfQU(vis): """check the correction for small non-linear absolute phase variation in different antenna """ plotms(vis=vis, ydatacolumn='corrected', xdatacolumn='corrected', xaxis='real', yaxis='imag', field=polcal_field, avgtime='1e9', avgchannel='64', avgbaseline=True, correlation='XY,YX', spw='3', coloraxis='corr', showgui=True, plotrange=[-0.06,0.06,-0.06,0.06])
def check_gain(phasecal_int='phase_int.gcal', phasecal_scan='phase_scan.gcal', ampcal_scan='amp_scan.gcal', dpi=600, gridrows=2, gridcols=2, plotdir='./plots'): """check the gain table In order to use this function, one should follow the same naming It is designed to plot the phase and amplitude splution from the gain calibrator Parameters: phase_int : str the file of integrated time (or specified short time) solution for phase variation phase_scan : str the file of scan based solution for gain calibrator, used for science target ampcal_scan : str the file of amplitude solution based on scan integration gridrows : int the number of rows default: 2 gridcols : int the number of columns default: 2 dpi : int the resolution of the saved png files default: 600 plotdir : str the root directory to put all the generated plots """ os.system('mkdir -p {}/gain_solution/'.format(plotdir)) if os.path.exists(phasecal_int): print('Plotting {}'.format(phasecal_int)) subgroups = group_antenna(phasecal_int, subgroup_member=gridrows*gridcols) for page, antenna in enumerate(subgroups): plotms(vis=phasecal_int, gridrows=gridrows, gridcols=gridcols, xaxis='time', yaxis='phase', antenna=antenna, iteraxis='antenna', coloraxis='corr', plotfile='{}/gain_solution/phase_int_page{}.png'.format(plotdir, page), plotrange=[0,0,-180,180], showgui=False, dpi=dpi, overwrite=True) else: print("Warning: you should give the correct integrated phase table! Set the phase_int parameter") if os.path.exists(phasecal_scan): print('Plotting {}'.format(phasecal_scan)) subgroups = group_antenna(phasecal_scan, subgroup_member=gridrows*gridcols) for page, antenna in enumerate(subgroups): plotms(vis=phasecal_scan, gridrows=gridrows, gridcols=gridcols, xaxis='time', yaxis='phase', antenna=antenna, iteraxis='antenna', coloraxis='corr', plotfile='{}/gain_solution/phase_scan_page{}.png'.format(plotdir, page), plotrange=[0,0,-180,180], showgui=False, dpi=dpi, overwrite=True) else: print("Warning: you should give the correct scan averaged phase table! Set the phase_scan parameter") if os.path.exists(ampcal_scan): print('Plotting {}'.format(ampcal_scan)) subgroups = group_antenna(ampcal_scan, subgroup_member=gridrows*gridcols) for page, antenna in enumerate(subgroups): for yaxis in ['amp', 'phase']: plotms(vis=ampcal_scan, gridrows=gridrows, gridcols=gridcols, xaxis='time', yaxis=yaxis, antenna=antenna, iteraxis='antenna', coloraxis='corr', plotfile='{}/gain_solution/{}_page{}.png'.format(plotdir, yaxis, page), showgui=False, dpi=dpi, overwrite=True) else: print("Warning: you should give the correct amp_scan calibration table! Set the amp_scan parameter")
def extractSpw(self,msName,intent = 'CALIBRATE_BANDPASS', listCal = []): "Extract the spectra from a spw of a given intent" es = aU.stuffForScienceDataReduction() # vm = aU.ValueMapping(msName) try: tb.open(msName) dataColNames = tb.colnames() tb.close() except: print("##") print("## Error to open : %s"%(msName)) print('## \n\n') return(False,[], [],[]) if 'CORRECTED_DATA' in dataColNames: dataCol = 'corrected' else: dataCol = 'data' tb.open(msName+'/FIELD') sourceIds = tb.getcol('SOURCE_ID') tb.close() intentSources = es.getIntentsAndSourceNames(msName) if intentSources[intent]['name'][0] == '': return(False, [], [], []) calIds = intentSources[intent]['sourceid'] calName = intentSources[intent]['name'] calIds = sorted(dict.fromkeys(calIds).keys()) calName = sorted(dict.fromkeys(calName).keys()) ### spw info spwInfo = es.getSpwInfo(msName) spwIds = sorted(spwInfo.keys()) print spwIds listFile = [] listCalFile = [] listSuccess = [] listSpw = [] for calNameJ in calName: found = False if calNameJ in listCal: found = True if not found: listCal.append(calNameJ) for spwj in spwIds: # spwChanFreqs = vm.spwInfo[j]['chanFreqs'] # print spwChanFreqs spwId = "%s"%(spwj) msNameWithoutSlash = msName.split('/')[-1] msNameDat = self.workingDirectory+msNameWithoutSlash calNameJwithoutmultiplename = calNameJ.split(";")[0] fileName = "%s-%s-%s-spw%s.dat"%(msNameDat,intent,calNameJwithoutmultiplename,spwj) print fileName successSpw = plotms(vis = msName ,xaxis="frequency",xdatacolumn = "",yaxis="amp",ydatacolumn = dataCol ,selectdata=True,field = calNameJ, spw = spwId ,timerange="",uvrange="",antenna="",scan="",correlation="",array="",observation="",msselect="",averagedata=True, avgchannel="1",avgtime="1e9",avgscan=True,avgfield=True, avgbaseline=True,avgantenna= False,avgspw=False,scalar=False, transform=False,freqframe="",restfreq="",veldef="RADIO",shift=[0.0, 0.0],extendflag=False,extcorr=False,extchannel=False, iteraxis="",plotfile = fileName ,expformat="txt", highres=False, overwrite=False,showgui=False) listFile.append(fileName) listCalFile.append(calNameJwithoutmultiplename) listSpw.append(spwj) listSuccess.append(successSpw) if not successSpw : print("## Problem with the extraction of %s ..."%(fileName)) print("vvvvvvvvvvvvvvvvvvvvvvvv") print listFile print("vvvvvvvvvvvvvvvvvvvvvvv") return(listSuccess, listFile, listCalFile, listSpw)
def check_info(vis=None, showgui=False, plotdir='./plots', basename=None, spw='', show_ants=True, show_mosaic=False, show_uvcoverage=True, show_elevation=True, show_allobs=True, show_uv=True, refant='1', overwrite=True, avgtime='1e8', avgchannel='1e8', show_fields=False, fields=None, show_intents=False, intents=['*BANDPASS*','*PHASE*','*TARGET*'], **kwargs): """ plot the basic information of the observation. Plots include: antenna positions, UV coverage, mosaic coverage(if possible) Examples: To give a quick overview check_info(vis=msfile, spw='') if you also want to give a glance for the calibrators and science target: plot_utils.check_info(obs, refant=refant, correlation='XX,YY', avgchannel='64', datacolumn='data') Args: vis (str): measurement file showgui (bool): show the plot window, the plotmosaic does not support yet, plotdir (str): the base directory for all the info plots. spw (str): the spectral windows, if unset or empty string all the spws will plot at the same time; specify the spws in stings can plot them one by one through the loop in spws.split(',') show_ants (bool): plot the positions of the antennas show_mosaic (bool): deprecated, it needs analysisUtils. Plot the relative positions of the mosaic show_uvcoverage (bool): plot the uv coverage of different field. Also depends the field number show_elevation (bool): plot the elevation with time for all the fields, show_allobs (bool): plot amplitude vs time for all the fields together refant (str): the reference antenna, set to '' to plot all the antennas overwrite (bool): set to True to overwrite all the existing plots intents (list): all the intents generated by the telescope fields: all the tageted fields, could be string (the casa style) or list like intents. Both intents and fields are provided, the fields will be used. """ if basename is None: basename = os.path.basename(vis) outdir = os.path.join(plotdir, "info-"+basename) os.system('mkdir -p {}'.format(outdir)) if show_ants and not os.path.exists('{}/antpos.png'.format(outdir)): # Checking antenna position, choosing the reference antenna print('Plotting antenna positions...') plotants(vis=vis, figfile='{}/antpos.png'.format(outdir)) if show_mosaic: # TODO, adapt the function from analysisUtils print("Warning, mosaic plot deprecated!") pass # if show_uvcoverage and not os.path.exists('{}/uvcoverage.png'.format(outdir)): # print("Plotting u-v coverage...") # plotms(vis=vis, xaxis='U', yaxis='V', coloraxis='field', # spw=spw, showgui=showgui, avgchannel=avgchannel, # plotfile='{}/all_uvcoverage.png'.format(outdir), # overwrite=overwrite) if show_elevation and not os.path.exists('{}/elevation.png'.format(outdir)): print("Plotting elevation with time...") # Checking the evevation, determine the need of elivation calibration plotms(vis=vis, xaxis='time', yaxis='elevation', spw=spw, avgchannel=avgchannel, coloraxis='field', highres=True, plotfile='{}/elevation.png'.format(outdir), showgui=showgui, overwrite=overwrite) if show_allobs and not os.path.exists('{}/all_observations.png'.format(outdir)): print("Plotting amplitude with time for all obs...") plotms(vis=vis, xaxis='time', yaxis='amp', spw=spw, highres=True, avgchannel=avgchannel, avgtime='60', coloraxis='field', plotfile='{}/all_observations.png'.format(outdir), showgui=showgui, overwrite=overwrite, **kwargs) if show_uv and not os.path.isfile('{}/uvcoverage.png'.format(outdir)): plotms(vis=vis, xaxis='U', yaxis='V', coloraxis='field', highres=True, spw=spw, showgui=showgui, avgchannel=avgchannel, plotfile='{}/uvcoverage.png'.format(outdir), overwrite=overwrite) if show_fields: if fields is None: print("Warning: plot all the fields togeather!") fields_list = ['',] elif isinstance(fields, (list, tuple)): fields_list = fields elif isinstance(fields, str): fields_list = fields.split(',') for myfield in fields_list: # amp change with time plotms(vis=vis, field=myfield, xaxis='time', yaxis='amp', antenna=refant, avgchannel=avgchannel, spw=spw, coloraxis='spw', plotfile='{}/field{}_amp_time.png'.format(outdir, myfield), highres=True, showgui=showgui, overwrite=overwrite, **kwargs) # amplitude change with freq plotms(vis=vis, field=myfield, xaxis='freq', yaxis='amp', antenna=refant, avgtime=avgtime,spw=spw, coloraxis='scan', plotfile='{}/field{}_amp_freq.png'.format(outdir, myfield), highres=True, showgui=showgui, overwrite=overwrite, **kwargs) # amp change with uvdist plotms(vis=vis, field=myfield, xaxis='uvdist', yaxis='amp', antenna=refant, avgchannel=avgchannel, spw=spw, coloraxis='spw', plotfile='{}/field{}_amp_uvdist.png'.format(outdir, myfield), highres=True, showgui=showgui, overwrite=overwrite, **kwargs) if show_intents: for myintent in intents: myintent_name = myintent[1:-1] # amp change with time plotms(vis=vis, intent=myintent, xaxis='time', yaxis='amp', antenna=refant, avgchannel=avgchannel, spw=spw, coloraxis='spw', plotfile='{}/{}_amp_time.png'.format(outdir, myintent_name), highres=True, showgui=showgui, overwrite=overwrite, **kwargs) # amplitude change with freq plotms(vis=vis, intent=myintent, xaxis='freq', yaxis='amp', antenna=refant, avgtime=avgtime,spw=spw, coloraxis='scan', plotfile='{}/{}_amp__freq.png'.format(outdir, myintent_name), highres=True, showgui=showgui, overwrite=overwrite, **kwargs) # amp change with uvdist plotms(vis=vis, intent=myintent, xaxis='uvdist', yaxis='amp', antenna=refant, avgchannel=avgchannel, spw=spw, coloraxis='spw', plotfile='{}/{}_amp_uvdist.png'.format(outdir, myintent_name), highres=True, showgui=showgui, overwrite=overwrite, **kwargs)
def check_bandpass(phaseint_cal='bpphase.gcal', bandpass_cal='bandpass.bcal', basename=None, dpi=600, gridrows=2, gridcols=2, plotdir='./plots/bandpass'): """check the data quality of bandpass calibrator and the calibration it can plot two solution: the short time gain (fgcal) and the bandpass solution (fbcal) Parameters ---------- phasecal_int : str the file of gain solution for bandpass calibrator bpcal : str the file of the bandpass solution gridrows : int the number of rows default: 2 gridcols : int the number of columns default: 2 dpi : int the resolution of the saved png files default: 600 plotdir : str the root directory to put all the generated plots """ if os.path.exists(phaseint_cal): if basename is None: outname = os.path.basename(phaseint_cal) else: outname = basename+'phaseint' outdir = os.path.join(plotdir, outname) os.system('mkdir -p {}'.format(outdir)) print('Plotting {}'.format(phaseint_cal)) subgroups = group_antenna(phaseint_cal, subgroup_member=gridrows*gridcols) for page, antenna in enumerate(subgroups): # after casa 6, consider using pathlib plotms(vis=phaseint_cal, gridrows=gridrows, gridcols=gridcols, xaxis='time', yaxis='phase', antenna=antenna, iteraxis='antenna', coloraxis='corr', plotfile='{}/phase_page{}.png'.format(outdir, page), plotrange=[0,0,-180,180], showgui=False, dpi=dpi, overwrite=True, highres=True) else: print("Warning: you should give the correct bandpass gain table! Set the fgcal parameter") if os.path.exists(bandpass_cal): if basename is None: outname = os.path.basename(bandpass_cal) else: outname = basename+'bandpass' outdir = os.path.join(plotdir, outname) os.system('mkdir -p {}'.format(outdir)) print('Plotting {}'.format(bandpass_cal)) subgroups = group_antenna(bandpass_cal, subgroup_member=gridrows*gridcols) for page, antenna in enumerate(subgroups): for yaxis in ['amp', 'phase']: plotms(vis=bandpass_cal, gridrows=gridrows, gridcols=gridcols, xaxis='freq', yaxis=yaxis, antenna=antenna, iteraxis='antenna', coloraxis='corr', plotfile='{}/{}_page{}.png'.format(outdir, yaxis, page), showgui=False, dpi=dpi, overwrite=True, highres=True) else: print("Warning: you should give the correct bandpass calibration table! Set the fbcal parameter")
def check_cal(vis='', spw='', refant='', ydatacolumn='corrected', basename=None, field='', yaxis=['amplitude', 'phase'], plot_freq=True, plot_time=True, plot_uvdist=True, overwrite=True, showgui=False, avgtime='1e8', avgchannel='1e8', gridrows=2, gridcols=3, dpi=600, plotdir='./plots', **kwargs): """ Check the calibrated data after `applycal` The wrapped tools based on `plotms` for manual calibration. Examples -------- check the amplitude and phase of calibrator change with time and frequency: (set refant to plot with baseline, which is much faster) # to iterate the baseline of refant check_cal(vis=msfile, spw='', field='bcal,gcal', refant='ea01') # to include all the antenna check_cal(vis=msfile, spw='', field='bcal,gcal') for the science target: check_cal(vis=msfile, spw='', field='science_field') Parameters ---------- vis : str measurements file spw : str same as casa default: '' refant : str the reference antenna, like 'CM03', 'DV48', 'ea01' if the refant is specified, the iteration axis will change to baseline, otherwise it will iterate through antennas default: '' ydatacolumn : str the ydatacolumn of `plotms` default: 'corrected' field : str the field or fileds to be plotted example: '0,2,3' or 'J1427-4260,Mars', not support '~' plot_freq : bool Plot the amplitude-vs-frequency, phase-vs-frequency for both data. default: True plot_time : bool plot the amplitude-vs-time, phase-vs-time for both data column default: True plot_uvdist : bool plot amplitude vs uvdist default: True overwrite : bool default: True showgui : bool default: True gridrows : int the number of rows default: gridrows=2 gridcols : int the number of columns default: gridcols=3 dpi : int the resolution of the saved png files default: 600 plotdir : str the root directory to put all the generated plots """ # checking the validation of parameters if vis == '': raise ValueError("You must give the measurements file name `vis`!") if basename is None: basename = os.path.basename(vis) outdir = os.path.join(plotdir, "checkcal-"+basename) os.system('mkdir -p {}'.format(outdir)) tb = tbtool() if field == '': # read all the fields tb.open(vis) field_list = np.unique(tb.getcol('FIELD_ID')) field = list2str(field_list) tb.close() # plot the frequency related scatter if plot_freq: print("Plot frequency related calibration for field: {} ...".format(field)) os.system('mkdir -p {}/freq_{}/'.format(outdir, ydatacolumn)) for field_single in field.split(','): print(">> field: {}".format(field_single)) for yx in yaxis: if refant == 'all': for spw_single in spw.split(','): plotms(vis=vis, field=field_single, xaxis='frequency', yaxis=yx, spw=spw_single, avgtime=avgtime, avgscan=False, coloraxis='corr', ydatacolumn=ydatacolumn, showgui=showgui, dpi = dpi, overwrite=overwrite, verbose=False, plotfile='{}/freq_{}/field{}-spw{}-{}_vs_freq.all.png'.format( outdir, ydatacolumn, field_single, spw_single, yx)) else: if refant == '': iteraxis = 'antenna' else: iteraxis = 'baseline' # generate all the antenna firstly subgroups = group_antenna(vis, refant=refant, subgroup_member=gridrows*gridcols) # print(subgroups) for page, subgroup in enumerate(subgroups): for spw_single in spw.split(','): if spw == '': mycoloraxis = 'spw' else: mycoloraxis = 'corr' plotms(vis=vis, field=field_single, xaxis='frequency', yaxis=yx, spw=spw_single, avgtime=avgtime, avgscan=False, coloraxis=mycoloraxis, antenna=subgroup, iteraxis=iteraxis, ydatacolumn=ydatacolumn, showgui=showgui, gridrows=gridrows, gridcols=gridcols, dpi = dpi, overwrite=overwrite, verbose=False, highres=True, plotfile='{}/freq_{}/field{}-spw{}-{}_vs_freq.page{}.png'.format( outdir, ydatacolumn, field_single, spw_single, yx, page), **kwargs) # the phase should be significantly improved after bandpass calibration # especially for the phase calibrator if plot_time: print("Plot time related calibration for field: {} ...".format(field)) os.system('mkdir -p {}/time_{}/'.format(outdir, ydatacolumn)) for field_single in field.split(','): print(">> field: {}".format(field_single)) for yx in yaxis: # plot the general consistency of each field if refant == 'all': for spw_single in spw.split(','): plotms(vis=vis, field=field_single, xaxis='time', yaxis=yx, spw=spw_single, avgchannel=avgchannel, coloraxis='corr', ydatacolumn=ydatacolumn, plotfile='{}/time_{}/field{}-spw{}-{}_vs_time.png'.format( outdir, ydatacolumn, field_single, spw_single, yx), showgui=showgui, dpi = dpi, overwrite=overwrite) else: if refant == '': iteraxis = 'antenna' else: iteraxis = 'baseline' subgroups = group_antenna(vis, refant=refant, subgroup_member=gridrows*gridcols) for page, subgroup in enumerate(subgroups): for spw_single in spw.split(','): if spw == '': mycoloraxis = 'spw' else: mycoloraxis = 'corr' plotms(vis=vis, field=field_single, xaxis='time', yaxis=yx, spw=spw_single, avgchannel=avgchannel, coloraxis=mycoloraxis, antenna=subgroup, iteraxis=iteraxis, ydatacolumn=ydatacolumn, showgui=showgui, gridrows=gridrows, gridcols=gridcols, plotfile='{}/time_{}/field{}_spw{}_{}_vs_time.page{}.png'.format( outdir, ydatacolumn, field_single, spw_single, yx, page), dpi = dpi, overwrite=overwrite, highres=True, **kwargs) if plot_uvdist: # well behaved point source should show flat amplitude with uvdist print("Plot uvdist related calibration for {} ...".format(field)) os.system('mkdir -p {}/uvdist/'.format(outdir)) for field_single in field.split(','): print('>> field: {}'.format(field_single)) for spw_single in spw.split(','): if spw == '': mycoloraxis = 'spw' else: mycoloraxis = 'corr' plotms(vis=vis, field=field_single, xaxis='uvdist', yaxis='amp', spw=spw_single, avgchannel=avgchannel, coloraxis='corr', ydatacolumn=ydatacolumn, plotfile='{}/uvdist/field{}_spw{}_amp_vs_uvdist.png'.format(outdir, field_single, spw_single), dpi=dpi, overwrite=overwrite, showgui=showgui, highres=True, **kwargs) plotms(vis=vis, field=field_single, xaxis='U', yaxis='V', spw=spw_single, avgchannel=avgchannel, coloraxis=mycoloraxis, ydatacolumn=ydatacolumn, plotfile='{}/uvdist/field{}_spw{}_uvcoverage.png'.format(outdir, field_single, spw_single), dpi=dpi, overwrite=overwrite, showgui=showgui, highres=True, **kwargs)
def check_tsys(tsystable=None, spws=None, ants_subgroups=None, gridcols=2, gridrows=3, basename=None, basedir='./', plotdir='./plots', showgui=False, dpi=400): """the stand alone plot function for tsys Example ------- check_tsys(tsystable='msfile1.tsys') check_tsys(tsystable='msfile1.tsys', spws='13,15,17,19') Parameters ---------- vis : str visibility of the measurement file tdmspws : str time domain mode spws, seperated with comma ants_subgroups (list): the list contains the subgroups to be plot into one figure spws : str time domain mode spws, for example: '2,3,4' or '2~3' gridrows : int the rows for subplots gridcols : int the columns for subplots plotdir : str the directory where to generate the plots showgui : bool set to "True" to open the gui window """ if basename is None: basename = os.path.basename(tsystable) if ants_subgroups is None: ants_subgroups = group_antenna(vis=tsystable, subgroup_member=gridrows*gridcols) outdir = '{}/tsys-{}'.format(plotdir, basename) os.system('mkdir -p {}'.format(outdir)) # plot tsys vs time, to pick out bad antenna for page,antenna in enumerate(ants_subgroups): plotms(vis=tsystable, xaxis='time', yaxis='Tsys', coloraxis='spw', antenna=antenna, gridcols=2, gridrows=gridrows, iteraxis='antenna', showgui=showgui, dpi=dpi, highres=True, plotfile='{}/Tsys_vs_time.page{}.png'.format(outdir, page)) # plot tsys vs frequency if spws is not None: for spw in spw_expand(spws): plotms(vis=tsystable, xaxis='channel', yaxis='Tsys', spw=spw, gridcols=2, gridrows=gridrows, iteraxis='antenna', coloraxis='corr', antenna=antenna, showgui=showgui, plotfile='{}/spw{}_tsys_vs_freq.page{}.png'.format(outdir, spw, page), dpi=dpi, highres=True) else: plotms(vis=tsystable, xaxis='freq', yaxis='Tsys', spw='', gridcols=2, gridrows=gridrows, iteraxis='antenna', coloraxis='corr', antenna=antenna, showgui=showgui, plotfile='{}/tsys_vs_freq.page{}.png'.format(outdir, page), dpi=dpi, highres=True)
def check_cal(vis=None, fdmspw=None, tdmspws=None, calibrator_fields=None, ants=None, refant=None, detail=1, ydatacolumn='corrected', bandpass_calibrator=None, phase_calibrator=None, science_field=None, flux_calibrator=None, plot_tsys=False, plot_freq=False, plot_time=False, plot_bandpass=False, plot_solutions=False, plot_target=False, plot_uvdist=False, overwrite=True, showgui=False, dpi=600, plotdir='./plots'): """check the calibrated data after applycal the wrapped plotms for self calibration Parameters ---------- vis : str measurements file fdmspw : str the spw of frequency domain mode tdmspws : str the spws of time domain mode, the spws used for tsys calibration usually 128 channels. example: '1,3,4', '1~3' calibrator_fields : list a list contains all the fields of calibrators example: ['0', '2', '3'] or ['J1427-4206', 'Mars'] science_field : str the fields of the science target example: 'Cen*' or '4~22' ydatacolumn : str the ydatacolumn of `plotms` detail : str what detail the plot generates 0: gather all the antenna based information without set the `interation` 1: generates all the plots with `interation`='antenna' 2: generates all the plots with `interation`='baseline', require `refant` ants : list all the antennas to be included refant : str the reference antenna, like 'CM03', 'DV48' bandpass_calibrator : str the field of bandpass calibrator example: '0' or 'J1427-4206' phase_calibrator : str the same as bandpass_calibrator but for bandpass flux_calibrator : str the same as bandpass_calibrator but for flux calibrator plot_tsys : bool plot the tsys calibration table, the filename should be vis+'.tsys' require: `tdmspws` plot_freq : bool plot the amplitude-vs-frequency, phase-vs-frequency for both data column and corrected data column require: `fdmspw`, `refant`, `calibrator_fields` plot_time : bool plot the amplitude-vs-time, phase-vs-time for both data column and corrected data column require: `fdmspw`, `refant`, `calibrator_fields` plot_uvdist : bool plot amplitude-vs-uvdist require: `calibrator_fields` plot_solutions : bool plot bandpass calibration and gain calibration require: `flux_calibrator`, and with vis+'.banpass.cal', vis+'.phase_inf.cal', vis+'flux.cal' availabe in current directory plot_target : bool plot the amplitude-vs-amplitude and amplitude-vs-frequency for the science target require: `science_field` plot_bandpass : bool the plot option to control the plotbandpass task. The default value is false since plotbandpass always make casa crash overwrite, showgui, dpi the same option for plotms, see casa document for more detail plotdir : str the root directory to put all the generated plots """ # Extract the antenna list from ms if ants is None: tb = tbtool() tb.open(vis + '/ANTENNA', nomodify=True) ants = tb.getcol('NAME') tb.close() # generates the antenna or baseline subgroups gridcols = 2 # default subgroup_member = 6 # default gridrows = subgroup_member / gridcols # default column number is 2 if detail >= 1: ants_subgroups = group_antenna(ants, subgroup_member=subgroup_member) if detail >= 2: if refant is None: refant = random.choice(ants) print('Warning: No refant specified, choose a random one!') baselines = refant + '&*' # all the related baseline baselines_subgroups = group_antenna(ants, refant, subgroup_member=subgroup_member) if bandpass_calibrator: calibrator_fields = [bandpass_calibrator] # plot the frequency related scatter if plot_freq: print("Plot frequency related calibration for fields: {} ...".format( calibrator_fields)) os.system('mkdir -p {}/freq_{}/'.format(plotdir, ydatacolumn)) for yaxis in ['amplitude', 'phase']: for field in calibrator_fields: if detail >= 0: for spw_single in spw_expand(fdmspw): plotms( vis=vis, field=field, xaxis='frequency', yaxis=yaxis, spw=spw_single, avgtime='1e8', avgscan=True, coloraxis='corr', ydatacolumn=ydatacolumn, showgui=showgui, dpi=dpi, overwrite=overwrite, verbose=False, plotfile='{}/freq_{}/field{}-spw{}-amp_vs_{}.all.png' .format(plotdir, ydatacolumn, field, spw_single, yaxis)) if detail >= 1: # antenna based plots for page, antenna in enumerate(ants_subgroups): for spw_single in spw_expand(fdmspw): plotms( vis=vis, field=field, xaxis='frequency', yaxis=yaxis, spw=spw_single, avgtime='1e8', avgscan=True, coloraxis='corr', antenna=antenna, iteraxis='antenna', ydatacolumn=ydatacolumn, showgui=showgui, gridrows=gridrows, gridcols=2, dpi=dpi, overwrite=overwrite, verbose=False, plotfile= '{}/freq_{}/field{}-spw{}-amp_vs_{}.page{}.png' .format(plotdir, ydatacolumn, field, spw_single, yaxis, page)) if detail >= 2: #baseline based plots for page, baselines in enumerate(baselines_subgroups): for spw_single in spw_expand(fdmspw): plotms( vis=vis, field=field, xaxis='frequency', yaxis=yaxis, spw=spw_single, avgtime='1e8', avgscan=True, coloraxis='corr', antenna=baselines, iteraxis='baseline', ydatacolumn=ydatacolumn, showgui=showgui, gridrows=gridrows, gridcols=2, dpi=dpi, overwrite=overwrite, verbose=False, plotfile= '{}/freq_{}/field{}-spw{}-amp_vs_{}.page{}.png' .format(plotdir, ydatacolumn, field, spw_single, yaxis, page)) # the phase should be significantly improved after bandpass calibration # especially for the phase calibrator if plot_time: print("Plot time related calibration for fields: {} ...".format( calibrator_fields)) os.system('mkdir -p {}/time_{}/'.format(plotdir, ydatacolumn)) for yaxis in ['amplitude', 'phase']: # plot the general consistency of each field for field in calibrator_fields: if detail >= 0: for spw_single in spw_expand(fdmspw): plotms(vis=vis, field=field, xaxis='time', yaxis=yaxis, spw=spw_single, avgchannel='1e8', coloraxis='corr', ydatacolumn=ydatacolumn, showgui=showgui, dpi=dpi, overwrite=overwrite, plotfile='{}/time_{}/field{}_{}_vs_time.png'. format(plotdir, ydatacolumn, field, yaxis)) if detail >= 1: # antenna based plots for page, antenna in enumerate(ants_subgroups): for spw_single in spw_expand(fdmspw): plotms(vis=vis, field=field, xaxis='time', yaxis=yaxis, spw=spw_single, avgchannel='1e8', coloraxis='corr', antenna=antenna, iteraxis='antenna', ydatacolumn=ydatacolumn, showgui=showgui, gridrows=gridrows, gridcols=2, dpi=dpi, overwrite=overwrite, plotfile= '{}/time_{}/field{}_{}_vs_time.page{}.png'. format(plotdir, ydatacolumn, field, yaxis, page)) if detail >= 2: # baseline based plots for page, baselines in enumerate(baselines_subgroups): for spw_single in spw_expand(fdmspw): plotms(vis=vis, field=field, xaxis='time', yaxis=yaxis, spw=spw_single, avgchannel='1e8', coloraxis='corr', antenna=baselines, iteraxis='baseline', ydatacolumn=ydatacolumn, showgui=showgui, gridrows=gridrows, gridcols=2, dpi=dpi, overwrite=overwrite, plotfile= '{}/time_{}/field{}_{}_vs_time.page{}.png'. format(plotdir, ydatacolumn, field, yaxis, page)) if plot_tsys: # plot tsys vs time, to pick out bad antenna check_tsys(vis=vis, ants_subgroups=ants_subgroups, plotdir=plotdir, tdmspws=tdmspws, gridrows=gridrows, gridcols=gridcols, showgui=showgui) if plot_uvdist: # well behaved point source should show flat amplitude with uvdist print("Plot uvdist related calibration for {} ...".format( calibrator_fields)) os.system('mkdir -p {}/uvdist/'.format(plotdir)) for field in calibrator_fields: plotms(vis=vis, field=field, xaxis='uvdist', yaxis='amp', avgchannel='1e8', coloraxis='corr', showgui=showgui, dpi=dpi, overwrite=overwrite, plotfile='{}/uvdist/field{}_amp_vs_uvdist.png'.format( plotdir, field)) if plot_solutions: print("Plot calibration solutions ...".format(calibrator_fields)) os.system('mkdir -p {}/solutions/'.format(plotdir)) # bandpass if plot_bandpass: aU.plotbandpass( caltable=vis + '.bandpass.cal', xaxis='freq', yaxis='both', showatm=True, interactive=showgui, subplot=42, figfile='{}/solutions/bandpasscal.png'.format(plotdir)) # flux calibrator model plotms(vis=vis, xaxis='uvdist', yaxis='amp', ydatacolumn='model', field=flux_calibrator, avgtime='1e8', coloraxis='corr', showgui=showgui, dpi=dpi, overwrite=overwrite, plotfile='{}/solutions/flux_model_amp.png'.format(plotdir)) plotms(vis=vis, xaxis='uvdist', yaxis='phase', ydatacolumn='model', field=flux_calibrator, avgtime='1e8', coloraxis='corr', showgui=showgui, dpi=dpi, overwrite=overwrite, plotfile='{}/solutions/flux_model_phase.png'.format(plotdir)) # phase calibration table for page, antenna in enumerate(ants_subgroups): plotms(vis=vis + '.phase_inf.cal', xaxis='time', yaxis='phase', coloraxis='corr', iteraxis='antenna', gridcols=2, gridrows=gridrows, showgui=showgui, dpi=dpi, overwrite=overwrite, plotfile='{}/solutions/phase_inf_cal_page{}.png'.format( plotdir, page)) # flux calibration table plotms(vis=vis + '.flux.cal', xaxis='time', yaxis='amp', coloraxis='corr', iteraxis='antenna', gridcols=2, gridrows=gridrows, showgui=showgui, dpi=dpi, overwrite=overwrite, plotfile='{}/solutions/flux_cal_page{}.png'.format( plotdir, page)) if plot_target: print("Giving the science target a glance ...") os.system('mkdir -p {}/target/'.format(plotdir)) if science_field is None: raise ValueError("Science field is not specified!") plotms(vis=vis, xaxis='uvdist', yaxis='amp', ydatacolumn=ydatacolumn, field=science_field, avgchannel='1e8', coloraxis='corr', plotfile='{}/target/target_amp_vs_uvdist.png'.format(plotdir), showgui=showgui, dpi=dpi, overwrite=overwrite) for spw in spw_expand(fdmspw): plotms(vis=vis, xaxis='freq', yaxis='amp', spw=spw, ydatacolumn=ydatacolumn, field=science_field, avgtime='1e8', avgscan=True, coloraxis='corr', plotfile='{}/target/target_amp_vs_freq.png'.format(plotdir), showgui=showgui, dpi=dpi, overwrite=overwrite)
def check_tsys(vis=None, tdmspws=None, ants_subgroups=None, gridcols=2, gridrows=3, plotdir='./plots', showgui=False): """the stand alone plot function for tsys Parameters ---------- vis : str visibility of the measurement file tdmspws : str time domain mode spws ants_subgroups : list the list contains the subgroups to be plot into one figure tdmspws : str time domain mode spws for example: '2,3,4' or '2~3' gridrows : int the rows for subplots gridcols : int the columns for subplots plotdir : str the directory where to generate the plots showgui : bool set to "True" to open the gui window """ if ants_subgroups is None: # Extract the antenna list from ms tb = tbtool() tb.open(vis + '/ANTENNA', nomodify=True) ants = tb.getcol('NAME') tb.close() ants_subgroups = group_antenna(ants, subgroup_member=gridrows * gridcols) os.system('mkdir -p {}/tsys/'.format(plotdir)) # plot tsys vs time, to pick out bad antenna for page, antenna in enumerate(ants_subgroups): plotms(vis=vis + '.tsys', xaxis='time', yaxis='Tsys', coloraxis='spw', antenna=antenna, gridcols=2, gridrows=gridrows, iteraxis='antenna', showgui=showgui, plotfile='{}/tsys/Tsys_vs_time.page{}.png'.format( plotdir, page)) # plot tsys vs frequency if tdmspws is None: raise ValueError("No tdmspws founded!") for spw in spw_expand(tdmspws): plotms(vis=vis + '.tsys', xaxis='freq', yaxis='Tsys', spw=spw, gridcols=2, gridrows=gridrows, iteraxis='antenna', coloraxis='corr', antenna=antenna, showgui=showgui, plotfile='{}/tsys/spw{}_tsys_vs_freq.page{}.png'.format( plotdir, spw, page))
def check_info(vis=None, showgui=False, plotdir='./plots', sciencespws='', show_ants=True, show_mosaic=True, show_uvcoverage=True, show_allobs=True): """ plot the basic information of the observation. Plots include: antenna positions, UV coverage, mosaic coverage(if possible) Parameters ---------- vis : str measurement file showgui : bool show the plot window, (the plotmosaic does not support yet) info_dir : str the base directory for all the info plots sciencespws : str the spw related to the science target show_mosaic : bool plot the relative positions of the mosaic show_ants : bool plot the positions of the antennae show_uvcoverage : bool plot the uv coverage of different field, or only the science target if sciencespws is specified show_allobs : bool plot the all the amp vs time """ os.system('mkdir -p {}/info'.format(plotdir)) plotdir = plotdir + '/info' if show_ants: plotants(vis=vis, figfile='{}/antenna_position.png'.format(plotdir)) if show_mosaic: aU.plotmosaic(vis, figfile='{}/mosaic.png'.format(plotdir)) if show_uvcoverage: plotms(vis=vis, xaxis='U', yaxis='V', coloraxis='field', spw=sciencespws, showgui=showgui, plotfile='{}/uvcoverage.png'.format(plotdir), overwrite=True) if show_allobs: plotms(vis=vis, xaxis='time', yaxis='amp', avgchannel='1e8', avgtime='100', coloraxis='field', showgui=showgui, plotfile='{}/all_observations.png'.format(plotdir), overwrite=True)