Esempio n. 1
0
def test_multiple_coarse():
    """
    Test two coarse channel files.

    Read in MWA correlator files with two different orderings of the files
    and check for object equality.
    """
    order1 = [filelist[0:3]]
    order2 = [filelist[0], filelist[2], filelist[1]]
    mwa_uv1 = UVData()
    mwa_uv2 = UVData()
    messages = [
        "telescope_location is not set",
        "coarse channels are not contiguous for this observation",
        "some coarse channel files were not submitted",
    ]
    uvtest.checkWarnings(mwa_uv1.read,
                         func_args=[order1],
                         nwarnings=3,
                         message=messages)
    uvtest.checkWarnings(mwa_uv2.read,
                         func_args=[order2],
                         nwarnings=3,
                         message=messages)
    assert mwa_uv1 == mwa_uv2
Esempio n. 2
0
def test_ReadFHDWriteReadUVFits_bad_obs_loc():
    """
    FHD to uvfits loopback test with bad obs location (and bad layout location).

    Read in FHD files, write out as uvfits, read back in and check for object
    equality.
    """
    fhd_uv = UVData()
    uvfits_uv = UVData()
    bad_obs_loc_file = testdir + testfile_prefix + 'bad_obs_loc_vis_XX.sav'
    files_use = [
        testfiles[0], testfiles[2], bad_obs_loc_file, testfiles[6],
        testfiles[7]
    ]
    messages = [
        'Telescope location derived from obs',
        'tile_names from obs structure does not match'
    ]
    uvtest.checkWarnings(fhd_uv.read_fhd, [files_use],
                         message=messages,
                         nwarnings=2)

    fhd_uv.write_uvfits(os.path.join(DATA_PATH,
                                     'test/outtest_FHD_1061316296.uvfits'),
                        spoof_nonessential=True)
    uvfits_uv.read_uvfits(
        os.path.join(DATA_PATH, 'test/outtest_FHD_1061316296.uvfits'))
    nt.assert_equal(fhd_uv, uvfits_uv)
Esempio n. 3
0
def test_to_waterfall_bl_flags_or():
    uvf = UVFlag(test_f_file)
    uvf.to_flag()
    uvf.weights_array = np.ones_like(uvf.weights_array)
    uvf.to_waterfall(method='or')
    nt.assert_true(uvf.type == 'waterfall')
    nt.assert_true(uvf.mode == 'flag')
    nt.assert_true(uvf.flag_array.shape == (len(uvf.time_array),
                                            len(uvf.freq_array),
                                            len(uvf.polarization_array)))
    nt.assert_true(
        np.array_equal(uvf.weights_array, np.ones_like(uvf.flag_array,
                                                       np.float)))
    uvf = UVFlag(test_f_file)
    uvf.to_flag()
    uvf.weights_array = np.ones_like(uvf.weights_array)
    uvf.weights_array[0, 0, 0, 0] = 0.2
    uvtest.checkWarnings(uvf.to_waterfall, [], {'method': 'or'},
                         nwarnings=1,
                         message='Currently weights are')
    nt.assert_true(uvf.type == 'waterfall')
    nt.assert_true(uvf.mode == 'flag')
    nt.assert_true(uvf.flag_array.shape == (len(uvf.time_array),
                                            len(uvf.freq_array),
                                            len(uvf.polarization_array)))
    nt.assert_true(
        np.array_equal(uvf.weights_array, np.ones_like(uvf.flag_array,
                                                       np.float)))
Esempio n. 4
0
def test_read_fhd_write_read_uvfits_bad_obs_loc(tmp_path):
    """
    FHD to uvfits loopback test with bad obs location (and bad layout location).

    Read in FHD files, write out as uvfits, read back in and check for object
    equality.
    """
    fhd_uv = UVData()
    uvfits_uv = UVData()
    bad_obs_loc_file = testdir + testfile_prefix + "bad_obs_loc_vis_XX.sav"
    files_use = [
        testfiles[0],
        testfiles[2],
        bad_obs_loc_file,
        testfiles[6],
        testfiles[7],
    ]
    messages = [
        "Telescope location derived from obs",
        "tile_names from obs structure does not match",
    ]
    uvtest.checkWarnings(fhd_uv.read, [files_use],
                         message=messages,
                         nwarnings=2)

    outfile = str(tmp_path / "outtest_FHD_1061316296.uvfits")
    fhd_uv.write_uvfits(
        outfile,
        spoof_nonessential=True,
    )
    uvfits_uv.read_uvfits(outfile)
    assert fhd_uv == uvfits_uv
