<commit_before>"""
2014 January 31
<NAME>

Varius utilities related to operations on uvfits data files.
"""

from __future__ import print_function

import numpy
from astropy.io import fits

def pcdload(visfile):

    # read in the uvfits data
    visheader = visfile[0].header

    # identify the telescope
    telescop = visheader['TELESCOP']

    if telescop == 'ALMA':

        # identify the phase center
        pcd_ra = visfile['AIPS SU '].data['RAEPO'][0]
        pcd_dec = visfile['AIPS SU '].data['DECEPO'][0]
        pcd = [pcd_ra, pcd_dec]
        return pcd

    if telescop == 'PdBI':

       # identify the channel frequency(ies):
        pcd_ra = visfile[0].header['OBSRA']
        pcd_dec = visfile[0].header['OBSDEC']
        pcd = [pcd_ra, pcd_dec]
        return pcd

def uvload(visfile):

    # read in the uvfits data
    #visfile = fits.open(visdataloc)
    visibilities = visfile[0].data
    visheader = visfile[0].header

    # identify the telescope
    telescop = visheader['TELESCOP']

    if telescop == 'ALMA':

        # identify the channel frequency(ies):
        visfreq = visfile[1].data
        freq0 = visheader['CRVAL4']
        dfreq = visheader['CDELT4']
        cfreq = visheader['CRPIX4']
        nvis = visibilities['DATA'][:, 0, 0, 0, 0, 0, 0].size
        nspw = visibilities['DATA'][0, 0, 0, :, 0, 0, 0].size
        nfreq = visibilities['DATA'][0, 0, 0, 0, :, 0, 0].size
        npol = visibilities['DATA'][0, 0, 0, 0, 0, :, 0].size
        uu = numpy.zeros([nvis, nspw, nfreq, npol])
        vv = numpy.zeros([nvis, nspw, nfreq, npol])
        #wgt = numpy.zeros([nvis, nspw, nfreq, npol])

        for ispw in range(nspw):
            if nspw > 1:
                freqif = freq0 + visfreq['IF FREQ'][0][ispw]
            else:
                freqif = freq0
            #uu[:, ispw] = freqif * visibilities['UU']
            #vv[:, ispw] = freqif * visibilities['VV']

            for ipol in range(npol):

                # then compute the spatial frequencies:
                if nfreq > 1:
                    freq = (numpy.arange(nfreq) - cfreq + 1) * dfreq + freqif
                    freqvis = numpy.meshgrid(freq, visibilities['UU'])
                    uu[:, ispw, :, ipol] = freqvis[0] * freqvis[1]
                    freqvis = numpy.meshgrid(freq, visibilities['VV'])
                    vv[:, ispw, :, ipol] = freqvis[0] * freqvis[1]
                else:
                    uu[:, ispw, 0, ipol] = freqif * visibilities['UU']
                    vv[:, ispw, 0, ipol] = freqif * visibilities['VV']

    if telescop == 'PdBI':

        # identify the channel frequency(ies):
        freq0 = visheader['CRVAL4']
        dfreq = visheader['CDELT4']
        cfreq = visheader['CRPIX4']
        nvis = visibilities['DATA'][:, 0, 0, 0, 0, 0].size
        nfreq = visibilities['DATA'][0, 0, 0, :, 0, 0].size
        npol = visibilities['DATA'][0, 0, 0, 0, :, 0].size
        uu = numpy.zeros([nvis, nfreq, npol])
        vv = numpy.zeros([nvis, nfreq, npol])
        #wgt = numpy.zeros([nvis, nspw, nfreq, npol])

        freqif = freq0
        #uu[:, ispw] = freqif * visibilities['UU']
        #vv[:, ispw] = freqif * visibilities['VV']

        for ipol in range(npol):

            # then compute the spatial frequencies:
            if nfreq > 1:
                freq = (numpy.arange(nfreq) - cfreq + 1) * dfreq + freqif
                freqvis = numpy.meshgrid(freq, visibilities['UU'])
                uu[:, :, ipol] = freqvis[0] * freqvis[1]
                freqvis = numpy.meshgrid(freq, visibilities['VV'])
                vv[:, :, ipol] = freqvis[0] * freqvis[1]
            else:
                uu[:, 0, ipol] = freqif * visibilities['UU']
                vv[:, 0, ipol] = freqif * visibilities['VV']
                #www = freqif * visibilities['WW']

    return uu, vv

def visload(visfile):
    # get the telescope name
    visheader = visfile[0].header
    #telescop = visheader['TELESCOP']

    # if we are dealing with SMA data
    if visheader['NAXIS'] == 6:
        data_real = visfile[0].data['DATA'][:,0,0,:,:,0]
        data_imag = visfile[0].data['DATA'][:,0,0,:,:,1]
        data_wgt = visfile[0].data['DATA'][:,0,0,:,:,2]

    # if we are dealing with ALMA data
    if visheader['NAXIS'] == 7:
        data_real = visfile[0].data['DATA'][:,0,0,:,:,:,0]
        data_imag = visfile[0].data['DATA'][:,0,0,:,:,:,1]
        data_wgt = visfile[0].data['DATA'][:,0,0,:,:,:,2]

    return data_real, data_imag, data_wgt

def getStatWgt(real_raw, imag_raw, wgt_raw):

    """
    Compute the weights as the rms scatter in the real and imaginary 
    visibilities.
    """<commit_msg>Bug fix for PdBI uvfits files.<commit_after>"""
2014 January 31
<NAME>

Varius utilities related to operations on uvfits data files.
"""

