Conversion Utilities

Convertwaiveredfits

Convert a waivered FITS file to various other formats.

Syntax for the command line:

convertwaiveredfits.py [-hm] [-o <outputFileName>,...] FILE ...

Convert the waivered FITS files (wFITS) to various formats. The default conversion format is multi-extension FITS (MEF).

Options:

-h, --help                       print this help message and exit

-v, --verbose                    turn on verbose output

-m, --multiExtensionConversion   convert to multi-extension
                                 FITS format (Default)

-o, --outputFileName             comma separated list of
                                 output file specifications
                                 one per input FILE
                                 Default: input file
                                 specification with the last
                                 character of the base name
                                 changed to `h` in multi-extension FITS format

For example, conversion of a WFPC2 waivered FITS file obtained from the MAST archive:

convertwaiveredfits u9zh010bm_c0f.fits

This will convert the waivered FITS file u9zh010bm_c0f.fits to multi-extension FITS format and generate the output file u9zh010bm_c0h.fits.

Conversion of multiple FITS files can be done using:

convertwaiveredfits -o out1.fits,out2.fits u9zh010bm_c0f.fits u9zh010bm_c1f.fits

This will convert the waivered FITS files u9zh010bm_c0f.fits and u9zh010bm_c1f.fits to multi-extension FITS format and generate the output files out1.fits and out2.fits.

param waiveredObject:
 

input object representing a waivered FITS file; either a astropy.io.fits.HDUList object, a file object, or a file specification.

type waiveredObject:
 

obj

param outputFileName:
 

file specification for the output file. Default: None - do not generate an output file

type outputFileName:
 

string

param forceFileOutput:
 

force the generation of an output file when the outputFileName parameter is None; the output file specification will be the same as the input file specification with the last character of the base name replaced with the character h in multi-extension FITS format.

Default: False

type forceFileOutput:
 

boolean

param convertTo:
 

target conversion type. Default: ‘multiExtension’

type convertTo:

string

param verbose:

provide verbose output. Default: False

type verbose:

boolean

returns:

hduListastropy.io.fits multi-extension FITS object containing converted output

rtype:

fits.HDUList

Examples

>>> from stsci.tools import convertwaiveredfits
>>> hdulist = convertwaiveredfits.convertwaiveredfits(
...     'u9zh010bm_c0f.fits', forceFileOutput=True)  # doctest: +SKIP

This will convert the waivered FITS file u9zh010bm_c0f.fits to multi-extension FITS format and write the output to the file u9zh010bm_c0h.fits; the returned HDUList is in multi-extension FITS format.

>>> from stsci.tools import convertwaiveredfits
>>> with open('u9zh010bm_c0f.fits', mode='rb') as inFile:
...     hdulist = convertwaiveredfits.convertwaiveredfits(inFile, 'out.fits')  # doctest: +SKIP

This will convert the waivered FITS file u9zh010bm_c0f.fits to multi-extension FITS format and write the output to the file out.fits; the returned HDUList is in multi-extension FITS format.

>>> from astropy.io import fits
>>> from stsci.tools import convertwaiveredfits
>>> with fits.open('u9zh010bm_c0f.fits') as inHdul:
...     hdulist = convertwaiveredfits.convertwaiveredfits(inHdul)  # doctest: +SKIP

This will convert the waivered FITS file u9zh010bm_c0f.fits to multi-extension FITS format; no output file is generated; the returned HDUList is in multi-extension format.

stsci.tools.convertwaiveredfits.convertwaiveredfits(waiveredObject, outputFileName=None, forceFileOutput=False, convertTo='multiExtension', verbose=False)

Convert the input waivered FITS object to various formats. The default conversion format is multi-extension FITS. Generate an output file in the desired format if requested.

Parameters:
  • input object representing a waivered FITS file; (waiveredObject) – either a astropy.io.fits.HDUList object, a file object, or a file specification
  • file specification for the output file (outputFileName) – Default: None - do not generate an output file
  • force the generation of an output file when the (forceFileOutput) –

    outputFileName parameter is None; the output file specification will be the same as the input file specification with the last character of the base name replaced with the character h in multi-extension FITS format.

    Default: False

  • target conversion type (convertTo) – Default: ‘multiExtension’
  • provide verbose output (verbose) – Default: False
Returns:

hdul an HDUList object in the requested format.

Exceptions:

ValueError Conversion type is unknown
stsci.tools.convertwaiveredfits.main()
stsci.tools.convertwaiveredfits.toMultiExtensionFits(waiveredObject, multiExtensionFileName=None, forceFileOutput=False, verbose=False)

Convert the input waivered FITS object to a multi-extension FITS HDUList object. Generate an output multi-extension FITS file if requested.

Parameters:
  • input object representing a waivered FITS file; (waiveredObject) – either a astroyp.io.fits.HDUList object, a file object, or a file specification
  • file specification for the output file (outputFileName) – Default: None - do not generate an output file
  • force the generation of an output file when the (forceFileOutput) – outputFileName parameter is None; the output file specification will be the same as the input file specification with the last character of the base name replaced with the character ‘h’. Default: False
  • provide verbose output (verbose) – Default: False