Esempio n. 5
0
def test_multi_files_axis():
    """Read multiple files at once with axis keyword."""
    fhd_uv1 = UVData()
    fhd_uv2 = UVData()
    test1 = list(np.array(testfiles)[[0, 1, 2, 4, 6, 7]])
    test2 = list(np.array(testfiles)[[0, 2, 3, 5, 6, 7]])
    uvtest.checkWarnings(
        fhd_uv1.read,
        [[test1, test2]],
        {
            "use_model": True,
            "axis": "polarization"
        },
        message=["Telescope location derived from obs"],
        nwarnings=2,
    )

    uvtest.checkWarnings(fhd_uv2.read, [testfiles], {"use_model": True},
                         known_warning="fhd")

    assert uvutils._check_histories(
        fhd_uv2.history + " Combined data "
        "along polarization axis using pyuvdata.",
        fhd_uv1.history,
    )

    fhd_uv1.history = fhd_uv2.history
    assert fhd_uv1 == fhd_uv2
Esempio n. 6
0
def test_ReadFHDWriteReadUVFits():
    """
    FHD to uvfits loopback test.

    Read in FHD files, write out as uvfits, read back in and check for object
    equality.
    """
    fhd_uv = UVData()
    uvfits_uv = UVData()
    if uvtest.pre_1_14_numpy:
        fhd_uv.read_fhd(testfiles)
    else:
        # numpy 1.14 introduced a new deprecation warning
        n_scipy_warnings, scipy_warn_list, scipy_category_list = uvtest.get_scipy_warnings(
        )
        uvtest.checkWarnings(fhd_uv.read_fhd, [testfiles],
                             message=scipy_warn_list,
                             category=scipy_category_list,
                             nwarnings=n_scipy_warnings)

    fhd_uv.write_uvfits(os.path.join(DATA_PATH,
                                     'test/outtest_FHD_1061316296.uvfits'),
                        spoof_nonessential=True)
    uvfits_uv.read_uvfits(
        os.path.join(DATA_PATH, 'test/outtest_FHD_1061316296.uvfits'))
    nt.assert_equal(fhd_uv, uvfits_uv)
    del (fhd_uv)
    del (uvfits_uv)
Esempio n. 7
0
def test_read_power_single_freq(cst_power_1freq):
    # test single frequency
    beam2 = UVBeam()

    beam1 = cst_power_1freq

    assert beam1.freq_array == [150e6]
    assert beam1.pixel_coordinate_system == "az_za"
    assert beam1.beam_type == "power"
    assert beam1.data_array.shape == (1, 1, 2, 1, 181, 360)

    # test single frequency and not rotating the polarization
    uvtest.checkWarnings(
        beam2.read_cst_beam,
        [cst_files[0]],
        {
            "beam_type": "power",
            "telescope_name": "TEST",
            "feed_name": "bob",
            "feed_version": "0.1",
            "model_name": "E-field pattern - Rigging height 4.9m",
            "model_version": "1.0",
            "rotate_pol": False,
        },
        message="No frequency provided. Detected frequency is",
    )

    assert beam2.freq_array == [150e6]
    assert beam2.pixel_coordinate_system == "az_za"
    assert beam2.beam_type == "power"
    assert beam2.polarization_array == np.array([-5])
    assert beam2.data_array.shape == (1, 1, 1, 1, 181, 360)
    assert np.allclose(beam1.data_array[:, :, 0, :, :, :], beam2.data_array)
Esempio n. 8
0
def test_input_flag_array():
    """
    Test when data file has input flag array.

    Currently we do not have a testfile, so we will artifically create one
    and check for internal consistency.
    """
    cal_in = UVCal()
    cal_out = UVCal()
    testfile = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.fitsA')
    write_file = os.path.join(DATA_PATH, 'test/outtest_input_flags.fits')
    message = testfile + ' appears to be an old calfits format which'
    uvtest.checkWarnings(cal_in.read_calfits, [testfile], message=message)
    cal_in.input_flag_array = np.zeros(cal_in._input_flag_array.expected_shape(cal_in), dtype=bool)
    cal_in.write_calfits(write_file, clobber=True)
    cal_out.read_calfits(write_file)
    nt.assert_equal(cal_in, cal_out)

    # Repeat for delay version
    testfile = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvc.fits')
    message = [testfile + ' appears to be an old calfits format which',
               testfile + ' appears to be an old calfits format for delay files']
    uvtest.checkWarnings(cal_in.read_calfits, [testfile], message=message,
                         nwarnings=2)
    cal_in.input_flag_array = np.zeros(cal_in._input_flag_array.expected_shape(cal_in), dtype=bool)
    cal_in.write_calfits(write_file, clobber=True)
    cal_out.read_calfits(write_file)
    nt.assert_equal(cal_in, cal_out)
    del(cal_in)
    del(cal_out)
