Previous topic

pycrtools.tasks.averagespectrum

Next topic

pycrtools.tasks.calibratefm

This Page

pycrtools.tasks.beamformer2

BeamFormer2([ws, parfile]) The function will calculate multiple beams for a list of files and a series of antennas (all integrated into one compex spectrum per beam).
fmin(func, x0[, args, xtol, ftol, maxiter, ...]) Minimize a function using the downhill simplex algorithm.
getfile(ws) To produce an error message in case the file does not exist

Calculate complex beams towards multiple directions. Also calculates the average spectrum in each beam and for an incoherent beam.

Module author: Heino Falcke <h.falcke@astro.ru.nl>

Example:

self=Task
self.beams[...,0].nyquistswap(self.NyquistZone)
fxb=cr.hArray(float,[2,self.blocklen],name="TIMESERIES_DATA"); fxb[...].saveinvfftw(self.beams[...,0],1);  fxb.abs()
fxb[...].plot(clf=True); cr.plt.show()
class pycrtools.tasks.beamformer2.BeamFormer2(ws=None, parfile=None, **kwargs)

The function will calculate multiple beams for a list of files and a series of antennas (all integrated into one compex spectrum per beam). Also incoherent beams can be calculated and the sifted time series of each antenna can be retrieved.

This beamformer will read all selected antennas at once into memory and hence is optimized for short datasets with many antennas (e.g. cosmic ray event ).

It can also be called without a datafile and just hArrays as input. In this case provide the following information:

Task(data=timeseries_data, antennas=file["SELECTED_DIPOLES"], antpos=file["ANTENNA_POSITIONS"], sample_interval=file["SAMPLE_INTERVAL"][0], pointings=[dict(az=143.4092*deg,el= 81.7932*deg, r=600.3)])

If the FFT of the time series data is already available, it can be provided with the parameter fft_data (in addition to the time series that - at this moment - is still required). You then have to also set dofft=False to avoid the FFT being recalculated.

The desired frequency resolution is provided with the parameter delta_nu, but by default this will be rounded off to the nearest value using channel numbers of a power of 2. This will then set the block size for reading in the data.

Results The resulting beam is stored in the array Task.beam and written to disk as an hArray with parameters stored in the header dict (use getHeader('BeamFormer2') to retrieve this.)

The incoherent and beamed average spectra are stored in Task.avspec_incoherent and Task.avspec respectively. They are also available as attributes to Task.bf.par (also when stored to disk).

The incoherent beam is found in Task.tbeam_incoherent.

The beam can be FFTed back to time using Task.tcalc and viewed with Task.tplot.

Input parameters

