ui.model
Class Spectra

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<DataCoordinate>
              extended by ui.model.Spectra
All Implemented Interfaces:
Serializable, Cloneable, Iterable<DataCoordinate>, Collection<DataCoordinate>, List<DataCoordinate>, RandomAccess

public class Spectra
extends ArrayList<DataCoordinate>

A Spectra is a kind of data model which contains a list of DataCoordinates which could represent intensity versus wavelength. This list can represents a continuous spectrum or a discrete line list such as atomic transitions. A spectra can be contrusted from a pre-existing list of datacoordinates or from a file. There are several methods which can return the minimum and maximum values of wavelength and intensity. The wavelength unit is a number by which the DataCoordinate wavelength value is multiplied; it can be chosen among a small list of predifined units or can be chosen by the user.

Author:
John Talbot
See Also:
Serialized Form

Field Summary
static String ATTRIBUTE_NAME
          The spectra attribute for the object's name (should use FITS header conventions for these)
static String ATTRIBUTE_WAVELENGTH_UNIT
          The spectra attribute for the object's name (should use FITS header conventions for these)
protected  HashMap attributes
           
protected  Calibration calibration
           
protected  char commentChar
           
protected  double[] continuum
          The polynomial fit coefficients to the continuum
protected  boolean continuumFitted
          An internal flag which indicates that the coefficients to continuum polynomial need to be computed.
protected  double maxX
           
protected  double maxY
           
protected  double minX
           
protected  double minY
           
protected  char separator
           
protected  boolean uniformSampling
           
protected  double wavelengthUnit
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Spectra(DataCoordinate[] aData, double aWavelengthUnit)
          Create a spectra using an array of DataCoordinate instances of the specified wavelength unit.
Spectra(double aWavelengthUnit)
          Create a blank spectra with the specified wavelength unit.
Spectra(File aFile)
          Create a spectra by loading a file.
Spectra(File aFile, double aWavelengthUnit)
          Create a spectra by loading file with the specified wavelength unit.
Spectra(List<DataCoordinate> aData, double aWavelengthUnit)
          Create a spectra using a list of DataCoordinate instances with the specified wavelength unit.
Spectra(Spectra aSpectra)
          Create a spectra using another spectra (copy constructor).
Spectra(String aFileName)
          Create a spectra by loading file with the specified file name.
 
Method Summary
 void append(Spectra aSpectra)
          Append the contents of given spectra to this spectra.
 void append(Spectra aSpectra, double aScale)
          Append the contents of given spectra to this spectra.
protected  double[] fitPolynomial()
           
 Object getAttribute(Object aKey)
          Get a spectra attribute using a key.
 Object[] getAttributeKeys()
          Get all the attribute keys.
 Calibration getCalibration()
          Get the calibration for this spectra, required when wavelength to pixel/point conversion is required
 char getCommentChar()
          Get the comment character which indicates a comment line to be ignored.
 double getContinuum(double aWavelength)
          Get the continuum of the spectra, obtained by fitting a polynomial to the regions of the spectra without emission lines.
 DataCoordinate getDataCoordinate(int anIndex)
          Get the data coordinate for a given index in the spectra array.
 double getIntensity(double aWavelength)
          Get the spectra intensity given an arbitrary wavelength, interpolate if necessary.
 double getIntensity(int position)
          Get the spectra intensity at the given integer position.
 double getIntensityMinusContinuum(double aWavelength)
          Get the intensity minus the continuum.
 DataCoordinate getScaledDataCoordinate(int anIndex)
          Get the data coordinate scaled to unit intensity for a given index in the spectra array and with the wavelength in meters.
 char getSeparator()
          Get the separator character used between the wavelength and the intensity in the the spectra file.
 double getWavelength(int position)
          Get the spectra wavelength at the given integer position.
protected  double interpolate(int point1, int point2, double aWavelength)
          Interpolate linearly the intensity at a specified wavelength position between two data points.
 boolean isUniformSampling()
          Is the wavelength sampling interval uniform.
 void load(File aFile)
          Load the spectra from a file and interpret the wavelength using the wavelengthUnit.
 void save(File aFile)
          Save the spectra as a file with properties encoded as comments.
 void scale(double wavelengthScale, double intensityScale)
          Scale the spectra wavelength and intensity by the given factors.
 void scaleIntensity(double aScale)
          Scale the spectra intensity by the given factor.
 void scaleWavelength(double aScale)
          Scale the spectra wavelength by the given factor.
 void setAttribute(Object aKey, Object aValue)
          Set an attribute using a key and its corresponding value.
 void setCalibration(Calibration aCalibration)
          Set the calibration for this spectra, required when wavelength to pixel/point conversion is required
 void setCommentChar(char aCommentChar)
          Set the comment character which indicates a comment line to be ignored.
 void setSeparator(char aSeparator)
          Set the separator character used between the wavelength and the intensity in the the spectra file.
 void setUniformSampling(boolean aUniformSampling)
           
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Field Detail