Esempio n. 9
0
def test_total_quality_array_size():
    """
    Test that total quality array defaults to the proper size
    """

    cal_in = UVCal()
    cal_out = UVCal()
    testfile = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.fitsA')
    message = testfile + ' appears to be an old calfits format which'
    uvtest.checkWarnings(cal_in.read_calfits, [testfile], message=message)

    # Create filler total quality array
    cal_in.total_quality_array = np.zeros(cal_in._total_quality_array.expected_shape(cal_in))

    proper_shape = (cal_in.Nspws, cal_in.Nfreqs, cal_in.Ntimes, cal_in.Njones)
    nt.assert_equal(cal_in.total_quality_array.shape, proper_shape)
    del(cal_in)

    # also test delay-type calibrations
    cal_in = UVCal()
    testfile = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvc.fits')
    message = [testfile + ' appears to be an old calfits format which',
               testfile + ' appears to be an old calfits format for delay files']
    uvtest.checkWarnings(cal_in.read_calfits, [testfile], message=message,
                         nwarnings=2)

    cal_in.total_quality_array = np.zeros(cal_in._total_quality_array.expected_shape(cal_in))

    proper_shape = (cal_in.Nspws, 1, cal_in.Ntimes, cal_in.Njones)
    nt.assert_equal(cal_in.total_quality_array.shape, proper_shape)
    del(cal_in)
Esempio n. 10
0
def test_dead_dipoles():
    beam1 = UVBeam()

    delays = np.zeros((2, 16), dtype="int")
    delays[:, 0] = 32

    uvtest.checkWarnings(
        beam1.read_mwa_beam,
        func_args=[filename],
        func_kwargs={
            "pixels_per_deg": 1,
            "delays": delays
        },
        message=("There are some terminated dipoles"),
    )

    delay_str = ("[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "
                 "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]")
    gain_str = ("[[0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, "
                "1.0, 1.0, 1.0, 1.0, 1.0], "
                "[0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, "
                "1.0, 1.0, 1.0, 1.0]]")
    history_str = ("Sujito et al. full embedded element beam, derived from "
                   "https://github.com/MWATelescope/mwa_pb/" +
                   "  delays set to " + delay_str + "  gains set to " +
                   gain_str + beam1.pyuvdata_version_str)
    assert uvutils._check_histories(history_str, beam1.history)
Esempio n. 11
0
def test_read_write_read_atca(tmp_path):
    uv_in = UVData()
    uv_out = UVData()
    atca_file = os.path.join(DATA_PATH, "atca_miriad")
    testfile = str(tmp_path / "outtest_atca_miriad.uv")
    uvtest.checkWarnings(
        uv_in.read,
        [atca_file],
        nwarnings=5,
        category=[UserWarning] * 5,
        message=[
            "Altitude is not present in Miriad file, and "
            "telescope ATCA is not in known_telescopes. ",
            "Altitude is not present",
            "Telescope location is set at sealevel at the file lat/lon "
            "coordinates. Antenna positions are present, but the mean antenna "
            "position does not give a telescope_location on the surface of the "
            "earth. Antenna positions do not appear to be on the surface of the "
            "earth and will be treated as relative.",
            "Telescope ATCA is not in known_telescopes.",
            "The uvw_array does not match the expected values given the antenna "
            "positions.",
        ],
    )
    uv_in.write_miriad(testfile, clobber=True)
    uv_out.read(testfile)
    assert uv_in == uv_out
Esempio n. 12
0
def test_extra_keywords_warnings(tmp_path):
    cal_in = UVCal()
    calfits_file = os.path.join(DATA_PATH, "zen.2457698.40355.xx.gain.calfits")
    testfile = str(tmp_path / "outtest_omnical.fits")
    cal_in.read_calfits(calfits_file)

    # check for warnings with extra_keywords keys that are too long
    cal_in.extra_keywords["test_long_key"] = True
    uvtest.checkWarnings(
        cal_in.check,
        message=[
            "key test_long_key in extra_keywords is longer than 8 characters"
        ],
    )
    uvtest.checkWarnings(
        cal_in.write_calfits,
        [testfile],
        {
            "run_check": False,
            "clobber": True
        },
        message=[
            "key test_long_key in extra_keywords is longer than 8 characters"
        ],
    )

    return
