How to use the pyuvsim.astropy_interface.Time function in pyuvsim

To help you get started, we’ve selected a few pyuvsim 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 / uvsim.py View on Github external
def __init__(self, sources, time, freq, baseline, telescope, freq_i=0):
        self.time = time
        self.freq = freq
        self.sources = sources  # SkyModel object
        self.baseline = baseline
        self.telescope = telescope
        self.freq_i = freq_i
        self.visibility_vector = None
        self.uvdata_index = None  # Where to add the visibility in the uvdata object.

        if isinstance(self.time, float):
            self.time = Time(self.time, format='jd')
        if isinstance(self.freq, float):
            self.freq = self.freq * units.Hz
        if sources.spectral_type == 'flat':
            self.freq_i = 0
github RadioAstronomySoftwareGroup / pyuvsim / pyuvsim / simsetup.py View on Github external
save: bool
        Save mock catalog as npz file.
    rseed: int
        If using the random configuration, pass in a RandomState seed.
    return_data: bool
        If True, return a SkyModelData object instead of SkyModel.

    Returns
    -------
    class:`pyradiosky.SkyModel` or class:`SkyModelData`
        The catalog, as either a SkyModel or a SkyModelData (if `return_data` is True)
    dict
        A dictionary of keywords used to define the catalog.
    """
    if not isinstance(time, Time):
        time = Time(time, scale='utc', format='jd')

    if array_location is None:
        array_location = EarthLocation(lat='-30d43m17.5s', lon='21d25m41.9s',
                                       height=1073.)

    if arrangement not in ['off-zenith', 'zenith', 'cross', 'triangle', 'long-line', 'hera_text',
                           'random']:
        raise KeyError("Invalid mock catalog arrangement: " + str(arrangement))

    mock_keywords = {
        'time': time.jd, 'arrangement': arrangement,
        'array_location': repr(
            (array_location.lat.deg, array_location.lon.deg, array_location.height.value))
    }

    if arrangement == 'off-zenith':
github RadioAstronomySoftwareGroup / pyuvsim / pyuvsim / simsetup.py View on Github external
uvparam_dict.update(parse_time_params(time_dict))

    # There does not seem to be any way to get polarization_array into uvparam_dict, so
    # let's add it explicitly.
    if "polarization_array" in param_dict:
        uvparam_dict['polarization_array'] = param_dict['polarization_array']

    # Parse polarizations
    if uvparam_dict.get('polarization_array', None) is None:
        uvparam_dict['polarization_array'] = np.array([-5, -6, -7, -8])
    if 'Npols' not in uvparam_dict:
        uvparam_dict['Npols'] = len(uvparam_dict['polarization_array'])

    if 'object_name' not in param_dict:
        tloc = EarthLocation.from_geocentric(*uvparam_dict['telescope_location'], unit='m')
        time = Time(uvparam_dict['time_array'][0], scale='utc', format='jd')
        src, _ = create_mock_catalog(time, arrangement='zenith', array_location=tloc)
        if 'sources' in param_dict:
            source_file_name = os.path.basename(param_dict['sources']['catalog'])
            uvparam_dict['object_name'] = '{}_ra{:.4f}_dec{:.4f}'.format(
                source_file_name, src.ra.deg[0], src.dec.deg[0]
            )
        else:
            uvparam_dict['object_name'] = 'Unspecified'
    else:
        uvparam_dict['object_name'] = param_dict['object_name']

    uv_obj = UVData()
    # use the __iter__ function on UVData to get list of UVParameters on UVData
    valid_param_names = [getattr(uv_obj, param).name for param in uv_obj]
    for k in valid_param_names:
        if k in param_dict:
github RadioAstronomySoftwareGroup / pyuvsim / pyuvsim / uvsim.py View on Github external
tloc = [np.float64(x) for x in input_uv.telescope_location]

    world = input_uv.extra_keywords.get('world', 'earth')

    if world.lower() == 'earth':
        location = EarthLocation.from_geocentric(*tloc, unit='m')
    elif world.lower() == 'moon':
        if not hasmoon:
            raise ValueError("Need lunarsky module to simulate an array on the Moon.")
        location = MoonLocation.from_selenocentric(*tloc, unit='m')
    else:
        raise ValueError("If world keyword is set, it must be either 'moon' or 'earth'.")
    telescope = Telescope(input_uv.telescope_name, location, beam_list)
    freq_array = input_uv.freq_array * units.Hz
    time_array = Time(input_uv.time_array, scale='utc', format='jd', location=telescope.location)
    for src_i in src_iter:
        sky = catalog.get_skymodel(src_i)
        if sky.component_type == 'healpix' and hasattr(sky, 'healpix_to_point'):
            sky.healpix_to_point()
        if sky.spectral_type != 'flat' and hasattr(sky, 'at_frequencies'):
            sky.at_frequencies(freq_array[0])
        elif sky.spectral_type == 'full':
            if not np.allclose(sky.freq_array, freq_array):
                raise ValueError("SkyModel spectral type is 'full', and "
                                 "its frequencies do not match simulation frequencies.")
        for task_index in task_ids:
            # Shape indicates slowest to fastest index.
            if not isinstance(task_index, tuple):
                task_index = np.unravel_index(task_index, tasks_shape)
            bl_i = task_index[bl_ax]
            time_i = task_index[time_ax]
github RadioAstronomySoftwareGroup / pyuvsim / pyuvsim / simsetup.py View on Github external
def _set_lsts_on_uvdata(uv_obj):

    # If the telescope location is a MoonLocation,
    # then uv_obj.extra_keywords['world'] == 'moon'.
    world = uv_obj.extra_keywords.get('world', 'earth')

    if world == 'earth':
        uv_obj.set_lsts_from_time_array()
    elif world == 'moon':
        if not 'hasmoon':
            raise ValueError("Cannot construct lsts for MoonLocation without lunarsky module")
        un_jds, inv = np.unique(uv_obj.time_array, return_inverse=True)
        loc = MoonLocation(*uv_obj.telescope_location, unit='m')
        times = Time(un_jds, format='jd', scale='utc', location=loc)
        uv_obj.lst_array = times.sidereal_time('apparent').rad[inv]
    else:
        raise ValueError(f"Invalid world {world}.")
    return uv_obj
github RadioAstronomySoftwareGroup / pyuvsim / pyuvsim / simsetup.py View on Github external
In degrees.
    save: bool
        Save mock catalog as npz file.
    rseed: int
        If using the random configuration, pass in a RandomState seed.
    return_data: bool
        If True, return a SkyModelData object instead of SkyModel.

    Returns
    -------
    class:`pyradiosky.SkyModel` or class:`SkyModelData`
        The catalog, as either a SkyModel or a SkyModelData (if `return_data` is True)
    dict
        A dictionary of keywords used to define the catalog.
    """
    if not isinstance(time, Time):
        time = Time(time, scale='utc', format='jd')

    if array_location is None:
        array_location = EarthLocation(lat='-30d43m17.5s', lon='21d25m41.9s',
                                       height=1073.)

    if arrangement not in ['off-zenith', 'zenith', 'cross', 'triangle', 'long-line', 'hera_text',
                           'random']:
        raise KeyError("Invalid mock catalog arrangement: " + str(arrangement))

    mock_keywords = {
        'time': time.jd, 'arrangement': arrangement,
        'array_location': repr(
            (array_location.lat.deg, array_location.lon.deg, array_location.height.value))
    }