pdat package¶
Top-level package for PulsarDataToolbox.
Submodules¶
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.
-
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.pypsrfits module¶
-
class
pdat.pypsrfits.
PyPSRFITS
(fname=None)[source]¶ A version of Paul Demorest’s pypsrfits routines added into the Pulsar Data Toolbox framework for ease of installation and documenting. I have replaced PSRFITS with PyPSRFITS to avoid confusion between this and the psrfits class, which is more generic.
See https://github.com/demorest/pypsrfits for more details.
This is a very simple python module for reading search-mode PSRFITS data into python. It requires the fitsio python module (and numpy of course).
Example usage:
# Import the module, open a file import pypsrfits f = pdat.PyPSRFITS(‘my_file.fits’)
# A full fitsio object for the file is available: f.fits
# The main header and SUBINT header are also accessible: f.hdr f.subhdr
# Read all data from row 13 d = f.get_data(13)
# Read all data in entire file, downsampling in time by # a factor of 256 d = f.get_data(0,-1,downsamp=256)
-
get_data
(start_row=0, end_row=None, downsamp=1, fdownsamp=1, apply_scales=True, get_ft=False, squeeze=False)[source]¶ Read the data from the specified rows and return it as a single array. Dimensions are [time, poln, chan]. options:
start_row: first subint read (0-based index) end_row: final subint to read. None implies end_row=start_row.
Negative values imply offset from the end, i.e. get_data(0,-1) would read the entire file. (Don’t forget that PSRFITS files are often huge so this might be a bad idea).- downsamp: downsample the data in time as they are being read in.
- The downsample factor should evenly divide the number of spectra per row. downsamp=0 means integrate each row completely.
- fdownsamp: downsample the data in freq as they are being read in.
- The downsample factor should evenly divide the number of channels.
- apply_scales: set to False to avoid applying the scale/offset
- data stored in the file.
get_ft: if True return time and freq arrays as well. squeeze: if True, “squeeze” the data array (remove len-1
dimensions).- Notes:
- Only 8, 16, and 32 bit data are currently understood
-