Esempio n. 13
0
def test_run_ant_metrics_one_file():
    a = utils.get_metrics_ArgumentParser('ant_metrics')
    if DATA_PATH not in sys.path:
        sys.path.append(DATA_PATH)
    arg1 = "--crossCut=5"
    arg2 = "--deadCut=5"
    arg3 = "--extension=.ant_metrics.hdf5"
    arg4 = "--metrics_path={}".format(os.path.join(DATA_PATH, 'test_output'))
    arg5 = "--vis_format=miriad"
    arg6 = "--alwaysDeadCut=10"
    arg7 = "--run_mean_vij"
    arg8 = "--run_red_corr"
    arg9 = "--run_cross_pols"
    arguments = ' '.join(
        [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9])

    # test running with a lone file
    lone_file = os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvcAA')
    cmd = ' '.join([arguments, lone_file])
    args = a.parse_args(cmd.split())
    history = cmd
    pols = list(args.pol.split(','))

    # this test raises a warning, then fails...
    uvtest.checkWarnings(pytest.raises, [
        AssertionError, ant_metrics.ant_metrics_run, args.files, pols,
        args.crossCut, args.deadCut, args.alwaysDeadCut, args.metrics_path,
        args.extension, args.vis_format, args.verbose, history,
        args.run_mean_vij, args.run_red_corr, args.run_cross_pols
    ],
                         nwarnings=1,
                         message='Could not find')
Esempio n. 14
0
def test_ReadFHDWriteReadUVFits_no_layout():
    """
    FHD to uvfits loopback test with no layout file.

    Read in FHD files, write out as uvfits, read back in and check for object
    equality.
    """
    fhd_uv = UVData()
    uvfits_uv = UVData()
    files_use = testfiles[:-3] + [testfiles[-2]]
    uvtest.checkWarnings(
        fhd_uv.read_fhd, [files_use],
        nwarnings=2,
        message=['No layout file', 'antenna_positions are not defined'],
        category=DeprecationWarning)

    uvtest.checkWarnings(
        fhd_uv.write_uvfits,
        [os.path.join(DATA_PATH, 'test/outtest_FHD_1061316296.uvfits')],
        func_kwargs={"spoof_nonessential": True},
        nwarnings=1,
        message=['antenna_positions are not defined'],
        category=DeprecationWarning)
    uvfits_uv.read_uvfits(
        os.path.join(DATA_PATH, 'test/outtest_FHD_1061316296.uvfits'))

    assert fhd_uv == uvfits_uv
Esempio n. 15
0
def test_UVH5ReadMultiple_files():
    """
    Test reading multiple uvh5 files
    """
    uv_full = UVData()
    uvfits_file = os.path.join(DATA_PATH,
                               'day2_TDEM0003_10s_norx_1src_1spw.uvfits')
    testfile1 = os.path.join(DATA_PATH, 'test/uv1.uvh5')
    testfile2 = os.path.join(DATA_PATH, 'test/uv2.uvh5')
    uvtest.checkWarnings(uv_full.read_uvfits, [uvfits_file],
                         message='Telescope EVLA is not')
    uv1 = copy.deepcopy(uv_full)
    uv2 = copy.deepcopy(uv_full)
    uv1.select(freq_chans=np.arange(0, 32))
    uv2.select(freq_chans=np.arange(32, 64))
    uv1.write_uvh5(testfile1, clobber=True)
    uv2.write_uvh5(testfile2, clobber=True)
    uv1.read([testfile1, testfile2])
    # Check history is correct, before replacing and doing a full object check
    nt.assert_true(
        uvutils._check_histories(
            uv_full.history + '  Downselected to '
            'specific frequencies using pyuvdata. '
            'Combined data along frequency axis using'
            ' pyuvdata.', uv1.history))
    uv1.history = uv_full.history
    nt.assert_equal(uv1, uv_full)

    # clean up
    os.remove(testfile1)
    os.remove(testfile2)

    return