FarField [default value: True ]
Form a beam towards the far field, i.e. no distance.
NyquistZone [default value: 1 ]
In which Nyquist zone was the data taken (e.g. NyquistZone=2 if data is from 100-200 MHz for 200 MHz sampling rate).
antennas
Antennas from which to select initially for the current file.
antpos
Cartesian coordinates of the current antenna relative to the phase center of the array.
avspec
Average spectrum in each beam over multiple blocks.
avspec_incoherent
The average spectrum of all blocks in an incoherent beam (i.e. squaring before adding).
beams
Output array containing the FFTed data for each beam.
block_duration
The length of a block in time units.
blockduration
Length in time units of one block of data, i.e. on time step in dynamic spectrum.
blocklen
The size of a block used for the FFT, limited by filesize.
blocksize
Length of the data for each antenna
cable_delays
An hArray containing ‘cable’ delays for each selected antenna in seconds as values. These delays will be added to the geometrical delays.
calc_tbeams [default value: True ]
Calculate the inverse FFT of all beams and return the shifted and beamformed time series for each beam in Task.tbeams
calc_timeseries [default value: False ]
If True also do the inverse FFT of all antennas and return the shifted time series for each antenna in data_shifted.
data
Main input array of raw data - can be set directly instead of providing a data file.
data_shifted
Array for plotting the shifted e-field of main beam
datafile
Data file object pointing to raw data.
delays
Contains the geometric delays for the current antenna for each beam
delta_frequency
Separation of two subsequent channels in final spectrum
delta_nu [default value: 1 ]
Desired frequency resolution - will be rounded off to get powers of 2 blocklen. Alternatively set blocklen directly.
delta_nu_used
Actual frequency resolution of dynamic spectrum
doabs [default value: True ]
Take the absolute of the tbeam.
dofft [default value: True ]
If False do not take the fft of the timeseries data. In this case it is assumed that the user has provided the array fft_data, which already contains the fft
doplot [default value: False ]
Plot current spectrum while processing.
dosquare [default value: False ]
Take the square (power) of the tbeam.
end_frequency
End frequency of spectrum
end_time
End of time axis.
fftdata
main input array of raw data
fftplan
Memory and plan for FFT
file_start_number [default value: 0 ]
Integer number pointing to the first file in the ‘filenames’ list with which to start. Can be changed to restart a calculation.
filefilter [default value: “$LOFARSOFT/data/lofar/RS307C-readfullsecondtbb1.h5” ]
Unix style filter (i.e., with *,~, $VARIABLE, etc.), to describe all the files to be processed.
filenames
List of filenames of data file to read raw data from.
filesize
Length of file for one antenna.
frequencies
Frequency axis for final power spectrum.
header
Header of datafile
invfftplan
Memory and plan for inverse FFT
mainbeam
The main beam which is used to plot things. Default= nbeams/2.
max_nblocks
Maximum number of blocks in file.
maxblocksflagged [default value: 2 ]
Maximum number of blocks that are allowed to be flagged before the entire spectrum of the chunk is discarded.
maxnantennas [default value: 96 ]
Maximum number of antennas per file to sum over (also used to allocate some vector sizes).
nantennas
The actual number of antennas available for calculation in the file (<maxnantennas).
nantennas_start [default value: 0 ]
Start with the nth antenna in each file (see also natennas_stride). Can be used for selecting odd/even antennas.
nantennas_stride [default value: 1 ]
Take only every nth antenna from antennas list (see also natennas_start). Use 2 to select odd/even.
nbeams
Number of beams to calculate.
nblocks
Number of blocks to read in.
newfigure [default value: True ]
Create a new figure for plotting for each new instance of the task.
output_dir [default value: “” ]
Directory where output file is to be written to.
output_filename
Filename (without directory, see output_dir) to store the final spectrum.
phase_center [default value: [0, 0, 0] ]
List or vector containing the X,Y,Z positions of the phase center of the array.
phase_center_array
List or vector containing the X,Y,Z positions of the phase center of the array.
phases
Complex phases for each beam and each freqeuncy channel used to calculate complex weights for beamforming.
plot_antennas
A list of antenna indices (from 0 to nantennas, i.e. relative to the selected antennas and not necessarily the same indices as in the file!) for which to plot the time series (if doplot>1).
plot_center [default value: 0.5 ]
Center plot at this relative distance from start of vector (0=left end, 1=right end).
plot_end
End plotting before this sample number.
plot_finish
Function to be called after each plot to determine whether to pause or not (see plotfinish())
plot_start
Start plotting from this sample number.
plotlen [default value: 4096 ]
How many channels +/- the center value to plot during the calculation (to allow progress checking).
plotskip [default value: 1 ]
Plot only every ‘plotskip’-th spectrum, skip the rest (should not be smaller than 1).
plotspec [default value: True ]
If True plot the beamformed average spectrum at the end, otherwise the time series.
pointings [default value: [{'el': 0.4886921905584123, 'az': 3.122394031817856}, {'el': 1.5707963267948966, 'r': 1, 'az': 0.0}] ]
List of coordinate dicts ({'az':az1,'el':elevation value}) containing pointing directions for each beam on the sky.
pointingsXYZ
Array of shape [nbeams,3] with x,y,z positions for each beam on the sky.
sample_interval
Length in time of one sample in raw data set.
smooth_width [default value: 0 ]
Do a Gaussian smoothing of the beamformed time-series data in Task.tbeam with this width.
speclen
Length of one spectrum.
spectrum_file
Complete filename including directory to store the final spectrum.
start_block [default value: 0 ]
Block number to start with. Will be used to to read the first block from file (if provided) and to calculate time.
start_frequency
Start frequency of spectrum
start_time
Start of time axis.
store_spectrum [default value: True ]
Store the final spectrum.
stride [default value: 1 ]
If stride>1 skip (stride-1) blocks.
tbeam_incoherent
Contains the power as a function of time of an incoherent beam (in the direction of the pointing) of all antennas (simply the square of the ADC values of the siffted time series data added).
times
Time axis for data.
tmpfileext [default value: ”.pcr” ]
Extension of filename for temporary data files (e.g., used if stride>1.)
tmpfilename [default value: “tmp” ]
Root filename for temporary data files.
verbose [default value: True ]
Print progress information.
weights
Complex weights for each beam and each freqeuncy channel used to calculate beams.