Returns:

mhdul an HDUList object in multi-extension FITS format.

Exceptions:

TypeError Input object is not a HDUList, a file object or a
file name

ReadGEIS

readgeis: Read GEIS file and convert it to a FITS extension file.

Usage:

readgeis.py [options] GEISname FITSname

GEISname is the input GEIS file in GEIS format, and FITSname is the output file in FITS format. GEISname can be a directory name. In this case, it will try to use all *.??h files as input file names.

If FITSname is omitted or is a directory name, this task will try to construct the output names from the input names, i.e.:

abc.xyh will have an output name of abc_xyf.fits

Options:
-h print the help (this text)
Example:

If used in Pythons script, a user can, e. g.:

>>> from stsci.tools import readgeis
>>> hdulist = readgeis.readgeis(GEISFileName)  
(do whatever with hdulist)
>>> hdulist.writeto(FITSFileName)  

The most basic usage from the command line:

readgeis.py test1.hhh test1.fits

This command will convert the input GEIS file test1.hhh to a FITS file test1.fits.

From the command line:

readgeis.py .

this will convert all *.??h files in the current directory to FITS files (of corresponding names) and write them in the current directory.

Another example of usage from the command line:

readgeis.py "u*" "*"

this will convert all u*.??h files in the current directory to FITS files (of corresponding names) and write them in the current directory. Note that when using wild cards, it is necessary to put them in quotes.

stsci.tools.readgeis.parse_path(f1, f2)

Parse two input arguments and return two lists of file names

stsci.tools.readgeis.readgeis(input)

Input GEIS files “input” will be read and a HDUList object will be returned.

The user can use the writeto method to write the HDUList object to a FITS file.

stsci.tools.readgeis.stsci(hdulist)

For STScI GEIS files, need to do extra steps.

stsci.tools.readgeis.stsci2(hdulist, filename)

For STScI GEIS files, need to do extra steps.

Check_files

The check_files module provides functions to perform verification of input file formats for use in betadrizzle. This set of functions also includes format conversion functions to convert GEIS or waiver-FITS HST images into multi-extension FITS (MEF) files.

stsci.tools.check_files.checkFITSFormat(filelist, ivmlist=None)

This code will check whether or not files are GEIS or WAIVER FITS and convert them to MEF if found. It also keeps the IVMLIST consistent with the input filelist, in the case that some inputs get dropped during the check/conversion.

stsci.tools.check_files.checkFiles(filelist, ivmlist=None)
  • Converts waiver fits sciece and data quality files to MEF format
  • Converts GEIS science and data quality files to MEF format
  • Checks for stis association tables and splits them into single imsets
  • Removes files with EXPTIME=0 and the corresponding ivm files
  • Removes files with NGOODPIX == 0 (to exclude saturated images)
  • Removes files with missing PA_V3 keyword

The list of science files should match the list of ivm files at the end.

stsci.tools.check_files.checkNGOODPIX(filelist)

Only for ACS, WFC3 and STIS, check NGOODPIX If all pixels are ‘bad’ on all chips, exclude this image from further processing. Similar checks requiring comparing ‘driz_sep_bits’ against WFPC2 c1f.fits arrays and NICMOS DQ arrays will need to be done separately (and later).

stsci.tools.check_files.checkPA_V3(fnames)
stsci.tools.check_files.checkStisFiles(filelist, ivmlist=None)
stsci.tools.check_files.check_exptime(filelist)

Removes files with EXPTIME==0 from filelist.

stsci.tools.check_files.convert2fits(sci_ivm)

Checks if a file is in WAIVER of GEIS format and converts it to MEF

stsci.tools.check_files.countInput(input)
stsci.tools.check_files.geis2mef(sciname, convert_dq=True)

Converts a GEIS science file and its corresponding data quality file (if present) to MEF format Writes out both files to disk. Returns the new name of the science image.

stsci.tools.check_files.isSTISSpectroscopic(fname)
stsci.tools.check_files.splitStis(stisfile, sci_count)

Split a STIS association file into multiple imset MEF files.

Split the corresponding spt file if present into single spt files. If an spt file can’t be split or is missing a Warning is printed.

Returns:names – a list with the names of the new flt files.
Return type:list
stsci.tools.check_files.stisExt2PrimKw(stisfiles)

Several kw which are usually in the primary header are in the extension header for STIS. They are copied to the primary header for convenience. List if kw: ‘DATE-OBS’, ‘EXPEND’, ‘EXPSTART’, ‘EXPTIME’

stsci.tools.check_files.stisObsCount(input)

Input: A stis multiextension file Output: Number of stis science extensions in input

stsci.tools.check_files.update_input(filelist, ivmlist=None, removed_files=None)

Removes files flagged to be removed from the input filelist. Removes the corresponding ivm files if present.

stsci.tools.check_files.waiver2mef(sciname, newname=None, convert_dq=True, writefits=True)

Converts a GEIS science file and its corresponding data quality file (if present) to MEF format Writes out both files to disk. Returns the new name of the science image.