How to use pyuvdata - 10 common examples

To help you get started, we’ve selected a few pyuvdata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RadioAstronomySoftwareGroup / pyuvdata / scripts / test_uvfits_equal.py View on Github external
parser.add_argument("uvfits2", help="name of second uvfits file to compare to first.")

args = parser.parse_args()

uvfits_file1 = args.uvfits1
if not op.isfile(uvfits_file1):
    raise IOError("There is no file named {}".format(args.uvfits_file1))

uvfits_file2 = args.uvfits2
if not op.isfile(uvfits_file2):
    raise IOError("There is no file named {}".format(args.uvfits_file2))

uv1 = UVData()
uv1.read_uvfits(uvfits_file1)

uv2 = UVData()
uv2.read_uvfits(uvfits_file2)

if uv1 == uv2:
    print("UVData objects from files are equal")
else:
    print("UVData objects from files are not equal")

del uv1
del uv2
github RadioAstronomySoftwareGroup / pyuvdata / pyuvdata / uvcal / calfits.py View on Github external
antdata = anthdu.data
            self.antenna_names = np.array(list(map(str, antdata["ANTNAME"])))
            self.antenna_numbers = np.array(list(map(int, antdata["ANTINDEX"])))
            self.ant_array = np.array(list(map(int, antdata["ANTARR"])))
            if np.min(self.ant_array) < 0:
                # ant_array was shorter than the other columns, so it was
                # padded with -1s.
                # Remove the padded entries.
                self.ant_array = self.ant_array[np.where(self.ant_array >= 0)[0]]

            self.channel_width = hdr.pop("CHWIDTH")
            self.integration_time = hdr.pop("INTTIME")
            self.telescope_name = hdr.pop("TELESCOP")
            self.history = str(hdr.get("HISTORY", ""))

            if not uvutils._check_history_version(
                self.history, self.pyuvdata_version_str
            ):
                if not self.history.endswith("\n"):
                    self.history += "\n"

                self.history += self.pyuvdata_version_str

            self.time_range = list(map(float, hdr.pop("TMERANGE").split(",")))
            self.gain_convention = hdr.pop("GNCONVEN")
            self.gain_scale = hdr.pop("GNSCALE", None)
            self.x_orientation = hdr.pop("XORIENT")
            self.cal_type = hdr.pop("CALTYPE")
            if self.cal_type == "delay":
                self.freq_range = list(map(float, hdr.pop("FRQRANGE").split(",")))
            else:
                if "FRQRANGE" in hdr:
github RadioAstronomySoftwareGroup / pyuvdata / pyuvdata / uvdata / uvfits.py View on Github external
# other info -- not required but frequently used
            self.object_name = vis_hdr.pop("OBJECT", None)
            self.telescope_name = vis_hdr.pop("TELESCOP", None)
            self.instrument = vis_hdr.pop("INSTRUME", None)
            latitude_degrees = vis_hdr.pop("LAT", None)
            longitude_degrees = vis_hdr.pop("LON", None)
            altitude = vis_hdr.pop("ALT", None)
            self.x_orientation = vis_hdr.pop("XORIENT", None)
            blt_order_str = vis_hdr.pop("BLTORDER", None)
            if blt_order_str is not None:
                self.blt_order = tuple(blt_order_str.split(", "))
                if self.blt_order == ("bda",):
                    self._blt_order.form = (1,)
            self.history = str(vis_hdr.get("HISTORY", ""))
            if not uvutils._check_history_version(
                self.history, self.pyuvdata_version_str
            ):
                self.history += self.pyuvdata_version_str

            self.vis_units = vis_hdr.pop("BUNIT", "UNCALIB")
            self.phase_center_epoch = vis_hdr.pop("EPOCH", None)
            self.phase_center_frame = vis_hdr.pop("PHSFRAME", None)

            self.extra_keywords = uvutils._get_fits_extra_keywords(
                vis_hdr, keywords_to_skip=["DATE-OBS"]
            )

            # Next read the antenna table
            ant_hdu = hdu_list[hdunames["AIPS AN"]]

            # stuff in the header
