コード例 #1
0
ファイル: casa_utils.py プロジェクト: Chuneeta/beam_solver
def subtract_model_ant(dset, ant, script='subtract_mod_ant', operation='subtract', delete=False):
    casa_opt = casawrapper.create_casa_options(nologger='0', nogui='0', nologfile='0')
    task_opt = "import numpy as np; import copy\n"
    task_opt += "operation='{}'\n".format(operation)
    task_opt += "ms = casac.table()\n"
    task_opt += "ms.open('{}', nomodify=False)\n".format(dset)
    task_opt += "datacol = 'CORRECTED_DATA' if 'CORRECTED_DATA' in ms.colnames() else 'DATA'\n"
    task_opt += "data = ms.getcol(datacol)\n"
    task_opt += "model = ms.getcol('MODEL_DATA')\n"
    task_opt += "A1 = ms.getcol('ANTENNA1')\n"
    task_opt += "inds = np.where(A1=={})\n".format(ant)
    task_opt += "data_bl = data[:, :, inds[0]]\n"
    task_opt += "mod_bl = model[:, :, inds[0]]\n"
    task_opt += "new_data = copy.deepcopy(data)\n"
    task_opt += "if operation == 'add':\n"
    task_opt += "   new_data[:, :, inds[0]] = data_bl + mod_bl\n"
    task_opt += "   ms.putcol(datacol, new_data)\n"
    task_opt += "else:\n"
    task_opt += "   new_data[:, :, inds[0]] = data_bl - mod_bl\n"
    task_opt += "   ms.putcol(datacol, new_data)\n"
    task_opt += "ms.close()"
    stdout = open(script + ".py", "w")
    stdout.write(task_opt)
    stdout.close()
    casawrapper.call_casa_script(script + ".py", casa_opt, delete=delete)
コード例 #2
0
ファイル: casa_utils.py プロジェクト: Chuneeta/beam_solver
def create_complist(infile, outfile='component.cl', script='create_cl', delete=False):
    """
    Creates component list of sources
    Parameters:
    -----------
    infile : Input text file containing the required parameters (see generate_complist_input function for the input format)
    outfile :  Output name of the component list
    Returns
    -------
    CASA Component with all the components
    """
    if os.path.exists(outfile):
        print ('WARNING: overwritting existed file')
        os.system('rm -rf {}'.format(outfile))
    stdout = open(script + '.py', 'wb')
    sources = numpy.loadtxt(infile, dtype='str', delimiter=':')
    if sources.ndim == 1: sources = sources.reshape((1, len(sources)))
    for src in sources:
        task_opt = "dir='{}', flux={}, fluxunit='Jy', shape='point', spectrumtype='spectral index', index={}, freq='{}MHz'".format(src[0], float(src[1]), float(src[2]), float(src[3])) 
        text = ('cl.addcomponent({})\n'.format(task_opt)).encode()
        stdout.write(text)    
    text = ("cl.rename('{}')\ncl.close()".format(outfile)).encode()
    stdout.write(text)
    stdout.close()
    casa_opt = casawrapper.create_casa_options(nologger='0', nogui='0', nologfile='0')
    casawrapper.call_casa_script(script + '.py', casa_opts=casa_opt, delete=delete)
コード例 #3
0
ファイル: casa_utils.py プロジェクト: Chuneeta/beam_solver
def writeto(dset, data_array, column_to, script='writeto', delete=False):
    casa_opt = casawrapper.create_casa_options(nologger='0', nogui='0', nologfile='0')
    task_opt = "ms = casac.table()\n"
    task_opt += "ms.open('{}', nomodify=False)\n".format(dset)
    task_opt += "if '{}' in ms.colnames():\n".format(column_to)
    task_opt += "   ms.putcol('{}', {})\n".format(column_to, data_array)
    task_opt += "ms.close()"
    stdout = open(script + ".py", "w")
    stdout.write(task_opt)
    stdout.close()
    casawrapper.call_casa_script(script + ".py", casa_opt, delete=delete)
コード例 #4
0
ファイル: casa_utils.py プロジェクト: Chuneeta/beam_solver
def change_pc(dset, script='pc', delete=False):
    casa_opt = casawrapper.create_casa_options(nologger='0', nogui='0', nologfile='0')
    task_opt = "import numpy as np\n"
    task_opt += "ms = casac.table()\n"
    task_opt += "ms.open('{}/FIELD', nomodify=False)\n".format(dset)
    task_opt += "pc =np.array([[[ 0.87707669]],[[-0.53722607]]])\n"
    task_opt += "ms.putcol('PHASE_DIR', pc)\n"
    task_opt += "ms.close()"
    stdout = open(script + ".py", "w")
    stdout.write(task_opt)
    stdout.close()
    casawrapper.call_casa_script(script + ".py", casa_opt, delete=delete)
