def test_multi_files(casa_uvfits, tmp_path): """ Reading multiple files at once. """ uv_full = casa_uvfits testfile1 = str(tmp_path / "uv1.uvfits") testfile2 = str(tmp_path / "uv2.uvfits") uv1 = uv_full.copy() uv2 = uv_full.copy() uv1.select(freq_chans=np.arange(0, 32)) uv2.select(freq_chans=np.arange(32, 64)) uv1.write_uvfits(testfile1) uv2.write_uvfits(testfile2) uv1.read(np.array([testfile1, testfile2]), file_type="uvfits") # Check history is correct, before replacing and doing a full object check assert 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 assert uv1 == uv_full # again, setting axis uv1.read([testfile1, testfile2], axis="freq") # Check history is correct, before replacing and doing a full object check assert 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 assert uv1 == uv_full # check with metadata_only uv_full = uv_full.copy(metadata_only=True) uv1 = UVData() uv1.read([testfile1, testfile2], read_data=False) # Check history is correct, before replacing and doing a full object check assert 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 assert uv1 == uv_full
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') uvtest.checkWarnings(uv_full.unphase_to_drift, category=DeprecationWarning, message='The xyz array in ENU_from_ECEF is being ' 'interpreted as (Npts, 3)') uv_full.conjugate_bls('ant1<ant2') 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, [[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 assert 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 assert uv1 == uv_full # again, setting axis uvtest.checkWarnings(uv1.read, [[testfile1, testfile2]], {'axis': 'freq'}, nwarnings=2, message=['Telescope EVLA is not']) # Check history is correct, before replacing and doing a full object check assert 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 assert uv1 == uv_full
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
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
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
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)
def test_multi_files(casa_uvfits, tmp_path): """ Reading multiple files at once. """ uv_full = casa_uvfits testfile1 = str(tmp_path / "uv1") testfile2 = str(tmp_path / "uv2") # rename telescope to avoid name warning uv_full.unphase_to_drift() uv_full.conjugate_bls("ant1<ant2") uv1 = uv_full.copy() uv2 = uv_full.copy() 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) del uv1 uv1 = UVData() uv1.read([testfile1, testfile2], file_type="miriad") # Check history is correct, before replacing and doing a full object check assert 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 assert uv1 == uv_full # again, setting axis del uv1 uv1 = UVData() uv1.read([testfile1, testfile2], axis="freq") # Check history is correct, before replacing and doing a full object check assert 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 assert uv1 == uv_full
def test_multi_unphase_on_read(casa_uvfits, tmp_path): uv_full = casa_uvfits uv_full2 = UVData() testfile1 = str(tmp_path / "uv1.uvfits") testfile2 = str(tmp_path / "uv2.uvfits") uv1 = uv_full.copy() uv2 = uv_full.copy() uv1.select(freq_chans=np.arange(0, 32)) uv2.select(freq_chans=np.arange(32, 64)) uv1.write_uvfits(testfile1) uv2.write_uvfits(testfile2) with uvtest.check_warnings( UserWarning, [ "Telescope EVLA is not", "The uvw_array does not match the expected values given the " "antenna positions.", "Telescope EVLA is not", "The uvw_array does not match the expected values given the " "antenna positions.", "The uvw_array does not match the expected values given the " "antenna positions.", "The uvw_array does not match the expected values given the " "antenna positions.", "Unphasing this UVData object to drift", "Unphasing other UVData object to drift", "The uvw_array does not match the expected values given the " "antenna positions.", ], ): uv1.read(np.array([testfile1, testfile2]), unphase_to_drift=True) # Check history is correct, before replacing and doing a full object check assert uvutils._check_histories( uv_full.history + " Downselected to " "specific frequencies using pyuvdata. " "Combined data along frequency axis " "using pyuvdata.", uv1.history, ) uv_full.unphase_to_drift() uv1.history = uv_full.history assert uv1 == uv_full # check unphasing when reading only one file with uvtest.check_warnings( UserWarning, [ "Telescope EVLA is not", "The uvw_array does not match the expected values given the " "antenna positions.", "Unphasing this UVData object to drift", ], ): uv_full2.read(casa_tutorial_uvfits, unphase_to_drift=True) assert uv_full2 == uv_full
def test_multi_phase_on_read(tmp_path): uv_full = UVData() uv_full2 = UVData() uvfits_file = os.path.join(DATA_PATH, "day2_TDEM0003_10s_norx_1src_1spw.uvfits") testfile1 = str(tmp_path / "uv1.uvfits") testfile2 = str(tmp_path / "uv2.uvfits") uv_full.read(uvfits_file) phase_center_radec = [ uv_full.phase_center_ra + 0.01, uv_full.phase_center_dec + 0.01, ] 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_uvfits(testfile1) uv2.write_uvfits(testfile2) uvtest.checkWarnings( uv1.read, func_args=[np.array([testfile1, testfile2])], func_kwargs={"phase_center_radec": phase_center_radec}, message=(["Telescope EVLA is not"] * 2 + [ "Phasing this UVData object to phase_center_radec", "Phasing this UVData object to phase_center_radec", ]), nwarnings=4, ) # Check history is correct, before replacing and doing a full object check assert uvutils._check_histories( uv_full.history + " Downselected to " "specific frequencies using pyuvdata. " "Combined data along frequency axis " "using pyuvdata.", uv1.history, ) uv_full.phase(*phase_center_radec) uv1.history = uv_full.history assert uv1 == uv_full # check phasing when reading only one file uvtest.checkWarnings( uv_full2.read, func_args=[uvfits_file], func_kwargs={"phase_center_radec": phase_center_radec}, message=([ "Telescope EVLA is not", "Phasing this UVData object to phase_center_radec", ]), nwarnings=2, ) assert uv_full2 == uv_full with pytest.raises(ValueError) as cm: uv_full2.read(uvfits_file, phase_center_radec=phase_center_radec[0]) assert str(cm.value).startswith("phase_center_radec should have length 2.")
def test_multi_files(): """ Reading multiple files at once. """ beam_full = UVBeam() beam_full.read_cst_beam(cst_files, beam_type='efield', frequency=[150e6, 123e6], telescope_name='TEST', feed_name='bob', feed_version='0.1', feed_pol=['x'], model_name='E-field pattern - Rigging height 4.9m', model_version='1.0') # add optional parameters for testing purposes beam_full.extra_keywords = {'KEY1': 'test_keyword'} beam_full.reference_input_impedance = 340. beam_full.reference_output_impedance = 50. beam_full.receiver_temperature_array = np.random.normal( 50.0, 5, size=(beam_full.Nspws, beam_full.Nfreqs)) beam_full.loss_array = np.random.normal(50.0, 5, size=(beam_full.Nspws, beam_full.Nfreqs)) beam_full.mismatch_array = np.random.normal(0.0, 1.0, size=(beam_full.Nspws, beam_full.Nfreqs)) beam_full.s_parameters = np.random.normal(0.0, 0.3, size=(4, beam_full.Nspws, beam_full.Nfreqs)) testfile1 = os.path.join(DATA_PATH, 'test/outtest_beam1.fits') testfile2 = os.path.join(DATA_PATH, 'test/outtest_beam2.fits') beam1 = beam_full.select(freq_chans=0, inplace=False) beam2 = beam_full.select(freq_chans=1, inplace=False) beam1.write_beamfits(testfile1, clobber=True) beam2.write_beamfits(testfile2, clobber=True) beam1.read_beamfits([testfile1, testfile2]) # Check history is correct, before replacing and doing a full object check nt.assert_true( uvutils._check_histories( beam_full.history + ' Downselected ' 'to specific frequencies using pyuvdata. ' 'Combined data along frequency axis using' ' pyuvdata.', beam1.history)) beam1.history = beam_full.history nt.assert_equal(beam1, beam_full)
def test_multi_unphase_on_read(tmp_path): uv_full = UVData() uv_full2 = UVData() uvfits_file = os.path.join(DATA_PATH, "day2_TDEM0003_10s_norx_1src_1spw.uvfits") testfile1 = str(tmp_path / "uv1.uvfits") testfile2 = str(tmp_path / "uv2.uvfits") uv_full.read(uvfits_file) 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_uvfits(testfile1) uv2.write_uvfits(testfile2) uvtest.checkWarnings( uv1.read, func_args=[np.array([testfile1, testfile2])], func_kwargs={"unphase_to_drift": True}, message=(["Telescope EVLA is not"] * 2 + [ "Unphasing this UVData object to drift", "Unphasing other UVData object to drift", ]), nwarnings=4, ) # Check history is correct, before replacing and doing a full object check assert uvutils._check_histories( uv_full.history + " Downselected to " "specific frequencies using pyuvdata. " "Combined data along frequency axis " "using pyuvdata.", uv1.history, ) uv_full.unphase_to_drift() uv1.history = uv_full.history assert uv1 == uv_full # check unphasing when reading only one file uvtest.checkWarnings( uv_full2.read, func_args=[uvfits_file], func_kwargs={"unphase_to_drift": True}, message=([ "Telescope EVLA is not", "Unphasing this UVData object to drift" ]), nwarnings=2, ) assert uv_full2 == uv_full
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.uvfits') testfile2 = os.path.join(DATA_PATH, 'test/uv2.uvfits') uvtest.checkWarnings(uv_full.read, [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_uvfits(testfile1) uv2.write_uvfits(testfile2) uvtest.checkWarnings(uv1.read, [[testfile1, testfile2]], nwarnings=2, message=['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) # check raises error if read_data and read_metadata are False nt.assert_raises(ValueError, uv1.read, [testfile1, testfile2], read_data=False, read_metadata=False) # check raises error if read_data is False and read_metadata is True nt.assert_raises(ValueError, uv1.read, [testfile1, testfile2], read_data=False, read_metadata=True) # check raises error if only reading data on a list of files uv1 = UVData() uvtest.checkWarnings(uv1.read, [uvfits_file], {'read_data': False}, message=['Telescope EVLA is not']) nt.assert_raises(ValueError, uv1.read, [testfile1, testfile2])
def test_multi_files_axis(fhd_model): """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]]) fhd_uv1.read(np.array([test1, test2]), use_model=True, axis="polarization") fhd_uv2 = fhd_model 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
def test_multi_files(cst_efield_2freq, tmp_path): """ Reading multiple files at once. """ beam_full = cst_efield_2freq # add optional parameters for testing purposes beam_full.extra_keywords = {"KEY1": "test_keyword"} beam_full.x_orientation = "east" beam_full.reference_impedance = 340.0 beam_full.receiver_temperature_array = np.random.normal( 50.0, 5, size=(beam_full.Nspws, beam_full.Nfreqs)) beam_full.loss_array = np.random.normal(50.0, 5, size=(beam_full.Nspws, beam_full.Nfreqs)) beam_full.mismatch_array = np.random.normal(0.0, 1.0, size=(beam_full.Nspws, beam_full.Nfreqs)) beam_full.s_parameters = np.random.normal(0.0, 0.3, size=(4, beam_full.Nspws, beam_full.Nfreqs)) testfile1 = str(tmp_path / "outtest_beam1.fits") testfile2 = str(tmp_path / "outtest_beam2.fits") beam1 = beam_full.select(freq_chans=0, inplace=False) beam2 = beam_full.select(freq_chans=1, inplace=False) beam1.write_beamfits(testfile1, clobber=True) beam2.write_beamfits(testfile2, clobber=True) beam1.read_beamfits([testfile1, testfile2]) # Check history is correct, before replacing and doing a full object check assert uvutils._check_histories( beam_full.history + " Downselected " "to specific frequencies using pyuvdata. " "Combined data along frequency axis using" " pyuvdata.", beam1.history, ) beam1.history = beam_full.history assert beam1 == beam_full
def test_multi_files(): """ Reading 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, [[test1, test2]], {'use_model': True}, 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
def test_multi_phase_on_read(casa_uvfits, tmp_path): uv_full = casa_uvfits uv_full2 = UVData() testfile1 = str(tmp_path / "uv1.uvfits") testfile2 = str(tmp_path / "uv2.uvfits") phase_center_radec = [ uv_full.phase_center_ra + 0.01, uv_full.phase_center_dec + 0.01, ] uv1 = uv_full.copy() uv2 = uv_full.copy() uv1.select(freq_chans=np.arange(0, 32)) uv2.select(freq_chans=np.arange(32, 64)) uv1.write_uvfits(testfile1) uv2.write_uvfits(testfile2) with uvtest.check_warnings( UserWarning, [ "Telescope EVLA is not", "The uvw_array does not match the expected values given the " "antenna positions.", "Telescope EVLA is not", "The uvw_array does not match the expected values given the " "antenna positions.", "Phasing this UVData object to phase_center_radec", "The uvw_array does not match the expected values given the " "antenna positions.", "The uvw_array does not match the expected values given the " "antenna positions.", "Phasing this UVData object to phase_center_radec", "The uvw_array does not match the expected values given the " "antenna positions.", ], ): uv1.read(np.array([testfile1, testfile2]), phase_center_radec=phase_center_radec) # Check history is correct, before replacing and doing a full object check assert uvutils._check_histories( uv_full.history + " Downselected to " "specific frequencies using pyuvdata. " "Combined data along frequency axis " "using pyuvdata.", uv1.history, ) uv_full.phase(*phase_center_radec) uv1.history = uv_full.history assert uv1 == uv_full # check phasing when reading only one file with uvtest.check_warnings( UserWarning, [ "Telescope EVLA is not", "The uvw_array does not match the expected values given the antenna " "positions.", "Phasing this UVData object to phase_center_radec", ], ): uv_full2.read(casa_tutorial_uvfits, phase_center_radec=phase_center_radec) assert uv_full2 == uv_full with pytest.raises(ValueError) as cm: uv_full2.read(casa_tutorial_uvfits, phase_center_radec=phase_center_radec[0]) assert str(cm.value).startswith("phase_center_radec should have length 2.")
def test_multi_files(tmp_path): """ Reading multiple files at once. """ uv_full = UVData() uvfits_file = os.path.join(DATA_PATH, "day2_TDEM0003_10s_norx_1src_1spw.uvfits") testfile1 = str(tmp_path / "uv1.uvfits") testfile2 = str(tmp_path / "uv2.uvfits") uv_full.read(uvfits_file) 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_uvfits(testfile1) uv2.write_uvfits(testfile2) uvtest.checkWarnings( uv1.read, func_args=[np.array([testfile1, testfile2])], func_kwargs={"file_type": "uvfits"}, message=2 * ["Telescope EVLA is not"], category=2 * [UserWarning], nwarnings=2, ) # Check history is correct, before replacing and doing a full object check assert 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 assert uv1 == uv_full # again, setting axis uv1.read([testfile1, testfile2], axis="freq") # Check history is correct, before replacing and doing a full object check assert 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 assert uv1 == uv_full # check with metadata_only uv_full = UVData() uv_full.read(uvfits_file, read_data=False) uv1 = UVData() uv1.read([testfile1, testfile2], read_data=False) # Check history is correct, before replacing and doing a full object check assert 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 assert uv1 == uv_full