Beispiel #1
0
def test_fits_to_fil():
    # from fits
    file = os.path.join(_install_dir, "data/small.fits")
    f = Your(file)
    w = Writer(f,
               nstart=0,
               nsamp=1,
               outname="temp",
               outdir="./",
               c_min=0,
               c_max=200)
    # test with outname
    w.to_fil()
    assert os.path.isfile("temp.fil")
    y = Your("temp.fil")
    assert y.your_header.nspectra == 1
    assert y.your_header.nchans == 200
    assert (y.get_data(0, 1) - f.get_data(0, 1)[:, 0:200]).sum() == 0
    os.remove("temp.fil")

    # test without outname
    w = Writer(f, outdir="./")
    w.to_fil()
    assert os.path.isfile("small_converted.fil")
    y = Your("small_converted.fil")
    assert y.your_header.nspectra == f.your_header.nspectra
    ns = y.your_header.nspectra
    assert y.your_header.nchans == f.your_header.nchans
    assert (y.get_data(0, ns) - f.get_data(0, ns)).sum() == 0
    os.remove("small_converted.fil")
Beispiel #2
0
def test_fil_to_fits():
    file = os.path.join(_install_dir, "data/small.fil")
    f = Your(file)
    w = Writer(
        f,
        outname="temp",
        outdir="./",
        flag_rfi=False,
        zero_dm_subt=False,
        nstart=1,
        nsamp=2,
        c_min=40,
        c_max=200,
    )
    # test with outname
    w.to_fits()
    assert os.path.isfile("temp.fits")
    y = Your("temp.fits")
    assert y.your_header.nspectra == 2
    assert y.your_header.nchans == 160
    assert (y.get_data(0, 2) - f.get_data(1, 2)[:, 40:200]).sum() == 0
    os.remove("temp.fits")

    # test without  outname
    w = Writer(f, outdir="./", flag_rfi=True, zero_dm_subt=True)
    w.to_fits()
    assert os.path.isfile("small_converted.fits")
    y = Your("small_converted.fits")
    assert y.your_header.nchans == f.your_header.nchans
    ns = y.your_header.nspectra
    os.remove("small_converted.fits")
Beispiel #3
0
def test_gulps(your_object):
    w = Writer(
        your_object,
        nstart=1,
        nsamp=2,
        gulp=2,
        outname="temp",
        c_min=10,
        c_max=200,
        outdir="./",
    )
    w.to_fil()
    assert os.path.isfile("temp.fil")

    w = Writer(
        your_object,
        nstart=1,
        nsamp=5,
        gulp=20,
        outname="temp",
        c_min=10,
        c_max=200,
        outdir="./",
    )
    w.to_fil()
    assert os.path.isfile("temp.fil")
    os.remove("temp.fil")
Beispiel #4
0
def test_fil_to_fil(your_object):
    # from fil
    w = Writer(
        your_object,
        nstart=1,
        nsamp=2,
        outname="temp",
        c_min=10,
        c_max=200,
        outdir="./",
        flag_rfi=False,
        zero_dm_subt=False,
    )
    # test with outname
    w.to_fil()
    assert os.path.isfile("temp.fil")
    y = Your("temp.fil")
    assert y.your_header.nspectra == 2
    assert y.your_header.nchans == 190
    assert (y.get_data(0, 2) -
            your_object.get_data(1, 2)[:, 10:200]).sum() == 0
    os.remove("temp.fil")

    # test without outname
    w = Writer(your_object, nstart=0, nsamp=10, outdir="./", flag_rfi=True)
    w.to_fil()
    assert os.path.isfile("small_converted.fil")
    y = Your("small_converted.fil")
    assert y.your_header.nspectra == 10
    assert y.your_header.nchans == your_object.your_header.nchans
    os.remove("small_converted.fil")
