spv.spectrum.factory
Class AbstractFileFactoryModule

java.lang.Object
  extended by spv.spectrum.factory.AbstractFileFactoryModule
All Implemented Interfaces:
SpectrumFileFactoryModule
Direct Known Subclasses:
ASCIIFactoryModule, Fits2DTableAbstractFactoryModule, Fits3DTableAbstractFactoryModule, ImageAbstractFactoryModule, SDSSFactoryModule, SEDFactoryModule, SEDVOTableFactoryModule, SPCFactoryModule, STIS2DFactoryModule

public abstract class AbstractFileFactoryModule
extends java.lang.Object
implements SpectrumFileFactoryModule

Abstract superclass of all instrument-specific factory modules.

Version:
1.0 - 25Mar02, 1.1 - 21Jun02
Author:
Ivo Busko (Space Telescope Science Institute)

Field Summary
protected static java.lang.String BIN_NUMBER_UNITS
           
protected static java.lang.String C_BACK
           
static java.lang.String C_DATA
           
protected static java.lang.String C_DQ
           
static java.lang.String C_ERROR
           
static java.lang.String C_FLUX
           
protected static java.lang.String C_GROSS
           
protected static java.lang.String C_NELEM
           
protected static java.lang.String C_NET
           
protected static java.lang.String C_SPORDER
           
static java.lang.String C_WAVELENGTH
           
 
Constructor Summary
AbstractFileFactoryModule()
           
 
Method Summary
 void addSSAPParameters(Spectrum sp, SpectrumSpecification ss)
          Adds SSAP parameters to the spectrum meta parameter list.
protected  void buildExtentMetaParameters(Spectrum sp)
          Populate meta parameters with extent values.
protected  void buildLocationMetaParameters(Spectrum sp)
          Populate meta parameters with location values.
protected  SingleSpectrum buildSingleSpectrum(SingleSpectrum sp, java.lang.String name, SpectrumSpecification ss, SpectrumHeader hdr, double[] wave, XUnits waveu, double[] flux, YUnits fluxu, double[] error, YUnits erroru, int[] dq, DQBits dqbits)
          Builds a SingleSpectrum instance.
protected  SingleSpectrum buildSingleSpectrum(SingleSpectrum sp, java.lang.String name, SpectrumSpecification ss, SpectrumHeader hdr, double[] wave, XUnits waveu, java.lang.String wavename, double[] flux, YUnits fluxu, java.lang.String fluxname, double[] error, YUnits erroru, java.lang.String errorname, int[] dq, DQBits dqbits)
          Builds a SingleSpectrum instance.
protected  SingleSpectrum buildSingleSpectrum(SingleSpectrum sp, java.lang.String name, SpectrumSpecification ss, SpectrumHeader hdr, double[] wave, XUnits waveu, java.lang.String wavename, double[] flux, YUnits fluxu, java.lang.String fluxname, double[] error, YUnits erroru, java.lang.String errorname, int[] dq, DQBits dqbits, java.lang.String emptyArrayErrorMessage)
          Builds a SingleSpectrum instance.
protected  void buildSpectralExtentMetaParameter(Spectrum sp)
          Populate meta parameters with spectral extent taken directly from the wavelength array.
protected  void buildTimeExtentMetaParameter(Spectrum sp, java.lang.String keyword)
          Populate meta parameters with time extent.
protected  YUnits fixIntensityUnits(YUnits units)
           
protected  void getGenericMetaParameter(Spectrum sp)
          Populate meta parameters with generic info.
protected  void getInstrumentPositionMetaParameter(Spectrum sp, java.lang.String ra, java.lang.String dec)
          Populate meta parameters with instrument position.
protected  void getPositionMetaParameter(Spectrum sp, java.lang.String ra, java.lang.String dec)
          Populate meta parameters with object position.
protected  void getTimeMetaParameter(Spectrum sp, java.lang.String start, java.lang.String end)
          Populate meta parameters with observation time.
protected  java.lang.String getUnits(nom.tam.fits.TableHDU hdu, java.lang.String colname)
          The JavaFITS library has a kludgy way of retrieving the physical units from a table column.
