pdat package

Submodules

pdat.cli module

pdat.pdat module

Main module.

class pdat.pdat.psrfits(psrfits_path, mode=u'rw', from_template=False, obs_mode=None, verbose=True)[source]

Bases: fitsio.fitslib.FITS

Class which inherits fitsio.FITS() (Python wrapper for cfitsio) class’s functionality, and add’s new functionality to easily manipulate and make PSRFITS files.

from_template : bool, str
Either a boolean which dictates if a copy would like to be made from a template, or a string which is the path to a user chosen template.
psrfits_path : str
Either the path to an existing PSRFITS file or the name for a new file.
obs_mode : Same as OBS_MODE in a standard PSRFITS, either SEARCH, PSR or
CAL for search mode, fold mode or calibration mode respectively.
mode : str, {‘r’, ‘rw, ‘READONLY’ or ‘READWRITE’}
Read/Write mode.
append_from_file(path, table=u'all')[source]

Method to append more subintegrations to a PSRFITS file from other PSRFITS files. Note: Tables are appended directly to the original file. Make a copy

before copying if you are unsure about appending. The array must match the columns (in the numpy.recarray sense) of the existing PSRFITS file.
path : str
Path to the new PSRFITS file to be appended.
table : list
List of BinTable HDU headers to append from file. Defaults to
appending all secondary BinTables. [‘HISTORY’,’PSRPARAM’,’POLYCO’,’SUBINT’]
close()[source]

Override of fitsio close method. Adds more variables to set to none. Close the fits file and set relevant metadata to None

copy_template_BinTable(ext_name, cols=u'all', dtypes=None)[source]
Method to copy PSRFITS binary tables exactly. This is
especially useful when using real PSRFITS files to make simulated data, i.e. if you would just like to replace the DATA arrays in the file with your simulated data, but keep the ancillary telescope information. This copies the BinTable as a numpy.recarray into the HDU_drafts dictionary.
ext_name : str, {‘PRIMARY’,’SUBINT’,’HISTORY’,’PSRPARAM’,’POLYCO’}
Binary Extension name to copy.
cols : str or list
Columns of the given BinTable to copy.
dtypes : list of tuples
Data types for numpy.recarray that will be the draft for the BinTable.
get_FITS_card_dict(hdr, name)[source]

Make a FITS card compatible dictionary from a template FITS header that matches the input name key in a standard FITS card/record. It is necessary to make a new FITS card/record to change values in the header. This function outputs a writeable dictionary which can then be used to change the value in the header using the hdr.add_record() method.

hdr : fitsio.fitslib.FITSHDR object
Template for the card.
name : str
The name key in the FITS record you wish to make.
get_HDU_dtypes(HDU)[source]

Returns a list of data types and array sizes needed to make a recarray. HDU = A FITS HDU.

get_colnames()[source]

Returns the names of all of the columns of data needed for a PSRFITS file.

make_FITS_card(hdr, name, new_value)[source]

Make a new FITS card/record using a FITS header as a template. This function makes a new card by finding the card/record in the template with the same name and replacing the value with new_value. Note: fitsio will set the dtype dependent on the form of the new_value for numbers.

hdr : fitsio.fitslib.FITSHDR
A fitsio.fitslib.FITSHDR object, which acts as the template.
name : str
A string that matches the name key in the FITS record you wish to make.
new_value : str, float
The new value you would like to replace.
make_HDU_rec_array(nrows, HDU_dtype_list)[source]

Makes a rec array with the set number of rows and data structure dictated by the dtype list.

replace_FITS_Record(hdr, name, new_value)[source]

Replace a Fits record with a new value in a fitsio.fitslib.FITSHDR object.

hdr : str or FITSHDR object
Header name.
name : FITS Record/Car
FITS Record/Card name to replace.
new_value : float, str
The new value of the parameter.
set_HDU_array_shape_and_dtype(HDU_dtype_list, name, new_array_shape=None, new_dtype=None)[source]

Takes a list of data types (output of get_HDU_dtypes()) and returns new list with the named element’s array shape and/or data type edited.

HDU_dtype_list :
dtype list for making recarray (output of get_HDU_dtypes()).
name : str
Name of parameter to edit.
new_array_shape : tuple
New array shape. Note 1-d arrays are of type (n,) in FITS files.
new_dtype :
New data type. See PSRFITS and fitsio documentation for recognized names.
set_draft_header(ext_name, hdr_dict)[source]

Set draft header entries for the new PSRFITS file from a dictionary.

psrfits_object : pdat.psrfits
Pulsar Data Toolbox PSRFITS object.
ext_name : str, {‘PRIMARY’,’SUBINT’,’HISTORY’,’PSRPARAM’,’POLYCO’}
Name of the header to replace the header entries.
hdr_dict : dict
Dictionary of header changes to be made to the template header. Template header entries are kept, unless replaced by this function.
set_hdr_from_draft(hdr)[source]

Sets a header of the PSRFITS file using the draft header derived from template.

set_subint_dims(nbin=1, nchan=2048, npol=4, nsblk=4096, nsubint=4, obs_mode=None, data_dtype=u'|u1')[source]
Method to set the appropriate parameters for the SUBINT BinTable of
a PSRFITS file of the given dimensions.

The parameters above are defined in the PSRFITS literature. The method automatically changes all the header information in the

template dependent on these values. The header template is set to these values.
A list version of a dtype array is made which has all the info needed
to make a SUBINT recarray. This can then be written to a PSRFITS file, using the command write_prsfits().
nbin : int
NBIN, number of bins. 1 for SEARCH mode data.
nchan : int
NCHAN, number of frequency channels.
npol : int
NPOL, number of polarization channels.
nsblk : int
NSBLK, size of the data chunks for search mode data. Set to 1 for PSR and CAL mode.
nsubint : int
NSUBINT or NAXIS2 . This is the number of rows or subintegrations in the PSRFITS file.
obs_mode : str , {‘SEARCH’, ‘PSR’, ‘CAL’}
Observation mode.
data_type : str
Data type of the DATA array (‘|u1’=int8 or ‘|u2’=int16).
write_PrimaryHDU_info_dict(ImHDU_template, new_ImHDU)[source]

Writes the information dictionary for a primary header Image HDU (new_ImHDU) using ImHDU_template as the template. Both are FITS HDUs.

ImHDU_template :
Template header.
new_ImHDU :
Header where template is copied.
write_psrfits(HDUs=None, hdr_from_draft=True)[source]
Function that takes the template headers and a dictionary of recarrays
to make into PSRFITS HDU’s. These should only include BinTable HDU Extensions, not the PRIMARY header (an ImageHDU). PRIMARY is dealt with a bit differently.
HDUs : dict, optional
Dictionary of recarrays to make into HDUs. Default is set to HDU_drafts
pdat.pdat.convert2asciii(dictionary)[source]

Changes all keys (i.e. assumes they are strings) to ASCII and values that are strings to ASCII. Specific to dictionaries.

pdat.pdat.list_arg(list_name, string)[source]

Returns the index of a particular string in a list of strings.

Module contents

Top-level package for PulsarDataToolbox.