1.146. FitsArchive

Full Name: herschel.ia.io.fits.FitsArchive
Alias: FitsArchive
Type: Java Class - Java Class
Import: from herschel.ia.io.fits import FitsArchive
Category

Input-output

Description

A class for reading and writing FITS files.

The FitsArchive provides a transparent way to store and retrieve Products as defined within the Herschel Data Processing software. FitsArchive is thread tolerant. It is not thread safe: do not share a FitsArchive object between several threads.

Examples

Example 1: default usage:
# write/read a Product in HCSS decorated format.
product = Product()
fits=FitsArchive()
fits.save(path,product)
product=fits.load(path)
Example 2: reading a HCSS FITS file which contains a removed class:
fits=FitsArchive()
product=fits.load(path,FitsArchive.HANDLE_MISSING_CLASSES)
Example 3: reading a externally generated FITS file into a Product:
# setup a new FitsArchive, but change the reader type
from herschel.ia.io.fits.reader.standard import StandardFitsReader
fits = FitsArchive(reader = StandardFitsReader())
product=fits.load(pathSrc)
# Saving the product will be done in HCSS decorated format.
fits.save(pathDst,product)
Example 4: reading a gzipped product:
fits=FitsArchive()
product=fits.load(path)
Example 5: reading a zipped product:
from java.util.zip import ZipFile, ZipEntry
fits = FitsArchive()
f = ZipFile(path)
entry = f.entries().nextElement() # the only entry
product = fits.load(f.getInputStream(entry))
Example 6: saving an empty ArrayDataset is allowed:
fits=FitsArchive()
ads=ArrayDataset()
product=Product("with empty ArrayDataset")
product['ads'] = ads
fits.save(pathDst, product) # works: image extension without image
Example 7: saving an empty column in a TableDataset is NOT allowed:
fits=FitsArchive()
tds=TableDataset()
tds.addColumn(Column())
product=Product("with empty Column in TableDataset")
product['tds'] = tds
try:
    fits.save(pathDst, product) # fails: binary table extensions require data
except:
    print "Exception raised"
pass
Example 8: saving the product minimising product metadata keyword translations and making keywords duplicity:
fits=FitsArchive()
product=Product()
fits.save(pathDst, product, 1, 1)
Example 9: saving a gzipped product
from java.util.zip import GZIPOutputStream
from java.io import FileOutputStream
product = Product()
fits=FitsArchive()
fits.save(GZIPOutputStream(FileOutputStream(pathDst)), product)

API Summary

Methods
Product load (String name)

Loads a Product from a FITS file.

Product load (String name, boolean handleMissingClasses)

Loads a Product from a FITS file.

Product load (String file)

Loads a Product from a FITS file.

Product load (String file, boolean handleMissingClasses)

Loads a Product from a FITS file.

Product load (InputStream is)

Loads a Product from a FITS InputStream.

Product load (InputStream is, boolean handleMissingClasses)

Loads a Product from a FITS InputStream.

save (String name, [Optionally derived] Product. product)

Saves a Product to a FITS file.

save (boolean compress, String name, [Optionally derived] Product. product)

Saves a Product to a FITS file.

save (String name, [Optionally derived] Product. product, Boolean. minimizeTranslations, [Optionally derived] Product. keysDuplicity)

Saves a Product to a FITS file.

save (boolean compress, String name, [Optionally derived] Product. product, Boolean. minimizeTranslations, [Optionally derived] Product. keysDuplicity)

Saves a Product to a FITS file.

save (File file, [Optionally derived] Product. product)

Saves a Product to a FITS file.

save (boolean compress, File file, [Optionally derived] Product. product)

Saves a Product to a FITS file.

save (File file, [Optionally derived] Product. product, Boolean. minimizeTranslations, [Optionally derived] Product. keysDuplicity)

Saves a Product to a FITS file.

save (boolean compress, File file, [Optionally derived] Product. product, Boolean. minimizeTranslations, [Optionally derived] Product. keysDuplicity)

Saves a Product to a FITS file.

save (OutputStream os, [Optionally derived] Product. product)

Saves a Product to an OutputStream (creating a FITS file).

save (OutputStream os, [Optionally derived] Product. product, Boolean. minimizeTranslations, [Optionally derived] Product. keysDuplicity)

Saves a Product to an OutputStream (creating a FITS file).

MetaData loadMeta (String name)

Loads a MetaData product object from a FITS file.

