def _read_gen (saveFlags, UVDatDataSet, maxchan):
    from mirtask._miriad_f import uvdatopn, uvdatrd
    from numpy import zeros, double, complex64, int32

    inp = None
    preamble = zeros (5, dtype=double)
    data = zeros (maxchan, dtype=complex64)
    flags = zeros (maxchan, dtype=int32)

    try:
        if saveFlags:
            while True:
                if inp is not None and inp.isOpen ():
                    inp.close ()

                (status, tin) = uvdatopn ()
                if not status:
                    break

                inp = UVDatDataSet (tin)
                rewrite = inp.rewriteFlags

                while True:
                    nread = uvdatrd (preamble, data, flags, maxchan)
                    if nread == 0:
                        break

                    f = flags[:nread]
                    yield inp, preamble, data[:nread], f
                    rewrite (f)
        else:
            while True:
                if inp is not None and inp.isOpen ():
                    inp.close ()

                (status, tin) = uvdatopn ()
                if not status:
                    break

                inp = UVDatDataSet (tin)

                while True:
                    nread = uvdatrd (preamble, data, flags, maxchan)
                    if nread == 0:
                        break

                    yield inp, preamble, data[:nread], flags[:nread]
    finally:
        if inp is not None and inp.isOpen ():
            inp.close ()
示例#2
0
def _read_gen(saveFlags, UVDatDataSet, maxchan):
    from mirtask._miriad_f import uvdatopn, uvdatrd
    from numpy import zeros, double, complex64, int32

    inp = None
    preamble = zeros(5, dtype=double)
    data = zeros(maxchan, dtype=complex64)
    flags = zeros(maxchan, dtype=int32)

    try:
        if saveFlags:
            while True:
                if inp is not None and inp.isOpen():
                    inp.close()

                (status, tin) = uvdatopn()
                if not status:
                    break

                inp = UVDatDataSet(tin)
                rewrite = inp.rewriteFlags

                while True:
                    nread = uvdatrd(preamble, data, flags, maxchan)
                    if nread == 0:
                        break

                    f = flags[:nread]
                    yield inp, preamble, data[:nread], f
                    rewrite(f)
        else:
            while True:
                if inp is not None and inp.isOpen():
                    inp.close()

                (status, tin) = uvdatopn()
                if not status:
                    break

                inp = UVDatDataSet(tin)

                while True:
                    nread = uvdatrd(preamble, data, flags, maxchan)
                    if nread == 0:
                        break

                    yield inp, preamble, data[:nread], flags[:nread]
    finally:
        if inp is not None and inp.isOpen():
            inp.close()
示例#3
0
def singleInputSet ():
    """Get a :class:`UVDatDataSet` object representing the input UV dataset.

:rtype: :class:`UVDatDataSet`
:returns: a UV data dataset

Retrieves a :class:`UVDatDataSet` object corresponding to the dataset
to be read by the UVDAT subsystem.

If you want to read the UV data associated with this handle, use
:func:`read` or :func:`setupAndRead`.

The subsystem can accept more than one input dataset generically, but
you should only call this function if UVDAT has been initialized to
read only one dataset. You can ensure this condition by passing the
*b* option to :func:`setupAndRead` or
:meth:`mirtask.keys.KeySpec.uvdat`. If you don't want to or can't
enforce this condition, use :func:`inputSets`.
"""

    # In certain cases (e.g. an empty dataset, which yields an
    # "Invalid preamble time/baseline" MiriadError if there's no coord
    # UV variable), UVDATOPN can fail with a bug('f') call but still
    # leave the dataset opened. This means that too many successive
    # such failures will fill up MIRIAD's static buffer of UV dataset
    # information and make it impossible to open more datasets. This
    # could be solved by catching the exception and calling
    # UVDATCLS().
    #
    # On the other hand, if, say, the desired dataset doesn't exist,
    # then we get a MiriadError without having the dataset opened, and
    # if we call UVDATCLS, we segfault.
    #
    # I haven't yet figured out a way to handle both of these cases
    # cleanly. With some hacking of UVDATOPN or the uvdat module
    # in general, something could be worked out. In the meantime, we
    # prefer to avoid the segfault.
    #
    # Similar code is relevant in _uvdat_compat_*:inputSets.

    status, tin = _miriad_f.uvdatopn ()

    if not status:
        raise RuntimeError ('No input datasets?!')

    # Count on the user or the __del__ to close this.
    return UVDatDataSet (tin)
示例#4
0
def _inputSets (UVDatDataSet):
    """Generate a sequence of DataSet objects representing the
visdata input sets."""
    ds = None
    try:
        while True:
            if ds is not None and ds.isOpen (): ds.close ()
            (status, tin) = _miriad_f.uvdatopn ()
            if not status: break
            ds = UVDatDataSet (tin)
            yield ds
    except:
        if ds is not None and ds.isOpen (): ds.close ()
    else:
        if ds is not None and ds.isOpen (): ds.close ()
    if ds is None:
        raise RuntimeError ('No input UV data sets?')