Exemplo n.º 1
0
def nfimage(dataff, filenr, sampnr):
    """
    Make near-field image.
    """
    polrep = 'S0'
    lofar_datatype = dataIO.datafolder_type(dataff)
    if lofar_datatype != 'acc' and lofar_datatype != 'xst':
        raise RuntimeError(
            "Datafolder '{}'\n not ACC or XST type data.".format(dataff))
    cvcobj = dataIO.CVCfiles(dataff)
    stnid = cvcobj.scanrecinfo.get_stnid()
    for fileidx in range(filenr, cvcobj.getnrfiles()):
        integration = cvcobj.scanrecinfo.get_integration()
        intgs = len(cvcobj.samptimeset[fileidx])
        for tidx in range(sampnr, intgs):
            xx, yy, nfimages = nearfield_grd_image(cvcobj, fileidx, tidx)
            t = cvcobj.samptimeset[fileidx][tidx]
            freq = cvcobj.freqset[fileidx][tidx]
            plotskyimage(xx,
                         yy,
                         nfimages,
                         polrep,
                         t,
                         freq,
                         stnid,
                         integration,
                         maskhrz=False)
Exemplo n.º 2
0
def image(args):
    """Image visibility-type data."""
    polrep = 'stokes'
    lofar_datatype = dataIO.datafolder_type(args.dataff)
    fluxperbeam = not args.fluxpersterradian
    if lofar_datatype != 'acc' and lofar_datatype != 'xst':
        raise RuntimeError("Datafolder '{}'\n not ACC or XST type data."
                           .format(args.dataff))
    cvcobj = dataIO.CVCfiles(args.dataff)
    calibrated = False
    if cvcobj.scanrecinfo.calibrationfile:
        calibrated = True
    stnid = cvcobj.scanrecinfo.get_stnid()
    for fileidx in range(args.filenr, cvcobj.getnrfiles()):
        integration = cvcobj.scanrecinfo.get_integration()
        intgs = len(cvcobj.samptimeset[fileidx])
        for tidx in range(args.sampnr, intgs):
            t = cvcobj.samptimeset[fileidx][tidx]
            freq = cvcobj.freqset[fileidx][tidx]
            skyimages, ll, mm, phaseref = \
                cvc_image(cvcobj, fileidx, tidx, args.phaseref,
                                  polrep=polrep, pbcor=args.correctpb,
                                  fluxperbeam=fluxperbeam)
            plotskyimage(ll, mm, skyimages, polrep, t, freq, stnid,
                                 integration, phaseref, calibrated,
                                 pbcor=args.correctpb, maskhrz=False,
                                 fluxperbeam=fluxperbeam)
Exemplo n.º 3
0
def applycal_cvcfolder(cvcpath, caltabpath):
    """Apply a calibration table file to a CVC folder.

    This creates a copy of the folder pointed to by cvcpath renamed with
    a '_cal_' before the ldat suffix. Then it applies the calibration table
    contained in the caltab file pointed to by caltabpath, to the CVC dataset
    and copies the caltab file used in the calibrated CVC folder.

    Parameters
    ----------
    cvcpath: str
        Path to CVC folder
    caltabpath: str
        Path to caltab file
    """
    try:
        caltab, header = calibrationtables.readcaltab(caltabpath)
    except:
        raise
    ldat_type = dataIO.datafolder_type(cvcpath)
    if ldat_type != "acc" and ldat_type != "xst":
        raise ValueError("Not CVC data.")
    # Copy CVC folder within parent folder and add the tag "_cal_" in the name
    # right before ldat_type suffix:
    spltpath = cvcpath.split("_")
    cvccalpath = "_".join(spltpath[:-1]) + "_cal_" + spltpath[-1]
    shutil.copytree(cvcpath, cvccalpath)
    # Read in cvcobj:
    cvcobj_cal = dataIO.CVCfiles(cvccalpath)
    nrfiles = cvcobj_cal.getnrfiles()
    # Loop over files in CVC folder:
    for filestep in range(nrfiles):
        if ldat_type == "xst":
            freq = cvcobj_cal.freqset[filestep][0]  # Freq const. over xst file
            sb, nz = modeparms.freq2sb(freq)
        else:
            sb = None  # Because this signals ACC data
        # Get actual covariance cubes:
        cvcdata_unc = cvcobj_cal[filestep]
        # Apply calibration
        cvcdata = ilisa.calim.calibration.applycaltab_cvc(
            cvcdata_unc, caltab, sb)
        # Replace uncalibrated data with calibrated:
        cvcobj_cal[filestep] = cvcdata
    # Note in ScanRecInfo about calibrating this dataset:
    cvcobj_cal.scanrecinfo.set_postcalibration(caltabpath, cvccalpath)
