Package wsatools :: Module FitsUtils
[hide private]

Module FitsUtils

source code

Tools to work with the VDFS FITS file collection.


Author: E. Sutorius, N.J.G. Cross

Organization: WFAU, IfA, University of Edinburgh

Contributors: I.A. Bond, R.S. Collins

Requires: PyFITS

Classes [hide private]
  FileList
The format of tuples giving file lists.
  FitsList
Generate lists for FITS directories.
Functions [hide private]
 
checksum(fileList)
Update checksum of given FITS files.
source code
 
combHeaders(priHeader, secHeader)
Combines the header keywords from a primary header and a secondary.
source code
 
compressFits(fileList)
Rice compress FITS files.
source code
dict(str: str)
createFileListDict(progTable, fileTag=None, workingDir=None, isList=False)
Creates a dictionary of full paths to the files that list the newly created file products to be ingested into the given database for the given programme, referenced by product type.
source code
str
createSuffix(combiFrameType)
Converts a combined frame type to a complete file name suffix.
source code
str
determineFrameType(filePathName)
Determines a file's frame type from the file name.
source code
 
findFileOnDisks(sysc, filePart, isDev) source code
list(tuple(int, float, float, int, int, str))
findProduct(progID, releaseNum, productID, prodType, prodInfo, filterTable, isDev=False, sysc=SystemConstants("WSA"), directory=None)
Finds all the available stacks that cover the mosaic in question.
source code
int
fixExponentBug(header)
Repairs the CC_PRES keyword values that prevent FITS files from being written.
source code
str
formatDateTime(dateTime, isDiffSec=True)
Formats a DateTime string.
source code
 
_fpackList(fileList, compress=True)
Execute fpack/funpack on every file in given list.
source code
list(tuple(str, list(str)))
getAllPaths(disks, fitsDirs=['ingest/fits'])
Find all paths with the given FITS sub-directory name if the given list of disks, where FITS files are stored.
source code
str
getCatalogue(filePath)
Returns: The full path to the catalogue file for the corresponding image file path.
source code
str
getConfMap(filePath)
Returns: The full path to the confidence image map for the corresponding image file path.
source code
str
getDate(filePath)
Returns: The date string of the filePath
source code
list(int)
getExtList(filePath)
Returns: The list of extensions.
source code
FileList
getFileList(filePath)
Returns: List of image, confidence map and catalogue file paths for given image file path.
source code
str
getFilteredImageName(filePath, directory=None)
Returns: The full path to the confidence image map for the corresponding image file path.
source code
str
getImageName(catPath)
Returns: The full path to image file for the corresponding catalogue file path.
source code
str
getListDrivenCat(outputDir, filePath)
Returns: The full path to the catalogue file for the corresponding image file path.
source code
float
getPixelScale(fileNamePath, extNum=None)
Returns: The pixel size in arcseconds of the given file.
source code
tuple(int,str)
getProductID(filePathName)
Returns: The productID and product type of the file
source code
str
getSwarpCat(filePath)
Returns: Returns the path to the corresponding catalogue of the given SWARP image, if the catalogue exists, else None.
source code
str
getSwarpConfMap(filePath)
Returns: Returns the path to the corresponding confidence map of the given SWARP image, if the confidence map exists, else None.
source code
 
isCompressed(filePathName)
Checks file to see if it is already compressed
source code
str
isSwarpProvVO(filePath)
Returns: Checks the type of Provenance file that comes with Swarp mosaics
source code
int
maxHdrBlockKeys()
Returns: Maximum number of keys in a FITS header block.
source code
int
maxHdrEntryLen()
Returns: Maximum length of a FITS header entry (minus keyword length).
source code
pyfits.HDUList
open(filePath, mode='readonly', doNotScale=True, **kwds)
Wrapper to pyfits.open() function to handle change of interface in versions subsequent to 2.3.1dev650 and the change in default behaviour since PyFITS version 1.4.1.
source code
 
parseHistory(card)
Temporary wrapper function to handle transition to pyfits 3.
source code
 
prepHeaders(filePathName, confPathName, components, expTimes=[], dfsIDString=None, bScale=None)
Prepares the headers of FITS files to be ingested into the archive, with the correct provenance etc.
source code
 
checkForUnicodeError(hduList, fileName)
Tests for unicode error
source code
 
