wodenpy.primary_beam¶
Ways to calculate the primary beam response on the CPU rather than the GPU.
use_everybeam¶
Wrappers around the EveryBeam library to calculate primary beam values. The core functionality is in the C++ library libuse_everybeam.so, which in turn contains wrappers about the EveryBeam library. Functions here call the C++ library to calculate the primary beam values, and return them to Python usable data types, via ctypes.
See https://everybeam.readthedocs.io/en/latest/index.html for more information on the EveryBeam library.
- use_everybeam.calc_coordinate_axes(positions: ndarray, central_lat: float, central_lon: float)[source]¶
Internal to a LOFAR measurement set, inside the LOFAR_ANTENNA_FIELD table, there is a column called COORDINATE_AXES. This has something to do with defining what the normal direction of the incoming radation is relative to a particular station. If moving a measurement set from one lat/long to another, this must be recalculated. Below is a best guess by JLBLine at how to do this. See the following doc string copied from EveryBeam which describes the coordinate system, from the EveryBeam/cpp/antenna.h::Antenna::CoordinateSystem function
See also
from the EveryBeam documentation:
Station coordinate system.
A right handed, cartesian, local coordinate system with coordinate axes p, q, and r is associated with each antenna field.
The r-axis is orthogonal to the antenna field, and points towards the local pseudo zenith.
The q-axis is the northern bisector of the X and Y dipoles, i.e. it is the reference direction from which the orientation of the dual dipole antennae is determined. The q-axis points towards the North at the core. At remote sites it is defined as the intersection of the antenna field plane and a plane parallel to the meridian plane at the core. This ensures the reference directions at all sites are similar.
The p-axis is orthogonal to both other axes, and points towards the East at the core.
The axes and origin of the anntena field coordinate system are expressed as vectors in the geocentric, cartesian, ITRF coordinate system, in meters.
“LOFAR Reference Plane and Reference Direction”, M.A. Brentjens, LOFAR-ASTRON-MEM-248.
Todo
find out how to do this properly. As described above, everything is supposed to be calculated relative to the array centre, or for remote stations, “the intersection of the antenna field plane and a plane parallel to the meridian plane at the core”. Wtf does that mean? Below, I calculate things relative to the local ENU for each station. This means the calculations for remote stations are way off, as the curvature of the earth changes what local up is the further you get from the core. If people need accurate remote stations, this needs to be fixed (or just don’t move the telescope).
- Parameters:
positions (np.ndarray) – Array of station positions in ECEF coordinates. Shape (num_positions, 3).
central_lat (float) – Latitude of the array centre in radians.
central_lon (float) – Longitude of the array centre in radians.
- Returns:
coordinate_axes – Array of coordinate axes for each station. Shape (num_positions, 3, 3). coordinate_axes[:, 0, :] are the p vectors, coordinate_axes[:, 1, :] are the q vectors, and coordinate_axes[:, 2, :] are the r vectors, as described in the docstring above.
- Return type:
np.ndarray
- use_everybeam.check_ms_telescope_type_matches_element_response(ms_path: str, element_response_model: str = 'default', logger: Logger = False) Tuple[str, str][source]¶
Check the requested element_response_model is compatible with the telescope type in the measurement set. If they don’t match, set the element response model to the default for the telescope type. This function uses the check_ms_telescope_type function in libuse_everybeam.so.
LOFAR: ‘hamaker’, ‘hamakerlba’, ‘lobes’ or ‘default’
OSKAR: ‘skala40_wave’ or ‘default’
Please note that ‘hamakerlba’, ‘lobes’ are not tested or supported in WODEN, and are not recommended for use. They are included for completeness.
Furthermore, please note that WODEN doesn’t use a base measurement set for the MWA primary beam, and so will throw an error here to make sure you’re not doing something the c++ code can’t handle.
- Parameters:
ms_path (str) – Path to the measurement set.
element_response_model (str, optional) – Requested Element response model to use. Defaults to ‘default’.
logger (Logger, optional) – Logger to use. Defaults to False; if False, create a new simple logger instance.
- Returns:
Tuple of the telescope type and the element response model to use.
- Return type:
Tuple[str, str]
- use_everybeam.convert_common_args_to_everybeam_args(ms_path: str, coeff_path: str, element_response_model: str, station_idxs: ndarray, freqs: ndarray, mjd_sec_times: ndarray) Tuple[source]¶
Convert input arugments common to all EveryBeam primary beam models into ctypes equivalents to pass to the C++ library.
- Parameters:
ms_path (str) – Path to the measurement set.
coeff_path (str) – Path to the coefficients file (only needed for MWA, pass the path to the hdf5 FEE file).
element_response_model (str) – Element response model to use. Can be ‘MWA’, ‘hamaker’, ‘skala40_wave’, or ‘default’.
station_idxs (np.ndarray) – Array of station indices to use.
freqs (np.ndarray) – Array of frequencies to use.
mjd_sec_times (np.ndarray) – Array of times in MJD seconds.
- Returns:
Tuple of the converted arguments in the format required by the EveryBeam library. Order of outputs is identical to order of inputs arguments.
- Return type:
Tuple[ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_double),ctypes.POINTER(ctypes.c_double)]
- use_everybeam.create_filtered_ms(ms_path: str, new_ms_path: str, ra0: float, dec0: float, recentre_array: bool = False, current_latitude: float = False, current_longitude: float = False, new_latitude: float = False, new_longitude: float = False)[source]¶
Create a reduced measurement to path new_ms_path with only the first time and frequency channel of the measurement set ms_path. Set the delay and reference directions to the given RA/Dec ra0,dec0. If recentre_array is True, also perform the necessary calculations and updates to move the array centre from current_latitude and current_longitude to new_latitude and new_longitude.
Runs
worker_create_filtered_ms()in a separate process to avoid python-casacore clashing with WODEN-built libuse_everybeam.so. Seeworker_create_filtered_ms()for more details.- Parameters:
ms_path (str) – Path to the original measurement set.
new_ms_path (str) – Path to the new measurement set.
ra0 (float) – Right ascension of the beam centre in radians.
dec0 (float) – Declination of the beam centre in radians.
recentre_array (bool, optional) – Whether to recentre the array to the new latitude and longitude. Defaults to False. If True, current_latitude, current_longitude, new_latitude, and new_longitude must be set.
current_latitude (float, optional) – Current latitude of the array in radians. Required if recentre_array is True.
current_longitude (float, optional) – Current longitude of the array in radians. Required if recentre_array is True.
new_latitude (float, optional) – New latitude of the array in radians. Required if recentre_array is True.
new_longitude (float, optional) – New longitude of the array in radians. Required if recentre_array is True.
- use_everybeam.enu_basis(lat: float, lon: float) Tuple[ndarray, ndarray, ndarray][source]¶
Calculate the ENU basis vectors in terms of earth-centred earth-fixed coords, for a given latitude lat and longitude lon.
- Parameters:
lat (float) – Latitude in radians.
lon (float) – Longitude in radians.
- Returns:
Tuple of the east, north, and up basis vectors.
- Return type:
Tuple[np.ndarray, np.ndarray, np.ndarray]
- use_everybeam.get_num_stations(ms_path: str) int[source]¶
Get the number of stations in a measurement set given by ms_path.
Runs
worker_get_num_stations()in a separate process to avoid python-casacore clashing with WODEN-built libuse_everybeam.so. Seeworker_get_num_stations()for more details.- Parameters:
ms_path (str) – Path to the measurement set.
- Returns:
Number of stations in the measurement set.
- Return type:
int
- use_everybeam.run_everybeam(ras: ndarray, decs: ndarray, freqs: ndarray, ms_path: str = False, beam_ra0: float = nan, beam_dec0: float = nan, times: ndarray[Time] = False, station_ids: ndarray = False, element_response_model='default', apply_beam_norms: bool = True, mwa_coeff_path: str = False, mwa_dipole_delays: ndarray = False, mwa_dipole_amps: ndarray = array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]), j2000_latitudes: ndarray = False, j2000_lsts: ndarray = False, iau_order: bool = False, element_only: bool = False, parallactic_rotate: bool = False, logger: Logger = False) ndarray[source]¶
Calculate the Jones matrices for a given set of coordinates, times, frequencies, and station ids using the EveryBeam library. Currently, LOFAR and OSKAR beams require a measurement set as an input. The MWA beam does not need a measurement set, but does need the path to the FEE coefficients hdf5 file.
For all beam types, ras, decs, freqs are required.
For LOFAR/OSKAR beams, ms_path, beam_ra0, beam_dec0, times, and station_ids are required.
For MWA beams, mwa_coeff_path, mwa_dipole_delays, j2000_latitudes, and j2000_lsts are required. j2000_latitudes should be the array latitude as precessed back to J2000, with j2000_lsts being the matching LST in J2000.
The returned Jones matrices will have shape (num_stations, num_times, num_freqs, num_radec, 2, 2). The MWA beam will always default to num_stations=1 as dipole flagging has not been implemented in the WODEN wrapper. All other beams will have num_stations=len(station_ids).
- Parameters:
ras (np.ndarray) – Right ascensions of the coordinates in radians.
decs (np.ndarray) – Declinations of the coordinates in radians.
freqs (np.ndarray) – Array of frequencies (Hz)
ms_path (str) – Path to the measurement set to load the EveryBeam telescope from.
beam_ra0 (float) – Right ascension (radians) of the beam pointing centre; the beam will be centered on this position and therefore move with time. Does not apply to MWA beam as that is locked in az,za.
beam_dec0 (float) – Declination (radians) of the beam pointing centre; the beam will be centered on this position and therefore move with time. Does not apply to MWA beam as that is locked in az,za.
times (np.ndarray) – Array of astropy.Time observation times.
station_ids (np.ndarray) – Array of station IDs. Will calculation n_stations=len(station_ids) worth of station beams (does not apply to MWA, which will only calculate a single beam).
element_response_model (str, optional) – The Everybeam element response model to use. Defaults to ‘hamaker’. Avaible options are ‘hamaker’ (LOFAR), ‘skala40_wave’ (OSKAR)
apply_beam_norms (bool, optional) – Whether to apply beam normalisation. Defaults to True. Achieved by calculating the beam response at beam centre, and multiplying all Jones by the inverse of this central beam response (does not apply to MWA beam).
mwa_coeff_path (str) – Path to the coefficients file (needed for MWA, pass the path to the hdf5 FEE file.)
mwa_dipole_delays (np.ndarray) – Array of dipole delays for the MWA stations. Must be of length 16.
mwa_dipole_amps (np.ndarray, optional) – Array of dipole amplitudes for the MWA stations. Must be of length 16.
j2000_latitudes (np.ndarray) – Latitudes in J2000 coordinates (needed for MWA beam az,za calculations).
j2000_lsts (np.ndarray) – Local sidereal times in J2000 coordinates (needed for MWA beam az,za calculations).
iau_order (bool, optional) – If True, use IAU polarisation ordering, so set jones[0,0] to the NS dipole and jones[1,1] to EW. If False, jones[0,0] is EW. Defaults to False
element_only (bool, optional) – Whether to use only the element response. Defaults to False. Use this to look at the dipole response only, not the beam formed response.
parallactic_rotate (bool, optional) – Whether to apply parallactic angle rotation. Defaults to False.
logger (Logger, optional) – Logger to use. Defaults to False; if False, create a new simple logger instance.
- Returns:
The calculated Jones matrices with shape (num_stations, num_times, num_freqs, num_coords, 2, 2).
- Return type:
np.ndarray
- use_everybeam.run_everybeam_over_threads(num_threads: int, ras: ndarray, decs: ndarray, freqs: ndarray, ms_path: str = False, beam_ra0: float = nan, beam_dec0: float = nan, times: ndarray[Time] = False, station_ids: ndarray = False, element_response_model='default', apply_beam_norms: bool = True, mwa_coeff_path: str = False, mwa_dipole_delays: ndarray = False, mwa_dipole_amps: ndarray = array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]), j2000_latitudes: ndarray = False, j2000_lsts: ndarray = False, iau_order: bool = False, element_only: bool = False, parallactic_rotate: bool = False, logger: Logger = False)[source]¶
Runs run_everybeam in parallel over num_threads threads, using concurrent.futures.ProcessPoolExecutor. See run_everybeam for more details of what each parameter does.
Creates a new EveryBeam telescope object from ms_path or a new EveryBeam MWA Tile beam from mwa_coeff_path for each thread. This has to be done because concurrent.futures.ProcessPoolExecutor has to pickle the function and all it’s arguments, and EveryBeam objects can’t be pickled. This is somewhat wasteful but I can’t work out a better way to make things parallel (without using MPI on the other end of things).
- Parameters:
num_threads (int) – Number of threads being in call by run_everybeam_over_threads. ras : np.ndarray Right ascensions of the coordinates in radians.
ras (np.ndarray) – Right ascensions of the coordinates in radians.
decs (np.ndarray) – Declinations of the coordinates in radians.
freqs (np.ndarray) – Array of frequencies (Hz)
ms_path (str) – Path to the measurement set to load the EveryBeam telescope from.
beam_ra0 (float) – Right ascension (radians) of the beam pointing centre; the beam will be centered on this position and therefore move with time. Does not apply to MWA beam as that is locked in az,za.
beam_dec0 (float) – Declination (radians) of the beam pointing centre; the beam will be centered on this position and therefore move with time. Does not apply to MWA beam as that is locked in az,za.
times (np.ndarray) – Array of astropy.Time observation times.
station_ids (np.ndarray) – Array of station IDs. Will calculation n_stations=len(station_ids) worth of station beams (does not apply to MWA, which will only calculate a single beam).
element_response_model (str, optional) – The Everybeam element response model to use. Defaults to ‘hamaker’. Avaible options are ‘hamaker’ (LOFAR), ‘skala40_wave’ (OSKAR)
apply_beam_norms (bool, optional) – Whether to apply beam normalisation. Defaults to True. Achieved by calculating the beam response at beam centre, and multiplying all Jones by the inverse of this central beam response (does not apply to MWA beam).
mwa_coeff_path (str) – Path to the coefficients file (needed for MWA, pass the path to the hdf5 FEE file.)
mwa_dipole_delays (np.ndarray) – Array of dipole delays for the MWA stations. Must be of length 16.
mwa_dipole_amps (np.ndarray, optional) – Array of dipole amplitudes for the MWA stations. Must be of length 16.
j2000_latitudes (np.ndarray) – Latitudes in J2000 coordinates (needed for MWA beam az,za calculations).
j2000_lsts (np.ndarray) – Local sidereal times in J2000 coordinates (needed for MWA beam az,za calculations).
iau_order (bool, optional) – If True, use IAU polarisation ordering, so set jones[0,0] to the NS dipole and jones[1,1] to EW. If False, jones[0,0] is EW. Defaults to False
element_only (bool, optional) – Whether to use only the element response. Defaults to False. Use this to look at the dipole response only, not the beam formed response.
parallactic_rotate (bool, optional) – Whether to apply parallactic angle rotation. Defaults to False.
logger (Logger, optional) – Logger to use. Defaults to False; if False, create a new simple logger instance.
- Returns:
The calculated Jones matrices with shape (num_stations, num_times, num_freqs, num_coord, 2, 2)
- Return type:
np.ndarray
- use_everybeam.run_everybeam_thread(num_threads: int, thread_id: int, ras: ndarray, decs: ndarray, freqs: ndarray, ms_path: str = False, beam_ra0: float = nan, beam_dec0: float = nan, times: ndarray[Time] = False, station_ids: ndarray = False, element_response_model='default', apply_beam_norms: bool = True, mwa_coeff_path: str = False, mwa_dipole_delays: ndarray = False, mwa_dipole_amps: ndarray = array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]), j2000_latitudes: ndarray = False, j2000_lsts: ndarray = False, iau_order: bool = False, element_only: bool = False, parallactic_rotate: bool = False, logger: Logger = False) Tuple[ndarray, int][source]¶
Thread function called by run_everybeam_over_threads to calculate the EveryBeam response in parrallel. Calls run_everybeam with a subset of the coordinates; see run_everybeam for more details of the parameters.
Creates a new EveryBeam telescope object from ms_path or a new EveryBeam MWA Tile beam from mwa_coeff_path for each thread. This has to be done because concurrent.futures.ProcessPoolExecutor has to pickle the function and all it’s arguments, and EveryBeam objects can’t be pickled. This is somewhat wasteful but I can’t work out a better way to make things parallel.
- Parameters:
num_threads (int) – Number of threads being in call by run_everybeam_over_threads.
thread_id (int) – ID of the current thread. Useds to work out what chunk of ras and decs to process.
ras (np.ndarray) – Right ascensions of the coordinates in radians.
decs (np.ndarray) – Declinations of the coordinates in radians.
freqs (np.ndarray) – Array of frequencies (Hz)
ms_path (str) – Path to the measurement set to load the EveryBeam telescope from.
beam_ra0 (float) – Right ascension (radians) of the beam pointing centre; the beam will be centered on this position and therefore move with time. Does not apply to MWA beam as that is locked in az,za.
beam_dec0 (float) – Declination (radians) of the beam pointing centre; the beam will be centered on this position and therefore move with time. Does not apply to MWA beam as that is locked in az,za.
times (np.ndarray) – Array of astropy.Time observation times.
station_ids (np.ndarray) – Array of station IDs. Will calculation n_stations=len(station_ids) worth of station beams (does not apply to MWA, which will only calculate a single beam).
element_response_model (str, optional) – The Everybeam element response model to use. Defaults to ‘hamaker’. Avaible options are ‘hamaker’ (LOFAR), ‘skala40_wave’ (OSKAR)
apply_beam_norms (bool, optional) – Whether to apply beam normalisation. Defaults to True. Achieved by calculating the beam response at beam centre, and multiplying all Jones by the inverse of this central beam response (does not apply to MWA beam).
mwa_coeff_path (str) – Path to the coefficients file (needed for MWA, pass the path to the hdf5 FEE file.)
mwa_dipole_delays (np.ndarray) – Array of dipole delays for the MWA stations. Must be of length 16.
mwa_dipole_amps (np.ndarray, optional) – Array of dipole amplitudes for the MWA stations. Must be of length 16.
j2000_latitudes (np.ndarray) – Latitudes in J2000 coordinates (needed for MWA beam az,za calculations).
j2000_lsts (np.ndarray) – Local sidereal times in J2000 coordinates (needed for MWA beam az,za calculations).
iau_order (bool, optional) – If True, use IAU polarisation ordering, so set jones[0,0] to the NS dipole and jones[1,1] to EW. If False, jones[0,0] is EW. Defaults to False
element_only (bool, optional) – Whether to use only the element response. Defaults to False. Use this to look at the dipole response only, not the beam formed response.
parallactic_rotate (bool, optional) – Whether to apply parallactic angle rotation. Defaults to False.
logger (Logger, optional) – Logger to use. Defaults to False; if False, create a new simple logger instance.
- Returns:
The calculated Jones matrices with shape (num_stations, num_times, num_freqs, num_coords_in_thread, 2, 2), as well as the thread ID. Use the thread ID to insert this thread output into the correct place in the final Jones matrix.
- Return type:
Tuple[np.ndarray, int]
- use_everybeam.run_lofar_beam(ms_path: str, element_response_model: bool, station_idxs: ndarray, beam_ra0: float, beam_dec0: float, ras: ndarray, decs: ndarray, mjd_sec_times: ndarray, freqs: ndarray, apply_beam_norms: bool = True, parallactic_rotate: bool = False, iau_order: bool = True, element_only: bool = False)[source]¶
Run the LOFAR beam model using the EveryBeam library. This function is a wrapper around the C++ library libuse_everybeam.so. It takes the input parameters and converts them to the appropriate ctypes types, then calls the C++ function to calculate the beam response. The output is a numpy array of the beam response, with shape (num_stations, num_times, num_freqs, num_coords, 2, 2).
- Parameters:
ms_path (str) – Path to the measurement set.
element_response_model (str) – Element response model to use. Can be ‘hamaker’, ‘hamakerlba’, ‘lobes’ or ‘default’.
station_idxs (np.ndarray) – Array of station indices to use.
beam_ra0 (float) – Right ascension of the beam center in radians.
beam_dec0 (float) – Declination of the beam center in radians.
ras (np.ndarray) – Right ascensions of the coordinates in radians.
decs (np.ndarray) – Declinations of the coordinates in radians.
mjd_sec_times (np.ndarray) – Array of times in MJD seconds.
freqs (np.ndarray) – Array of frequencies to use.
apply_beam_norms (bool) – Whether to apply beam normalisation. Defaults to True. Achieved by calculating the beam response at beam centre, and multiplying all Jones by the inverse of this central beam response.
parallactic_rotate (bool) – Whether to apply parallactic angle rotation. Defaults to False.
iau_order (bool) – If True, use IAU polarisation ordering, so set jones[0,0] to the NS dipole and jones[1,1] to EW. If False, jones[0,0] is EW.
element_only (bool) – Whether to use only the element response. Defaults to False. Use this to look at the dipole response only, not the beam formed response.
- Returns:
The calculated Jones matrices with shape (num_stations, num_times, num_freqs, num_coords, 2, 2).
- Return type:
np.ndarray
- use_everybeam.run_mwa_beam(delays: ndarray, coeff_path: str, ras: ndarray, decs: ndarray, j2000_lsts: ndarray, j2000_latitudes: ndarray, freqs: ndarray, amps: ndarray = array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]), apply_beam_norms: bool = False, parallactic_rotate: bool = True, iau_order: bool = True, element_only: bool = False)[source]¶
Run the MWA beam model using the EveryBeam library. This function is a wrapper around the C++ library libuse_everybeam.so. It takes the input parameters and converts them to the appropriate ctypes types, then calls the C++ function to calculate the beam response. The output is a numpy array of the beam response, with shape (num_stations, num_times, num_freqs, num_coords, 2, 2).
- Parameters:
delays (np.ndarray) – Array of length 16 of MWA pointing delays
coeff_path (str) – Path to the hdf5 FEE file.
ras (np.ndarray) – Right ascensions of the coordinates in radians.
decs (np.ndarray) – Declinations of the coordinates in radians.
mjd_sec_times (np.ndarray) – Array of times in MJD seconds.
j2000_lsts (np.ndarray) – Local sidereal times in J2000 coordinates.
j2000_latitudes (np.ndarray) – Latitudes in J2000 coordinates.
freqs (np.ndarray) – Array of frequencies to use.
amps (np.ndarray) – Array of length 16 of MWA dipole amplitudes. Defaults to all ones.
apply_beam_norms (bool) – Whether to apply beam normalisation. Defaults to False. The beam seems to be normalised by EveryBeam by default, so this is not ne eded.
parallactic_rotate (bool) – Whether to apply parallactic angle rotation. Defaults to True.
iau_order (bool) – If True, use IAU polarisation ordering, so set jones[0,0] to the NS dipole and jones[1,1] to EW. If False, jones[0,0] is EW.
element_only (bool) – Whether to use only the element response. Defaults to False. Use this to look at the dipole response only, not the beam formed response. Does this by settings all amplitudes bar the first dipole, so defaults to the first dipole only.
- Returns:
The calculated Jones matrices with shape (num_stations, num_times, num_freqs, num_coords, 2, 2). Note that this is to have a consistent shape with other EveryBeam functions which can have varying station patterns; at the moment, num_stations is hard-coded to 1 for MWA.
- Return type:
np.ndarray
- use_everybeam.run_oskar_beam(ms_path: str, element_response_model: bool, station_idxs: ndarray, beam_ra0: float, beam_dec0: float, ras: ndarray, decs: ndarray, mjd_sec_times: ndarray, freqs: ndarray, apply_beam_norms: bool, parallactic_rotate: bool, iau_order: bool = True, element_only: bool = False)[source]¶
Run the OSKAR beam model using the EveryBeam library.
This function is a wrapper around the C++ library libuse_everybeam.so. It takes the input parameters and converts them to the appropriate ctypes types, then calls the C++ function to calculate the beam response. The output is a numpy array of the beam response, with shape (num_stations, num_times, num_freqs, num_coords, 2, 2).
NOTE: This function is currently identical to the LOFAR beam function. Both LOFAR and OSKAR call the PhasedArrayBeam class in the C++ library. These functions have only been lightly tested for functionality. So I’ve kept them separate in case it’s discovered they need different default values in the future.
- Parameters:
ms_path (str) – Path to the measurement set.
element_response_model (str) – Element response model to use. Can be ‘hamaker’, ‘hamakerlba’, ‘lobes’ or ‘default’.
station_idxs (np.ndarray) – Array of station indices to use.
beam_ra0 (float) – Right ascension of the beam center in radians.
beam_dec0 (float) – Declination of the beam center in radians.
ras (np.ndarray) – Right ascensions of the coordinates in radians.
decs (np.ndarray) – Declinations of the coordinates in radians.
mjd_sec_times (np.ndarray) – Array of times in MJD seconds.
freqs (np.ndarray) – Array of frequencies to use.
apply_beam_norms (bool) – Whether to apply beam normalisation. Defaults to True. Achieved by calculating the beam response at beam centre, and multiplying all Jones by the inverse of this central beam response.
parallactic_rotate (bool) – Whether to apply parallactic angle rotation. Defaults to False.
iau_order (bool) – If True, use IAU polarisation ordering, so set jones[0,0] to the NS dipole and jones[1,1] to EW. If False, jones[0,0] is EW.
element_only (bool) – Whether to use only the element response. Defaults to False. Use this to look at the dipole response only, not the beam formed response.
- Returns:
The calculated Jones matrices with shape (num_stations, num_times, num_freqs, num_coords, 2, 2).
- Return type:
np.ndarray
- use_everybeam.worker_create_filtered_ms(ms_path: str, new_ms_path: str, ra0: float, dec0: float, recentre_array: bool = False, current_latitude: float = False, current_longitude: float = False, new_latitude: float = False, new_longitude: float = False) None[source]¶
Create a reduced measurement to path new_ms_path with only the first time and frequency channel of the measurement set ms_path. Set the delay and reference directions to the given RA/Dec ra0,dec0.
The EveryBeam functions that WODEN wraps read the beam centre value directly from the measurement set. Rather than downloading a specific MS which exactly the pointing we want, we just make the smallest possible copy of the MS with the first time and frequency channel, and set the delay and reference direction to what we want.
If recentre_array is True, also perform the necessary calculations and updates to move the array centre from current_latitude and current_longitude to new_latitude and new_longitude.
This function is run in a separate process to avoid python-casacore clashing with WODEN-built libuse_everybeam.so. Running import casacore creates a c++ state with a number of library paths and casacore global variables. If libuse_everybeam.so has been built with against a different casacore library, this causes epic intermittent errors and segfaults. To void this, run the import in this separate thread process, which isolates the state of the c++ library.
- Parameters:
ms_path (str) – Path to the original measurement set.
new_ms_path (str) – Path to the new measurement set.
ra0 (float) – Right ascension of the beam centre in radians.
dec0 (float) – Declination of the beam centre in radians.
recentre_array (bool, optional) – Whether to recentre the array to the new latitude and longitude. Defaults to False. If True, current_latitude, current_longitude, new_latitude, and new_longitude must be set.
current_latitude (float, optional) – Current latitude of the array in radians. Required if recentre_array is True.
current_longitude (float, optional) – Current longitude of the array in radians. Required if recentre_array is True.
new_latitude (float, optional) – New latitude of the array in radians. Required if recentre_array is True.
new_longitude (float, optional) – New longitude of the array in radians. Required if recentre_array is True.
- use_everybeam.worker_get_num_stations(ms_path: str, q: Queue) int[source]¶
Worker function to get the number of stations in the measurement set given by ms_path, and put the in the queue q.
This is done in a separate process because it uses python-casacore. Running import casacore creates a c++ state with a number of library paths and casacore global variables. If libuse_everybeam.so has been built with against a different casacore library, this causes epic intermittent errors and segfaults. To void this, run the import in this separate thread process, which isolates the state of the c++ library.
TODO: All calls to python-casacore should be done via direct calls to casacore in c++ in libuse_everybeam.so. This removes all conflicts; however, this is a large task and will take time to implement. For now, this is a workaround to avoid the segfaults and errors.
- Parameters:
ms_path (str) – Path to the measurement set.
q (Queue) – Queue to put the number of stations in.
use_uvbeam¶
Wrappers around pyuvdata.UVBeam to calculate primary beam values.
See https://pyuvdata.readthedocs.io/en/latest/uvbeam.html for more information on the UVBeam class.
- use_uvbeam.calc_uvbeam_for_components(components: Components_Python, uvbeam_objs: array, all_freqs: ndarray, j2000_latitudes: ndarray, j2000_lsts: ndarray, iau_order: bool = True, parallactic_rotate: bool = True, logger: Logger = False) None[source]¶
For a set of components with filled ras,decs attributes, calculate the primary beam Jones matrices for all UVBeam objects in uvbeam_objs at the given frequencies all_freqs. Uses j2000_latitudes and j2000_lsts to calculate az,za for all time steps. Stores the results in the components gxs,Dxs,Dys,gys attributes. The beam values will eventually be used by the compiled code, either on the CPU or GPU.
- Parameters:
components (Components_Python) – An initialised Components_Python object with the ras, decs attributes filled with the coordinates of the components. Should also have the gxs, Dxs, Dys, gys attributes setup as an array of np.float32 or np.float64 of length len(uvbeam_objs)*len(all_freqs)*len(j2000_lsts)*len(components.ras). float32 or float64 depends on if running simulation in “float” or “double” mode.
uvbeam_objs (np.ndarray[UVBeam]) – Array of initiliased UVBeam objects.
all_freqs (np.ndarray) – Array of frequencies in Hz.
j2000_latitudes (np.ndarray) – Latitudes in J2000 coordinates.
j2000_lsts (np.ndarray) – Local sidereal times in J2000 coordinates.
freqs (np.ndarray) – Array of frequencies.
iau_order (bool, optional) – Whether to return the Jones matrices in IAU order (NS = X, EW = Y). Defaults to False. parallactic_rotate : bool, optional
parallactic_rotate (bool, optional) – Whether to apply parallactic angle rotation. Defaults to True.
logger (Logger, optional) – A logger object to log messages. If False, a default logger is created. Defaults to False.
- use_uvbeam.run_uvbeam(uvbeam_objs: ndarray[UVBeam], ras: ndarray, decs: ndarray, j2000_latitudes: ndarray, j2000_lsts: ndarray, freqs: ndarray, iau_order: bool = False, parallactic_rotate: bool = True, freq_interp: bool = True, logger: Logger = False) ndarray[source]¶
Calculate the Jones matrices for a given set of directions, times (via j2000_lsts and j2000_latitudes), frequencies, and stations (a.k.a tiles for MWA), using an array of UVBeam objects. j2000_latitudes should be the array latitude as precessed back to J2000, with j2000_lsts being the matching LST in J2000. Uses these values to calculate the azimuth and zenith angles for each station at each time.
- Parameters:
uvbeam_objs (np.ndarray[UVBeam]) – Array of initiliased UVBeam objects.
ras (np.ndarray) – Right ascensions of the coordinates in radians.
decs (np.ndarray) – Declinations of the coordinates in radians.
j2000_latitudes (np.ndarray) – Latitudes in J2000 coordinates.
j2000_lsts (np.ndarray) – Local sidereal times in J2000 coordinates.
freqs (np.ndarray) – Array of frequencies.
iau_order (bool, optional) – Whether to return the Jones matrices in IAU order (NS = X, EW = Y). Defaults to False.
parallactic_rotate (bool, optional) – Whether to apply parallactic angle rotation. Defaults to True.
freq_interp (bool, optional) – Whether to use frequency interpolation. Defaults to True. If True, uses the default interpolation method of UVBeam.
logger (Logger, optional) – A logger object to log messages. If False, a default logger is created. Defaults to False.
- Returns:
The calculated Jones matrices with shape (num_stations, num_times, num_freqs, num_coords, 2, 2).
- Return type:
np.ndarray
- use_uvbeam.setup_HERA_uvbeams_from_CST(filenames: list[str], freqs: ndarray[float], logger: Logger = False) array[source]¶
Setup the HERA uvbeam object, using a list of CST simulation files and corresponding frequencies.
Currently only supports a single beam object, so the output is a 1D array of length 1. Can be extended to support multiple beams by modifying filenames and freqs to be 2D arrays. However, currently only have access to a single set of CST files.
- Parameters:
filenames (list[str]) – A list of paths to CST simulation files containing the HERA beam at various frequencies
freqs (np.ndarray) – Array of frequencies in Hz.
logger (Logger, optional) – A logger object to log messages. If False, a default logger is created. Defaults to False.
- Returns:
Array of HERA uvbeam objects, currently of length 1.
- Return type:
np.array
- use_uvbeam.setup_HERA_uvbeams_from_single_file(filepath: str, logger: Logger = False) array[source]¶
Setup the HERA uvbeam object, using the single file path to a UVBeam file (e.g. a beam FITS file). Will try to initialise the UVBeam object using the pyuvdata.UVBeam.from_file method.
Currently only supports a single beam object, so the output is a 1D array of length 1. Can be extended to support multiple beams by modifying to taking in a list of filepaths.
- Parameters:
filepath (str) – Path to a single UVBeam file (e.g. a FITS file) containing the HERA beam
logger (Logger, optional) – A logger object to log messages. If False, a default logger is created. Defaults to False.
- Returns:
Array of HERA uvbeam objects, currently of length 1.
- Return type:
np.array
- use_uvbeam.setup_MWA_uvbeams(hdf5_path: str, freqs: ndarray, delays: ndarray = None, amplitudes: ndarray = None, pixels_per_deg: float = 5) array[source]¶
Setup the MWA uvbeam objects for a given set of frequencies and delays.
Delays should be as appears in the metafits file, so 16 integers.
Amplitudes should have a length which is a multiple of 32; 16 amplitudes for each dipole, for each tile. So if you want three unqiue tile beams, submit an amplitude array of length 96.
- Parameters:
hdf5_path (str) – Path to the hdf5 file containing the MWA FEE beam model.
freqs (np.ndarray) – Array of frequencies in Hz.
delays (np.ndarray, optional) – Array of delays as integers as written in the metafits file. If not given, all delays set to 0.
amplitudes (np.ndarray, optional) – Array of amplitudes. If None, amplitudes of 1.0 used everywhere. Should be in format output from wodenpy.run_setup.check_args a.k.a 16 amps for NS dipole for tile 1, 16 amps for EW dipole for tile 1, 16 amps for NS dipole for tile 2, etc. Should be a multiple of 32.
pixels_per_deg (float, optional) – Number of pixels per degree for UVBeam to use. Defaults to 5.
- Returns:
Array of MWA uvbeam objects, of length len(amplitudes)/32.
- Return type:
np.array