Beispiel #5
0
def test_4pol_fits_to_fits():
    file = os.path.join(_install_dir, "data/test_4pol.fits")
    your_obj = Your(file)

    w = Writer(your_obj,
               nstart=1,
               nsamp=20,
               gulp=20,
               outname="temp_4pol",
               outdir="./",
               npoln=4)
    w.to_fits()

    y = Your("temp_4pol.fits")
    assert y.your_header.nspectra == 20
    assert y.your_header.nchans == your_obj.your_header.nchans
    assert (y.get_data(0, 5, npoln=4) -
            your_obj.get_data(1, 5, npoln=4)).sum() == 0
    os.remove("temp_4pol.fits")
Beispiel #6
0
def test_failing_replacement_policy(your_object):
    with pytest.raises(ValueError):
        w = Writer(
            your_object,
            outname="temp",
            outdir="./",
            flag_rfi=True,
            zero_dm_subt=False,
            replacement_policy="blah",
        )
Beispiel #7
0
def test_frequency_decimatation(your_object):
    with pytest.raises(NotImplementedError):
        w = Writer(
            your_object,
            outname="temp",
            outdir="./",
            flag_rfi=False,
            zero_dm_subt=False,
            frequency_decimation_factor=2,
        )
Beispiel #8
0
def test_pol(your_object):
    w = Writer(
        your_object,
        outname="temp",
        outdir="./",
        flag_rfi=True,
        zero_dm_subt=False,
        npoln=1,
    )
    assert w.poln_order == "AA+BB"

    with pytest.raises(ValueError):
        w = Writer(
            your_object,
            outname="temp",
            outdir="./",
            flag_rfi=True,
            zero_dm_subt=False,
            npoln=3,
        )
        w.poln_order
Beispiel #9
0
def test_fil_to_fil():
    # from fil
    file = os.path.join(_install_dir, 'data/small.fil')
    f = Your(file)
    w = Writer(f)
    # test with outname
    w.to_fil(nstart=0,
             nsamp=2,
             outname='temp.fil',
             c=[0, 200],
             outdir='./',
             flag_rfi=True,
             zero_dm_subt=True)
    assert os.path.isfile('temp.fil')
    y = Your('temp.fil')
    assert y.your_header.nspectra == 2
    assert y.your_header.nchans == 200
    os.remove('temp.fil')

    # test without outname
    w.to_fil(nstart=0, nsamp=1, outdir='./')
    assert os.path.isfile('small_converted.fil')
    y = Your('small_converted.fil')
    assert y.your_header.nspectra == 1
    assert y.your_header.nchans == f.your_header.nchans
    os.remove('small_converted.fil')
Beispiel #10
0
def test_fits_to_fits():
    file = os.path.join(_install_dir, 'data/small.fits')
    f = Your(file)
    w = Writer(f)
    # test with outname
    w.to_fits(outname='temp.fits', outdir='./', nstart=0, nsamp=2)
    assert os.path.isfile('temp.fits')
    y = Your('temp.fits')
    assert y.your_header.nspectra == 2
    assert y.your_header.nchans == f.your_header.nchans
    os.remove('temp.fits')

    # test without  outname
    w.to_fits(outdir='./', c=[0, 10])
    assert os.path.isfile('small_converted.fits')
    y = Your('small_converted.fits')
    assert y.your_header.nchans == 10
    os.remove('small_converted.fits')