MetaData loadMeta (File file)

Loads a MetaData product object from a FITS file.

MetaData loadMeta (InputStream is)

Loads a MetaData product object from a FITS file.

MetaData loadMeta (String name, integer hduIndex)

Loads a MetaData object from a FITS file at the specified HDU index.

MetaData loadMeta (String name, integer hduIndex, integer commentExtraSpacesToRemove)

Loads a MetaData object from a FITS file at the specified HDU index.

MetaData loadMeta (File file, integer hduIndex)

Loads a MetaData object from a FITS file at the specified HDU index.

MetaData loadMeta (File file, integer hduIndex, integer commentExtraSpacesToRemove)

Loads a MetaData object from a FITS file at the specified HDU index.

MetaData loadMeta (InputStream is, integer hduIndex)

Loads a MetaData object from a FITS file at the specified HDU index.

MetaData loadMeta (InputStream is, integer hduIndex, integer commentExtraSpacesToRemove)

Loads a MetaData object from a FITS file at the specified HDU index.

MetaData loadMeta (String name, integer hduIndex, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

MetaData loadMeta (String name, integer hduIndex, integer commentExtraSpacesToRemove, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

MetaData loadMeta (File file, integer hduIndex, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

MetaData loadMeta (File file, integer hduIndex, integer commentExtraSpacesToRemove, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

MetaData loadMeta (InputStream is, integer hduIndex, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

MetaData loadMeta (InputStream is, integer hduIndex, integer commentExtraSpacesToRemove, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

API Details

Fields

FitsReader HCSS_READER

HCSS FITS Reader

A FITS reader that expects a FITS format that was produced by this archive implementation. This is a shared object among any FitsArchive instance. In a multithreaded environment, you should use a new instance of a reader.

It can handle nested structures, derived datasets and quantities of the data within FITS.

This is the default reader when you create a FitsArchive.

Examples
creating a new FitsArchive
fits=FitsArchive() # default reader=FitsArchive.HCSS_READER
creating a new FitsArchive
fits=FitsArchive(reader=FitsArchive.HCSS_READER)
FitsReader STANDARD_READER

Generic FITS Reader

A generic FITS reader for FITS files that are not created by the HCSS FitsArchive. This is a shared object among any FitsArchive instance. In a multithreaded environment, you should use a new instance of a reader.

This reader can read FITS files that were generated by other software as long as it complies to the FITS standard and translates the contents into a Product.

Examples
Import data from an externally generated FITS file
fits=FitsArchive(reader=FitsArchive.STANDARD_READER)
product=fits.load(path) # Where path is e.g. "/home/joe/external.fits"
Reusing this FitsArchive but changing the reader
fits.reader=fits.HCSS_READER
product=fits.load(path) # Where path is e.g. "/home/joe/hcss.fits"
FitsReader RAW_READER
Example
creating a new FitsArchive with a RawFitsReader
fits = FitsArchive()
fits.setReader(FitsArchive.RAW_READER)
rules = fits.getRules()
rules.setDictionary(None)
meta = fits.loadMeta(path)

Methods

Product load (String name)

Loads a Product from a FITS file.

Loads a Product from a FITS file using the current reader.

Argument
String name [INPUT, MANDATORY, default=no default value]

Name of the FITS file

Return
Product

An object of the herschel.ia.dataset.Product family.

Product load (String name, boolean handleMissingClasses)

Loads a Product from a FITS file.

Loads a Product from a FITS file using the current reader.

Arguments
String name [INPUT, MANDATORY, default=no default value]

Name of the FITS file

boolean handleMissingClasses [INPUT, MANDATORY, default=no default value]

For creating dummy classes when an HCSS class is not found.

Return
Product

An object of the herschel.ia.dataset.Product family.

Product load (String file)

Loads a Product from a FITS file.

Loads a Product from a FITS file using the current reader.

Argument
String file [INPUT, MANDATORY, default=no default value]

FITS file

Return
Product

An object of the herschel.ia.dataset.Product family.

Product load (String file, boolean handleMissingClasses)

Loads a Product from a FITS file.

Loads a Product from a FITS file using the current reader.

Arguments
String file [INPUT, MANDATORY, default=no default value]

FITS file

boolean handleMissingClasses [INPUT, MANDATORY, default=no default value]

For creating dummy classes when an HCSS class is not found.

Return
Product

An object of the herschel.ia.dataset.Product family.

Product load (InputStream is)

Loads a Product from a FITS InputStream.

Loads a Product from a FITS InputStream using the current reader.

Argument
InputStream is [INPUT, MANDATORY, default=no default value]

InputStream to the FITS file

Return
Product

An object of the herschel.ia.dataset.Product family.

Product load (InputStream is, boolean handleMissingClasses)

Loads a Product from a FITS InputStream.

Loads a Product from a FITS InputStream using the current reader. The user must close the InputStream.

Arguments
InputStream is [INPUT, MANDATORY, default=no default value]

InputStream to the FITS file

boolean handleMissingClasses [INPUT, MANDATORY, default=no default value]

For creating dummy classes when an HCSS class is not found.

Return
Product

An object of the herschel.ia.dataset.Product family.

save (String name, [Optionally derived] Product. product)

Saves a Product to a FITS file.

Saves a Product to a FITS file with sufficient information to preserve the quantities of the data as well as the original dataset type and contents.

Arguments
String name [INPUT, MANDATORY, default=no default value]

Name of the FITS file

[Optionally derived] Product. product [INPUT, MANDATORY, default=no default value]

An object of the herschel.ia.dataset.Product family.

save (boolean compress, String name, [Optionally derived] Product. product)

Saves a Product to a FITS file.

Saves a Product to a FITS file with sufficient information to preserve the quantities of the data as well as the original dataset type and contents.

Arguments
boolean compress [INPUT, MANDATORY, default=no default value]

'true' for writing a gzip FITS file.

String name [INPUT, MANDATORY, default=no default value]

Name of the FITS file

[Optionally derived] Product. product [INPUT, MANDATORY, default=no default value]

An object of the herschel.ia.dataset.Product family.

save (String name, [Optionally derived] Product. product, Boolean. minimizeTranslations, [Optionally derived] Product. keysDuplicity)

Saves a Product to a FITS file.

Saves a Product to a FITS file with sufficient information to preserve the quantities of the data as well as the original dataset type and contents.

Arguments
String name [INPUT, MANDATORY, default=no default value]

Name of the FITS file

[Optionally derived] Product. product [INPUT, MANDATORY, default=no default value]

An object of the herschel.ia.dataset.Product family.

Boolean. minimizeTranslations [INPUT, MANDATORY, default=no default value]

Specifies if some keywords that are not in any dictionary will be transalted without using 'META' following some rules.

[Optionally derived] Product. keysDuplicity [INPUT, MANDATORY, default=no default value]

Specifies if a keyword will be translated to several FITS keywords.

save (boolean compress, String name, [Optionally derived] Product. product, Boolean. minimizeTranslations, [Optionally derived] Product. keysDuplicity)

Saves a Product to a FITS file.

Saves a Product to a FITS file with sufficient information to preserve the quantities of the data as well as the original dataset type and contents.

Arguments
boolean compress [INPUT, MANDATORY, default=no default value]

'true' for writting a gzip FITS file.

String name [INPUT, MANDATORY, default=no default value]

Name of the FITS file

[Optionally derived] Product. product [INPUT, MANDATORY, default=no default value]

An object of the herschel.ia.dataset.Product family.

Boolean. minimizeTranslations [INPUT, MANDATORY, default=no default value]

Specifies if some keywords that are not in any dictionary will be transalted without using 'META' following some rules.

[Optionally derived] Product. keysDuplicity [INPUT, MANDATORY, default=no default value]

Specifies if a keyword will be translated to several FITS keywords.

save (File file, [Optionally derived] Product. product)

Saves a Product to a FITS file.

Saves a Product to a FITS file with sufficient information to preserve the quantities of the data as well as the original dataset type and contents.

Arguments
File file [INPUT, MANDATORY, default=no default value]

FITS file

[Optionally derived] Product. product [INPUT, MANDATORY, default=no default value]

An object of the herschel.ia.dataset.Product family.

save (boolean compress, File file, [Optionally derived] Product. product)

Saves a Product to a FITS file.

Saves a Product to a FITS file with sufficient information to preserve the quantities of the data as well as the original dataset type and contents.

Arguments
boolean compress [INPUT, MANDATORY, default=no default value]

'true' for writting a gzip FITS file.

File file [INPUT, MANDATORY, default=no default value]

FITS file

[Optionally derived] Product. product [INPUT, MANDATORY, default=no default value]

An object of the herschel.ia.dataset.Product family.

save (File file, [Optionally derived] Product. product, Boolean. minimizeTranslations, [Optionally derived] Product. keysDuplicity)

Saves a Product to a FITS file.

Saves a Product to a FITS file with sufficient information to preserve the quantities of the data as well as the original dataset type and contents.

Arguments
File file [INPUT, MANDATORY, default=no default value]

FITS file.

[Optionally derived] Product. product [INPUT, MANDATORY, default=no default value]

An object of the herschel.ia.dataset.Product family.

Boolean. minimizeTranslations [INPUT, MANDATORY, default=no default value]

Specifies if some keywords that are not in any dictionary will be transalted without using 'META' following some rules.

[Optionally derived] Product. keysDuplicity [INPUT, MANDATORY, default=no default value]

Specifies if a keyword will be translated to several FITS keywords.

save (boolean compress, File file, [Optionally derived] Product. product, Boolean. minimizeTranslations, [Optionally derived] Product. keysDuplicity)

Saves a Product to a FITS file.

Saves a Product to a FITS file with sufficient information to preserve the quantities of the data as well as the original dataset type and contents.

Arguments
boolean compress [INPUT, MANDATORY, default=no default value]

'true' for writting a gzip FITS file.

File file [INPUT, MANDATORY, default=no default value]

FITS file.

[Optionally derived] Product. product [INPUT, MANDATORY, default=no default value]

An object of the herschel.ia.dataset.Product family.

Boolean. minimizeTranslations [INPUT, MANDATORY, default=no default value]

Specifies if some keywords that are not in any dictionary will be transalted without using 'META' following some rules.

[Optionally derived] Product. keysDuplicity [INPUT, MANDATORY, default=no default value]

Specifies if a keyword will be translated to several FITS keywords.

save (OutputStream os, [Optionally derived] Product. product)

Saves a Product to an OutputStream (creating a FITS file).

Saves a Product to an OutputStream, creating a FITS file with sufficient information to preserve the quantities of the data as well as the original dataset type and contents. The OutputStream is closed by this method.

Arguments
OutputStream os [INPUT, MANDATORY, default=no default value]

OutputStream.

[Optionally derived] Product. product [INPUT, MANDATORY, default=no default value]

An object of the herschel.ia.dataset.Product family.

save (OutputStream os, [Optionally derived] Product. product, Boolean. minimizeTranslations, [Optionally derived] Product. keysDuplicity)

Saves a Product to an OutputStream (creating a FITS file).

Saves a Product to an OutputStream, creating a FITS file with sufficient information to preserve the quantities of the data as well as the original dataset type and contents. The OutputStream is closed by this method.

Arguments
OutputStream os [INPUT, MANDATORY, default=no default value]

OutputStream.

[Optionally derived] Product. product [INPUT, MANDATORY, default=no default value]

An object of the herschel.ia.dataset.Product family.

Boolean. minimizeTranslations [INPUT, MANDATORY, default=no default value]

Specifies if some keywords that are not in any dictionary will be transalted without using 'META' following some rules.

[Optionally derived] Product. keysDuplicity [INPUT, MANDATORY, default=no default value]

Specifies if a keyword will be translated to several FITS keywords.

MetaData loadMeta (String name)

Loads a MetaData product object from a FITS file.

Loads a MetaData product object using the current reader.

Argument
String name [INPUT, MANDATORY, default=no default value]

Name of the FITS file

Return
MetaData

A MetaData product object.

MetaData loadMeta (File file)

Loads a MetaData product object from a FITS file.

Loads a MetaData product object using the current reader.

Argument
File file [INPUT, MANDATORY, default=no default value]

Name of the FITS file

Return
MetaData

A MetaData product object.

MetaData loadMeta (InputStream is)

Loads a MetaData product object from a FITS file.

Loads a MetaData product object using the current reader. The user must close the InputStream.

Argument
InputStream is [INPUT, MANDATORY, default=no default value]

InputStream to the FITS file.

Return
MetaData

A MetaData product object.

MetaData loadMeta (String name, integer hduIndex)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0.

Arguments
String name [INPUT, MANDATORY, default=no default value]

Name of the FITS file

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

Return
MetaData

A MetaData object at the specified HDU index.

MetaData loadMeta (String name, integer hduIndex, integer commentExtraSpacesToRemove)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0.

Arguments
String name [INPUT, MANDATORY, default=no default value]

Name of the FITS file

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

integer commentExtraSpacesToRemove [INPUT, MANDATORY, default=no default value]

Comment extra spaces to be removed.

Return
MetaData

A MetaData object at the specified HDU index.

MetaData loadMeta (File file, integer hduIndex)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0.

Arguments
File file [INPUT, MANDATORY, default=no default value]

Name of the FITS file

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

Return
MetaData

A MetaData object at the specified HDU index.

MetaData loadMeta (File file, integer hduIndex, integer commentExtraSpacesToRemove)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0.

Arguments
File file [INPUT, MANDATORY, default=no default value]

Name of the FITS file

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

integer commentExtraSpacesToRemove [INPUT, MANDATORY, default=no default value]

Comment extra spaces to be removed.

Return
MetaData

A MetaData object at the specified HDU index.

MetaData loadMeta (InputStream is, integer hduIndex)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0. The user must close the InputStream.

Arguments
InputStream is [INPUT, MANDATORY, default=no default value]

InputStream to the FITS file.

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

Return
MetaData

A MetaData object at the specified HDU index.

MetaData loadMeta (InputStream is, integer hduIndex, integer commentExtraSpacesToRemove)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0. The user must close the InputStream.

Arguments
InputStream is [INPUT, MANDATORY, default=no default value]

InputStream to the FITS file.

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

integer commentExtraSpacesToRemove [INPUT, MANDATORY, default=no default value]

Comment extra spaces to be removed.

Return
MetaData

A MetaData object at the specified HDU index.

MetaData loadMeta (String name, integer hduIndex, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0.

Arguments
String name [INPUT, MANDATORY, default=no default value]

Name of the FITS file

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

boolean handleMissingClasses [INPUT, MANDATORY, default=no default value]

For creating dummy classes when an HCSS class is not found.

Return
MetaData

A MetaData object at the specified HDU index.

MetaData loadMeta (String name, integer hduIndex, integer commentExtraSpacesToRemove, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0.

Arguments
String name [INPUT, MANDATORY, default=no default value]

Name of the FITS file

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

integer commentExtraSpacesToRemove [INPUT, MANDATORY, default=no default value]

Comment extra spaces to be removed.

boolean handleMissingClasses [INPUT, MANDATORY, default=no default value]

For creating dummy classes when an HCSS class is not found.

Return
MetaData

A MetaData object at the specified HDU index.

MetaData loadMeta (File file, integer hduIndex, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0.

Arguments
File file [INPUT, MANDATORY, default=no default value]

Name of the FITS file

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

boolean handleMissingClasses [INPUT, MANDATORY, default=no default value]

For creating dummy classes when an HCSS class is not found.

Return
MetaData

A MetaData object at the specified HDU index.

MetaData loadMeta (File file, integer hduIndex, integer commentExtraSpacesToRemove, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0.

Arguments
File file [INPUT, MANDATORY, default=no default value]

Name of the FITS file

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

integer commentExtraSpacesToRemove [INPUT, MANDATORY, default=no default value]

Comment extra spaces to be removed.

boolean handleMissingClasses [INPUT, MANDATORY, default=no default value]

For creating dummy classes when an HCSS class is not found.

Return
MetaData

A MetaData object at the specified HDU index.

MetaData loadMeta (InputStream is, integer hduIndex, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0. The user must close the InputStream.

Arguments
InputStream is [INPUT, MANDATORY, default=no default value]

InputStream to the FITS file.

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

boolean handleMissingClasses [INPUT, MANDATORY, default=no default value]

For creating dummy classes when an HCSS class is not found.

Return
MetaData

A MetaData object at the specified HDU index.

MetaData loadMeta (InputStream is, integer hduIndex, integer commentExtraSpacesToRemove, boolean handleMissingClasses)

Loads a MetaData object from a FITS file at the specified HDU index.

Loads a MetaData object using the current reader for HDU index 0. Loads a MetaData object using STANDARD_READER for HDU index greater than 0. The user must close the InputStream.

Arguments
InputStream is [INPUT, MANDATORY, default=no default value]

InputStream to the FITS file.

integer hduIndex [INPUT, MANDATORY, default=no default value]

HDU index.

integer commentExtraSpacesToRemove [INPUT, MANDATORY, default=no default value]

Comment extra spaces to be removed.

boolean handleMissingClasses [INPUT, MANDATORY, default=no default value]

For creating dummy classes when an HCSS class is not found.

Return
MetaData

A MetaData object at the specified HDU index.

See also