Esempio n. 16
0
def test_casa_nonascii_bytes_antenna_names():
    """Test that nonascii bytes in antenna names are handled properly."""
    uv1 = UVData()
    testfile = os.path.join(DATA_PATH,
                            "corrected2_zen.2458106.28114.ant012.HH.uvfits")
    # this file has issues with the telescope location so turn checking off
    uvtest.checkWarnings(
        uv1.read,
        func_args=[testfile],
        func_kwargs={"run_check": False},
        message=["Telescope mock-HERA is not in known_telescopes."],
    )
    # fmt: off
    expected_ant_names = [
        'HH0', 'HH1', 'HH2', 'H2', 'H2', 'H2', 'H2', 'H2', 'H2', 'H2', 'H2',
        'HH11', 'HH12', 'HH13', 'HH14', 'H14', 'H14', 'H14', 'H14', 'H14',
        'H14', 'H14', 'H14', 'HH23', 'HH24', 'HH25', 'HH26', 'HH27', 'H27',
        'H27', 'H27', 'H27', 'H27', 'H27', 'H27', 'H27', 'HH36', 'HH37',
        'HH38', 'HH39', 'HH40', 'HH41', 'H41', 'H41', 'H41', 'H41', 'H41',
        'H41', 'H41', 'H41', 'HH50', 'HH51', 'HH52', 'HH53', 'HH54', 'HH55',
        'H55', 'H55', 'H55', 'H55', 'H55', 'H55', 'H55', 'H55', 'H55', 'HH65',
        'HH66', 'HH67', 'HH68', 'HH69', 'HH70', 'HH71', 'H71', 'H71', 'H71',
        'H71', 'H71', 'H71', 'H71', 'H71', 'H71', 'H71', 'HH82', 'HH83',
        'HH84', 'HH85', 'HH86', 'HH87', 'HH88', 'H88', 'H88', 'H88', 'H88',
        'H88', 'H88', 'H88', 'H88', 'H88', 'HH98', 'H98', 'H98', 'H98', 'H98',
        'H98', 'H98', 'H98', 'H98', 'H98', 'H98', 'H98', 'H98', 'H98', 'H98',
        'H98', 'H98', 'H98', 'H98', 'H98', 'H98', 'H98', 'HH120', 'HH121',
        'HH122', 'HH123', 'HH124', 'H124', 'H124', 'H124', 'H124', 'H124',
        'H124', 'H124', 'H124', 'H124', 'H124', 'H124', 'HH136', 'HH137',
        'HH138', 'HH139', 'HH140', 'HH141', 'HH142', 'HH143'
    ]
    # fmt: on
    assert uv1.antenna_names == expected_ant_names
Esempio n. 17
0
def test_ReadMiriadWriteUVH5ReadUVH5():
    """
    Miriad round trip test
    """
    uv_in = UVData()
    uv_out = UVData()
    miriad_file = os.path.join(DATA_PATH, 'zen.2456865.60537.xy.uvcRREAA')
    testfile = os.path.join(DATA_PATH, 'test', 'outtest_miriad.uvh5')
    uvtest.checkWarnings(uv_in.read_miriad, [miriad_file],
                         nwarnings=1,
                         category=[UserWarning],
                         message=['Altitude is not present'])
    uv_in.write_uvh5(testfile, clobber=True)
    uv_out.read(testfile)
    nt.assert_equal(uv_in, uv_out)

    # also test round-tripping phased data
    uv_in.phase_to_time(Time(np.mean(uv_in.time_array), format='jd'))
    uv_in.write_uvh5(testfile, clobber=True)
    uv_out.read(testfile)

    nt.assert_equal(uv_in, uv_out)

    # clean up
    os.remove(testfile)

    return
Esempio n. 18
0
def test_readwriteread_large_antnums(tmp_path, casa_uvfits):
    uv_in = casa_uvfits
    uv_out = UVData()
    write_file = str(tmp_path / "outtest_casa.uvfits")

    # check that if antenna_numbers are > 256 everything works
    uv_in.antenna_numbers = uv_in.antenna_numbers + 256
    uv_in.ant_1_array = uv_in.ant_1_array + 256
    uv_in.ant_2_array = uv_in.ant_2_array + 256
    uv_in.baseline_array = uv_in.antnums_to_baseline(uv_in.ant_1_array,
                                                     uv_in.ant_2_array)
    uvtest.checkWarnings(
        uv_in.write_uvfits,
        [write_file],
        message=[
            "The uvw_array does not match the expected values given the antenna "
            "positions",
            "antnums_to_baseline: found > 256 antennas, using 2048 baseline",
        ],
        nwarnings=2,
    )
    uv_out.read(write_file)
    assert uv_in == uv_out

    return
