def test_get_itrf(): df = utils.get_itrf() ovro_lon = -118.283400 * u.deg ovro_lat = 37.233386 * u.deg ovro_height = 1188 * u.m df = utils.get_itrf(latlon_center=(ovro_lat, ovro_lon, ovro_height))
def test_get(): df = utils.get_itrf(csvfile=antposfile)
def test_end2end(tmpdir): data_path = pkg_resources.resource_filename('dsamfs', 'data/') param_path = '{0}/test_parameters.yaml'.format(data_path) header_path = '{0}/test_header.txt'.format(data_path) print(param_path) run_fringestopping(param_file=param_path, header_file=header_path, output_dir=tmpdir) fname = glob.glob('{0}/*.hdf5'.format(tmpdir))[0] UV = UVData() UV.read(fname, file_type='uvh5') # Check that the baselines are in the correct order nant = UV.Nants_data abi = get_autobl_indices(nant, casa=False) ant1, ant2 = UV.baseline_to_antnums(UV.baseline_array) antenna_order = ant2[abi] + 1 print(antenna_order) assert np.all(ant1[abi] == ant2[abi]) print(UV.time_array[:10]) print(type(UV.time_array)) print(UV.time_array.dtype) # Check that we can convert to uvfits uvh5_to_ms(fname, fname.replace('.hdf5', '')) assert os.path.exists(fname.replace('hdf5', 'ms')) ms = cc.ms() status = ms.open(fname.replace('hdf5', 'ms')) assert status uvw_ms = ms.getdata('uvw')['uvw'] ms.close() # Check that the UVW coordinates are right in the fits file f = pf.open(fname.replace('hdf5', 'fits')) uu = (f['PRIMARY'].data['UU'] * u.s * c.c).to_value(u.m) vv = (f['PRIMARY'].data['VV'] * u.s * c.c).to_value(u.m) ww = (f['PRIMARY'].data['WW'] * u.s * c.c).to_value(u.m) ant1_array = f['PRIMARY'].data['ANTENNA1'] ant2_array = f['PRIMARY'].data['ANTENNA2'] df_itrf = get_itrf() antenna_positions = np.array([ df_itrf['x_m'], df_itrf['y_m'], df_itrf['z_m'] ]).T - UV.telescope_location blen = np.zeros((ant1_array.shape[0], 3)) for i, ant1 in enumerate(ant1_array): ant2 = ant2_array[i] blen[i, ...] = antenna_positions[int(ant2)-1, :] - \ antenna_positions[int(ant1)-1, :] print(ant1_array[:2], ant2_array[:2]) assert ant1_array[1] == ant1_array[ 0] # Check that ant1 and ant2 are defined properly time = Time(f['PRIMARY'].data['DATE'], format='jd').mjd for i in range(10): try: if f['PRIMARY'].header['CTYPE{0}'.format(i)] == 'RA': ra = f['PRIMARY'].header['CRVAL{0}'.format(i)] * u.deg elif f['PRIMARY'].header['CTYPE{0}'.format(i)] == 'DEC': dec = f['PRIMARY'].header['CRVAL{0}'.format(i)] * u.deg except KeyError: continue assert ra is not None assert dec is not None print(time.shape, blen.shape) uvw = calc_uvw_blt(blen, time, 'J2000', ra, dec) # Doesnt make sense uvw = -1 * uvw print(uvw[:2]) print(uu[:2]) print(vv[:2]) print(ww[:2]) # Why have the uvw coordinates been inverted? assert np.all(np.abs(uvw[:, 0] - uu) < 1e-1) assert np.all(np.abs(uvw[:, 1] - vv) < 1e-1) assert np.all(np.abs(uvw[:, 2] - ww) < 1e-1) assert np.all(np.abs(uvw - uvw_ms.T) < 1e-2) UV = UVData() UV.read(fname.replace('hdf5', 'ms'), file_type='ms') assert np.all(np.abs(UV.antenna_diameters - 4.65) < 1e-4)
import numpy as np from antpos import utils # antenna positions df = utils.get_itrf(stations='../data/ant_ids_case2.csv') xx = np.asarray(df['x_m'].array) yy = np.asarray(df['y_m'].array) zz = np.asarray(df['z_m'].array) np.savez('antlist_case2.npz', xx=xx, yy=yy, zz=zz)
def initialize_uvh5_file(fhdf, nfreq, npol, pt_dec, antenna_order, fobs, fs_table=None): """Initializes an HDF5 file according to the UVH5 specification. For details on the specification of the UVH5 file format, see the pyuvdata memo "UVH5 file format" from November 28, 2018. Parameters ---------- fhdf5 : file handler The hdf5 file to initialize. nbls : int The number of baselines in the correlated data. nfreq : int The number of frequency channels in the correlated data. npol : int The number of polarizations in the correlated data. pt_dec : float The declination at which the visbilities are phased, in radians. antenna_order : array The order of the antennas. The antennas should be specified as integers between 1 and 117 inclusive. (E.g. DSA-24 should be identified as 24.) fs_table : str The full path to the table used in fringestopping. Defaults None. """ # also need the itrf coordinates of the antennas df = get_itrf(latlon_center=(ct.OVRO_LAT * u.rad, ct.OVRO_LON * u.rad, ct.OVRO_ALT * u.m)) ant_itrf = np.array([df['dx_m'], df['dy_m'], df['dz_m']]).T nants_telescope = max(df.index) # have to have some way of calculating the ant_1_array and # ant_2_array order and uvw array. The uvw array should be constant but # still has to have dimensions (nblts, 3) # Header parameters header = fhdf.create_group("Header") data = fhdf.create_group("Data") # The following must be defined header["latitude"] = (ct.OVRO_LAT * u.rad).to_value(u.deg) header["longitude"] = (ct.OVRO_LON * u.rad).to_value(u.deg) header["altitude"] = ct.OVRO_ALT header["telescope_name"] = np.string_("OVRO_MMA") header["instrument"] = np.string_("DSA") header["object_name"] = np.string_("search") header["history"] = np.string_( "written by dsa110-meridian-fringestopping " "on {0}".format(datetime.now().strftime('%Y-%m-%dT%H:%M:%S'))) header["phase_type"] = np.string_("drift") header["phase_center_app_dec"] = pt_dec header["Nants_data"] = len(antenna_order) header["Nants_telescope"] = nants_telescope header["antenna_diameters"] = np.ones(nants_telescope) * 4.65 # ant_1_array and ant_2_array have ot be updated header.create_dataset("ant_1_array", (0, ), maxshape=(None, ), dtype=np.int, chunks=True, data=None) header.create_dataset("ant_2_array", (0, ), maxshape=(None, ), dtype=np.int, chunks=True, data=None) antenna_names = np.array( ['{0}'.format(ant_no + 1) for ant_no in range(nants_telescope)], dtype="S4") header.create_dataset("antenna_names", (nants_telescope, ), dtype="S4", data=antenna_names) header["antenna_numbers"] = np.arange(nants_telescope) header["Nbls"] = ( (header["Nants_data"][()] + 1) * header["Nants_data"][()]) // 2 header["Nblts"] = 0 header["Nfreqs"] = nfreq header["Npols"] = npol header["Ntimes"] = 0 header["Nspws"] = 1 header.create_dataset("uvw_array", (0, 3), maxshape=(None, 3), dtype=np.float32, chunks=True, data=None) header.create_dataset("time_array", (0, ), maxshape=(None, ), dtype=np.float64, chunks=True, data=None) header.create_dataset("integration_time", (0, ), maxshape=(None, ), dtype=np.float64, chunks=True, data=None) header["freq_array"] = fobs[np.newaxis, :] * 1e9 header["channel_width"] = np.abs(np.median(np.diff(fobs)) * 1e9) header["spw_array"] = np.array([1]) # Polarization array is defined at the top of page 8 of # AIPS memo 117: # Values of 1 through 4 are assiged to Stokes I, Q, U, V # Values of -5 through -8 to XX, YY, XY, YX if npol == 4: header["polarization_array"] = np.array([-5, -7, -8, -6]) else: header["polarization_array"] = np.array([-5, -6]) header["antenna_positions"] = ant_itrf # Optional parameters extra = header.create_group("extra_keywords") extra["phase_center_dec"] = pt_dec extra["ha_phase_center"] = 0. extra["phase_center_epoch"] = 'HADEC' if fs_table is not None: extra["fs_table"] = np.string_(fs_table) snapdelays = pu.get_delays(np.array(antenna_order), nants_telescope) extra["applied_delays_ns"] = np.string_(' '.join( [str(d) for d in snapdelays.flatten()])) # Data sets data.create_dataset("visdata", (0, 1, nfreq, npol), maxshape=(None, 1, nfreq, npol), dtype=np.complex64, chunks=True, data=None) data.create_dataset("flags", (0, 1, nfreq, npol), maxshape=(None, 1, nfreq, npol), dtype=np.bool, chunks=True, data=None) # likely set flags_dataset all to 1? data.create_dataset("nsamples", (0, 1, nfreq, npol), maxshape=(None, 1, nfreq, npol), dtype=np.float32)