VCSBeam
Macros | Functions | Variables
primary_beam.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <mwalib.h>
#include <mwa_hyperbeam.h>
#include "vcsbeam.h"
#include "gpu_macros.h"
Include dependency graph for primary_beam.c:

Macros

#define NCOMPLEXELEMENTS   4
 

Functions

void handle_hyperbeam_error (char file[], int line_num, const char function_name[])
 Calculates the beam model Jones matrices for the given pointings. More...
 
void vmCalcB (vcsbeam_context *vm, beam_geom *beam_geom_vals)
 
void vmCreatePrimaryBeam (vcsbeam_context *vm)
 Allocates memory for the beam model Jones matrices. More...
 
void free_primary_beam (primary_beam *pb)
 Frees the memory allocated in vmCreatePrimaryBeam() More...
 
void create_delays_amps_from_metafits (MetafitsMetadata *obs_metadata, uint32_t ***delays, double ***amps)
 Constructs "delay" and "amp" arrays required by Hyperbeam. More...
 
void free_delays_amps (MetafitsMetadata *obs_metadata, uint32_t **delays, double **amps)
 Frees the memory allocated in create_delays_amps_from_metafits(). More...
 
int hash_dipole_config (double *amps)
 Implements a hash lookup for dead/live dipole configurations. More...
 
void parallactic_angle_correction (double *Ppa, double lat, double az, double za)
 Calculates the parallactic angle correction matrix, \({\bf P}_\text{pa}\). More...
 
void calc_normalised_beam_response (FEEBeam *beam, double az, double za, double freq_hz, uint32_t *delays, double *amps, double *IQUV, gpuDoubleComplex *J, bool apply_pa_correction)
 Calculates the normalised primary beam response to a Stokes I, Q, U, or V sky. More...
 

Variables

const double Isky [] = { 0.5, 0. , 0. , 0. , 0. , 0. , 0.5, 0. }
 The coherency matrix for a pure Stokes I sky. More...
 
const double Qsky [] = { 0.5, 0. , 0. , 0. , 0. , 0. , -0.5, 0. }
 The coherency matrix for a pure Stokes Q sky. More...
 
const double Usky [] = { 0. , 0. , 0.5, 0. , 0.5, 0. , 0. , 0. }
 The coherency matrix for a pure Stokes U sky. More...
 
const double Vsky [] = { 0. , 0. , 0. , -0.5, 0 , 0.5, 0. , 0. }
 The coherency matrix for a pure Stokes V sky. More...
 
const double * sky [] = { Isky, Qsky, Usky, Vsky }
 The set of coherency matrices for pure Stokes I, Q, U, and V skies. More...
 

Macro Definition Documentation

◆ NCOMPLEXELEMENTS

#define NCOMPLEXELEMENTS   4

Function Documentation

◆ calc_normalised_beam_response()

void calc_normalised_beam_response ( FEEBeam *  beam,
double  az,
double  za,
double  freq_hz,
uint32_t *  delays,
double *  amps,
double *  IQUV,
gpuDoubleComplex *  J,
bool  apply_pa_correction 
)

Calculates the normalised primary beam response to a Stokes I, Q, U, or V sky.

Parameters
beamA Hyperbeam object
[in]azThe azimuth (radians)
[in]zaThe zenith angle (radians)
[in]freq_hzThe frequency (Hz)
[in]delaysThe dipole delays that define a primary beam pointing
[in]ampsThe dipole amplitudes that define the live/dead configuration
[out]IQUVThe beam response
[out]JA pointer to the beam model Jones matrix
apply_pa_correctionWhether to apply the parallactic angle correction to J

IQUV must point to already-allocated memory with size \(N_s\).

This function will allocate memory for J, which must be freed by the caller.

◆ create_delays_amps_from_metafits()

void create_delays_amps_from_metafits ( MetafitsMetadata *  obs_metadata,
uint32_t ***  delays,
double ***  amps 
)

Constructs "delay" and "amp" arrays required by Hyperbeam.

Parameters
[in]obs_metadataA MetafitsMetadata object containing the delays and amps.
[out]delaysA pointer to an array of delay values, with layout \(N_i \times N_d\)
[out]ampsA pointer to an array of amp values, with layout \(N_i \times N_d\)

Delays can be brought directly across from the MetafitsMetadata struct. The "conversion" from delays to amps is straightforward: All amps are "1.0" unless the delay is 32, in which case the amp should be "0.0". (The value 32 is the number assigned to a faulty or broken dipole.)

This function allocates memory for both delays and amps. This can be freed by a call to free_delays_amps().

◆ free_delays_amps()