Beispiel #11
0
    if your_object.your_header.nspectra < 2**18:
        nsamps_gulp = your_object.your_header.nspectra
    else:
        nsamps_gulp = int(
            np.max([(2**np.ceil(np.log2(dispersion_delay_samples))), 2**18]))

    if values.channel_end > 0:
        c_max = values.channel_end
    else:
        c_max = None

    your_dada_writer = Writer(
        your_object=your_object,
        progress=~values.no_progress,
        c_min=values.channel_start,
        c_max=c_max,
        savgol_sigma=values.savgol_sigma,
        spectral_kurtosis_sigma=values.spectral_kurtosis_sigma,
        savgol_frequency_window=values.savgol_frequency_window,
        flag_rfi=values.flag_rfi,
    )
    your_dada_writer.setup_dada(
    )  # need to run the set up inorder to get the dada key

    if values.mask:
        logging.info(f"Reading RFI mask from {values.mask}")
        mask = np.loadtxt(values.mask)
        if len(mask.shape) == 1:
            bad_chans = list(mask)
        else:
            logging.warning(
                "RFI mask not understood, can only be 1D. Not using RFI flagging."
Beispiel #12
0
        'writer_%Y_%m_%d_%H_%M_%S_%f.log')

    if values.verbose:
        logging.basicConfig(filename=log_filename,
                            level=logging.DEBUG,
                            format=logging_format)
    else:
        logging.basicConfig(filename=log_filename,
                            level=logging.INFO,
                            format=logging_format)

    logging.info("Input Arguments:-")
    for arg, value in sorted(vars(values).items()):
        logging.info("Argument %s: %r", arg, value)
    y = Your(values.files)
    w = Writer(y)

    if values.type == 'fits':
        w.to_fits(c=values.chans,
                  nstart=values.nstart,
                  nsamp=values.nsamp,
                  outdir=values.outdir,
                  outname=values.out_name,
                  progress=values.no_progress,
                  flag_rfi=values.flag_rfi,
                  sk_sig=values.sk_sig,
                  sg_fw=values.sg_fw,
                  sg_sig=values.sg_sig,
                  zero_dm_subt=values.zero_dm_subt)
    elif values.type == 'fil':
        w.to_fil(c=values.chans,
Beispiel #13
0
                handlers=[RichHandler(rich_tracebacks=True)],
            )

    logging.info("Input Arguments:-")
    for arg, value in sorted(vars(values).items()):
        logging.info("Argument %s: %r", arg, value)
    y = Your(values.files)
    w = Writer(
        y,
        c_min=values.chans[0],
        c_max=values.chans[1],
        nstart=values.nstart,
        nsamp=values.nsamp,
        outdir=values.outdir,
        outname=values.out_name,
        progress=values.no_progress,
        flag_rfi=values.flag_rfi,
        spectral_kurtosis_sigma=values.spectral_kurtosis_sigma,
        savgol_frequency_window=values.savgol_frequency_window,
        savgol_sigma=values.savgol_sigma,
        zero_dm_subt=values.zero_dm_subt,
        time_decimation_factor=values.time_decimation_factor,
        frequency_decimation_factor=values.frequency_decimation_factor,
    )

    if values.type == "fits":
        w.to_fits()
    elif values.type == "fil":
        w.to_fil()
    else:
        raise ValueError("Type can either be 'fits' or 'fil'")
Beispiel #14
0
    logging.info("Input Arguments:-")
    for arg, value in sorted(vars(values).items()):
        logging.info("Argument %s: %r", arg, value)
    y = Your(values.files)
    w = Writer(
        y,
        c_min=values.chans[0],
        c_max=values.chans[1],
        nstart=values.nstart,
        nsamp=values.nsamp,
        outdir=values.outdir,
        outname=values.out_name,
        progress=values.no_progress,
        flag_rfi=values.flag_rfi,
        spectral_kurtosis_sigma=values.spectral_kurtosis_sigma,
        savgol_frequency_window=values.savgol_frequency_window,
        savgol_sigma=values.savgol_sigma,
        gulp=values.gulp_size,
        zero_dm_subt=values.zero_dm_subt,
        time_decimation_factor=values.time_decimation_factor,
        frequency_decimation_factor=values.frequency_decimation_factor,
        replacement_policy=values.replacement_policy,
        npoln=values.num_polarisation,
        highest_frequency_first=values.highest_frequency_first,
    )

    if values.type == "fits":
        w.to_fits(npsub=values.npsub)
    elif values.type == "fil":
        w.to_fil()