removeDuplicateKeywords(filePathName)
Removes duplicate keywords from given FITS file header.
source code
 
stripServer(filePathName)
Strip server name from file path.
source code
 
uncompressFits(fileList)
Rice uncompress FITS files.
source code
 
updateFitsStamp(fileName, timeStamp)
Update the FITS file timestamp accordingly.
source code
int
writeToFitsHdu(fitsFile, hduno, key, value, descr, redoing=False, verify='exception')
Write a FITS key, it's value and comment into the HDU of a given file.
source code
Variables [hide private]
  _blockLen = 2880
Maximum length of a FITS header block in bytes
  __package__ = 'wsatools'
Function Details [hide private]

checksum(fileList)

source code 

Update checksum of given FITS files.

Note: Parallel tests prove to be as slow as series due to I/O limit.

combHeaders(priHeader, secHeader)

source code 

Combines the header keywords from a primary header and a secondary. Useful for converting stacks to mosaics.

Parameters:
  • priHeader (pyfits.Header) - Primary header to update.
  • secHeader (pyfits.Header) - Secondary header from which to obtain data.

compressFits(fileList)

source code 

Rice compress FITS files.

Parameters:
  • fileList (list(str)) - A list of FITS files.

createFileListDict(progTable, fileTag=None, workingDir=None, isList=False)

source code 

Creates a dictionary of full paths to the files that list the newly created file products to be ingested into the given database for the given programme, referenced by product type.

Parameters:
  • progTable (DataFactory.ProgrammeTable) - Programme table for the ingest database with the current row set to that of the desired programme if this is a list of files for only one programme.
  • fileTag (str) - Optionally, additionally tag the file name with this tag, otherwise the programme acronym is used.
  • workingDir (str) - Optionally specify directory path to create the file lists.
  • isList (bool) - ?
Returns: dict(str: str)
Full path to the file list of each product type, referenced by product type.

createSuffix(combiFrameType)

source code 

Converts a combined frame type to a complete file name suffix.

Parameters:
  • combiFrameType (str) - Database frame type of file.
Returns: str
The complete file name suffix.

determineFrameType(filePathName)

source code 

Determines a file's frame type from the file name.

Parameters:
  • filePathName (str) - Path to FITS image file.
Returns: str
The database frame type.

findProduct(progID, releaseNum, productID, prodType, prodInfo, filterTable, isDev=False, sysc=SystemConstants("WSA"), directory=None)

source code 

Finds all the available stacks that cover the mosaic in question.

Parameters:
  • progID (int) - Programme ID.
  • releaseNum (int) - Release number of stack.
  • productID (int) - ID of product
  • prodType (string) - Type of product
  • prodInfo (Namedtuple (or dict)) - Details of the product
  • filterTable (DataFactory.Table) - Table object containing attributes of filter table.
  • isDev (bool) - If True, just check development directory else check all disks.
  • sysc (SystemConstants) - Initialised SystemConstants object.
  • directory (str) - ?
Returns: list(tuple(int, float, float, int, int, str))
A list of stack attributes (productID, RA, Dec, filterID, date, filePathName) for each stack in the mosaic.

fixExponentBug(header)

source code 

Repairs the CC_PRES keyword values that prevent FITS files from being written.

Parameters:
  • header (pyfits.Header) - A FITS file header.
Returns: int
1 if change made else 0

formatDateTime(dateTime, isDiffSec=True)

source code 

Formats a DateTime string.

Parameters:
  • dateTime (mx.DateTime) - DateTime object to format.
Returns: str
Correctly formatted date time string.

_fpackList(fileList, compress=True)

source code 

Execute fpack/funpack on every file in given list. Used by public functions, compressFits() and uncompressFits().

Parameters:
  • fileList (list(str)) - A list of FITS files.
  • compress (bool) - If True, compress the FITS file, otherwise uncompress.

Note: Parallel tests prove to be as slow as series due to I/O limit.

getAllPaths(disks, fitsDirs=['ingest/fits'])

source code 

Find all paths with the given FITS sub-directory name if the given list of disks, where FITS files are stored.

Parameters:
Returns: list(tuple(str, list(str)))
A list of pairs of FITS sub-directory path with a list of the date sub-directories in that path (e.g. [('/disk01/wsa/fits/', ['20050101', '20060202'])]).

getCatalogue(filePath)

source code 
Returns: str
The full path to the catalogue file for the corresponding image file path.