コード例 #5
0
ファイル: casa_utils.py プロジェクト: Chuneeta/beam_solver
def get_freq(dset, outname, script='get_freqs', delete=False):
    casa_opt = casawrapper.create_casa_options(nologger='0', nogui='0', nologfile='0')
    task_opt = "import numpy as np\n"
    task_opt += "ms = casac.table()\n"
    task_opt += "ms.open('{}/SPECTRAL_WINDOW', nomodify=False)\n".format(dset)
    task_opt += "freqs = ms.getcol('CHAN_FREQ')\n"
    task_opt += "ms.close()\n"
    task_opt += "np.save('{}', freqs)".format(outname)
    stdout = open(script + ".py", "w")
    stdout.write(task_opt)
    stdout.close()
    casawrapper.call_casa_script(script + ".py", casa_opt, delete=delete)
コード例 #6
0
ファイル: casa_utils.py プロジェクト: Chuneeta/beam_solver
def set_to_unflag(dset, script='unflag', delete=False):
    casa_opt = casawrapper.create_casa_options(nologger='0', nogui='0', nologfile='0')
    task_opt = "import numpy as np\n"
    task_opt += "ms = casac.table()\n"
    task_opt += "ms.open('{}', nomodify=False)\n".format(dset)
    task_opt += "flags = ms.getcol('FLAG')\n"
    task_opt += "new_flags = np.zeros(flags.shape, dtype=np.bool)\n"
    task_opt += "ms.putcol('FLAG', new_flags)\n"
    task_opt += "ms.close()"
    stdout = open(script + ".py", "w")
    stdout.write(task_opt)
    stdout.close()
    casawrapper.call_casa_script(script + ".py", casa_opt, delete=delete)
コード例 #7
0
ファイル: casa_utils.py プロジェクト: Chuneeta/beam_solver
def read_col(dset, column, outfile='data', script='read_col', delete=False):
    casa_opt = casawrapper.create_casa_options(nologger='0', nogui='0', nologfile='0')
    task_opt = "ms = casac.table()\n"
    task_opt += "ms.open('{}', nomodify=False)\n".format(dset)
    task_opt += "if '{}' in ms.colnames():\n".format(column)
    task_opt += "   data = ms.getcol('{}')\n".format(column)
    task_opt += "ms.close()\n"
    task_opt += "import numpy as np\n"
    task_opt += "np.save('{}', data)".format(outfile)
    stdout = open(script + ".py", "w")
    stdout.write(task_opt)
    stdout.close()
    casawrapper.call_casa_script(script + ".py", casa_opt, delete=delete)
コード例 #8
0
ファイル: casa_utils.py プロジェクト: Chuneeta/beam_solver
def subtract_model(dset, script='subtract_mod', operation='subtract', delete=False):
    casa_opt = casawrapper.create_casa_options(nologger='0', nogui='0', nologfile='0')
    task_opt = "operation='{}'\n".format(operation)
    task_opt += "ms = casac.table()\n"
    task_opt += "ms.open('{}', nomodify=False)\n".format(dset)
    task_opt += "datacol = 'CORRECTED_DATA' if 'CORRECTED_DATA' in ms.colnames() else 'DATA'\n"
    task_opt += "data = ms.getcol(datacol)\n"
    task_opt += "if 'MODEL_DATA' in ms.colnames():\n"
    #task_opt += "data = ms.getcol('CORRECTED_DATA') if 'CORRECTED_DATA' in ms.colnames() else ms.getcol('DATA')\n"
    task_opt += "   if operation == 'add':\n"
    task_opt += "       ms.putcol(datacol, data + ms.getcol('MODEL_DATA'))\n"
    task_opt += "   else:\n"
    task_opt += "       ms.putcol(datacol, data - ms.getcol('MODEL_DATA'))\n"
    task_opt += "ms.close()"
    stdout = open(script + ".py", "w")
    stdout.write(task_opt)
    stdout.close()
    casawrapper.call_casa_script(script + ".py", casa_opt, delete=delete)
コード例 #9
0
def test_call_casa_script():
    direc = os.getcwd()
    scriptname = os.path.join(direc, 'execute.py')
    cw.call_casa_script(scriptname, casa_opts={'nologger': '0'}, delete=True)
    nt.assert_false(os.path.exists(scriptname))