Esempio n. 19
0
def test_breakReadFHD():
    """Try various cases of incomplete file lists."""
    fhd_uv = UVData()
    nt.assert_raises(StandardError, fhd_uv.read_fhd,
                     testfiles[1:])  # Missing flags
    del (fhd_uv)
    fhd_uv = UVData()
    subfiles = [
        item for sublist in [testfiles[0:2], testfiles[3:]] for item in sublist
    ]
    nt.assert_raises(StandardError, fhd_uv.read_fhd,
                     subfiles)  # Missing params
    del (fhd_uv)
    fhd_uv = UVData()
    nt.assert_raises(StandardError, fhd_uv.read_fhd, ['foo'])  # No data files
    del (fhd_uv)
    fhd_uv = UVData()
    if uvtest.pre_1_14_numpy:
        uvtest.checkWarnings(fhd_uv.read_fhd, [testfiles[:-1]],
                             message=['No settings'])
    else:
        # numpy 1.14 introduced a new deprecation warning
        n_scipy_warnings, scipy_warn_list, scipy_category_list = uvtest.get_scipy_warnings(
        )
        warn_list = ['No settings'] + scipy_warn_list
        category_list = [UserWarning] + scipy_category_list
        uvtest.checkWarnings(fhd_uv.read_fhd, [testfiles[:-1]],
                             message=warn_list,
                             category=category_list,
                             nwarnings=n_scipy_warnings + 1)
    # Check only pyuvdata history with no settings file
    nt.assert_equal(
        fhd_uv.history,
        fhd_uv.pyuvdata_version_str)  # Check empty history with no settings
    del (fhd_uv)
Esempio n. 20
0
def test_LatLonAlt_from_XYZ():
    """Test conversion from ECEF xyz to lat/lon/alt with reference values."""
    out_latlonalt = pyuvdata.LatLonAlt_from_XYZ(ref_xyz)
    # Got reference by forcing http://www.oc.nps.edu/oc2902w/coord/llhxyz.htm
    # to give additional precision.
    nt.assert_true(np.allclose(ref_latlonalt, out_latlonalt, rtol=0,
                               atol=1e-3))
    nt.assert_raises(ValueError, pyuvdata.LatLonAlt_from_XYZ, ref_latlonalt)

    # test passing multiple values
    xyz_mult = np.stack((np.array(ref_xyz), np.array(ref_xyz)))
    lat_vec, lon_vec, alt_vec = pyuvdata.LatLonAlt_from_XYZ(xyz_mult)
    nt.assert_true(
        np.allclose(ref_latlonalt, (lat_vec[1], lon_vec[1], alt_vec[1]),
                    rtol=0,
                    atol=1e-3))
    # check warning if array transposed
    uvtest.checkWarnings(pyuvdata.LatLonAlt_from_XYZ, [xyz_mult.T],
                         message='The expected shape of ECEF xyz array',
                         category=PendingDeprecationWarning)
    # check warning if  3 x 3 array
    xyz_3 = np.stack((np.array(ref_xyz), np.array(ref_xyz), np.array(ref_xyz)))
    uvtest.checkWarnings(pyuvdata.LatLonAlt_from_XYZ, [xyz_3],
                         message='The xyz array in LatLonAlt_from_XYZ is',
                         category=PendingDeprecationWarning)
    # check error if only 2 coordinates
    nt.assert_raises(ValueError, pyuvdata.LatLonAlt_from_XYZ, xyz_mult[:, 0:2])

    # test error checking
    nt.assert_raises(ValueError, pyuvdata.LatLonAlt_from_XYZ, ref_xyz[0:1])
Esempio n. 21
0
def test_multi_files():
    """
    Reading multiple files at once.
    """
    uv_full = UVData()
    uvfits_file = os.path.join(DATA_PATH,
                               'day2_TDEM0003_10s_norx_1src_1spw.uvfits')
    testfile1 = os.path.join(DATA_PATH, 'test/uv1')
    testfile2 = os.path.join(DATA_PATH, 'test/uv2')
    uvtest.checkWarnings(uv_full.read_uvfits, [uvfits_file],
                         message='Telescope EVLA is not')
    uv_full.unphase_to_drift()
    uv1 = copy.deepcopy(uv_full)
    uv2 = copy.deepcopy(uv_full)
    uv1.select(freq_chans=np.arange(0, 32))
    uv2.select(freq_chans=np.arange(32, 64))
    uv1.write_miriad(testfile1, clobber=True)
    uv2.write_miriad(testfile2, clobber=True)
    uvtest.checkWarnings(
        uv1.read_miriad, [[testfile1, testfile2]],
        nwarnings=2,
        message=['Telescope EVLA is not', 'Telescope EVLA is not'])
    # Check history is correct, before replacing and doing a full object check
    nt.assert_true(
        uvutils.check_histories(
            uv_full.history + '  Downselected to '
            'specific frequencies using pyuvdata. '
            'Combined data along frequency axis using'
            ' pyuvdata.', uv1.history))
    uv1.history = uv_full.history
    nt.assert_equal(uv1, uv_full)