protected  java.net.URL getURL(java.lang.String filename)
          Returns the URL given a file name.
protected  boolean isFullD(double[] array)
          Returns true if array is not empty.
protected  boolean isFullI(int[] array)
          Returns true if array is not empty.
protected  boolean isTwoD(FitsFileAttributes ffa)
          Checks if a binary table carries arrays, or is a flat 2-D table.
abstract  boolean isValidInstrument(FitsFileAttributes ffa)
          Tests if a file contains spectra from a specific instrument.
abstract  FileDescriptor makeFileDescriptor(java.lang.String filename, nom.tam.fits.Fits fits)
          Creates a FileDescriptor object.
abstract  Spectrum makeSpectrum(SpectrumSpecification ss, nom.tam.fits.Fits fits)
          Creates a Spectrum object.
abstract  SpectrumSpecification makeSpectrumSpecification(java.net.URL url, nom.tam.fits.Fits fits)
          Returns a SpectrumSpecification object of the appropriate sub-type, given a completely specified file name.
protected  void maskAll(Spectrum sp)
          Masks all anomalies in the input spectrum.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

C_FLUX

public static final java.lang.String C_FLUX

C_DATA

public static final java.lang.String C_DATA

C_ERROR

public static final java.lang.String C_ERROR

C_WAVELENGTH

public static final java.lang.String C_WAVELENGTH

C_SPORDER

protected static final java.lang.String C_SPORDER

C_NELEM

protected static final java.lang.String C_NELEM

C_GROSS

protected static final java.lang.String C_GROSS

C_BACK

protected static final java.lang.String C_BACK

C_NET

protected static final java.lang.String C_NET

C_DQ

protected static final java.lang.String C_DQ

BIN_NUMBER_UNITS

protected static final java.lang.String BIN_NUMBER_UNITS
Constructor Detail

AbstractFileFactoryModule

public AbstractFileFactoryModule()
Method Detail

makeSpectrum

public abstract Spectrum makeSpectrum(SpectrumSpecification ss,
                                      nom.tam.fits.Fits fits)
                               throws nom.tam.fits.FitsException,
                                      java.io.IOException,
                                      SpectrumException
Creates a Spectrum object.

Specified by:
makeSpectrum in interface SpectrumFileFactoryModule
Parameters:
ss - the spectrum specification
fits - the associated Fits object, or null if any
Returns:
the spectrum object
Throws:
java.io.IOException
nom.tam.fits.FitsException
SpectrumException

makeSpectrumSpecification

public abstract SpectrumSpecification makeSpectrumSpecification(java.net.URL url,
                                                                nom.tam.fits.Fits fits)
                                                         throws nom.tam.fits.FitsException,
                                                                java.io.IOException
Returns a SpectrumSpecification object of the appropriate sub-type, given a completely specified file name.

Specified by:
makeSpectrumSpecification in interface SpectrumFileFactoryModule
Parameters:
url - the URL with the file name complete will all specifications necessary to locate a valid spectrum, such as FITS extension, row selector, image section, etc.
fits - the associated Fits object, or null if any
Returns:
the SpectrumSpecification object of the appropriate sub-type
Throws:
java.io.IOException
nom.tam.fits.FitsException

makeFileDescriptor

public abstract FileDescriptor makeFileDescriptor(java.lang.String filename,
                                                  nom.tam.fits.Fits fits)
                                           throws nom.tam.fits.FitsException,
                                                  java.io.IOException,
                                                  SpectrumException
Creates a FileDescriptor object. The file name cannot have any constructs such as FITS extension specifiers, row/column selectors or image sections.

Specified by:
makeFileDescriptor in interface SpectrumFileFactoryModule
Parameters:
filename - the file name
fits - the associated Fits object, or null if any
Returns:
the FileDescripto object of the appropriate sub-type
Throws:
java.io.IOException
nom.tam.fits.FitsException
SpectrumException

isValidInstrument

