Fake Data
lsl.sim - Simulate various types of LWA data. The following follow DP
format writers are avaliable:
- In addition, there are two simulation modules to generate fake data sets::
- dp - generate DP-level data sets for basic signals and point source
- vis - generate visibility data sets for use with the aipy module
Writers
New in version 0.3.
TBW
Python module for creating creating, validating, and writing simulated
TBW frames to a file.
-
class lsl.sim.tbw.SimFrame(stand=None, frameCount=None, dataBits=12, obsTime=None, xy=None)
Bases: lsl.reader.tbw.Frame
tbw.SimFrame extends the lsl.reader.tbw.Frame object to yield a method
for easily creating DP ICD-compliant raw TBW frames. Frames created with
this method can be written to a file via the methods writeRawFrame() function.
-
createRawFrame()
- Re-express a simulated TBW frame as a numpy array of unsigned 8-bit
integers. Returns a numpy array if the frame is valid. If the frame
is not ICD-compliant, a errors.baseSimError-type error is raised.
-
isValid(raiseErrors=False)
- Check if simulated TBW frame is valid or not. Valid frames return
True and invalid frames False. If the ‘raiseErrors’ keyword is set,
isValid() raises an error when a problem with the frame structure is
encountered.
-
loadFrame(tbwFrame)
- Populate the a tbw.SimFrame object with a pre-made frame.
-
writeRawFrame(fh)
- Write a simulated TBW frame to a filehandle if the frame is valid.
If the frame is not ICD-compliant, a errors.baseSimError-type error is
raised.
-
lsl.sim.tbw.frame2frame(tbwFrame)
- Convert a lsl.reader.tbw.Frame object to a raw DP TBW frame.
TBN
Python module for creating creating, validating, and writing simulated
TBN frames to a file.
-
class lsl.sim.tbn.SimFrame(stand=None, pol=None, frameCount=None, obsTime=None, iq=None)
Bases: lsl.reader.tbn.Frame
tbn.SimFrame extends the lsl.reader.tbn.Frame object to yield a method
for easily creating DP ICD-compliant raw TBN frames. Frames created with
this method can be written to a file via the methods writeRawFrame() function.
-
createRawFrame()
- Re-express a simulated TBN frame as a numpy array of unsigned 8-bit
integers. Returns a numpy array if the frame is valid. If the frame
is not ICD-compliant, a errors.baseSimError-type error is raised.
-
isValid(raiseErrors=False)
- Check if simulated TBN frame is valid or not. Valid frames return
True and invalid frames False. If the ‘raiseErrors’ keyword is set,
isValid raises an error when a problem is encountered.
-
loadFrame(tbnFrame)
- Populate the a tbn.SimFrame object with a pre-made frame.
-
writeRawFrame(fh)
- Write a simulated TBN frame to a filehandle if the frame is valid.
If the frame is not ICD-compliant, a errors.baseSimError-type error
is raised.
-
lsl.sim.tbn.frame2frame(tbnFrame)
- Convert a lsl.reader.tbn.Frame object to a raw DP TBN frame.
DRX
Python module for creating creating, validating, and writing simulated
DRX frames to a file.
-
class lsl.sim.drx.SimFrame(beam=None, tune=None, pol=None, filterCode=None, timeOffset=None, frameCount=None, obsTime=None, flags=None, iq=None)
Bases: lsl.reader.drx.Frame
drx.SimFrame extends the lsl.reader.drx.Frame object to yield a method
for easily creating DP ICD-compliant raw DRX frames. Frames created with
this method can be written to a file via the methods writeRawFrame() function.
-
createRawFrame()
- Re-express a simulated DRX frame as a numpy array of unsigned 8-bit
integers. Returns a numpy array if the frame is valid. If the frame
is not ICD-compliant, a errors.baseSimError-type error is raised.
-
isValid(raiseErrors=False)
- Check if simulated DRX frame is valid or not. Valid frames return
True and invalid frames False. If the ‘raiseErrors’ keyword is set,
isValid raises an error when a problem is encountered.
-
loadFrame(drxFrame)
- Populate the a drx.SimFrame object with a pre-made frame.
-
writeRawFrame(fh)
- Write a simulated DRX frame to a filehandle if the frame is valid.
If the frame is not ICD-compliant, a errors.baseSimError-type error
is raised.
-
lsl.sim.drx.frame2frame(drxFrame)
- Convert a lsl.reader.drx.Frame object to a raw DP DRX frame.
Simulators
Digitial Processor Data
New in version 0.3.
Module to simulate observations made with the DP system.
-
lsl.sim.dp.basicSignal(fh, stands, nFrames, mode='DRX', filter=6, nTuning=2, bits=12, tStart=0, noiseStrength=0.10000000000000001, verbose=False)
Generate a collection of frames with a basic test signal for TBW, TBN,
and DRX. The signals for the three modes are:
- TBW
- noise + 40 MHz signal for x-pol.
- noise + 60 MHz signal for y-pol.
-> odd stands
- noise + 30 MHz signal for x-pol.
- noise + 50 MHz signal for ypol.
-> even stands
- TBN
- noise + (sampleRate/4) kHz signal for x-pol. and noise +
(-sampleRate/4) for y-pol.
- DRX
- noise + (sampleRate/4) kHz signal for x-pol. and noise +
(-sampleRate/4) for y-pol. -> tuning 1
- noise + (-sampleRate/3) kHz signal for x-pol. and noise +
(sampleRate/3) for y-pol. -> tuning 2
All modes need to have stands (beams in the case of DRX) and number of
frames to generate. TBW also needs to ‘bits’ keyword set to generate
either 12-bit or 4-bit data. The TBN and DRX frames need the ‘filter’
keyword set to specify the filter width. In addition, the ‘stands’
argument is interpreted as beam numbers for DRX.
Changed in version 0.4.4: Added the noiseStrength keyword to control how much noise is added to
the data.
-
lsl.sim.dp.pointSource(fh, stands, src, nFrames, mode='TBN', CentralFreq=49000000.0, filter=7, bits=12, tStart=0, phaseCenter='z', noiseStrength=0.10000000000000001, verbose=False)
Generate a collection of frames with a point source signal for TBW
and TBN. The point source is specified as a aipy.src object.
All modes need to have stands (beams in the case of DRX) and number of
frames to generate. TBW also needs to `bits’ keyword set to generate
either 12-bit or 4-bit data. The TBN frames need the `filter’ keyword
set to specify the filter width.
Changed in version 0.4.4: Added the noiseStrength keyword to control how much noise is added to
the data.
Visibility Data
Module for generating simulated arrays and visilibity data. The chief
functions of this module are:
- buildSimArray
- given a station object, a list of stands, and a list of frequencies, build
a AIPY AntennaArray-like object. This module can also generate AntennaArray
objects with positional errors by setting the ‘PosError’ keyword to a
positive value.
- buildSimData
- given a SimArray and a list of aipy.src sources, build up a collection of
visibilities for a given set of Julian dates
- scaleData
- given a dictionary of simulated visibilities from buildSimData, apply
antenna-based gains and delays to the visibilities
- shiftData
given a dictionary of simulated visibilities from buildSimData, shift the uvw
coordinates of the visibilities.
.. note:
This only changes the uvw values and does not phase-shift the data.
The format of the data dictionaries mentioned above is:
- primary keys
The primary keys store the major aspects of the visiblity data, e.g.,
frequency coverage, baseline pairs, uvw coordinates, etc. Valid keys are:
- freq - list of frequencies used in Hz
- isMasked - whether or not the visibility data have been masked
(numpy.compress’d)
- bls - list of baselines in (stand 1, stand2) format
- uvw - list of uvw coordinates as 3-element numpy arrays
- vis - list of visibility numpy arrays
- wgt - list of weight arrays with the same length as the visilitity arrays
- msk - list of mask arrays used for the data. 1 = masked, 0 = valid
- jd - list of Julian dates associated with each list element
- secondary keys
The bls, uvw, vis, wgt, msk, and jd primary keys also have secondary keys that
indicate which polarizations are being stored. Valid keys are:
In addition to simulation functions, this module includes buildGriddedImage
which takes a dictionary of visibilities and returns and aipy.im.ImgW object.
Changed in version 0.3.0: This module was formerly called lsl.sim.sim
-
class lsl.sim.vis.Antenna(x, y, z, beam, phsoff=[, 0.0, 0.0], bp_r=array([, 1], ), bp_i=array([, 0], ), amp=1, pointing=(0.0, 1.5707963267948966, 0), stand=0, **kwargs)
Modification to the aipy.amp.Antenna class to also store the stand ID
number in the Antenna.stand attribute. This also add a getBeamShape
attribute that pulls in the old vis.getBeamShape function.
-
get_beam_shape(pol='x')
- Return a 360 by 90 by nFreqs numpy array showning the beam pattern of a
particular antenna in the array. The first two dimensions of the output
array contain the azimuth (from 0 to 359 degrees in 1 degree steps) and
altitlude (from 0 to 89 degrees in 1 degree steps).
-
class lsl.sim.vis.AntennaArray(location, ants, **kwargs)
Modification to the aipy.ant.AntennaArray class to add a fuction to
retrieve the stands stored in the AntennaArray.ants attribute. Also add
a function to set the array time from a UNIX timestamp.
-
get_stands()
- Return a numpy array listing the stands found in the AntennaArray
object.
-
set_unixtime(timestamp)
- Set the array time using a UNIX timestamp (epoch 1970).
-
sim(i, j, pol='xx')
Simulate visibilites for the specified (i,j) baseline and
polarization. sim_cache() must be called at each time step before
this will return valid results.
This function differs from aipy.amp.AntennaArray.sim in the fast that
ionref and srcshape are both None in the call to gen_phs and that
resolve_src is set to False.
-
lsl.sim.vis.buildSimArray(station, antennas, freq, jd=None, PosError=0.0, ForceFlat=False, verbose=False)
Build a AIPY AntennaArray for simulation purposes. Inputs are a station
object defined from the lwa_common module, a numpy array of stand numbers,
and a numpy array of frequencies in either Hz of GHz. Optional inputs are
a Julian Date to set the array to and a positional error terms that perturbs
each of the stands in x, y, and z. The output of this module is an AIPY
AntennaArray object.
The shape of the antenna response is either flat (gain of 1 in all
directions) or modeled by a collection of spherical harmonics that are poly-
nomials in frequency. The spherical harmonics are used if the file
‘beam_shape.npz’ is found in the current directory.
Changed in version 0.4.0: Switched over to passing in Antenna instances generated by the
lsl.common.station module instead of a list of stand ID numbers.
-
lsl.sim.vis.buildSimData(aa, srcs, pols=[, 'xx', 'yy', 'xy', 'yx'], jd=None, phaseCenter='z', baselines=None, mask=None, verbose=False)
Given an AIPY AntennaArray object and a dictionary of sources from
aipy.src.get_catalog, returned a data dictionary of simulated data taken at
zenith. Optinally, the data can be masked using some referenced (observed)
data set or only a specific sub-set of baselines.
- ..versionchanged:: 0.4.0
- Added the ‘pols’ keyword to only compute certain polarization components
-
lsl.sim.vis.scaleData(dataDict, amps, delays)
Apply a set of antenna-based real gain values and phase delays in ns to a
data dictionary. Returned the new scaled and delayed dictionary.
- ..versionchanged:: 0.4.0
- The delays are now expected to be in nanoseconds rather than radians.
-
lsl.sim.vis.shiftData(dataDict, aa)
- Shift the uvw coordinates in one data dictionary to a new set of uvw
coordinates that correspond to a new AntennaArray object. This is useful
for looking at how positional errors in the array affect the data.
-
lsl.sim.vis.buildGriddedImage(dataDict, MapSize=30, MapRes=0.5, MapWRes=0.10000000000000001, pol='xx', chan=None)
- Given a data dictionary, build an aipy.img.ImgW object of gridded uv data
which can be used for imaging. The ImgW object itself is returned by this
function to make it more versatile.