コード例 #1
0
def _checkfile(filename, datacolumn):
    import re
    # Currently this supports only ms files
    # As such there is no reason to check filetype.
    # If it cannot be opened as ms it will not be supported.
    #     if re.match('^.*[mM][sS]/*$', filename) is not None:
    try:
        from taskinit import ms
        ms.open(filename)
        ms.done()
    except ImportError:
        # This probably means that it was run from a pure python session.
        # We will relegate any checks that it is a valid ms file to the
        # stacker.
        if not os.access(filename, os.F_OK):
            raise RuntimeError(
                'Could not find data file "{}".'.format(filename))

    filename = filename
    filetype = FILE_TYPE_MS
    fileoptions = 0
    if datacolumn == 'data':
        fileoptions = MS_DATACOLUMN_DATA
    elif datacolumn == 'model' or datacolumn == 'model_data':
        fileoptions = MS_MODELCOLUMN_DATA


#     elif re.match('^.*[fF][iI][tT][sS]$', filename) is not None:
#         raise NotImplementedError('FITS format is currently not supported.')
    return filetype, filename, fileoptions
コード例 #2
0
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
コード例 #3
0
ファイル: uvutil.py プロジェクト: astro313/uvmcmcfit
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
コード例 #4
0
ファイル: uvutil.py プロジェクト: astro313/uvmcmcfit
def checkMS(msFile, cont=True):
    """ get the number of spw and channels in the measurement set
    for continuum: combine into 1 channel and spw before running uvmcmcfit

    Parameters
    ----------
    msFile: string
        CASA measurement set

    Returns
    -------
    nspw:
        number of spw
    nchan:
        number of channels

    """
    from taskinit import ms
    ms.open(msFile)
    metadata = ms.metadata()
    ms.done()
    nspw = metadata.nspw()
    for i in range(nspw):
        # number of channels in each spw
        nchan = metadata.nchan(spw)
    metadata.done()
    return nspw, nchan
コード例 #5
0
def make_pbfile(vis, pbfile):
    from taskinit import im, ms, ia, qa, tb
    import numpy as np
    from scipy.constants import c

    ms.open(vis)
    fields = ms.range('field_id')['field_id']
    ms.done()
    im.open(vis)
    im.selectvis(field=fields[0])
    ms.open(vis)
    freq = np.mean(ms.range('chan_freq')['chan_freq'])
    phase_dir = ms.range('phase_dir')['phase_dir']['direction']
    ms.done()

    phase_dir = phase_dir[0][0], phase_dir[1][0]
    phase_dir = [
        qa.formxxx(str(phase_dir[0]) + 'rad', format='hms'),
        qa.formxxx(str(phase_dir[1]) + 'rad', format='dms')
    ]
    phase_dir = 'J2000 ' + ' '.join(phase_dir)

    tb.open(vis + '/ANTENNA/')
    dishdia = np.min(tb.getcol('DISH_DIAMETER'))
    tb.done()

    # pb of 512 pix cover pb down to 0.001
    # ensure largest pixel to pixel var to .01
    minpb = 0.001
    nx = 512
    cellconv = (nx * np.sqrt(np.log(2) / np.log(1 / minpb)))**-1

    beam = c / freq / dishdia
    cell = {}
    cell['value'] = beam * cellconv
    cell['unit'] = 'rad'

    #     nx = int(3*3e8/freq/dishdia*1.22*180/
    #              math.pi*3600/qa.convert(advise['cell'],
    #              'arcsec')['value'])
    # Chosen as to be 3 times fwhm of primary beam,
    # should include up to approximately .01 of peak flux

    im.defineimage(nx=nx, ny=nx, cellx=cell, celly=cell, phasecenter=phase_dir)
    im.setvp(dovp=True)
    im.makeimage(type='pb', image=pbfile)
    im.done()
    ia.open(pbfile)
    cs = ia.coordsys()
    cs.setreferencevalue(type='direction', value=[0., 0.])
    ia.setcoordsys(cs.torecord())
    ia.maskhandler('delete', 'mask0')
    ia.done()
コード例 #6
0
ファイル: __init__.py プロジェクト: thatoeugine/stacker
def guesspb(vis):
    """
    Produces a PrimaryBeamModel from a measurementset
    """
    print(vis)
    from taskinit import ms, tb, qa
    ms.open(vis)
    freq = (np.mean(ms.range('chan_freq')['chan_freq']) / 1e9)
    ms.done()
    tb.open(vis + '/OBSERVATION')
    telescope = tb.getcol('TELESCOPE_NAME')[0]
    tb.done()
    pbfile = '{0}-{1:.1f}GHz.pb'.format(telescope, freq)
    print(pbfile)
    if not os.access(pbfile, os.F_OK):
        stacker.make_pbfile(vis, pbfile)
    return MSPrimaryBeamModel(pbfile)