public abstract boolean isValidInstrument(FitsFileAttributes ffa)
                                   throws nom.tam.fits.FitsException,
                                          java.io.IOException
Tests if a file contains spectra from a specific instrument.

Specified by:
isValidInstrument in interface SpectrumFileFactoryModule
Parameters:
ffa - attributes of the FITS file
Returns:
true if the file matches the instrument, false otherwise.
Throws:
nom.tam.fits.FitsException
java.io.IOException

addSSAPParameters

public void addSSAPParameters(Spectrum sp,
                              SpectrumSpecification ss)
Adds SSAP parameters to the spectrum meta parameter list.

Specified by:
addSSAPParameters in interface SpectrumFileFactoryModule
Parameters:
sp - the spectrum to be updated
ss - the spectrum specification holding SSAP parameters

buildSingleSpectrum

protected SingleSpectrum buildSingleSpectrum(SingleSpectrum sp,
                                             java.lang.String name,
                                             SpectrumSpecification ss,
                                             SpectrumHeader hdr,
                                             double[] wave,
                                             XUnits waveu,
                                             double[] flux,
                                             YUnits fluxu,
                                             double[] error,
                                             YUnits erroru,
                                             int[] dq,
                                             DQBits dqbits)
                                      throws SpectrumException
Builds a SingleSpectrum instance. The wavelength and flux array get their standard names.

Parameters:
sp - the empty instance to be built
name - the name
ss - the spectrum specification
hdr - the header
wave - the wavelenth array
waveu - the units associated with the wavelength array
flux - the flux array
fluxu - the units associated with the flux array
error - the error array
erroru - the units associated with the error array
dq - the data quality array
dqbits - the DQBits object associated with the dq array
Returns:
the SingleSpectrum instance
Throws:
SpectrumException

buildSingleSpectrum

protected SingleSpectrum buildSingleSpectrum(SingleSpectrum sp,
                                             java.lang.String name,
                                             SpectrumSpecification ss,
                                             SpectrumHeader hdr,
                                             double[] wave,
                                             XUnits waveu,
                                             java.lang.String wavename,
                                             double[] flux,
                                             YUnits fluxu,
                                             java.lang.String fluxname,
                                             double[] error,
                                             YUnits erroru,
                                             java.lang.String errorname,
                                             int[] dq,
                                             DQBits dqbits)
                                      throws SpectrumException
Builds a SingleSpectrum instance.

Parameters:
sp - the empty instance to be built
name - the spectrum name
ss - the spectrum specification
hdr - the header
wave - the wavelenth array
waveu - the units associated with the wavelength array
wavename - the name of the wavelength array
flux - the flux array
fluxu - the units associated with the flux array
fluxname - the name of the flux array
error - the error array
erroru - the units associated with the error array
errorname - the name of the error array
dq - the data quality array
dqbits - the DQBits object associated with the dq array
Returns:
the SingleSpectrum instance
Throws:
SpectrumException

buildSingleSpectrum

protected SingleSpectrum buildSingleSpectrum(SingleSpectrum sp,
                                             java.lang.String name,
                                             SpectrumSpecification ss,
                                             SpectrumHeader hdr,
                                             double[] wave,
                                             XUnits waveu,
                                             java.lang.String wavename,
                                             double[] flux,
                                             YUnits fluxu,
                                             java.lang.String fluxname,
                                             double[] error,
                                             YUnits erroru,
                                             java.lang.String errorname,
                                             int[] dq,
                                             DQBits dqbits,
                                             java.lang.String emptyArrayErrorMessage)
                                      throws SpectrumException
Builds a SingleSpectrum instance.

This method includes a check for very long spectra. With more than 20,000 or so data points, plotting becomes painfully slow (bug in GeneralPath Java2D class). This method inserts data break points in the input arrays in case the input arrays exceed a given size.

