How to use the pyuvdata.UVBeam function in pyuvdata

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 / pyuvsim / pyuvsim / telescope.py View on Github external
if isinstance(beam_model, (AnalyticBeam, UVBeam)):
            return beam_model
        if beam_model.startswith('analytic'):
            bspl = beam_model.split('_')
            model = bspl[1]

            to_set = {}
            for extra in bspl[2:]:
                par, val = extra.split('=')
                full = self._float_params[par]
                to_set[full] = float(val)

            return AnalyticBeam(model, **to_set)

        path = beam_model  # beam_model = path to beamfits
        uvb = UVBeam()
        if use_shared_mem and (mpi.world_comm is not None):
            if mpi.rank == 0:
                uvb.read_beamfits(path)
                uvb.peak_normalize()
            for key, attr in uvb.__dict__.items():
                if not isinstance(attr, parameter.UVParameter):
                    continue
                if key == '_data_array':
                    uvb.__dict__[key].value = mpi.shared_mem_bcast(attr.value, root=0)
                else:
                    uvb.__dict__[key].value = mpi.world_comm.bcast(attr.value, root=0)
            mpi.world_comm.Barrier()
        else:
            uvb.read_beamfits(path)
        for key, val in self.uvb_params.items():
            setattr(uvb, key, val)
github RadioAstronomySoftwareGroup / pyuvsim / pyuvsim / telescope.py View on Github external
def _str_to_obj(self, beam_model, use_shared_mem=False):
        # Convert beam strings to objects.
        if isinstance(beam_model, (AnalyticBeam, UVBeam)):
            return beam_model
        if beam_model.startswith('analytic'):
            bspl = beam_model.split('_')
            model = bspl[1]

            to_set = {}
            for extra in bspl[2:]:
                par, val = extra.split('=')
                full = self._float_params[par]
                to_set[full] = float(val)

            return AnalyticBeam(model, **to_set)

        path = beam_model  # beam_model = path to beamfits
        uvb = UVBeam()
        if use_shared_mem and (mpi.world_comm is not None):
github RadioAstronomySoftwareGroup / pyuvsim / scripts / run_profile_pyuvsim.py View on Github external
input_uv.antenna_positions = input_uv.antenna_positions[:Nants, :]
    input_uv.Nants_data = Nants
    input_uv.Nants_telescope = Nants

    # Time selection:
    inds = np.array([np.arange(args.Nbls) + i
                     * input_uv.Nbls for i in range(args.Ntimes)]).flatten()
    input_uv.time_array = input_uv.time_array[inds]
    input_uv.lst_array = input_uv.lst_array[inds]
    input_uv.Nbls = args.Nbls
    input_uv.Nblts = args.Nbls * args.Ntimes

    # Beam selection:
    # Default is uniform
    if args.beam == 'hera':
        beam = UVBeam()
        beamfile = '/users/alanman/data/alanman/NickFagnoniBeams/HERA_NicCST_fullfreq.uvbeam'
        beam_list = [beamfile]

    mock_keywords = {'mock_arrangement': 'random', 'Nsrcs': args.Nsrcs,
                     'min_alt': min_alt, 'time': input_uv.time_array[0]}
    print("Beam: {}".format(beam_list[0]))
    params['sources'].update(**mock_keywords)

    # Catalog setup
    catalog, _ = simsetup.initialize_catalog_from_params(params)

