filtools package¶
-
class
filtools.
FilterbankIO
[source]¶ Bases:
object
This class deals with reading from and writing to sigproc filterbank files.
To read a filterbank file, first set up a new
FilterbankIO
object, and use theread_header()
method to read the header parameters. The FilterbankIO object is then ready to be used for reading. To read the file, we use theread_block()
method to read samples from the file.Example:
inputfile = filtools.FilterbankIO() inputfile.read_header("example.fil") data = inputfile.read_block(1024) # Reads 1024 samples from the file
Note
- Currently
FilterbankIO
supports sigproc data files with the following properties: - Single IF (i.e. single polarisation)
- Fixed channel bandwidth (i.e. each channel has same bandwidth/offset)
- And, data type is one of:
- 1-bit unsigned integer
- 2-bit unsigned integer
- 4-bit unsigned integer
- 8-bit unsigned integer
- 16-bit unsigned integer
- 32-bit floating point
-
header
¶ The header dict can be used to provide direct access to the sigproc header parameters. Parameters changed here before calling
write_header()
can change the ouput header parameters. However, it is usually best to access information about the data using the other methods provided below, as the structure can be re-used for other data types.
-
clone_header
()[source]¶ Create a new
FilterbankIO
object with the header parameters copied from this objectReturns: A new FilterbankIO
object
-
close
()[source]¶ Close the input file, reset the read/write state of the
FilterbankIO
object
-
current_position
()[source]¶ Print the current position of the file pointer in samples.
The next call to
read_block()
orwrite_block()
will read or write from this sample.
-
get_writer
()[source]¶ Returns an optimised write function. Used by
write_block()
.
-
read_block
(nsamples, dtype=<class 'numpy.float32'>)[source]¶ Read a block of data.
This will read up to
nsamples
from the file, returning a 2-d array indexed first by sample and then by channel. i.e. the shape of the returned array will be (nsamples_read,nchannels).If the file has reached the end of file, then less than nsamples will be read, and if past the end of the file, an array of size (0,nchannels) will be returned.
Note
On first call this method is dynamically replaced using
get_reader()
to define an optimised verison of the reader method. This should be invisiable to most users.Parameters: - nsamples – The number of samples to read.
- dtype – A numpy compatible data type. Data will be converted to this type using the astype numpy method, and should be at least large enough to hold the read data types.
Returns: A 2-d numpy array of requested type.
-
read_header
(filename)[source]¶ Read header from sigproc filterbank file
Parameters: filename (str) – filename to read Returns: Number of bytes read (i.e. size of header) This method will also put the
FilterbankIO
object in a state for reading the file, i.e. enabling theread_block()
method.Header parameters can be accessed by the methods of the
FilterbankIO
object, or by direct interface with the sigproc API using theheader
dict member.
-
seconds_since
(sample, mjdref)[source]¶ Get the number of seconds since
mjdref
at sample numbersample
.Parameters: - sample – Integer sample number
- refmjd – Reference mjd
Returns: seconds since
mjdref
at samplesample
-
seconds_since_start
(sample)[source]¶ Get the number of seconds since start of observation at sample number
sample
.
-
seek_to_sample
(sample)[source]¶ Position the file pointer at given sample number (index from zero).
The next call to
read_block()
orwrite_block()
will start at the given sample. E.g.fil.seek_to_sample(100) block = fil.read_block(128) # block[0] is sample number 100
-
write_block
(block)[source]¶ Write a block of data to a file opened for writing.
The data block should be a numpy array in the same format as would be obtained from
read_block()
. The data will be truncated and cast to the required type to write to the file using the ndarray.astype method from numpy.The block should have shape (nsamples,nchannels), where nsamples is the number of samples to write.
Parameters: block – A 2-d numpy array to write. Note
On first call this this method is dynamically replaced using
get_writer()
to define an optimised verison of the writer method. This should be invisiable to most users.
-
write_header
(filename)[source]¶ Write the current state to a new sigproc filterbank file
Parameters: filename – filename to write Returns: Number of bytes written (i.e. size of header) This method will also put the
FilterbankIO
object in a state for writing data to the file, i.e. enabling thewrite_block()
method.
- Currently
-
class
filtools.
FluxScale
(scale=1, offset=0)¶ Bases:
object
Helps scaling flux density data to the data format.
This is used either by directly specifying a scale and offset to apply, or by setting a gain and Tsys value, or by specifying physical telescope parameters to define the gain and Tsys.
-
init
(tsamp, bw, npol_avg=2)[source]¶ Call this once you have set the gain and tsys to set up the scaling.
Parameters: - tsamp – sample time in seconds.
- bw – channel bandwidth in MHz.
- npol_avg – Number of polarisations that have been averaged already (1 or 2).
-
set_gain_from_file
(file)[source]¶ Read a yaml file with a telescope definition. Properties are: tsys, n_antenna, diameter, efficiency and/or gain.
-
-
class
filtools.
SimpleIntegerise
(thresh=1e-08)¶ Bases:
object
Converts floats to integers assuming previously digitised data had a uniform underlying distribution.
Parameters: thresh – Ignore values below this to improve performance (default 1e-8).
Subpackages¶
Submodules¶
filtools.sigproc module¶
-
class
filtools.sigproc.
FilterbankIO
[source]¶ Bases:
object
This class deals with reading from and writing to sigproc filterbank files.
To read a filterbank file, first set up a new
FilterbankIO
object, and use theread_header()
method to read the header parameters. The FilterbankIO object is then ready to be used for reading. To read the file, we use theread_block()
method to read samples from the file.Example:
inputfile = filtools.FilterbankIO() inputfile.read_header("example.fil") data = inputfile.read_block(1024) # Reads 1024 samples from the file
Note
- Currently
FilterbankIO
supports sigproc data files with the following properties: - Single IF (i.e. single polarisation)
- Fixed channel bandwidth (i.e. each channel has same bandwidth/offset)
- And, data type is one of:
- 1-bit unsigned integer
- 2-bit unsigned integer
- 4-bit unsigned integer
- 8-bit unsigned integer
- 16-bit unsigned integer
- 32-bit floating point
-
header
¶ The header dict can be used to provide direct access to the sigproc header parameters. Parameters changed here before calling
write_header()
can change the ouput header parameters. However, it is usually best to access information about the data using the other methods provided below, as the structure can be re-used for other data types.
-
clone_header
()[source]¶ Create a new
FilterbankIO
object with the header parameters copied from this objectReturns: A new FilterbankIO
object
-
close
()[source]¶ Close the input file, reset the read/write state of the
FilterbankIO
object
-
current_position
()[source]¶ Print the current position of the file pointer in samples.
The next call to
read_block()
orwrite_block()
will read or write from this sample.
-
get_writer
()[source]¶ Returns an optimised write function. Used by
write_block()
.
-
read_block
(nsamples, dtype=<class 'numpy.float32'>)[source]¶ Read a block of data.
This will read up to
nsamples
from the file, returning a 2-d array indexed first by sample and then by channel. i.e. the shape of the returned array will be (nsamples_read,nchannels).If the file has reached the end of file, then less than nsamples will be read, and if past the end of the file, an array of size (0,nchannels) will be returned.
Note
On first call this method is dynamically replaced using
get_reader()
to define an optimised verison of the reader method. This should be invisiable to most users.Parameters: - nsamples – The number of samples to read.
- dtype – A numpy compatible data type. Data will be converted to this type using the astype numpy method, and should be at least large enough to hold the read data types.
Returns: A 2-d numpy array of requested type.
-
read_header
(filename)[source]¶ Read header from sigproc filterbank file
Parameters: filename (str) – filename to read Returns: Number of bytes read (i.e. size of header) This method will also put the
FilterbankIO
object in a state for reading the file, i.e. enabling theread_block()
method.Header parameters can be accessed by the methods of the
FilterbankIO
object, or by direct interface with the sigproc API using theheader
dict member.
-
seconds_since
(sample, mjdref)[source]¶ Get the number of seconds since
mjdref
at sample numbersample
.Parameters: - sample – Integer sample number
- refmjd – Reference mjd
Returns: seconds since
mjdref
at samplesample
-
seconds_since_start
(sample)[source]¶ Get the number of seconds since start of observation at sample number
sample
.
-
seek_to_sample
(sample)[source]¶ Position the file pointer at given sample number (index from zero).
The next call to
read_block()
orwrite_block()
will start at the given sample. E.g.fil.seek_to_sample(100) block = fil.read_block(128) # block[0] is sample number 100
-
write_block
(block)[source]¶ Write a block of data to a file opened for writing.
The data block should be a numpy array in the same format as would be obtained from
read_block()
. The data will be truncated and cast to the required type to write to the file using the ndarray.astype method from numpy.The block should have shape (nsamples,nchannels), where nsamples is the number of samples to write.
Parameters: block – A 2-d numpy array to write. Note
On first call this this method is dynamically replaced using
get_writer()
to define an optimised verison of the writer method. This should be invisiable to most users.
-
write_header
(filename)[source]¶ Write the current state to a new sigproc filterbank file
Parameters: filename – filename to write Returns: Number of bytes written (i.e. size of header) This method will also put the
FilterbankIO
object in a state for writing data to the file, i.e. enabling thewrite_block()
method.
- Currently