Parameters:
sp - the empty instance to be built
name - the spectrum name
ss - the spectrum specification
hdr - the header
wave - the wavelenth array
waveu - the units associated with the wavelength array
wavename - the name of the wavelength array
flux - the flux array
fluxu - the units associated with the flux array
fluxname - the name of the flux array
error - the error array
erroru - the units associated with the error array
errorname - the name of the error array
dq - the data quality array
dqbits - the DQBits object associated with the dq array
emptyArrayErrorMessage - error message for empty ydata array condition
Returns:
the SingleSpectrum instance
Throws:
SpectrumException

fixIntensityUnits

protected YUnits fixIntensityUnits(YUnits units)

getUnits

protected java.lang.String getUnits(nom.tam.fits.TableHDU hdu,
                                    java.lang.String colname)
The JavaFITS library has a kludgy way of retrieving the physical units from a table column. This method is basicaly a capsule to hide the nastiness away. Why not provide a plain getUnits method ?

Parameters:
hdu - the HDU that contains the table
colname - the column name
Returns:
the units associated with the given column. If no columnn is found, returns the "UNITLESS" string.

isFullD

protected boolean isFullD(double[] array)
Returns true if array is not empty. Empty array is signaled by all its elements having the same stored value.

Returns:
true if array is not empty

isFullI

protected boolean isFullI(int[] array)
Returns true if array is not empty. Empty array is signaled by all its elements having the same stored value.

Returns:
true if array is not empty

getURL

protected java.net.URL getURL(java.lang.String filename)
Returns the URL given a file name.

Parameters:
filename - the file name
Returns:
the URL

maskAll

protected void maskAll(Spectrum sp)
Masks all anomalies in the input spectrum.

Parameters:
sp - the spectrum to be masked

isTwoD

protected boolean isTwoD(FitsFileAttributes ffa)
                  throws nom.tam.fits.FitsException,
                         java.io.IOException
Checks if a binary table carries arrays, or is a flat 2-D table.

Parameters:
ffa - the file attributes object
Returns:
true if no array columns exist
Throws:
nom.tam.fits.FitsException
java.io.IOException

getGenericMetaParameter

protected void getGenericMetaParameter(Spectrum sp)
Populate meta parameters with generic info.

Parameters:
sp - spectrum whose meta parameters are to be updated

getPositionMetaParameter

protected void getPositionMetaParameter(Spectrum sp,
                                        java.lang.String ra,
                                        java.lang.String dec)
Populate meta parameters with object position.

This method populates both the nominal and the instrument positions. Subclasses should call explictly method getInstrumentPositionMetaParameter if different header keywords are used for each one.

Parameters:
sp - spectrum whose meta parameters are to be updated
ra - R.A. keyword in header
dec - DEC keyword in header

getInstrumentPositionMetaParameter

protected void getInstrumentPositionMetaParameter(Spectrum sp,
                                                  java.lang.String ra,
                                                  java.lang.String dec)
Populate meta parameters with instrument position.

Parameters:
sp - spectrum whose meta parameters are to be updated
ra - R.A. keyword in header
dec - DEC keyword in header

getTimeMetaParameter

protected void getTimeMetaParameter(Spectrum sp,
                                    java.lang.String start,
                                    java.lang.String end)
Populate meta parameters with observation time.

Parameters:
sp - the spectrum whose meta parameters are to be updated
start - the header keyword with start time
end - the header keyword with end time

buildSpectralExtentMetaParameter

protected void buildSpectralExtentMetaParameter(Spectrum sp)
Populate meta parameters with spectral extent taken directly from the wavelength array.

Parameters:
sp - the spectrum whose meta parameters are to be updated

buildTimeExtentMetaParameter

protected void buildTimeExtentMetaParameter(Spectrum sp,
                                            java.lang.String keyword)
Populate meta parameters with time extent.

Parameters:
sp - the spectrum whose meta parameters are to be updated
keyword - the header keyword with the exposure time

buildLocationMetaParameters

protected void buildLocationMetaParameters(Spectrum sp)
Populate meta parameters with location values.

Parameters:
sp - the spectrum whose meta parameters are to be updated

buildExtentMetaParameters

protected void buildExtentMetaParameters(Spectrum sp)
Populate meta parameters with extent values.

Parameters:
sp - the spectrum whose meta parameters are to be updated