comm = mpi.world_comm
input_uv = comm.bcast(input_uv, root=0)
beam_list = comm.bcast(beam_list, root=0)
beam_dict = comm.bcast(beam_dict, root=0)
catalog = mpi.shared_mem_bcast(catalog, root=0)
github RadioAstronomySoftwareGroup / pyuvsim / pyuvsim / telescope.py View on Github external
beam_objs : list
            If any UVBeams are found in this list, they will be scraped
            for relevant parameters.

        strict : bool
            If True, will raise an error if the UVBeams in beam_objs
            have conflicting parameters.

        Notes
        -----
        If beam_objs has strings in it, this will simply return an empty dict.
        """

        new_pars = {}
        for bm in beam_objs:
            if isinstance(bm, UVBeam):
                for key in self.uvb_params.keys():
                    val = getattr(bm, key)
                    if key not in new_pars:
                        new_pars[key] = []
                    if val is not None:
                        new_pars[key].append(val)
        for key, vals in new_pars.items():
            svals = set(vals)
            if len(svals) == 1:
                new_pars[key] = svals.pop()
            elif len(svals) > 1:
                try:
                    raise ValueError('Conflicting settings for {}: {}'.format(key, str(svals)))
                except ValueError as err:
                    if strict:
                        raise err
github RadioAstronomySoftwareGroup / pyuvdata / scripts / pyuvdata_inspect.py View on Github external
nargs="*",
    default=[],
    help="pyuvdata object files to run on",
)

# parse arguments
args = a.parse_args()

# check for empty attributes
if len(args.attrs) == 0 and args.interactive is False:
    raise Exception("no attributes fed...")
if len(args.files) == 0:
    raise Exception("no files fed...")

# pack data objects, their names, and read functions
objs = [UVData, UVCal, UVBeam]
ob_names = ["UVData", "UVCal", "UVBeam"]
ob_reads = [
    ["read", "read_miriad", "read_fhd", "read_ms", "read_uvfits", "read_uvh5"],
    ["read_calfits", "read_fhd_cal"],
    ["read_beamfits", "read_cst_beam"],
]

# iterate through files
Nfiles = len(args.files)
uv = []
exit_clean = True
for i, f in enumerate(args.files):
    # check file exists
    if os.path.exists(f) is False:
        print("{0} doesn't exist".format(f))
        if i == (Nfiles - 1):
github RadioAstronomySoftwareGroup / pyuvdata / docs / make_beam_parameters.py View on Github external
def write_beamparams_rst(write_file=None):
    beam = UVBeam()
    out = "UVBeam Parameters\n======================================\n"
    out += (
        "These are the standard attributes of UVBeam objects.\n\nUnder the hood "
        "they are actually properties based on UVParameter objects.\n\n"
    )
    out += "Required\n----------------\n"
    out += (
        "These parameters are required to have a sensible UVBeam object and \n"
        "are required for most kinds of beam files."
    )
    out += "\n\n"
    for thing in beam.required():
        obj = getattr(beam, thing)
        out += "**{name}**\n".format(name=obj.name)
        out += "     {desc}\n".format(desc=obj.description)
        out += "\n"
github RadioAstronomySoftwareGroup / pyuvdata / pyuvdata / mwa_beam.py View on Github external
# start index to populate
        ind_start = (n - 1) ** 2 + 2 * (n - 1)
        # stop index to populate
        ind_stop = n ** 2 + 2 * n
        # assign
        P_sin[np.arange(ind_start, ind_stop), :] = np.vstack([np.flipud(Pm_sin[1::, :]), Pm_sin])
        P1[np.arange(ind_start, ind_stop), :] = np.vstack([np.flipud(Pm1[1::, :]), Pm1])

    # fix for theta = 0 and theta = pi (properly handled in P1sin, so use that function )
    P_sin[:, theta == 0] = np.array([P1sin(nmax, 0)[0]]).transpose()
    P_sin[:, theta == np.pi] = np.array([P1sin(nmax, np.pi)[0]]).transpose()

    return P_sin.transpose(), P1.transpose()


class MWABeam(UVBeam):
    """
    Defines an MWA-specific subclass of UVBeam for representing MWA beams.

    This class should not be interacted with directly, instead use the
    read_mwa_beam method on the UVBeam class.

    This is based on https://github.com/MWATelescope/mwa_pb/ but we don’t import
    that module because it’s not python 3 compatible
    """

    def _read_metadata(self, h5filepath):
        """
        Get metadata (frequencies, polarizations, dipole numbers) from input file.

        Parameters
        ----------