Exemplo n.º 4
0
def gsmcal(dataff, filenr, sampnr, fluxpersterradian):
    ccm = measures()
    gs_model = 'LFSM'
    imsize = 200
    fluxperbeam = True
    l = numpy.linspace(-1, 1, imsize)
    m = numpy.linspace(-1, 1, imsize)
    ll, mm = numpy.meshgrid(l, m)
    #normcolor = colors.LogNorm()
    # The code below is almost cut-n-pasted from imaging.image()
    polrep = 'stokes'
    lofar_datatype = dataIO.datafolder_type(dataff)
    fluxperbeam = not fluxpersterradian
    if lofar_datatype != 'acc' and lofar_datatype != 'xst':
        raise RuntimeError(
            "Datafolder '{}'\n not ACC or XST type data.".format(dataff))
    cvcobj = dataIO.CVCfiles(dataff)
    calibrated = False
    if cvcobj.scanrecinfo.calibrationfile:
        calibrated = True
    stnid = cvcobj.scanrecinfo.get_stnid()
    lon, lat, h = imaging.ITRF2lonlat(cvcobj.stn_pos[0, 0],
                                      cvcobj.stn_pos[1, 0], cvcobj.stn_pos[2,
                                                                           0])
    stn_pos_x, stn_pos_y, stn_pos_z = cvcobj.stn_pos[0, 0], cvcobj.stn_pos[1, 0], \
                                      cvcobj.stn_pos[2, 0]
    ccm.doframe(
        ccm.position('ITRF',
                     str(stn_pos_x) + 'm',
                     str(stn_pos_y) + 'm',
                     str(stn_pos_z) + 'm'))
    for fileidx in range(filenr, cvcobj.getnrfiles()):
        integration = cvcobj.scanrecinfo.get_integration()
        intgs = len(cvcobj.samptimeset[fileidx])
        for tidx in range(sampnr, intgs):
            t = cvcobj.samptimeset[fileidx][tidx]
            freq = cvcobj.freqset[fileidx][tidx]
            img = skymodels.globaldiffuseskymodel(t, (lon, lat, h),
                                                  freq,
                                                  gs_model=gs_model,
                                                  imsize=imsize)
            ccm.doframe(ccm.epoch('UTC', t.isoformat('T')))
            phaseref_ccm = ccm.measure(
                ccm.direction('AZEL', '0.0rad',
                              str(numpy.deg2rad(90)) + 'rad'), 'J2000')
            phaseref = (phaseref_ccm['m0']['value'],
                        phaseref_ccm['m1']['value'], phaseref_ccm['refer'])
            uvw_sl = imaging.calc_uvw(t, phaseref, cvcobj.stn_pos,
                                      cvcobj.stn_antpos)
            vis_mod = vcz(ll,
                          mm,
                          img,
                          freq,
                          uvw_sl,
                          imag_is_fd=not (fluxperbeam))
            cvcpol_lin = dataIO.cvc2polrep(cvcobj[fileidx], crlpolrep='lin')
            cvpol_lin = cvcpol_lin[:, :, tidx, ...].squeeze()
            cvpol_x = cvpol_lin[0, 0, ...].squeeze()
            cvpol_y = cvpol_lin[1, 1, ...].squeeze()
            vis_meas_xx = cvpol_x
            vis_meas_yy = cvpol_y
            g_xx = stefcal(vis_meas_xx, vis_mod / 2.0)
            g_yy = stefcal(vis_meas_yy, vis_mod / 2.0)
            inv_g_xx = 1 / g_xx
            inv_g_yy = 1 / g_yy
            vis_cal_xx = inv_g_xx[:, numpy.newaxis] * vis_meas_xx * numpy.conj(
                inv_g_xx)
            vis_cal_yy = inv_g_yy[:, numpy.newaxis] * vis_meas_yy * numpy.conj(
                inv_g_yy)
            vis_cal_I = vis_cal_xx + vis_cal_yy
            vis_resid_I = vis_cal_I - vis_mod
            xstpol = numpy.array([[vis_cal_I,
                                   numpy.zeros_like(vis_mod)],
                                  [numpy.zeros_like(vis_mod), vis_resid_I]])
            skyimages, _l, _m = imaging.beamformed_image(
                xstpol,
                uvw_sl.T,
                freq,
                use_autocorr=True,
                lmsize=2.0,
                nrpix=imsize,
                polrep='linear',
                fluxperbeam=fluxperbeam)
            imaging.plotskyimage(_l,
                                 _m,
                                 skyimages,
                                 'linear',
                                 t,
                                 freq,
                                 stnid,
                                 integration,
                                 phaseref,
                                 calibrated,
                                 pbcor=False,
                                 maskhrz=False,
                                 fluxperbeam=fluxperbeam)
