Package gavo :: Package helpers :: Module fitstricks
[frames] | no frames]

Module fitstricks

source code

Helpers for manipulating FITS files.

In contrast to fitstools, this is not for online processing or import of files, but just for the manipulation before processing.

Rough guideline: if it's about writing fixed fits files, it probably belongs here, otherwise it goes to fitstools.

Realistically, this module has been hemorraghing functions to fitstools and probably should be removed completely.

One important function it has grown is FITS header templates. These can be used by processors. If these use custom templates, they should register them (or regret it later). See registerTemplate's docstring.

Functions
 
copyFields(header, cardList, ignoredHeaders=frozenset(DEFAULT_IGNORED_HEADERS))
copies over all cards from cardList into header, excluding headers named in ignoredHeaders.
source code
 
getHeaderAsDict(hdr)
returns the "normal" key-value pairs from hdr in a dictionary.
source code
 
registerTemplate(templateName, template)
registers a named FITS header template.
source code
 
getTemplateForName(templateName)
returns the FITS template sequence for templateName.
source code
 
getNameForTemplate(template)
returns the name under which the FITS template has been registred.
source code
 
getTemplateNameFromHistory(hdr)
returns the template name used for generating hdr.
source code
 
makeHeaderFromTemplate(template, originalHeader=None, **values)
returns a new pyfits.Header from template with values filled in.
source code
 
updateTemplatedHeader(hdr, templateName=None, **kwargs)
return hdr updated with kwargs.
source code
Variables
  DEFAULT_IGNORED_HEADERS = ["simple", "bitpix", "naxis", "image...
  MINIMAL_IMAGE_TEMPLATE = [pyfits.Card("SIMPLE", True), pyfits....
  WCS_TEMPLATE = [pyfits.Card(value= "-------------------- Spati...
  WFPDB_TEMPLATE = MINIMAL_IMAGE_TEMPLATE+ [pyfits.Card(value= "...
Function Details

copyFields(header, cardList, ignoredHeaders=frozenset(DEFAULT_IGNORED_HEADERS))

source code 

copies over all cards from cardList into header, excluding headers named in ignoredHeaders.

ignoredHeaders must be all lowercase.

getHeaderAsDict(hdr)

source code 

returns the "normal" key-value pairs from hdr in a dictionary.

Comment, history and blank cards are excluded; the comments from the cards are lost, too.

registerTemplate(templateName, template)

source code 

registers a named FITS header template.

Registering lets DaCHS figure out the template from a history entry it leaves, so it's certainly a good idea to do that.

For templateName, use something containing a bit of your signature (e.g., ariAncientPlate rather than just ancientPlate).

getTemplateForName(templateName)

source code 

returns the FITS template sequence for templateName.

A NotFoundError is raised if no such template exists.

getTemplateNameFromHistory(hdr)

source code 

returns the template name used for generating hdr.

A ReportableError is raised if the info signature is missing.

makeHeaderFromTemplate(template, originalHeader=None, **values)

source code 

returns a new pyfits.Header from template with values filled in.

template usually is the name of a template previously registered with registerTemplate, or one of DaCHS predefined template names (currently, minimal and wfpdb). In a pinch, you can also pass in an immediate headers.

originalHeader can be a pre-existing header; the history and comment cards are copied over from it, and if any of its other cards have not yet been added to the header, they will be added in the order that they apprear there.

values for which no template item is given are added in random order after the template unless an originalHeader is passed. In that case, they are assumed to originate there and are ignored.

updateTemplatedHeader(hdr, templateName=None, **kwargs)

source code 

return hdr updated with kwargs.

hdr is assumed to have been created with makeHeaderFromTemplate and contain the template name in a history entry.

You can pass in templateName to keep DaCHS from trying to get things from the header.

[It is probably better to use makeHeaderFromTemplate directly, passing in the orginalHeader; that preserves the order of non-templated headers].


Variables Details

DEFAULT_IGNORED_HEADERS

Value:
["simple", "bitpix", "naxis", "imageh", "imagew", "naxis1", "naxis2", \
"datamin", "datamax", "date"]

MINIMAL_IMAGE_TEMPLATE

Value:
[pyfits.Card("SIMPLE", True), pyfits.Card("EXTEND", True), ("BITPIX", \
"Array data type"), pyfits.Card("NAXIS", 2), ("NAXIS1", "Number of ele\
ments along 1st axis"), ("NAXIS2", "Number of elements along 2nd axis"\
), ("BZERO", "Zero point of pixel scaling function"), ("BSCALE", "Slop\
e of pixel scaling function"),]

WCS_TEMPLATE

Value:
[pyfits.Card(value= "-------------------- Spatial WCS"), ('EQUNIOX', "\
Equinox of RA and Dec"), ('RADESYS', "Reference System used for RA and\
 Dec"), ('WCSAXES', "Number of FITS axes covered by WCS"), ('CTYPE1', \
"Projection on axis 1"), ('CTYPE2', "Projection on axis 2"), ('LONPOLE\
', "See sect 2.4 of WCS paper II"), ('LATPOLE', "See sect 2.4 of WCS p\
aper II"), ('CRVAL1', "Longitude  of reference point"), ('CRVAL2', "La\
titude of reference point"), ('CRPIX1', "X reference pixel"), ('CRPIX2\
', "Y reference pixel"), ('CUNIT1', "X pixel scale units"), ('CUNIT2',\
...

WFPDB_TEMPLATE

Value:
MINIMAL_IMAGE_TEMPLATE+ [pyfits.Card(value= "-------------------- Orig\
inal data of observation"), ("DATEORIG", "Original recorded date of th\
e observation"), ("TMS-ORIG", "Start of the observation (logs)"), ("TM\
E-ORIG", "End of the observation (logs)"), ("TIMEFLAG", "Quality flag \
of the recorded observation time"), ("RA-ORIG", "RA of plate center as\
 given in source"), ("DEC-ORIG", "Dec of plate center as given in sour\
ce"), ("COORFLAG", "Quality flag of the recorded coordinates"), ("OBJE\
CT", "Observed object or field"), ("OBJTYPE", "Object type as in WFPDB\
...