def test_fine_channels(tmp_path): """ Break read_mwa_corr_fits by submitting files with different fine channels. Test that error is raised if files with different numbers of fine channels are submitted. """ mwa_uv = UVData() bad_fine = str(tmp_path / "bad_gpubox06_01.fits") with fits.open(filelist[2]) as mini6: mini6[1].data = np.concatenate((mini6[1].data, mini6[1].data)) mini6.writeto(bad_fine) with pytest.raises(ValueError) as cm: mwa_uv.read([bad_fine, filelist[1]]) assert str(cm.value).startswith("files submitted have different fine") del mwa_uv
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")
def test_diff_obs(tmp_path): """ Break read_mwa_corr_fits by submitting files from different observations. Test that error is raised if files from different observations are submitted in the same file list. """ mwa_uv = UVData() bad_obs = str(tmp_path / "bad2_gpubox06_01.fits") with fits.open(filelist[2]) as mini6: mini6[0].header["OBSID"] = "1131733555" mini6.writeto(bad_obs) with pytest.raises(ValueError) as cm: mwa_uv.read([bad_obs, filelist[0], filelist[1]]) assert str(cm.value).startswith("files from different observations") del mwa_uv
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=PendingDeprecationWarning, message='The xyz array in ENU_from_ECEF is being ' 'interpreted as (Npts, 3)') 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 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)
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
def test_read_metadata_only(tmp_path): """Test reading an MWA corr fits file as metadata only.""" uvd = UVData() messages = [ "telescope_location is not set", "some coarse channel files were not submitted", ] with uvtest.check_warnings(UserWarning, messages): uvd.read_mwa_corr_fits( filelist[0:2], correct_cable_len=True, phase_to_pointing_center=True, read_data=False, ) assert uvd.metadata_only
def test_file_with_bad_extra_words(): """Test file with bad extra words is iterated and popped correctly.""" fname = os.path.join(DATA_PATH, 'test_miriad_changing_extra.uv') uv = UVData() warn_message = [ 'Altitude is not present in Miriad file, ' 'using known location values for PAPER.', 'Mean of empty slice.', 'invalid value encountered in double_scalars', 'npols=4 but found 1 pols in data file', 'Mean of empty slice.', 'invalid value encountered in double_scalars', 'antenna number 0 has visibilities associated with it, ' 'but it has a position of (0,0,0)', 'antenna number 26 has visibilities associated with it, ' 'but it has a position of (0,0,0)', ] warn_category = ([UserWarning] + [RuntimeWarning] * 2 + [UserWarning] + [RuntimeWarning] * 2 + [UserWarning] * 2) # This is an old PAPER file, run_check must be set to false # The antenna positions is (0, 0, 0) vector uv = uvtest.checkWarnings(uv.read_miriad, func_args=[fname], func_kwargs={'run_check': False}, category=warn_category, nwarnings=len(warn_message), message=warn_message)
def test_file_extension(tmp_path): """ Break read_mwa_corr_fits by submitting file with the wrong extension. Test that error is raised if a file with an extension that is not fits, metafits, or mwaf is submitted. """ mwa_uv = UVData() bad_ext = str(tmp_path / "1131733552.meta") with fits.open(filelist[0]) as meta: meta.writeto(bad_ext) with pytest.raises(ValueError) as cm: mwa_uv.read(bad_ext, file_type="mwa_corr_fits") assert str( cm.value).startswith("only fits, metafits, and mwaf files supported") del mwa_uv
def write_dataparams_rst(write_file=None): UV = UVData() out = "UVData Parameters\n==========================\n" out += ( "These are the standard attributes of UVData objects.\n\nUnder the hood " "they are actually properties based on UVParameter objects.\n\nAngle type " "attributes also have convenience properties named the same thing \nwith " "'_degrees' appended through which you can get or set the value in " "degrees.\n\nSimilarly location type attributes (which are given in " "topocentric xyz coordinates) \nhave convenience properties named the " "same thing with '_lat_lon_alt' and \n'_lat_lon_alt_degrees' appended " "through which you can get or set the values using \nlatitude, longitude and " "altitude values in radians or degrees and meters.\n\n" ) out += "Required\n----------------\n" out += ( "These parameters are required to have a sensible UVData object and \n" "are required for most kinds of uv data files." ) out += "\n\n" for thing in UV.required(): obj = getattr(UV, thing) out += "**{name}**\n".format(name=obj.name) out += " {desc}\n".format(desc=obj.description) out += "\n" out += "Optional\n----------------\n" out += ( "These parameters are defined by one or more file standard but are not " "always required.\nSome of them are required depending on the " "phase_type (as noted below)." ) out += "\n\n" for thing in UV.extra(): obj = getattr(UV, thing) out += "**{name}**\n".format(name=obj.name) out += " {desc}\n".format(desc=obj.description) out += "\n" t = Time.now() t.out_subfmt = "date" out += "last updated: {date}".format(date=t.iso) if write_file is None: write_path = os.path.dirname(os.path.abspath(inspect.stack()[0][1])) write_file = os.path.join(write_path, "uvdata_parameters.rst") F = open(write_file, "w") F.write(out) print("wrote " + write_file)
def test_read_write_read_miriad_partial_with_warnings(uv_in_paper, tmp_path): full, uv_out, write_file = uv_in_paper # check partial read selections full.write_miriad(write_file, clobber=True) uv_in = UVData() # check handling for generic read selections unsupported by read_miriad unique_times = np.unique(full.time_array) times_to_keep = unique_times[ ((unique_times > 2456865.607) & (unique_times < 2456865.609)) ] uvtest.checkWarnings( uv_in.read, func_args=[write_file], func_kwargs={"times": times_to_keep}, nwarnings=3, message=[ "Warning: a select on read keyword is set", "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.", ], ) exp_uv = full.select(times=times_to_keep, inplace=False) assert uv_in == exp_uv uv_in = UVData() # check handling for generic read selections unsupported by read_miriad blts_select = np.where(full.time_array == unique_times[0])[0] ants_keep = [0, 2, 4] uvtest.checkWarnings( uv_in.read, func_args=[write_file], func_kwargs={"blt_inds": blts_select, "antenna_nums": ants_keep}, nwarnings=3, message=[ "Warning: blt_inds is set along with select on read", "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.", ], ) exp_uv = full.select(blt_inds=blts_select, antenna_nums=ants_keep, inplace=False) assert uv_in != exp_uv
def test_antpos_units(): """ Read uvfits, write miriad. Check written antpos are in ns. """ uv = UVData() uvfits_file = os.path.join(DATA_PATH, 'day2_TDEM0003_10s_norx_1src_1spw.uvfits') testfile = os.path.join(DATA_PATH, 'test/uv_antpos_units') uvtest.checkWarnings(uv.read_uvfits, [uvfits_file], message='Telescope EVLA is not') uv.write_miriad(testfile, clobber=True) auv = amiriad.UV(testfile) aantpos = auv['antpos'].reshape(3, -1).T * const.c.to('m/ns').value aantpos = aantpos[uv.antenna_numbers, :] aantpos = (uvutils.ECEF_from_rotECEF( aantpos, uv.telescope_location_lat_lon_alt[1]) - uv.telescope_location) nt.assert_true(np.allclose(aantpos, uv.antenna_positions))
def test_read_write_read_miriad_partial_bls(uv_in_paper, select_kwargs, tmp_path): # check partial read selections full, uv_out, write_file = uv_in_paper full.write_miriad(write_file, clobber=True) uv_in = UVData() # test only specified bls were read, and that flipped antpair is loaded too uv_in.read(write_file, **select_kwargs) antpairs = uv_in.get_antpairs() # indexing here is to ignore polarization if present, maybe there is a better way bls = select_kwargs["bls"] if isinstance(bls, tuple): bls = [bls] assert np.all([bl[:2] in antpairs or bl[:2][::-1] in antpairs for bl in bls]) exp_uv = full.select(inplace=False, **select_kwargs) assert uv_in == exp_uv
def test_add_errors(): uv = UVData() uv.read_miriad(test_d_file) uvc = UVCal() uvc.read_calfits(test_c_file) uv1 = UVFlag(uv) # Mismatched classes nt.assert_raises(ValueError, uv1.__add__, 3) # Mismatched types uv2 = UVFlag(uvc) nt.assert_raises(ValueError, uv1.__add__, uv2) # Mismatched modes uv3 = UVFlag(uv, mode='flag') nt.assert_raises(ValueError, uv1.__add__, uv3) # Invalid axes nt.assert_raises(ValueError, uv1.__add__, uv1, axis='antenna') nt.assert_raises(ValueError, uv2.__add__, uv2, axis='baseline')
def test_ReadNRAOWriteMiriadReadMiriad(): """Test reading in a CASA tutorial uvfits file, writing and reading as miriad""" uvfits_uv = UVData() miriad_uv = UVData() testfile = os.path.join(DATA_PATH, 'day2_TDEM0003_10s_norx_1src_1spw.uvfits') expected_extra_keywords = [ 'OBSERVER', 'SORTORD', 'SPECSYS', 'RESTFREQ', 'ORIGIN' ] uvtest.checkWarnings(uvfits_uv.read_uvfits, [testfile], message='Telescope EVLA is not') uvfits_uv.write_miriad(testfile + '.uv', clobber=True) uvtest.checkWarnings(miriad_uv.read_miriad, [testfile + '.uv'], message='Telescope EVLA is not') nt.assert_equal(uvfits_uv, miriad_uv) del (uvfits_uv) del (miriad_uv)
def test_readMSWriteMiriad_CASAHistory(): """ read in .ms file. Write to a miriad file, read back in and check for history parameter """ ms_uv = UVData() miriad_uv = UVData() ms_file = os.path.join(DATA_PATH, 'day2_TDEM0003_10s_norx_1src_1spw.ms') testfile = os.path.join(DATA_PATH, 'test/outtest_miriad') uvtest.checkWarnings(ms_uv.read_ms, [ms_file], message='Telescope EVLA is not', nwarnings=0) ms_uv.write_miriad(testfile, clobber=True) uvtest.checkWarnings(miriad_uv.read_miriad, [testfile], message='Telescope EVLA is not') nt.assert_equal(miriad_uv, ms_uv)
def test_misaligned_times(tmp_path): """ Break read_mwa_corr_fits by submitting files with misaligned times. Test that error is raised if file start times are different by an amount that is not an integer multiiple of the integration time. """ mwa_uv = UVData() bad_obs = str(tmp_path / "bad3_gpubox06_01.fits") with fits.open(filelist[2]) as mini6: mini6[1].header["MILLITIM"] = 250 mini6.writeto(bad_obs) with pytest.raises(ValueError) as cm: mwa_uv.read([bad_obs, filelist[0], filelist[1]]) assert str( cm.value).startswith("coarse channel start times are misaligned") del mwa_uv
def test_read_fhd_write_read_uvfits(fhd_data, tmp_path): """ FHD to uvfits loopback test. Read in FHD files, write out as uvfits, read back in and check for object equality. """ fhd_uv = fhd_data uvfits_uv = UVData() 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
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_xrfi_h1c_run_input_calfits(self): # input calfits uvd = UVData() uvd.read_miriad(test_d_file) ext = '.flag' outtest1 = os.path.join(xrfi_path, os.path.basename(test_c_file)) + '.x' + ext outtest2 = os.path.join(xrfi_path, os.path.basename(test_c_file)) + '.g' + ext if os.path.exists(outtest1): os.remove(outtest1) if os.path.exists(outtest2): os.remove(outtest2) xrfi.xrfi_h1c_run(uvd, history='Just a test.', filename=test_d_file, extension=ext, summary=True, model_file=test_d_file, model_file_format='miriad', calfits_file=test_c_file, xrfi_path=xrfi_path, kt_size=3) nt.assert_true(os.path.exists(outtest1)) nt.assert_true(os.path.exists(outtest2))
def test_aa_get_params(self): # generate aa from file fn = os.path.join(DATA_PATH, self.test_file) uvd = UVData() uvd.read_miriad(fn) aa = utils.get_aa_from_uv(uvd) # change one antenna position, and read it back in to check it's the same antpos = {'x': 0., 'y': 1., 'z': 2.} params = aa.get_params() for key in antpos.keys(): params['0'][key] = antpos[key] aa.set_params(params) new_params = aa.get_params() new_top = [new_params['0'][key] for key in antpos.keys()] old_top = [antpos[key] for key in antpos.keys()] assert np.allclose(old_top, new_top)
def test_noSPW(): """Test reading in a PAPER uvfits file with no spw axis.""" UV = UVData() testfile_no_spw = os.path.join(DATA_PATH, 'zen.2456865.60537.xy.uvcRREAAM.uvfits') uvtest.checkWarnings(UV.read_uvfits, [testfile_no_spw], known_warning='paper_uvfits') del (UV)
def test_select_on_read(): mwa_uv = UVData() mwa_uv2 = UVData() mwa_uv.read_mwa_corr_fits(filelist[0:2], correct_cable_len=True) unique_times = np.unique(mwa_uv.time_array) select_times = unique_times[np.where( (unique_times >= np.min(mwa_uv.time_array)) & (unique_times <= np.mean(mwa_uv.time_array)))] mwa_uv.select(times=select_times) uvtest.checkWarnings( mwa_uv2.read, func_args=[filelist[0:2]], func_kwargs={ "correct_cable_len": True, "time_range": [np.min(mwa_uv.time_array), np.mean(mwa_uv.time_array)], }, message=[ 'Warning: select on read keyword set, but file_type is "mwa_corr_fits"', "telescope_location is not set. Using known values for MWA.", "some coarse channel files were not submitted", ], nwarnings=3, ) assert mwa_uv == mwa_uv2
def test_run_simulation_partial_freq(): # read gsm test file skymod_file = os.path.join(DATA_PATH, "gsm_nside32.hdf5") sky = sky_model.SkyModel() sky.read_hdf5(skymod_file) # setup uvdata to match freq of gsm test file bls = [(0, 11), (0, 12), (0, 13)] uvd = simulator.setup_uvdata( array_layout=os.path.join(DATA_PATH, "configs/HERA65_layout.csv"), telescope_location=(-30.72152777777791, 21.428305555555557, 1073.0000000093132), telescope_name="HERA", Ntimes=60, time_cadence=100.0, start_time=2458101.0, pols=["xx"], bls=bls, make_full=True, run_check=True, freq_array=sky.freqs, ) test_uvh5 = os.path.join(simtest.TESTDATA_PATH, "test_freq_parallel_sim.uvh5") uvd.write_uvh5(test_uvh5, clobber=True) # run simulation beamfile = os.path.join(DATA_PATH, "HERA_NF_dipole_power.beamfits") beam = beam_model.PowerBeam(beamfile) freq_chans = np.arange(3) simulator.run_simulation_partial_freq(freq_chans, test_uvh5, skymod_file, fov=180, beam=beam) # test that partial frequency sim worked uvd2 = UVData() uvd2.read_uvh5(test_uvh5) d = uvd2.get_data(0, 11) assert not (np.isclose(d[:, freq_chans], 0.0).all()) assert np.isclose(d[:, freq_chans[-1] + 1:], 0.0).all() # clean up os.remove(test_uvh5)
def test_combine_uvpspec_errors(self): # setup uvp build uvd = UVData() uvd.read_miriad( os.path.join(DATA_PATH, 'zen.even.xx.LST.1.28828.uvOCRSA')) beam = pspecbeam.PSpecBeamUV( os.path.join(DATA_PATH, "HERA_NF_dipole_power.beamfits")) bls = [(37, 38), (38, 39), (52, 53)] uvp1 = testing.uvpspec_from_data(uvd, bls, spw_ranges=[(20, 30), (60, 90)], beam=beam) # test failure due to overlapping data uvp2 = copy.deepcopy(uvp1) pytest.raises(AssertionError, uvpspec.combine_uvpspec, [uvp1, uvp2]) # test multiple non-overlapping data axes uvp2 = copy.deepcopy(uvp1) uvp2.polpair_array[0] = 1414 uvp2.freq_array[0] = 0.0 pytest.raises(AssertionError, uvpspec.combine_uvpspec, [uvp1, uvp2]) # test partial data overlap failure uvp2 = testing.uvpspec_from_data(uvd, [(37, 38), (38, 39), (53, 54)], spw_ranges=[(20, 30), (60, 90)], beam=beam) pytest.raises(AssertionError, uvpspec.combine_uvpspec, [uvp1, uvp2]) uvp2 = testing.uvpspec_from_data(uvd, bls, spw_ranges=[(20, 30), (60, 105)], beam=beam) pytest.raises(AssertionError, uvpspec.combine_uvpspec, [uvp1, uvp2]) uvp2 = copy.deepcopy(uvp1) uvp2.polpair_array[0] = 1414 uvp2 = uvpspec.combine_uvpspec([uvp1, uvp2], verbose=False) pytest.raises(AssertionError, uvpspec.combine_uvpspec, [uvp1, uvp2]) # test failure due to variable static metadata uvp2.weighting = 'foo' pytest.raises(AssertionError, uvpspec.combine_uvpspec, [uvp1, uvp2]) uvp2.weighting = 'identity' del uvp2.OmegaP del uvp2.OmegaPP pytest.raises(AssertionError, uvpspec.combine_uvpspec, [uvp1, uvp2])
def test_flag_nsample_basic(): """ Test that the flag(without flag_int) and nsample arrays correctly reflect data. """ uv = UVData() uv.read_mwa_corr_fits(filelist[0:3], flag_init=False) # check that only bad antennas are flagged for all times, freqs, pols bad_ants = [59, 114] good_ants = list(range(128)) for j in bad_ants: good_ants.remove(j) bad = uv.select(antenna_nums=bad_ants, inplace=False) good = uv.select(antenna_nums=good_ants, inplace=False) assert np.all(bad.flag_array) # TODO: Spw axis to be collapsed in future release good.flag_array = good.flag_array.reshape( (good.Ntimes, good.Nbls, 1, good.Nfreqs, good.Npols) ) # good ants should be flagged except for the first time and second freq, # and for the second time and first freq assert np.all(good.flag_array[1:-1, :, :, :, :]) assert np.all(good.flag_array[0, :, :, 1, :] == 0) assert np.all(good.flag_array[-1, :, :, 0, :] == 0) assert np.all(good.flag_array[0, :, :, 0, :]) assert np.all(good.flag_array[-1, :, :, 1, :]) # check that nsample array is filled properly # TODO: Spw axis to be collapsed in future release uv.nsample_array = uv.nsample_array.reshape( (uv.Ntimes, uv.Nbls, 1, uv.Nfreqs, uv.Npols) ) assert np.all(uv.nsample_array[1:-1, :, :, :, :] == 0.0) assert np.all(uv.nsample_array[0, :, :, 1, :] == 1.0) assert np.all(uv.nsample_array[-1, :, :, 0, :] == 1.0) assert np.all(uv.nsample_array[0, :, :, 0, :] == 0.0) assert np.all(uv.nsample_array[-1, :, :, 1, :] == 0.0)
def test_breakReadUVFits(): """Test errors on reading in a uvfits file with subarrays and other problems.""" UV = UVData() multi_subarray_file = os.path.join(DATA_PATH, 'multi_subarray.uvfits') uvtest.checkWarnings(nt.assert_raises, [ValueError, UV.read_uvfits, multi_subarray_file], message='Telescope EVLA is not') del (UV)
def test_ReadUVH5Errors(): """ Test raising errors in read_uvh5 function """ uv_in = UVData() fake_file = os.path.join(DATA_PATH, 'fake_file.hdf5') nt.assert_raises(IOError, uv_in.read_uvh5, fake_file) return
def test_write_uvdata(save_format, tmpdir): """ Test function that defines filenames from parameter dict """ uv = UVData() uv.read_uvfits(triangle_uvfits_file) ofname = str(tmpdir.join('test_file')) filing_dict = {'outfile_name': ofname} expected_ofname = simutils.write_uvdata(uv, filing_dict, return_filename=True, out_format=save_format) ofname = os.path.join('.', ofname) if save_format == 'uvfits' or save_format is None: assert ofname + '.uvfits' == expected_ofname elif save_format == 'uvh5': assert ofname + '.uvh5' == expected_ofname else: assert ofname == expected_ofname
def test_read_change_type(): uv = UVData() uv.read_miriad(test_d_file) uvc = UVCal() uvc.read_calfits(test_c_file) uvf = UVFlag(uvc) uvf.write(test_outfile, clobber=True) nt.assert_true(hasattr(uvf, 'ant_array')) uvf.read(test_f_file) nt.assert_false(hasattr(uvf, 'ant_array')) nt.assert_true(hasattr(uvf, 'baseline_array')) nt.assert_true(hasattr(uvf, 'ant_1_array')) nt.assert_true(hasattr(uvf, 'ant_2_array')) uvf.read(test_outfile) nt.assert_true(hasattr(uvf, 'ant_array')) nt.assert_false(hasattr(uvf, 'baseline_array')) nt.assert_false(hasattr(uvf, 'ant_1_array')) nt.assert_false(hasattr(uvf, 'ant_2_array'))
class TestFitsFile(unittest.TestCase): filename = '' def setUp(self): self.uvd = UVData() self.uvd.read_uvfits(self.filename) self.cycle_pols = { 'XX': [(0, 0), (0, 2), (0, 4), (2, 2), (2, 4), (4, 4)], 'YY': [(1, 1), (1, 3), (1, 5), (3, 3), (3, 5), (5, 5)], 'XY': [(0, 1), (0, 3), (0, 5), (2, 3), (2, 5), (4, 5)], 'YX': [(1, 0), (1, 2), (1, 4), (3, 2), (3, 4), (5, 4)] } self.pol = self.filename.split('.')[-2] def signed_int(self, x): """Return two's complement interpretation for 4bit integers""" if (x & 0x8): return (x - 16) else: return x def gen_tvg_pol(self, pol, mode='ramp'): if mode == 'ramp': ramp = np.arange(2**13, dtype='>B') tv = ramp + pol if mode == 'const': tv = np.zeros(NCHANS * 4, dtype='>B') tv = tv + pol tv_imag = np.asarray([self.signed_int(x) for x in (tv & (0x0f))]) tv_real = np.asarray([self.signed_int(x) for x in (tv >> 4)]) tv = tv_real + 1j * tv_imag return tv def test_real(self): bls = self.cycle_pols[self.pol] for i, (ant1, ant2) in enumerate( zip(self.uvd.ant_1_array, self.uvd.ant_2_array)): data = self.uvd.get_data(ant1, ant2) tspec = self.gen_tvg_pol(bls[i][0]) * np.conj( self.gen_tvg_pol(bls[i][1])) tspec = np.sum(tspec.reshape(-1, 8), axis=1) self.assertTrue(np.all(tspec.real == data.real))
opts,args = o.parse_args(sys.argv[1:]) #window='blackman-harris' #dir='/users/jkerriga/data/jkerriga/8DayLST/even/Pzen.2456242.30605.uvcRREcACOTUcHPA' uv = a.miriad.UV(args[0]) chans = uv['nchan'] aa = a.cal.get_aa(opts.cal, uv['sdf'], uv['sfreq'], chans) filters = C.dspec.wedge_width_by_bl(aa, uv['sdf'], chans, offset=0.0) #print filters.keys() del(uv) print args #print filters[(41,49)] #uthresh,lthresh = filters[(41,49)] #mir = uvdata.miriad.Miriad() for files in args: mir = UVData() try: mir.read_miriad(files) except: pass for i in filters.keys(): print i bsl = mir.antnums_to_baseline(i[0],i[1]) bidx = mir.baseline_array==bsl d1 = mir.data_array[bidx,0,:,0] #*n.logical_not(mir.flag_array[bidx,0,:,0]).astype(float) d2 = mir.data_array[bidx,0,:,1] #*n.logical_not(mir.flag_array[bidx,0,:,0]).astype(float) # bh = n.ones(151,dtype=complex) bh = a.dsp.gen_window(chans,window='blackman-harris') # bh = n.ones(chans,dtype=complex)
freqs = np.round(np.arange(freqs_arr[0], freqs_arr[1] + opts.freq_res, opts.freq_res), decimals=3) freqs = freqs[np.where(freqs <= freqs_arr[1])] elif not (',' in opts.freq and '-' in opts.freq): freqs = [float(opts.freq)] nfreqs = len(freqs) if opts.snapshot: hours = np.array([np.pi/2]) else: low_lim = np.pi/2-0.5*opts.width*np.pi/180 high_lim = np.pi/2+0.5*opts.width*np.pi/180 hours = np.linspace(low_lim, high_lim, 10) decs = np.ones_like(hours)*np.pi/2 #zenith transitting point source uv = UVData() if opts.data is not None: # Read in telescope data if opts.data.endswith('.uvfits'): uv.read_uvfits(opts.data) else: uv.read_miriad(opts.data) ant_pos = uv.antenna_positions + uv.telescope_location lat,lon,alt = uv.telescope_location_lat_lon_alt ant_pos = uvu.ENU_from_ECEF(ant_pos.T, lat, lon, alt).T blns = uv.get_baseline_nums() elif opts.positions is not None: # Read in antenna positions from file ant_pos = np.load(opts.positions) blns = np.zeros(0, dtype=int)
#!/bin/env python ## Uses pyuvdata's select function to pull specific antennas from input files, appending "A" to the end. from pyuvdata import UVData import sys, optparse,os import aipy as a o = optparse.OptionParser() o.add_option("-a", "--ants", help="Antennas to select (AIPY options)") opts,args = o.parse_args(sys.argv[1:]) uvd = UVData() for filename in args: print filename, '->', filename+'A' if os.path.exists(filename+'A'): print ' File exists... skipping.' continue uvd.read_miriad(filename) baselines = ("_" in opts.ants) ### If baselines are listed specifically, select by baselines. Otherwise, limit to the antennas listed in ants. if baselines: ants=a.scripting.parse_ants(opts.ants,uvd.Nants_telescope) bl_list=[] for cnt,(bl,include,pol) in enumerate(ants): i,j = uvd.baseline_to_antnums(bl) bl_list.append((int(i),int(j))) uvd.select(ant_pairs_nums=bl_list) else:
#SBATCH -J extract_antpos #SBATCH --mem=30G #SBATCH --time=3:00:00 ### Given a uvfits or miriad file, extracts the relative positions of antennas from the baseline array using pyuvdata from pyuvdata import UVData import sys, numpy as np, os import pickle import pylab as p from astropy.coordinates import Angle from astropy import units as u uvd = UVData() generic_cal_filepath = '/users/alanman/brownscripts/ael/generic_cal.py' if os.path.isfile(sys.argv[1]): uvd.read_uvfits(sys.argv[1]) elif os.path.isdir(sys.argv[1]): uvd.read_miriad(sys.argv[1]) else: print "Invalid file type" sys.exit() if uvd.phase_type == 'phased': uvd.unphase_to_drift() Nants = uvd.Nants_telescope