ATTRIBUTE_NAME

public static final String ATTRIBUTE_NAME
The spectra attribute for the object's name (should use FITS header conventions for these)

See Also:
Constant Field Values

ATTRIBUTE_WAVELENGTH_UNIT

public static final String ATTRIBUTE_WAVELENGTH_UNIT
The spectra attribute for the object's name (should use FITS header conventions for these)

See Also:
Constant Field Values

separator

protected char separator

commentChar

protected char commentChar

minX

protected double minX

maxX

protected double maxX

minY

protected double minY

maxY

protected double maxY

calibration

protected Calibration calibration

wavelengthUnit

protected double wavelengthUnit

uniformSampling

protected boolean uniformSampling

attributes

protected HashMap attributes

continuumFitted

protected boolean continuumFitted
An internal flag which indicates that the coefficients to continuum polynomial need to be computed.


continuum

protected double[] continuum
The polynomial fit coefficients to the continuum

Constructor Detail

Spectra

public Spectra(String aFileName)
Create a spectra by loading file with the specified file name.

Parameters:
aFileName - a file name pointing to file containing the spectra data

Spectra

public Spectra(File aFile)
Create a spectra by loading a file.

Parameters:
aFile - a file containing the spectra data

Spectra

public Spectra(File aFile,
               double aWavelengthUnit)
Create a spectra by loading file with the specified wavelength unit.

Parameters:
aFile - a file containing the spectra data
aWavelengthUnit - the wavelength unit, all x coordinates in the data will be multipled by this number.

Spectra

public Spectra(DataCoordinate[] aData,
               double aWavelengthUnit)
Create a spectra using an array of DataCoordinate instances of the specified wavelength unit.

Parameters:
aData - an array of data coordinates representing spectra points
aWavelengthUnit - the wavelength unit, all x coordinates in the data will be multipled by this number.

Spectra

public Spectra(List<DataCoordinate> aData,
               double aWavelengthUnit)
Create a spectra using a list of DataCoordinate instances with the specified wavelength unit.

Parameters:
aData - an ordered collection of data coordinates representing spectra points
aWavelengthUnit - the wavelength unit, all x coordinates in the data will be multipled by this number.

Spectra

public Spectra(double aWavelengthUnit)
Create a blank spectra with the specified wavelength unit. DataCoordinates can be added later by using the add() method.

Parameters:
aWavelengthUnit - the wavelength unit, all x coordinates in the data will be multipled by this number.

Spectra

public Spectra(Spectra aSpectra)
Create a spectra using another spectra (copy constructor).

Parameters:
aSpectra - a spectra to be cloned
Method Detail

load

public void load(File aFile)
Load the spectra from a file and interpret the wavelength using the wavelengthUnit.

Parameters:
aFile - a file containing xy pairs, one per line, x and y separatated by a space

save

public void save(File aFile)
Save the spectra as a file with properties encoded as comments.

Parameters:
aFile - a file in which xy pairs will be added, one per line, x and y separatated by a space

append

public void append(Spectra aSpectra)
Append the contents of given spectra to this spectra. If regions overlap then the new spectra will replace the old. The added spectra does not have to be sequential, it come before this spectra. A future version of this method could optionally scale the source spectra to more smoothly 'sew' the two spectra together in the overlap region. A future version of this method could contain a scaling value if the other spectra differs in vertical scale.

Parameters:
aSpectra - a spectra which will be appended to this spectra

append

public void append(Spectra aSpectra,
                   double aScale)
Append the contents of given spectra to this spectra. If regions overlap then the new spectra will replace the old. The added spectra does not have to be sequential, it come before this spectra. A future version of this method could optionally scale the source spectra to more smoothly 'sew' the two spectra together in the overlap region.

Parameters:
aSpectra - a spectra which will be appended to this spectra
aScale - a scaling value to be used if the other spectra differs in vertical scale.