Exemplo n.º 5
0
def image(dataff,
          filenr,
          sampnr,
          phaseref,
          correctpb,
          fluxpersterradian,
          show_gsm=False):
    """\
    Image visibility-type data.

    Optionally show corresponding GSM map (requires PyGDSM).

    Parameters
    ----------
    filenr :  int
        File number.
    sampnr : int
        Sample number.
    phaseref : tuple
        Direction of phase center.
    correctpb : bool
        Should primary beam correction be applied?
    fluxpersterradian : bool
        Should returned data be in physical dimension of flux per sterradian?
    show_gsm : bool
        Should a global sky model be shown?
    """
    polrep = 'stokes'
    lofar_datatype = dataIO.datafolder_type(dataff)
    fluxperbeam = not fluxpersterradian
    if lofar_datatype != 'acc' and lofar_datatype != 'xst':
        raise RuntimeError(
            "Datafolder '{}'\n not ACC or XST type data.".format(dataff))
    cvcobj = dataIO.CVCfiles(dataff)
    calibrated = False
    if cvcobj.scanrecinfo.calibrationfile:
        calibrated = True
    stnid = cvcobj.scanrecinfo.get_stnid()
    for fileidx in range(filenr, cvcobj.getnrfiles()):
        integration = cvcobj.scanrecinfo.get_integration()
        intgs = len(cvcobj.samptimeset[fileidx])
        for tidx in range(sampnr, intgs):
            t = cvcobj.samptimeset[fileidx][tidx]
            freq = cvcobj.freqset[fileidx][tidx]
            skyimages, ll, mm, _phaseref_ = \
                cvc_image(cvcobj, fileidx, tidx, phaseref,
                                  polrep=polrep, pbcor=correctpb,
                                  fluxperbeam=fluxperbeam)
            plotskyimage(ll,
                         mm,
                         skyimages,
                         polrep,
                         t,
                         freq,
                         stnid,
                         integration,
                         _phaseref_,
                         calibrated,
                         pbcor=correctpb,
                         maskhrz=False,
                         fluxperbeam=fluxperbeam)
            if show_gsm:
                gs_model = 'LFSM'
                imsize = 200
                lon, lat, h = ITRF2lonlat(cvcobj.stn_pos[0, 0],
                                          cvcobj.stn_pos[1, 0],
                                          cvcobj.stn_pos[2, 0])
                try:
                    img = globaldiffuseskymodel(t, (lon, lat, h),
                                                freq,
                                                gs_model=gs_model,
                                                imsize=imsize)
                except ValueError:
                    print("Warning: skipping GSM plot since frequency invalid")
                l, m = numpy.linspace(-1, 1,
                                      imsize), numpy.linspace(-1, 1, imsize)
                ll, mm = numpy.meshgrid(l, m)
                img_zero = numpy.zeros_like(img, dtype=float)
                plotskyimage(ll,
                             mm, (img, img_zero, img_zero, img_zero),
                             'stokes',
                             t,
                             freq,
                             stnid,
                             integration,
                             _phaseref_,
                             calibrated,
                             pbcor=correctpb,
                             maskhrz=False,
                             fluxperbeam=fluxperbeam)