void free_delays_amps ( MetafitsMetadata *  obs_metadata,
uint32_t **  delays,
double **  amps 
)

Frees the memory allocated in create_delays_amps_from_metafits().

Parameters
obs_metadataA MetafitsMetadata object
delaysThe array of delay values to be freed
ampsThe array of amp values to be freed

Here, the MetafitsMetadata is used to find \(N_i\) (one of the dimensions of delays and amps).

◆ free_primary_beam()

void free_primary_beam ( primary_beam *  pb)

Frees the memory allocated in vmCreatePrimaryBeam()

Todo:
Change name to vm...

◆ handle_hyperbeam_error()

void handle_hyperbeam_error ( char  file[],
int  line_num,
const char  function_name[] 
)

Calculates the beam model Jones matrices for the given pointings.

Parameters
vmThe VCSBeam context struct
beam_geom_valsAn array of beam_geom objects containing the pointing information

This function uses Hyperbeam to calculate the beam model Jones matrices for each pointing in beam_geom_vals.

Only those configurations of live (i.e. non-dead) dipoles which exist in the array are calculated, in order to save calculation time.

The parallactic angle correction is applied, so that the final matrices, which are stored in pb→B, are in the basis

\[ {\bf B} = \begin{bmatrix} B_{qx} & B_{qy} \\ B_{px} & B_{py} \end{bmatrix}. \]

◆ hash_dipole_config()

int hash_dipole_config ( double *  amps)

Implements a hash lookup for dead/live dipole configurations.

Parameters
ampsThe array of amps whose configuration is to be hashed
Returns
The hashed index for this configuration

In order to avoid recalculating the FEE beam for repeated dipole configurations, we have to keep track of which configurations have already been calculated. We do this through a boolean array, and this function converts dipole configurations into indices of this array. In other words, this function assigns meaning to the array.

Since dead dipoles are relatively rare, we only consider configurations in which up to two dipoles are dead. Any more than that and the we can recalculate the Jones matrix with minimal entropy. In this case, this function returns MANY_DEAD_DIPOLES. The other remaining cases are:

  • 0 dead dipoles = 1 configuration
  • 1 dead dipole = 16 configurations
  • 2 dead dipoles = 120 configurations
  • 16 dead dipoles = 1 configuration

for a grand total of 138 indices. They are ordered as follows:

idx configuration (0=dead, 1=live)
0 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
1 [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
2 [1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
3 [1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
...
16 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]
17 [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
18 [0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
19 [0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
...
31 [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]
32 [1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
33 [1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
...
135 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0]
136 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0]
137 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

This function defines "dead" as amps=0.0, "live" otherwise.

◆ parallactic_angle_correction()

void parallactic_angle_correction ( double *  Ppa,
double  lat,
double  az,
double  za 
)

Calculates the parallactic angle correction matrix, \({\bf P}_\text{pa}\).

Parameters
[out]PpaThe output rotation matrix
[in]latThe observing latitude (radians)
[in]azThe azimuth angle (radians)
[in]zaThe zenith angle (radians)

This function computes the parallactic angle correction matrix in the basis (see Parallactic angle correction):

\[ {\bf P}_\text{pa} = \begin{bmatrix} P_{\theta x} & P_{\theta y} \\ P_{\phi x} & P_{\phi y} \end{bmatrix}. \]

◆ vmCalcB()

void vmCalcB ( vcsbeam_context *  vm,
beam_geom *  beam_geom_vals 
)

◆ vmCreatePrimaryBeam()

void vmCreatePrimaryBeam ( vcsbeam_context *  vm)

Allocates memory for the beam model Jones matrices.

The resulting array (vm→B) has dimensions \(N_b \times N_a \times N_p \times N_p\).

Variable Documentation

◆ Isky

const double Isky[] = { 0.5, 0. , 0. , 0. , 0. , 0. , 0.5, 0. }

The coherency matrix for a pure Stokes I sky.

◆ Qsky

const double Qsky[] = { 0.5, 0. , 0. , 0. , 0. , 0. , -0.5, 0. }

The coherency matrix for a pure Stokes Q sky.

◆ sky

const double* sky[] = { Isky, Qsky, Usky, Vsky }

The set of coherency matrices for pure Stokes I, Q, U, and V skies.

◆ Usky

const double Usky[] = { 0. , 0. , 0.5, 0. , 0.5, 0. , 0. , 0. }

The coherency matrix for a pure Stokes U sky.

◆ Vsky

const double Vsky[] = { 0. , 0. , 0. , -0.5, 0 , 0.5, 0. , 0. }

The coherency matrix for a pure Stokes V sky.