wodenpy.primary_beam¶
Ways to calculate the primary beam response on the CPU rather than the GPU.
use_everybeam¶
- class use_everybeam.EB_fake[source]¶
A fake everybeam class so we can build the documentation online in ReadTheDocs without installing everybeam, which is non-trivial
- use_everybeam.calc_everybeam_rotation(direction: ndarray, north: ndarray, east: ndarray) ndarray[source]¶
Given an ITRF 3-vector in the direction of interest direction, and the associated north and east vectors, calculate the 2x2 rotation matrix to rotate by parallactic angle.
Translated from EveryBeam beamformer.cc BeamFormer::LocalResponse const vector3r_t e_phi = normalize(cross(direction)); const vector3r_t e_theta = cross(e_phi, direction); result *= {dot(e_theta, options.north), dot(e_theta, options.east),
dot(e_phi, options.north), dot(e_phi, options.east)};
- Parameters:
direction (np.ndarray) – A 3-element array representing the direction ITRF vector.
north (np.ndarray) – A 3-element array representing the north vector.
east (np.ndarray) – A 3-element array representing the east vector.
- Returns:
A 2x2 rotation matrix.
- Return type:
np.ndarray
- use_everybeam.eb_local_xyz_from_radec(ra: float, dec: float, altaz_frame: AltAz, delta_az: float = 1.5707963267948966, negative_azimuth=True)[source]¶
Get the local cartesian coordinates used by EveryBeam from a given RA, Dec, and AltAz frame. This function transforms the given right ascension (RA) and declination (Dec) into local cartesian coordinates based on the provided AltAz frame. The azimuth is adjusted by reversing it and adding 90 degrees (or a specified delta) to match the expected coordinates.
This function is used to emulate the way the EveryBeam does it’s parallactic rotation. delta_az is set to π/2 by experiment to match outputs from EveryBeam. Not really needed, as when can use EveryBeam to do the parallactic rotation for everything aside the MWA beam.
- Parameters:
ra (float) – Right ascension in radians.
dec (float) – Declination in radians.
altaz_frame (astropy.coordinates.AltAz) – The AltAz frame to transform the coordinates into.
delta_az (float, optional) – The azimuth adjustment in radians. Default is π/2.
negative_azimuth (bool, optional) – If True, the azimuth is reversed before adding the delta. Default is True.
- Returns:
A 3xN array of the local cartesian coordinates.
- Return type:
numpy.ndarray
- use_everybeam.eb_north_east(direction: ndarray, ncp_t: ndarray) Tuple[ndarray, ndarray][source]¶
Compute the north and east vectors given a direction ITRF vector, and the ITRF vector towards the north celestial pole. This function calculates the east vector by taking the cross product of the normal vector (ncp_t) and the direction vector, and then normalizes it. The north vector is then calculated as the cross product of the direction vector and the east vector.
Translated from EveryBeam station.cc Station::ComputeElementResponse
const vector3r_t east = normalize(cross(ncp_t, direction)); const vector3r_t north = cross(direction, east); options.east = east; options.north = north;
- Parameters:
direction (np.ndarray) – A 3-element array representing the direction vector.
ncp_t (np.ndarray) – A 3-element array representing the normal vector.
- Returns:
A tuple containing the north and east vectors as 3-element arrays.
- Return type:
Tuple[np.ndarray, np.ndarray]
- use_everybeam.load_LOFAR_telescope(ms_path: str, response_model: str = 'hamaker', use_differential_beam: bool = False) None[source]¶
Load an LOFAR telescope from a measurement set. Settings lifted directly from https://everybeam.readthedocs.io/en/latest/tree/demos/lofar-lobes.html
- Parameters:
ms_path (str) – Path to the measurement set
response_model (str, optional) – Response model to use, by default “hamaker”
use_differential_beam (bool, optional) – Use the differential beam a.k.a return a “normalised” beam, by default False
- Returns:
Telescope object
- Return type:
eb.LOFAR
- use_everybeam.load_MWA_telescope(ms_path: str, coeff_path: str, use_local_mwa: bool = True) None[source]¶
Load an MWA telescope from a measurement set.
- Parameters:
ms_path (str) – Path to the measurement set
response_model (str, optional) – Response model to use, by default “lobes”
use_local_mwa (bool, optional) – Use the local MWA model, which takes za/az instead of RA/Dec. Defaults to True
- Returns:
Telescope object, either MWA (if use_local_mwa is False) or MWALocal (if use_local_mwa is True)
- Return type:
Union[eb.MWA, eb.MWALocal]
- use_everybeam.load_OSKAR_telescope(ms_path: str, response_model='skala40_wave', use_differential_beam: bool = True) None[source]¶
Load an OSKAR telescope from a measurement set.
- Parameters:
ms_path (str) – Path to the measurement set
response_model (str, optional) – Response model to use, by default “skala40_wave”
use_differential_beam (bool, optional) – Use the differential beam a.k.a return a “normalised” beam, by default True
- Returns:
Telescope object
- Return type:
eb.OSKAR
- use_everybeam.radec_to_xyz(ra: float, dec: float, time: Time)[source]¶
Convert RA and Dec ICRS coordinates to ITRS cartesian coordinates.
Taken from the everybeam documentation https://everybeam.readthedocs.io/en/latest/tree/demos/lofar-array-factor.html
- Parameters:
ra (astropy.coordinates.Angle) – Right ascension
dec (astropy.coordinates.Angle) – Declination
instance (time float astropy time)
- Returns:
NumPy array containing the ITRS X, Y and Z coordinates
- Return type:
pointing_xyz (ndarray)
- use_everybeam.run_everybeam(ras: ndarray, decs: ndarray, beam_ra0: float, beam_dec0: float, j2000_latitudes: ndarray, j2000_lsts: ndarray, current_latitude: float, current_longitude: float, times: ndarray, freqs: ndarray, telescope: None, station_ids: ndarray, apply_beam_norms: bool = True, reorder_jones: bool = False, element_only: bool = False, eb_rotate: bool = False, parallactic_rotate: bool = False, para_angle_offset: float = 0) ndarray[source]¶
Calculate the Jones matrices for a given set of coordinates, times, frequencies, and station ids using the EveryBeam library. j2000_latitudes should be the array latitude as precessed back to J2000, with j2000_lsts being the matching LST in J2000. current_latitude and current_longitude should be latitude and longitude of the array at the time of the observation. telescope should be an EveryBeam telescope object.
- Parameters:
ras (np.ndarray) – Right ascensions of the coordinates in radians.
decs (np.ndarray) – Declinations of the coordinates in radians.
beam_ra0 (float) – Right ascension of the beam center in radians.
beam_dec0 (float) – Declination of the beam center in radians.
j2000_latitudes (np.ndarray) – Latitudes in J2000 coordinates.
j2000_lsts (np.ndarray) – Local sidereal times in J2000 coordinates.
current_latitude (float) – Current latitude in radians.
current_longitude (float) – Current longitude in radians.
times (np.ndarray) – Array of observation times.
freqs (np.ndarray) – Array of frequencies.
telescope ((eb.Telescope):) – Telescope object from the EveryBeam library.
station_ids (np.ndarray) – Array of station IDs.
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.
reorder_jones (bool, optional) – Whether to reorder the Jones matrices. Defaults to False. Just rearranges the Jones matrix from [[0,0, 0,1,], [1,0, 1,1]] to [[1,1, 1,0,], [0,1, 0,0]].
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.
eb_rotate (bool, optional) – Whether to apply parallactic rotation using EveryBeam. Defaults to False. Should probably be used for everything apart from MWA beams.
parallactic_rotate (bool, optional) – Whether to apply parallactic angle rotation using wodenpy. Defaults to False. Should be True for MWA beams if you want rotation. If True for a non-MWA beam, wodenpy should match the output as if eb_rotate was True.
para_angle_offset (float, optional) – Offset to add to the parallactic angle. Defaults to 0.
- 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, ms_path: str, coeff_path: str, ras: ndarray, decs: ndarray, ra0: float, dec0: float, j2000_latitudes: ndarray, j2000_lsts: ndarray, current_latitude: float, current_longitude: float, times: ndarray, freqs: ndarray, station_ids: ndarray, use_differential_beam: bool = True, apply_beam_norms: bool = True, reorder_jones: bool = False, element_only: bool = False, eb_rotate: bool = False, parallactic_rotate: bool = True, use_local_mwa: bool = True, para_angle_offset: float = 0, element_response_model='hamaker')[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 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.
ms_path (str) – Path to the measurement set to load the EveryBeam telescope from.
ras (np.ndarray) – Right ascensions of the coordinates in radians.
decs (np.ndarray) – Declinations of the coordinates in radians.
beam_ra0 (float) – Right ascension of the beam center in radians.
beam_dec0 (float) – Declination of the beam center in radians.
j2000_latitudes (np.ndarray) – Latitudes in J2000 coordinates.
j2000_lsts (np.ndarray) – Local sidereal times in J2000 coordinates.
current_latitude (float) – Current latitude in radians.
current_longitude (float) – Current longitude in radians.
times (np.ndarray) – Array of observation times.
freqs (np.ndarray) – Array of frequencies.
station_ids (np.ndarray) – Array of station IDs.
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.
reorder_jones (bool, optional) – Whether to reorder the Jones matrices. Defaults to False. Just rearranges the Jones matrix from [[0,0, 0,1,], [1,0, 1,1]] to [[1,1, 1,0,], [0,1, 0,0]].
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.
eb_rotate (bool, optional) – Whether to apply parallactic rotation using EveryBeam. Defaults to False. Should probably be used for everything apart from MWA beams.
parallactic_rotate (bool, optional) – Whether to apply parallactic angle rotation using wodenpy. Defaults to False. Should be True for MWA beams if you want rotation. If True for a non-MWA beam, wodenpy should match the output as if eb_rotate was True.
para_angle_offset (float, optional) – Offset to add to the parallactic angle. Defaults to 0.
element_response_model (str, optional) – The Everybeam element response model to use. Defaults to ‘hamaker’. Avaible options are ‘hamaker’ (LOFAR), ‘skala40_wave’ (OSKAR), and ‘MWA’ (MWA).
use_local_mwa (bool, optional) – Whether to use the local MWA model. Defaults to True. The local MWA model takes za/az instead of RA/Dec.
- 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, ms_path: str, coeff_path: str, ras: ndarray, decs: ndarray, ra0: float, dec0: float, j2000_latitudes: ndarray, j2000_lsts: ndarray, current_latitude: float, current_longitude: float, times: ndarray, freqs: ndarray, station_ids: ndarray, use_differential_beam: bool = True, apply_beam_norms: bool = True, reorder_jones: bool = False, element_only: bool = False, eb_rotate: bool = False, parallactic_rotate: bool = True, para_angle_offset: float = 0, element_response_model='hamaker', use_local_mwa: bool = True) 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 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.
ms_path (str) – Path to the measurement set to load the EveryBeam telescope from.
ras (np.ndarray) – Right ascensions of the coordinates in radians.
decs (np.ndarray) – Declinations of the coordinates in radians.
beam_ra0 (float) – Right ascension of the beam center in radians.
beam_dec0 (float) – Declination of the beam center in radians.
j2000_latitudes (np.ndarray) – Latitudes in J2000 coordinates.
j2000_lsts (np.ndarray) – Local sidereal times in J2000 coordinates.
current_latitude (float) – Current latitude in radians.
current_longitude (float) – Current longitude in radians.
times (np.ndarray) – Array of observation times.
freqs (np.ndarray) – Array of frequencies.
station_ids (np.ndarray) – Array of station IDs.
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.
reorder_jones (bool, optional) – Whether to reorder the Jones matrices. Defaults to False. Just rearranges the Jones matrix from [[0,0, 0,1,], [1,0, 1,1]] to [[1,1, 1,0,], [0,1, 0,0]].
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.
eb_rotate (bool, optional) – Whether to apply parallactic rotation using EveryBeam. Defaults to False. Should probably be used for everything apart from MWA beams.
parallactic_rotate (bool, optional) – Whether to apply parallactic angle rotation using wodenpy. Defaults to False. Should be True for MWA beams if you want rotation. If True for a non-MWA beam, wodenpy should match the output as if eb_rotate was True.
para_angle_offset (float, optional) – Offset to add to the parallactic angle. Defaults to 0.
element_response_model (str, optional) – The Everybeam element response model to use. Defaults to ‘hamaker’. Avaible options are ‘hamaker’ (LOFAR), ‘skala40_wave’ (OSKAR), and ‘MWA’ (MWA).
use_local_mwa (bool, optional) – Whether to use the local MWA model. Defaults to True. The local MWA model takes za/az instead of RA/Dec.
- 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]