Output parameters

antenna_list [default value: {} ]
List of antenna indices used as input from each filename.
antennas_used
A set of antenna names that were actually included in the average spectrum, excluding the flagged ones.
figure [default value: None ]
The matplotlib figure containing the plot

nofAntennas

nspectraadded
Number of spectra added per block.
nspectraflagged
Number of spectra flagged per block.
dynplot(dynspec, plot_cleanspec=None, dmin=None, dmax=None, cmin=None, cmax=None)

Plot the dynamic spectrum. Provide the dynamic spectrum computed by the Task DynamicSpectrum as input.

Parameter Default Description
plot_cleanspec None If False, don’t plot the cleaned spectrum (provided as dynspec.par.cleanspec).
dmin None Minimum z-value (intensity) in dynamic spectrum to plot
dmax None Maximum z-value (intensity) in dynamic spectrum to plot
cmin None Minimum z-value (intensity) in clean dynamic spectrum to plot
cmax None Maximum z-value (intensity) in clean dynamic spectrum to plot

Example:

tload "DynamicSpectrum"
dsp=cr.hArrayRead("Saturn.h5.dynspec.pcr")
Task.dynplot(dsp,cmin=2.2*10**-5,cmax=0.002,dmin=6.8,dmax=10)
optimizeDirection(start_direction=None, smooth=7, verbose=False)

Use scipy’s fmin function (downhill-simplex minimizer) to obtain a maximum pulse power.

run()

Run the program.

smoothedPulsePowerMaximizer(direction, verbose=False)

Maximizer function to be called with scipy.fmin. Parameter ‘direction’ is a tuple (az, el) in radians. (but somehow, the fmin function passes an np.array([az, el]) instead...)

It calls self.run() again, with a new ‘self.pointings’ towards given direction.

tcalc(beams=None, block=0, NyquistZone=1, doabs=False, dosquare=False, smooth=0)

Calculate the time series after beamforming, i.e. take the result of the BeamForm task, i.e. an array of dimensions [self.nblocks,self.nbeams,self.speclen], do a NyquistSwap, if necessary, and then an inverse FFT.

Parameter Default Description
beams None Input array. Take self.beams from task, if None.
NyquistZone 1 NyquistZone=2,4,... means flip the data left to right before FFT.
doabs False Take the absolute of the timeseries, if True.
smooth 0 If > 0 smooth datat with a Gaussian kernel of that size.

The final time series (all blocks) is stored in Task.tbeams and returned.

tplot(beams=None, block=0, NyquistZone=1, doabs=True, dosquare=False, smooth=0, mosaic=True, plotspec=False, xlim=None, ylim=None, recalc=False)

Take the result of the BeamForm task, i.e. an array of dimensions [self.nblocks,self.nbeams,self.speclen], do a NyquistSwap, if necessary, and then calculate an inverse FFT. If the time series (self.tbeams) has already been caclulated it will only be recalculated if explicitly asked for with recalc=True.

Properties

Parameter Default Description
beams None Input array. Take self.beams from task, if None.
recalc False If true force a recalculation of the time series beam if it exists
block 0 Which block to plot, or Ellipsis (‘...’) for all
NyquistZone 1 NyquistZone=2,4,... means flip the data left to right before FFT.
doabs True Take the absolute of the timeseries before plotting.
smooth 0 If > 0 smooth data with a Gaussian kernel of that size.
plotspec False If True plot the average spectrum instead.
xlim None Tuple with minimum and maximum limits for the x-axis.
ylim None Tuple with minimum and maximum limits for the y-axis.

The final time series (all blocks) is stored in Task.tbeams.

pycrtools.tasks.beamformer2.getfile(ws)

To produce an error message in case the file does not exist