github RadioAstronomySoftwareGroup / pyuvdata / pyuvdata / uvdata.py View on Github external
if len(ant_str[str_pos:].split(',')) > 1:
                        ant_pairs_nums = self.get_antpairs()
                elif ant_str[str_pos:].upper().startswith('AUTO'):
                    for pair in ant_pairs_data:
                        if (pair[0] == pair[1]
                                and pair not in ant_pairs_nums):
                            ant_pairs_nums.append(pair)
                elif ant_str[str_pos:].upper().startswith('CROSS'):
                    for pair in ant_pairs_data:
                        if not (pair[0] == pair[1]
                                or pair in ant_pairs_nums):
                            ant_pairs_nums.append(pair)
                elif ant_str[str_pos:].upper().startswith('PI'):
                    polarizations.append(uvutils.polstr2num('pI'))
                elif ant_str[str_pos:].upper().startswith('PQ'):
                    polarizations.append(uvutils.polstr2num('pQ'))
                elif ant_str[str_pos:].upper().startswith('PU'):
                    polarizations.append(uvutils.polstr2num('pU'))
                elif ant_str[str_pos:].upper().startswith('PV'):
                    polarizations.append(uvutils.polstr2num('pV'))
                else:
                    raise ValueError('Unparsible argument {s}'.format(s=ant_str))

                comma_cnt = ant_str[str_pos:].find(',')
                if comma_cnt >= 0:
                    str_pos += comma_cnt + 1
                else:
                    str_pos = len(ant_str)
            else:
                m = m.groups()
                str_pos += len(m[0])
                if m[2] is None:
github RadioAstronomySoftwareGroup / pyuvdata / pyuvdata / uvdata / uvfits.py View on Github external
self.Nspws = 1
                self.spw_array = np.array([0])

                # the axis number for phase center depends on if the spw exists
                self.phase_center_ra_degrees = np.float(vis_hdr.pop("CRVAL5"))
                self.phase_center_dec_degrees = np.float(vis_hdr.pop("CRVAL6"))

            # get shapes
            self.Nfreqs = vis_hdr.pop("NAXIS4")
            self.Npols = vis_hdr.pop("NAXIS3")
            self.Nblts = vis_hdr.pop("GCOUNT")

            self.freq_array = uvutils._fits_gethduaxis(vis_hdu, 4)
            self.freq_array.shape = (self.Nspws,) + self.freq_array.shape
            self.channel_width = vis_hdr.pop("CDELT4")
            self.polarization_array = np.int32(uvutils._fits_gethduaxis(vis_hdu, 3))

            # other info -- not required but frequently used
            self.object_name = vis_hdr.pop("OBJECT", None)
            self.telescope_name = vis_hdr.pop("TELESCOP", None)
            self.instrument = vis_hdr.pop("INSTRUME", None)
            latitude_degrees = vis_hdr.pop("LAT", None)
            longitude_degrees = vis_hdr.pop("LON", None)
            altitude = vis_hdr.pop("ALT", None)
            self.x_orientation = vis_hdr.pop("XORIENT", None)
            blt_order_str = vis_hdr.pop("BLTORDER", None)
            if blt_order_str is not None:
                self.blt_order = tuple(blt_order_str.split(", "))
                if self.blt_order == ("bda",):
                    self._blt_order.form = (1,)
            self.history = str(vis_hdr.get("HISTORY", ""))
            if not uvutils._check_history_version(
github RadioAstronomySoftwareGroup / pyuvdata / pyuvdata / uvbeam / beamfits.py View on Github external
self.data_array = data

                # Note: This axis is called STOKES by analogy with the equivalent
                # uvfits axis
                # However, this is confusing because it is NOT a true Stokes axis,
                #   it is really the polarization axis.
                if (
                    primary_header.pop("CTYPE" + str(ax_nums["feed_pol"]))
                    .lower()
                    .strip()
                    == "stokes"
                ):
                    self.Npols = primary_header.pop("NAXIS" + str(ax_nums["feed_pol"]))

                self.polarization_array = np.int32(
                    uvutils._fits_gethduaxis(primary_hdu, ax_nums["feed_pol"])
                )
                self._set_power()
            elif self.beam_type == "efield":
                self._set_efield()
                if n_dimensions < n_efield_dims:
                    raise ValueError(
                        "beam_type is efield and data dimensionality is too low"
                    )
                complex_arrs = np.split(data, 2, axis=0)
                self.data_array = np.squeeze(
                    complex_arrs[0] + 1j * complex_arrs[1], axis=0
                )
                if (
                    primary_header.pop("CTYPE" + str(ax_nums["feed_pol"]))
                    .lower()
                    .strip()
github RadioAstronomySoftwareGroup / pyuvsim / scripts / uvfits_to_yaml.py View on Github external
parser = argparse.ArgumentParser(description=("Generate basic simulation parameters from uvfits."))

parser.add_argument('file_in', metavar='', type=str, nargs='+')
parser.add_argument('-p','--paraml_fname', type=str, default='')

args = parser.parse_args()

uv_fname = args.file_in[0]

yaml_fname= args.paraml_fname
if yaml_fname == '':
    yaml_fname = '.'.join(os.path.basenem(uv_fname).split('.')[:-1]) + '.yaml'   #Replace extension

input_uv = UVData()
input_uv.read_uvfits(uv_fname, read_data=False)

freq_array = input_uv.freq_array[0,:].tolist()
time_array = input_uv.time_array.tolist()

param_dict = dict(

    start_time = time_array[0],
    end_time = time_array[-1],
    Ntimes = input_uv.Ntimes,

    integration_time = input_uv.integration_time,
    
    start_freq = freq_array[0],
    end_freq = freq_array[-1],
    channel_width = input_uv.channel_width,
github RadioAstronomySoftwareGroup / pyuvdata / scripts / renumber_ants.py View on Github external
)
a.add_argument(
    "--filetype",
    default="uvfits",
    type=str,
    help="filetype, options=['uvfits', 'miriad']",
)

# get args
args = a.parse_args()

if os.path.exists(args.file_out) and args.overwrite is False:
    print("{} exists. Use --overwrite to overwrite the file.".format(args.file_out))
    sys.exit(0)

uv_obj = UVData()
if args.filetype == "uvfits":
    uv_obj.read_uvfits(args.file_in)
elif args.filetype == "miriad":
    uv_obj.read_miriad(args.file_in)
else:
    raise IOError("didn't recognize filetype {}".format(args.filetype))

large_ant_nums = sorted(
    uv_obj.antenna_numbers[np.where(uv_obj.antenna_numbers > 254)[0]]
)

new_nums = sorted(set(range(255)) - set(uv_obj.antenna_numbers))
if len(new_nums) < len(large_ant_nums):
    raise ValueError("too many antennas in dataset, cannot renumber all below 255")
new_nums = new_nums[-1 * len(large_ant_nums) :]
renumber_dict = dict(list(zip(large_ant_nums, new_nums)))
github RadioAstronomySoftwareGroup / pyuvdata / pyuvdata / uvdata / aipy_extracts.py View on Github external
if itype == "?":
            return self._rdhd_special(name)

        h = self.haccess(name, "read")
        rv = []

        if len(itype) == 1:
            if itype == "a":
                offset = 0
            else:
                t, offset = _miriad.hread_init(h)
                assert itype == t

            while True:
                try:
                    c, o = _miriad.hread(h, offset, itype)
                except IOError:
                    break

                if itype == "a":
                    try:
                        c = str(c[:o], "utf-8")
                    except TypeError:
                        c = c[:o]

                rv.append(c)
                offset += o

            if itype == "a":
                rv = "".join(rv)
        else:
            t, offset = _miriad.hread_init(h)
github RadioAstronomySoftwareGroup / pyuvdata / pyuvdata / uvdata / aipy_extracts.py View on Github external
try:
                        c = str(c[:o], "utf-8")
                    except TypeError:
                        c = c[:o]

                rv.append(c)
                offset += o

            if itype == "a":
                rv = "".join(rv)
        else:
            t, offset = _miriad.hread_init(h)
            assert t == "b"

            for t in itype:
                v, o = _miriad.hread(h, offset, t)
                rv.append(v)
                offset += o

        _miriad.hdaccess(h)

        if len(rv) == 1:
            return rv[0]
        elif type(rv) == str:
            return rv
        else:
            return np.array(rv)