Esempio n. 22
0
def test_read_multi(tmp_path):
    """Test reading in multiple files."""
    testdir2 = os.path.join(DATA_PATH, "fhd_cal_data/set2")
    obs_testfile_list = [
        obs_testfile,
        os.path.join(testdir2, testfile_prefix + "obs.sav"),
    ]
    cal_testfile_list = [
        cal_testfile,
        os.path.join(testdir2, testfile_prefix + "cal.sav"),
    ]
    settings_testfile_list = [
        settings_testfile,
        os.path.join(testdir2, testfile_prefix + "settings.txt"),
    ]

    fhd_cal = UVCal()
    calfits_cal = UVCal()
    uvtest.checkWarnings(
        fhd_cal.read_fhd_cal,
        func_args=[cal_testfile_list, obs_testfile_list],
        func_kwargs={"settings_file": settings_testfile_list},
        message="UVParameter diffuse_model does not match",
    )

    outfile = str(tmp_path / "outtest_FHDcal_1061311664.calfits")
    fhd_cal.write_calfits(outfile, clobber=True)
    calfits_cal.read_calfits(outfile)
    assert fhd_cal == calfits_cal
Esempio n. 23
0
def test_multi_files():
    """Read multiple files at once."""
    fhd_uv1 = UVData()
    fhd_uv2 = UVData()
    test1 = list(np.array(testfiles)[[0, 1, 2, 4, 6, 7]])
    test2 = list(np.array(testfiles)[[0, 2, 3, 5, 6, 7]])
    uvtest.checkWarnings(
        fhd_uv1.read,
        func_args=[np.array([test1, test2])],
        func_kwargs={
            "use_model": True,
            "file_type": "fhd"
        },
        message=(2 * ["Telescope location derived from obs"]),
        category=2 * [UserWarning],
        nwarnings=2,
    )

    uvtest.checkWarnings(fhd_uv2.read, [testfiles], {"use_model": True},
                         known_warning="fhd")

    assert uvutils._check_histories(
        fhd_uv2.history + " Combined data "
        "along polarization axis using pyuvdata.",
        fhd_uv1.history,
    )

    fhd_uv1.history = fhd_uv2.history
    assert fhd_uv1 == fhd_uv2
Esempio n. 24
0
def test_UVH5SingleIntegrationTime():
    """
    Check backwards compatibility warning for files with a single integration time
    """
    uv_in = UVData()
    uv_out = UVData()
    uvfits_file = os.path.join(DATA_PATH,
                               'day2_TDEM0003_10s_norx_1src_1spw.uvfits')
    testfile = os.path.join(DATA_PATH, 'test', 'outtest_uvfits.uvh5')
    uvtest.checkWarnings(uv_in.read_uvfits, [uvfits_file],
                         message='Telescope EVLA is not')
    uv_in.write_uvh5(testfile, clobber=True)

    # change integration_time in file to be a single number
    with h5py.File(testfile, 'r+') as f:
        int_time = f['/Header/integration_time'].value[0]
        del (f['/Header/integration_time'])
        f['/Header/integration_time'] = int_time
    uvtest.checkWarnings(
        uv_out.read_uvh5, [testfile],
        message='outtest_uvfits.uvh5 appears to be an old uvh5 format')
    nt.assert_equal(uv_in, uv_out)

    # clean up
    os.remove(testfile)

    return
Esempio n. 25
0
def test_read_fhd_write_read_uvfits_no_layout():
    """
    Test errors/warnings with with no layout file.
    """
    fhd_uv = UVData()
    files_use = testfiles[:-3] + [testfiles[-2]]

    # check warning raised
    uvtest.checkWarnings(
        fhd_uv.read,
        func_args=[files_use],
        func_kwargs={"run_check": False},
        message="No layout file",
        nwarnings=1,
        category=UserWarning,
    )

    with pytest.raises(ValueError) as cm:
        uvtest.checkWarnings(
            fhd_uv.read,
            func_args=[files_use],
            message="No layout file",
            nwarnings=1,
            category=UserWarning,
        )
    assert str(cm.value).startswith(
        "Required UVParameter _antenna_positions has not been set")