scaleIntensity

public void scaleIntensity(double aScale)
Scale the spectra intensity by the given factor.

Parameters:
aScale - a scale factor to multiply the spectra intensity values.

scaleWavelength

public void scaleWavelength(double aScale)
Scale the spectra wavelength by the given factor.

Parameters:
aScale - a scale factor to multiply the spectra wavelength values.

scale

public void scale(double wavelengthScale,
                  double intensityScale)
Scale the spectra wavelength and intensity by the given factors.

Parameters:
wavelengthScale - a scale factor to multiply the spectra wavelength values.
intensityScale - a scale factor to multiply the spectra intensity values.

getWavelength

public double getWavelength(int position)
Get the spectra wavelength at the given integer position.

Parameters:
position - the integer position at which to obtain the wavelength

getIntensity

public double getIntensity(int position)
Get the spectra intensity at the given integer position.

Parameters:
position - the integer position at which to obtain the intensity

getIntensity

public double getIntensity(double aWavelength)
Get the spectra intensity given an arbitrary wavelength, interpolate if necessary.

Parameters:
aWavelength - the wavelength position at which the intensity is obtained

interpolate

protected double interpolate(int point1,
                             int point2,
                             double aWavelength)
Interpolate linearly the intensity at a specified wavelength position between two data points. Preconditions: (1) The separation between points 1 and 2 must be greater than or equal to 1. (2) The wavelength must lie within the interval

Parameters:
point1 - integer representing the first point
point2 - integer representing the second point
aWavelength -

getIntensityMinusContinuum

public double getIntensityMinusContinuum(double aWavelength)
Get the intensity minus the continuum. The spectra is obtained by substracting a polynomical which approximate the average continuum. This creates a flattened spectrum in wich emission lines dominate.

Parameters:
aWavelength -

getContinuum

public double getContinuum(double aWavelength)
Get the continuum of the spectra, obtained by fitting a polynomial to the regions of the spectra without emission lines.

Parameters:
aWavelength -

fitPolynomial

protected double[] fitPolynomial()

getDataCoordinate

public DataCoordinate getDataCoordinate(int anIndex)
Get the data coordinate for a given index in the spectra array.

Parameters:
anIndex - the position in the spectral point array

getScaledDataCoordinate

public DataCoordinate getScaledDataCoordinate(int anIndex)
Get the data coordinate scaled to unit intensity for a given index in the spectra array and with the wavelength in meters. The units are obtained from the calibration object in this spectra.

Parameters:
anIndex - the position in the spectral point array

getCalibration

public Calibration getCalibration()
Get the calibration for this spectra, required when wavelength to pixel/point conversion is required


setCalibration

public void setCalibration(Calibration aCalibration)
Set the calibration for this spectra, required when wavelength to pixel/point conversion is required

Parameters:
aCalibration - a calibration object

getSeparator

public char getSeparator()
Get the separator character used between the wavelength and the intensity in the the spectra file.

Returns:
a character used to separate the wavelength and intensity

setSeparator

public void setSeparator(char aSeparator)
Set the separator character used between the wavelength and the intensity in the the spectra file.

Parameters:
aSeparator - a character used to separate the wavelength and intensity

getCommentChar

public char getCommentChar()
Get the comment character which indicates a comment line to be ignored. A future option could be to parse comment lines for FITS headers.

Returns:
a character used to mark a comment line

setCommentChar

public void setCommentChar(char aCommentChar)
Set the comment character which indicates a comment line to be ignored.

Parameters:
aCommentChar - a character used to mark a comment line

getAttributeKeys

public Object[] getAttributeKeys()
Get all the attribute keys.

Returns:
an array or keys one for each attribute

getAttribute

public Object getAttribute(Object aKey)
Get a spectra attribute using a key.

Parameters:
aKey - an object representing a key
Returns:
an object which represents the value corresponding to the key

setAttribute

public void setAttribute(Object aKey,
                         Object aValue)
Set an attribute using a key and its corresponding value.

Parameters:
aKey - an object representing a key
aValue - an object which represents the value corresponding to the key

isUniformSampling

public boolean isUniformSampling()
Is the wavelength sampling interval uniform. This should be automatically detected from the data file by substracting subsequent wavelength samples and determining that their separation is the same throughout the spectra.


setUniformSampling

public void setUniformSampling(boolean aUniformSampling)