Here, I will give a very brief tutorial on usingSigPyProcinteractively in the IPython5 shell. The examples below use SigPyProc0.1.2, Python 2.7.3 and IPython 0.12.1.
4http://numpy.scipy.org/,http://matplotlib.org/
5http://ipython.org/
SigPyProc 135 A.2.1 Opening a filterbank file
Below, I give and example of how to load a filterbank file intoSigPyProc.
In [1]: from SigPyProc.Readers import load
In [2]: myFil = load("tutorial.fil")
Initially we must import a method or function which allows us to access a filterbank file. In this case I use the load function, which is a convenience function for loading all data types with standard file extensions (i.e. .dat, .tim, .fil, .fft, etc.). Next we create an object representing our filterbank file. In the above example, I have named this ‘myFil’. This object currently contains all observational metadata, stored in the form of attributes. For example:
In [4]: myFil.nsamples Out[4]: 187520
In [5]: myFil.nchans Out[5]: 64
We may also obtain a brief summary of the file by typing the name of the object:
In [22]: myFil Out[22]:
<class ‘SigPyProc.BaseData.BaseData’>
basename : tutorial
data_type : Filterbank file
fch1 (MHz) : 1510.0
filelen : 3000564
filename : tutorial.fil
foff (MHz) : -1.09
hdrlen : 244
machine_id : FAKE
nbits : 2
nbytes : 3000320
nchans : 64
nifs : 1
nsamples : 187520
source_name : P250_DM30
SigPyProc 136
telescope_id : Fake
tsamp (s) : 0.00032
tstart (MJD) : 50000.0
TheSigPyProc.BaseData.BaseDataclass (of which ‘myFil’ is an instance), contains several methods for the manipulation of the filterbank file. For example;
• dedisperse
De-disperse the observation to a given DM.
• downsample
Downsample the filterbank file in time and/or frequency.
• fold
Phase-fold the filterbank file at a given period, DM and acceleration.
• getChan
Select a single frequency channel from the filterbank file.
• readBlock
Return a section of the observation as a 2-D array.
Below, we will take a closer look at the output of the dedispersemethod.
A.2.2 De-dispersing a filterbank file
The first thing we will want to do before de-dispersing our file, is to set the number of threads available to OpenMP. To do this we use thesetNthreads method. Although this step is not required, it will significantly improve the speed of the de-dispersion.
In [5]: myFil.setNthreads(2)
All methods available to ‘myFil’ that use OpenMP, will now have access to two CPU threads. Having set the number of threads, we can now go ahead and de-disperse our file. Here the only argument the dedispersemethod requires, is the DM that we wish to de-disperse to.
In [6]: myTim = myFil.dedisperse(100)
Filterbank reading plan:
SigPyProc 137
---Called on file: tutorial.fil
Called by: dedisperse
Number of samps: 187520 Number of reads: 18 Nsamps per read: 10000 Nsamps of final read: 8510 Nsamps to skip back: 55
Execution time: 0.040064 seconds
Thededispersemethod returns an instance of theSigPyProc.BaseTimeSeries.BaseTimeSeries class, which I have named ‘myTim’. Just as with the ‘myFil’ object, we may obtain a
summary of ‘myTim’ by simply typing its name.
In [7]: myTim Out[7]:
<class ‘SigPyProc.BaseTimeSeries.BaseTimeSeries’>
basename : tutorial
data_type : Timeseries file
fch1 (MHz) : 1510.0
filelen : 3000564
filename : tutorial.fil
foff (MHz) : -1.09
hdrlen : 244
machine_id : FAKE
nbits : 32
nbytes : 3000320
nchans : 1
nifs : 1
nsamples : 187465
refdm (pccm^-3) : 100
source_name : P: 250.000000000000 ms, DM: 30.000 telescope_id : Fake
tsamp (s) : 0.00032
tstart (MJD) : 50000.0
We can access the raw data contained within ‘myTim’ in two ways. First, we can use the Ndarray attribute, to grant access to the data in the form of a standardNumpy array:
SigPyProc 138
In [8]: myTim.Ndarray
Out[8]: array([ 107., 109., 105., ..., 105., 109., 103.], dtype=float32)
In [9]: myTim.Ndarray[0]
Out[9]: 107.0
Second, we can access the data as aCtypesarray. which may be passed as aCfunction argument:
In [10]: myTim.Cbuffer
Out[10]: <SigPyProc.Utils.c_float_Array_187465 at 0x457a560>
In [11]: myTim.Cbuffer[0]
Out[11]: 107.0
The ‘myTim’ object contains several methods for manipulation of the time series, in-cluding;
• applyBoxcar
Smooth the time series with a boxcar filter.
• downsample
Downsample the time series.
• runningMean
Compute the running mean of the time series.
• runningMedian
Compute the running median of the time series (with a fast algorithm).
• rFFT
Take the 1-D, real-to-complex DFT of the time series (using FFTW, see Section 2.2.4.2).
Below we will take a closer look at the output of therFFT method.
A.2.3 Performing a discrete Fourier transform Taking the DFT of ‘myTim’ is as simple as:
In [12]: mySpec = myTim.rFFT()
SigPyProc 139 Here, ‘mySpec’ is an instance of the SigPyProc.BaseSpectrum.BaseSpectrum class, and contains both the complex DFT output and the formed power spectrum (shown here as Numpyarrays, but also accessible as Ctypesarrays).
In [13]: mySpec.fftBuffer.Ndarray #FFTW output Out[13]:
array([ 1.96329040e+07, 0.00000000e+00, -2.93994995e+02, ...,
-2.38658051e+02, 2.78900000e+03, 0.00000000e+00], dtype=float32)
In [14]: mySpec.Ndarray #Power spectrum Out[14]:
array([ 0. , 0. , 0. , ..., 2272.41503906,
2514.97167969, 3218.59545898], dtype=float32)
In this case, the power spectrum has undergone both Fourier interpolation (see Section 2.2.4.3) and brute-force suppression of the lowest frequencies (see Section 2.2.4.4).
Several methods are provided for the manipulation of the power spectrum, including:
• rednoise
Remove an interpolated rednoise curve from the spectrum (see Section 2.2.4.4).
• sumHarms
Perform N harmonic sums of the spectrum (see Section 2.2.4.5).
• findCands
Identify significant signals in the spectrum.
• zapbirds
Remove power from a list of ‘bad’ frequencies.
• iFFT
Compute the 1-D, complex-to-real DFT of the spectrum (using FFTW, see Section 2.2.4.2).
A.2.4 Putting it together
Taking everything mentioned above, we can envisage an extremely minimal pulsar searching pipeline:
In [1]: myFil = FilReader("tutorial.fil")
SigPyProc 140 In [2]: myCands = F.dedisperse(1000).seek()
In [3]: myFold = myFil.foldCand(myCands.cands[0])
In [4]: myFold.optimise()
In [5]: myFold.freeze()
In the above example, I first open the filterbank file by directly using the FilReader method. Next, I de-disperse the data to a DM of 1000 pc cm−3 and use the seek method. This a convenience method for performing a DFT, whitening the resulting spectrum and searching it for significant signals. I then fold the top candidate in the data using thefoldCand method of the ‘myFil’ instance. Finally, I optimise the fold (performing a series of small searches in DM and P space), before saving it in a native format using thefreeze method of the ‘myFold’ instance.