from __future__ import print_function

import numpy
from astropy.io import fits

def pcdload(visfile):

    # identify the dimensions of the data in the uvfits file
    visheader = visfile[0].header

    if visheader['NAXIS'] == 7:

        # identify the phase center
        pcd_ra = visfile['AIPS SU '].data['RAEPO'][0]
        pcd_dec = visfile['AIPS SU '].data['DECEPO'][0]
        pcd = [pcd_ra, pcd_dec]
        return pcd

    if visheader['NAXIS'] == 6:

       # identify the channel frequency(ies):
        pcd_ra = visfile[0].header['OBSRA']
        pcd_dec = visfile[0].header['OBSDEC']
        pcd = [pcd_ra, pcd_dec]
        return pcd

def uvload(visfile):

    # read in the uvfits data
    visibilities = visfile[0].data
    visheader = visfile[0].header

    if visheader['NAXIS'] == 7:

        # identify the channel frequency(ies):
        visfreq = visfile[1].data
        freq0 = visheader['CRVAL4']
        dfreq = visheader['CDELT4']
        cfreq = visheader['CRPIX4']
        nvis = visibilities['DATA'][:, 0, 0, 0, 0, 0, 0].size
        nspw = visibilities['DATA'][0, 0, 0, :, 0, 0, 0].size
        nfreq = visibilities['DATA'][0, 0, 0, 0, :, 0, 0].size
        npol = visibilities['DATA'][0, 0, 0, 0, 0, :, 0].size
        uu = numpy.zeros([nvis, nspw, nfreq, npol])
        vv = numpy.zeros([nvis, nspw, nfreq, npol])
        #wgt = numpy.zeros([nvis, nspw, nfreq, npol])

        for ispw in range(nspw):
            if nspw > 1:
                freqif = freq0 + visfreq['IF FREQ'][0][ispw]
            else:
                freqif = freq0
            #uu[:, ispw] = freqif * visibilities['UU']
            #vv[:, ispw] = freqif * visibilities['VV']

            for ipol in range(npol):

                # then compute the spatial frequencies:
                if nfreq > 1:
                    freq = (numpy.arange(nfreq) - cfreq + 1) * dfreq + freqif
                    freqvis = numpy.meshgrid(freq, visibilities['UU'])
                    uu[:, ispw, :, ipol] = freqvis[0] * freqvis[1]
                    freqvis = numpy.meshgrid(freq, visibilities['VV'])
                    vv[:, ispw, :, ipol] = freqvis[0] * freqvis[1]
                else:
                    uu[:, ispw, 0, ipol] = freqif * visibilities['UU']
                    vv[:, ispw, 0, ipol] = freqif * visibilities['VV']

    if visheader['NAXIS'] == 6:

        # identify the channel frequency(ies):
        freq0 = visheader['CRVAL4']
        dfreq = visheader['CDELT4']
        cfreq = visheader['CRPIX4']
        nvis = visibilities['DATA'][:, 0, 0, 0, 0, 0].size
        nfreq = visibilities['DATA'][0, 0, 0, :, 0, 0].size
        npol = visibilities['DATA'][0, 0, 0, 0, :, 0].size
        uu = numpy.zeros([nvis, nfreq, npol])
        vv = numpy.zeros([nvis, nfreq, npol])
        #wgt = numpy.zeros([nvis, nspw, nfreq, npol])

        freqif = freq0
        #uu[:, ispw] = freqif * visibilities['UU']
        #vv[:, ispw] = freqif * visibilities['VV']

        for ipol in range(npol):

            # then compute the spatial frequencies:
            if nfreq > 1:
                freq = (numpy.arange(nfreq) - cfreq + 1) * dfreq + freqif
                freqvis = numpy.meshgrid(freq, visibilities['UU'])
                uu[:, :, ipol] = freqvis[0] * freqvis[1]
                freqvis = numpy.meshgrid(freq, visibilities['VV'])
                vv[:, :, ipol] = freqvis[0] * freqvis[1]
            else:
                uu[:, 0, ipol] = freqif * visibilities['UU']
                vv[:, 0, ipol] = freqif * visibilities['VV']
                #www = freqif * visibilities['WW']

    return uu, vv

def visload(visfile):
    # get the telescope name
    visheader = visfile[0].header
    #telescop = visheader['TELESCOP']

    # if we are dealing with SMA data
    if visheader['NAXIS'] == 6:
        data_real = visfile[0].data['DATA'][:,0,0,:,:,0]
        data_imag = visfile[0].data['DATA'][:,0,0,:,:,1]
        data_wgt = visfile[0].data['DATA'][:,0,0,:,:,2]

    # if we are dealing with ALMA or PdBI data
    if visheader['NAXIS'] == 7:
        data_real = visfile[0].data['DATA'][:,0,0,:,:,:,0]
        data_imag = visfile[0].data['DATA'][:,0,0,:,:,:,1]
        data_wgt = visfile[0].data['DATA'][:,0,0,:,:,:,2]

    return data_real, data_imag, data_wgt

def getStatWgt(real_raw, imag_raw, wgt_raw):

    """
    Compute the weights as the rms scatter in the real and imaginary 
    visibilities.
    """
{'fraction_non_alphanumeric': 0.15471411522187262, 'fraction_numerical': 0.024085928176196158, 'mean_word_length': 2.163349347975292, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '280006', 'n_tokens_mistral': 3457, 'n_tokens_neox': 3245, 'n_words': 774}