Esempio n. 26
0
def test_UVH5OptionalParameters():
    """
    Test reading and writing optional parameters not in sample files
    """
    uv_in = UVData()
    uv_out = UVData()
    uvfits_file = os.path.join(DATA_PATH,
                               'day2_TDEM0003_10s_norx_1src_1spw.uvfits')
    uvtest.checkWarnings(uv_in.read_uvfits, [uvfits_file],
                         message='Telescope EVLA is not')
    testfile = os.path.join(DATA_PATH, 'test', 'outtest_uvfits.uvh5')

    # set optional parameters
    uv_in.x_orientation = 'east'
    uv_in.antenna_diameters = np.ones_like(uv_in.antenna_numbers) * 1.
    uv_in.uvplane_reference_time = 0

    # write out and read back in
    uv_in.write_uvh5(testfile, clobber=True)
    uv_out.read(testfile)
    nt.assert_equal(uv_in, uv_out)

    # clean up
    os.remove(testfile)

    return
Esempio n. 27
0
def test_ReadFHDWriteReadUVFits_no_settings():
    """
    FHD to uvfits loopback test with no settings file.

    Read in FHD files, write out as uvfits, read back in and check for object
    equality.
    """
    fhd_uv = UVData()
    uvfits_uv = UVData()
    messages = ['No settings', 'Telescope location derived from obs']
    uvtest.checkWarnings(fhd_uv.read_fhd, [testfiles[:-2]],
                         message=messages,
                         nwarnings=2)

    # Check only pyuvdata history with no settings file
    nt.assert_equal(
        fhd_uv.history,
        fhd_uv.pyuvdata_version_str)  # Check empty history with no settings

    fhd_uv.write_uvfits(os.path.join(DATA_PATH,
                                     'test/outtest_FHD_1061316296.uvfits'),
                        spoof_nonessential=True)
    uvfits_uv.read_uvfits(
        os.path.join(DATA_PATH, 'test/outtest_FHD_1061316296.uvfits'))
    nt.assert_equal(fhd_uv, uvfits_uv)
Esempio n. 28
0
def test_UVH5CompressionOptions():
    """
    Test writing data with compression filters
    """
    uv_in = UVData()
    uv_out = UVData()
    uvfits_file = os.path.join(DATA_PATH,
                               'day2_TDEM0003_10s_norx_1src_1spw.uvfits')
    uvtest.checkWarnings(uv_in.read_uvfits, [uvfits_file],
                         message='Telescope EVLA is not')
    testfile = os.path.join(DATA_PATH, 'test',
                            'outtest_uvfits_compression.uvh5')

    # write out and read back in
    uv_in.write_uvh5(testfile,
                     clobber=True,
                     data_compression="lzf",
                     flags_compression=None,
                     nsample_compression=None)
    uv_out.read(testfile)
    nt.assert_equal(uv_in, uv_out)

    # clean up
    os.remove(testfile)

    return
Esempio n. 29
0
def test_to_waterfall_waterfall():
    uvf = UVFlag(test_f_file)
    uvf.weights_array = np.ones_like(uvf.weights_array)
    uvf.to_waterfall()
    uvtest.checkWarnings(uvf.to_waterfall, [], {},
                         nwarnings=1,
                         message='This object is already a waterfall')
Esempio n. 30
0
def test_read_mwa_multi_concat(tmp_path):
    """Test reading in two sets of files with fast concatenation."""
    # modify file so that time arrays are matching
    mod_mini_6 = str(tmp_path / "mini_gpubox06_01.fits")
    with fits.open(filelist[2]) as mini6:
        mini6[1].header["time"] = 1447698337
        mini6.writeto(mod_mini_6)
    set1 = filelist[0:2]
    set2 = [filelist[0], mod_mini_6]
    mwa_uv = UVData()
    mwa_uv.read([set1, set2], axis="freq")

    mwa_uv2 = UVData()
    messages = [
        "telescope_location is not set",
        "some coarse channel files were not submitted",
        "telescope_location is not set",
        "some coarse channel files were not submitted",
    ]
    category = [UserWarning] * 4
    uvtest.checkWarnings(
        mwa_uv2.read,
        func_args=[[set1, set2]],
        func_kwargs={
            "axis": "freq",
            "file_type": "mwa_corr_fits"
        },
        nwarnings=4,
        message=messages,
        category=category,
    )
    assert mwa_uv == mwa_uv2
    os.remove(mod_mini_6)