getConfMap(filePath)

source code 
Returns: str
The full path to the confidence image map for the corresponding image file path.

getDate(filePath)

source code 
Returns: str
The date string of the filePath

getExtList(filePath)

source code 
Returns: list(int)
The list of extensions.

getFileList(filePath)

source code 
Returns: FileList
List of image, confidence map and catalogue file paths for given image file path.

getFilteredImageName(filePath, directory=None)

source code 
Returns: str
The full path to the confidence image map for the corresponding image file path.

getImageName(catPath)

source code 
Returns: str
The full path to image file for the corresponding catalogue file path.

getListDrivenCat(outputDir, filePath)

source code 
Returns: str
The full path to the catalogue file for the corresponding image file path.

getPixelScale(fileNamePath, extNum=None)

source code 
Returns: float
The pixel size in arcseconds of the given file.

getProductID(filePathName)

source code 
Returns: tuple(int,str)
The productID and product type of the file

getSwarpCat(filePath)

source code 
Returns: str
Returns the path to the corresponding catalogue of the given SWARP image, if the catalogue exists, else None.

getSwarpConfMap(filePath)

source code 
Returns: str
Returns the path to the corresponding confidence map of the given SWARP image, if the confidence map exists, else None.

isCompressed(filePathName)

source code 

Checks file to see if it is already compressed

Parameters:
  • filePathName (str) - Full path to FITS file.

isSwarpProvVO(filePath)

source code 
Returns: str
Checks the type of Provenance file that comes with Swarp mosaics

maxHdrBlockKeys()

source code 
Returns: int
Maximum number of keys in a FITS header block.

maxHdrEntryLen()

source code 
Returns: int
Maximum length of a FITS header entry (minus keyword length).

open(filePath, mode='readonly', doNotScale=True, **kwds)

source code 

Wrapper to pyfits.open() function to handle change of interface in versions subsequent to 2.3.1dev650 and the change in default behaviour since PyFITS version 1.4.1.

Parameters:
  • filePath (str) - Full path to FITS file to open.
  • mode (str) - File access mode, e.g. "readonly", "update" (see pyfits.open() for complete list).
  • doNotScale (bool) - If True, image data is not scaled using BSCALE/BZERO values when read.
  • kwds (dict) - Any additional keyword arguments supported by pyfits.open().
Returns: pyfits.HDUList
PyFITS HDUList object for the open file.

prepHeaders(filePathName, confPathName, components, expTimes=[], dfsIDString=None, bScale=None)

source code 

Prepares the headers of FITS files to be ingested into the archive, with the correct provenance etc. This ensures that the FITS files produced by WFAU with CASU software tools, e.g. deep stacks, mosaics, difference images etc. all contain the correct header information prior to ingest.

Parameters:
  • filePathName (str) - Full path to FITS file that requires its headers to be prepared for ingest.
  • confPathName (str) - Full path to the corresponding confidence map.
  • components (list(FileList)) - A list containing the full paths to every component FITS file that went into the FITS file to be updated, i.e. the provenance information.
  • expTimes (list(float)) - List of total exposure times for each extension.
  • bScale (list(float)) - If image has floating point data scaled to integers then supply the bScale values for each extension.

removeDuplicateKeywords(filePathName)

source code 

Removes duplicate keywords from given FITS file header.

Parameters:
  • filePathName (str) - Full path to FITS file.

uncompressFits(fileList)

source code 

Rice uncompress FITS files.

Parameters:
  • fileList (list(str)) - A list of FITS files.

updateFitsStamp(fileName, timeStamp)

source code 

Update the FITS file timestamp accordingly.

Parameters:
  • fileName (str) - FITS file to be updated.
  • timeStamp (long) - WFAU timestamp (datedir+filetimestamp).

writeToFitsHdu(fitsFile, hduno, key, value, descr, redoing=False, verify='exception')

source code 

Write a FITS key, it's value and comment into the HDU of a given file.

Parameters:
  • fitsFile (pyfits.HDUList) - The open FITS file to be altered.
  • hduno (tuple(int)) - Tuple of HDU numbers.
  • key (str) - FITS key to be added.
  • value (str) - The value of the FITS key.
  • descr (str) - Description of the FITS key.
  • redoing (bool) - Write mfid and timestamp anyways.
Returns: int
Status (1 = success, 0 = failure)