jsky.science
Class Wavelength1DArray

java.lang.Object
  extended by jsky.science.AbstractScienceObject
      extended by jsky.science.AbstractScienceObjectNode
          extended by jsky.science.AbstractWavelength1D
              extended by jsky.science.Wavelength1DArray
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, java.util.EventListener, ScienceObjectModel, ScienceObjectNodeModel, Wavelength1DModel, ReplaceablePropertyChangeListener
Direct Known Subclasses:
Spectrum1DArray

public class Wavelength1DArray
extends AbstractWavelength1D

Implements the Wavelength1DModel as a pair of arrays one containing wavelength points and the other containing data values at each of those wavelengths. This model uses the Wavelength class for management of Wavelength units, but makes no assumptions about the units of the data values.

It anticipates (but does not currently require) that the wavelength data is monotonically increasing. It does NOT assume that the wavelength points are equi-distant.

This class also works with the FITS routines to read from a FITS formatted file.

This code was developed by NASA, Goddard Space Flight Center, Code 588 for the Scientist's Expert Assistant (SEA) project for Next Generation Space Telescope (NGST).

Version:
07.16.00
Author:
Sandy Grosvenor
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class jsky.science.AbstractScienceObject
AbstractScienceObject.EventMonitor
 
Field Summary
static java.lang.String DATA_PROPERTY
           
 
Fields inherited from class jsky.science.AbstractWavelength1D
fFluxUnits, MAXWAVELENGTH_PROPERTY, MINWAVELENGTH_PROPERTY, NUMPOINTS_PROPERTY
 
Fields inherited from class jsky.science.AbstractScienceObjectNode
cloneIndent
 
Fields inherited from interface jsky.science.ScienceObjectNodeModel
DATA_SOURCE_PROPERTY, MORE_DATA_PROPERTY
 
Fields inherited from interface jsky.science.ScienceObjectModel
NAME_PROPERTY, PENDING_PROPERTY, VALID_PROPERTY
 
Constructor Summary
  Wavelength1DArray()
          Creates a new Wavelength1DArray with no Name, 100 data points, and 100-1100 Nanometers range.
  Wavelength1DArray(int inVal)
          Creates new Wavelenth1DArray of specified number of points and default range (100-1100 Nanometers).
  Wavelength1DArray(java.lang.String inName)
          Creates a new Wavelength1DArray with the specified Name, 100 data points, and 100-1100 Nanometers range.
protected Wavelength1DArray(java.lang.String inProp, double wLo, double wHi, int inPts)
          Creates a new Wavelength1DArray with no name, specified number of points, and specified minimum and maximum wavelength values in the curent default Wavelength units.
  Wavelength1DArray(java.lang.String inProp, Wavelength inMin, Wavelength inMax, int inPts)
          Creates a new Wavelength1DArray with no name, specified number of points, and specified minimum and maximum Wavelength range.
  Wavelength1DArray(Wavelength1DModel baseModel)
          Creates a new Wavelength1DArray from an existing Wavelength1DModel.
  Wavelength1DArray(Wavelength inMin, Wavelength inMax, int inPts)
          Creates a new Wavelength1DArray with no name, specified number of points, and specified minimum and maximum wavelength range.
 
Method Summary
 void add(Wavelength1DModel that)
          Adds the specified dataset to this dataset, converting the specified dataset to use existing wavelength points, then adds them to current data.
 void alignData(Wavelength1DModel baseDs)
          Resets the length and wavelength elements to match the input Wavelength1DArray uses the getData() method to interpolate between old wavelength values and new wavelength values
 java.lang.Object clone()
          Clones this object, and does a DEEP clone on the fChildren.
 void combineData(Wavelength1DModel baseDs, int nPts)
          Used to reduce the number of data points.
 boolean equals(java.lang.Object obj)
          Adds equals() checks on the object's DataSources and Children
 double getArea(Wavelength minWl, Wavelength maxWl, boolean interpolate)
          Returns the area "under the curve" of the model from the specified minimum to maximum wavelengths.
 int getIndexOf(double targetWL)
          Returns the 1st index in the dataset to have a wavelength greater/equal to specified wavelength.
 int getIndexOf(Wavelength targetWL)
          Returns the 1st index in the dataset to have a wavelength greater/equal to specified wavelength.
 int getNumPoints()
          Returns the number of points in the array
protected  double getValue(double targetWl)
          Returns the data value at a wavelength specified as a double.
 double getValue(Wavelength inWl)
          Returns the data value at the specified Wavelength.
 double getValueAtIndex(int index)
          Returns the data value at the specified index
 Wavelength getWavelengthAtIndex(int index)
          Returns the wavelength data value for specified index as a Wavelength
 double getWavelengthAtIndexAsDouble(int index)
          Returns the wavelength data value for specified index as a double value in the current default wavelength units
 java.lang.String getWavelengthUnits()
          Returns the units at which the wavelength double values are currently stored
 void mergeData(Wavelength1DModel inDS)
          Folds all inDS point values into this dataset, checking each wavelength in inDS and add the data value to the appropriate location in this dataset.
 void multiply(double m)
          Multiplies every element in the array by the parameter
 void parse(java.io.InputStream istr)
          Deprecated. use Wavelength1DArrayParser.parse instead
 void parse(java.io.InputStream istr, java.lang.String wlUnits)
          Deprecated. use Wavelength1DArrayParser.parse instead
 void parse(java.io.Reader rdr)
          Deprecated. use Wavelength1DArrayParser.parse instead
 void parseAscii(java.io.Reader rdr, java.lang.String wlUnits)
          Deprecated. use Wavelength1DArrayParser.parse instead
 void parseFits(java.io.InputStream istr, java.lang.String wlColName, java.lang.String wlUnits, java.lang.String dataColName, java.lang.String dataUnits)
          Deprecated. use Wavelength1DArrayParser.parse instead
 void replaceDataSet(Wavelength1DArray newData)
          Replaces the data arrays with the inbound dataset protected so that only descendents can do this, no checking for units or other protections exist
 void setAllNaN()
          Sets all datapoints data and wavelength to Double.NaN.
 void setAllNaN(boolean dataOnly)
          Sets all datapoints to Double.NaN.
 void setFluxUnits(java.lang.String units)
          a DUMMY implementation: Saves the string but does NOTHING with it.
 void setNumPoints(int newP)
          Changes the length of the dataset, with a new total length, preserves the old data truncate the end if new number of points is less than current or filling with zeros if the new number is more than the current.
 void setPending(boolean b)
          Overriding to public access
 void setValue(Wavelength wavelength, double value)
          Sets the data value at the specified Wavelength in the array.
 void setValueAtIndex(int index, double inVal)
          Changes the stored data value at the specified index
 void setWavelengthAtIndex(int index, double inWL)
          Sets the wavelength value for specified index as a double in the current default Wavelength units.
 void setWavelengthAtIndex(int index, Wavelength inWL)
          Sets the Wavelength value for specified index.
 double[] toArrayData()
          Returns the current data points array
 double[] toArrayData(double[] wllist)
          Returns an array of data points for the specifed set of wavelengths
protected  double[] toArrayData(double minwl, double maxwl, int nPts)
          Returns a set of data values to match the requested range of wavelengths in doubles.
 double[] toArrayData(Wavelength minW, Wavelength maxW, int nPts)
          Returns a set of data values to match the requested range of wavelengths in Wavelengths
 double[] toArrayWavelengths()
          Returns the entire array of wavelength data points
protected  double[] toArrayWavelengths(double minwl, double maxwl, int nPts)
          Returns an array of wavelength datapoints.
 double[] toArrayWavelengths(Wavelength minW, Wavelength maxW, int nPts, java.lang.String units)
          Returns a subset of the array wavelengths with parameters specified as Wavelengths
 void trim()
          Trims off zero value datapoints and the beginning or end of the wavelength
 
Methods inherited from class jsky.science.AbstractWavelength1D
calcArea, calculateArea, getArea, getArea, getArea, getFluxUnits, getIndexOf, getIndexOf, getIndexOf, getIndexOf, isEditable, toArrayWavelengths
 
Methods inherited from class jsky.science.AbstractScienceObjectNode
addChild, getChildren, getDataSource, indexOfChild, initializeTransients, isHolding, isMoreDataAvailable, isPending, isUpToDate, isValid, namedClone, processUpdates, removeAllChildren, removeChild, repeat, replaceChild, replaceObject, requestMoreData, retrieveMoreData, saveAsText, saveAsText, setDataSource, setHolding, setMoreDataAvailable, setTracing, setUpdatesPending, update
 
Methods inherited from class jsky.science.AbstractScienceObject
addEventMonitor, addPropertyChangeListener, areNamesEqual, clearAllListeners, compareTo, createDefaultName, firePropertyChange, firePropertyChange, fireReplaceObject, fireReplaceObject, fireReplaceObject, fireVetoableChange, fireVetoableChange, getException, getLabel, getName, getObjectIdString, getObjectIdString, getParent, isTracing, notifyEventMonitors, propertyChange, removeEventMonitor, removePropertyChangeListener, replaceObjectNYI, setException, setName, setParent, setTraceAll, toString, writeDebug, writeError
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jsky.science.Wavelength1DModel
addPropertyChangeListener, removePropertyChangeListener
 
Methods inherited from interface jsky.science.ScienceObjectNodeModel
addChild, getChildren, getDataSource, isMoreDataAvailable, isPending, removeAllChildren, removeChild, replaceChild, requestMoreData, retrieveMoreData, setDataSource, setMoreDataAvailable
 
Methods inherited from interface jsky.science.ScienceObjectModel
clearAllListeners, firePropertyChange, getException, getLabel, getName, getParent, isHolding, isTracing, isValid, setException, setHolding, setName, setParent, setTracing
 
Methods inherited from interface jsky.util.ReplaceablePropertyChangeListener
replaceObject
 
Methods inherited from interface java.beans.PropertyChangeListener
propertyChange
 

Field Detail

DATA_PROPERTY

public static final java.lang.String DATA_PROPERTY
See Also:
Constant Field Values
Constructor Detail

Wavelength1DArray

public Wavelength1DArray()
Creates a new Wavelength1DArray with no Name, 100 data points, and 100-1100 Nanometers range.


Wavelength1DArray

public Wavelength1DArray(int inVal)
Creates new Wavelenth1DArray of specified number of points and default range (100-1100 Nanometers).

Parameters:
inVal - integer of number of desired points in dataset

Wavelength1DArray

public Wavelength1DArray(java.lang.String inName)
Creates a new Wavelength1DArray with the specified Name, 100 data points, and 100-1100 Nanometers range.


Wavelength1DArray

public Wavelength1DArray(Wavelength inMin,
                         Wavelength inMax,
                         int inPts)
Creates a new Wavelength1DArray with no name, specified number of points, and specified minimum and maximum wavelength range.

Parameters:
inMin - Minimum Wavelength for the dataset
inMax - Maximum Wavelength for the dataset
inPts - number of points in the dataset

Wavelength1DArray

public Wavelength1DArray(Wavelength1DModel baseModel)
Creates a new Wavelength1DArray from an existing Wavelength1DModel.


Wavelength1DArray

public Wavelength1DArray(java.lang.String inProp,
                         Wavelength inMin,
                         Wavelength inMax,
                         int inPts)
Creates a new Wavelength1DArray with no name, specified number of points, and specified minimum and maximum Wavelength range. The min/max wavelengths are specified as Wavelength objects.

Parameters:
inProp - name for the array
inMin - Minimum Wavelength for the dataset
inMax - Maximum Wavelength for the dataset
inPts - number of points in the dataset

Wavelength1DArray

protected Wavelength1DArray(java.lang.String inProp,
                            double wLo,
                            double wHi,
                            int inPts)
Creates a new Wavelength1DArray with no name, specified number of points, and specified minimum and maximum wavelength values in the curent default Wavelength units.

Parameters:
inProp - name for the array
wLo - Minimum wavelength value in default units for the dataset
wHi - Maximum wavelength value in default units for the dataset
inPts - number of points in the dataset
Method Detail

equals

public boolean equals(java.lang.Object obj)
Description copied from class: AbstractScienceObjectNode
Adds equals() checks on the object's DataSources and Children

Overrides:
equals in class AbstractScienceObjectNode

setPending

public void setPending(boolean b)
Overriding to public access

Overrides:
setPending in class AbstractScienceObjectNode

setWavelengthAtIndex

public void setWavelengthAtIndex(int index,
                                 Wavelength inWL)
Sets the Wavelength value for specified index.

Parameters:
index - index in the array for the new wavelength point
inWL - for the wavelength as a Wavelength

setWavelengthAtIndex

public void setWavelengthAtIndex(int index,
                                 double inWL)
Sets the wavelength value for specified index as a double in the current default Wavelength units.

Parameters:
index - index in the array for the new wavelength point
inWL - for the wavelength as a double in the current default Wavelength units

getArea

public double getArea(Wavelength minWl,
                      Wavelength maxWl,
                      boolean interpolate)
Returns the area "under the curve" of the model from the specified minimum to maximum wavelengths. If min or max is outside a defined wl area, then 0 values are assumed

Specified by:
getArea in interface Wavelength1DModel
Overrides:
getArea in class AbstractWavelength1D
Parameters:
minWl - the starting wavelength for area
maxWl - the maximum wavelength for calculations.
interpolate - When true, the data points are treated as points on a curve and the area calculation uses linear interpolation between points. When false, the data points are treated as "bins" with no interpolation between points.

This method may be overridden by subclasses (such as Wavelength1DArray) to create a more efficient array of wavelengths and data values to pass to the main calculateArea() method


toArrayWavelengths

public double[] toArrayWavelengths()
Returns the entire array of wavelength data points


toArrayWavelengths

public double[] toArrayWavelengths(Wavelength minW,
                                   Wavelength maxW,
                                   int nPts,
                                   java.lang.String units)
Returns a subset of the array wavelengths with parameters specified as Wavelengths


toArrayWavelengths

protected double[] toArrayWavelengths(double minwl,
                                      double maxwl,
                                      int nPts)
Returns an array of wavelength datapoints. Overridden here to return a subset of the existing wavelength points if possible rather than new set of points.

To return a subset, the min and max wavelength must match existing data points and the number of requested points must either be 0 or match the number of points in the existing wavelength subset.

If the min and max wavelengths do not match existing points or the number of points does not match, then a new array of wavelengths is return from min to max specified wavelengths and equal increments to provide for the specified number of points


toArrayData

public double[] toArrayData(double[] wllist)
Returns an array of data points for the specifed set of wavelengths

Specified by:
toArrayData in interface Wavelength1DModel
Overrides:
toArrayData in class AbstractWavelength1D

toArrayData

public double[] toArrayData()
Returns the current data points array


toArrayData

public double[] toArrayData(Wavelength minW,
                            Wavelength maxW,
                            int nPts)
Returns a set of data values to match the requested range of wavelengths in Wavelengths


toArrayData

protected double[] toArrayData(double minwl,
                               double maxwl,
                               int nPts)
Returns a set of data values to match the requested range of wavelengths in doubles. The precise sub wavelengths used is obtained from the toArrayWavelengths( double minwl, double maxwl, int npts) results


replaceDataSet

public void replaceDataSet(Wavelength1DArray newData)
Replaces the data arrays with the inbound dataset protected so that only descendents can do this, no checking for units or other protections exist


getWavelengthAtIndex

public Wavelength getWavelengthAtIndex(int index)
Returns the wavelength data value for specified index as a Wavelength


getWavelengthAtIndexAsDouble

public double getWavelengthAtIndexAsDouble(int index)
Returns the wavelength data value for specified index as a double value in the current default wavelength units


getWavelengthUnits

public java.lang.String getWavelengthUnits()
Returns the units at which the wavelength double values are currently stored


getIndexOf

public int getIndexOf(double targetWL)
Returns the 1st index in the dataset to have a wavelength greater/equal to specified wavelength.

Parameters:
targetWL - is a double of the wavelength in the default units of the dataset search is done on a binary basis for efficiency

getIndexOf

public int getIndexOf(Wavelength targetWL)
Returns the 1st index in the dataset to have a wavelength greater/equal to specified wavelength.

Parameters:
targetWL - is a double of the wavelength in the default units of the dataset search is done on a binary basis for efficiency

setValue

public void setValue(Wavelength wavelength,
                     double value)
Sets the data value at the specified Wavelength in the array. If the exact wavelength does not exist, and new value is inserted into the list.

Specified by:
setValue in interface Wavelength1DModel
Overrides:
setValue in class AbstractWavelength1D

setValueAtIndex

public void setValueAtIndex(int index,
                            double inVal)
Changes the stored data value at the specified index


getValueAtIndex

public double getValueAtIndex(int index)
Returns the data value at the specified index


clone

public java.lang.Object clone()
Description copied from class: AbstractScienceObjectNode
Clones this object, and does a DEEP clone on the fChildren.

NOTE: for subclasses! If a subclass has a separate variable or list that points at fChildren, remember that after this clone() method is completed all fChildren will have also been cloned.

So subclasses may need to "repoint" variables or elemenets of lists that reference child objects, but should NOT re-clone those children.

See ExposureGroup.clone() and Exposure.clone() as examples of classes that need to re-proint existing pointers to correctly point at the correct elements.

Specified by:
clone in interface ScienceObjectModel
Overrides:
clone in class AbstractScienceObjectNode

getValue

public double getValue(Wavelength inWl)
Returns the data value at the specified Wavelength. If the wavelength is not a specific point in the array, then the value is interpolated based on the previous and subsequent wavelengths in the array


getValue

protected double getValue(double targetWl)
Returns the data value at a wavelength specified as a double. If the wavelength is not a specific point in the array, then the value is interpolated based on the previous and subsequent wavelengths in the array


setAllNaN

public void setAllNaN(boolean dataOnly)
Sets all datapoints to Double.NaN.

Parameters:
dataOnly - boolean, if true the wavelengths will be left untouched only the data will be made Double.NaN

setAllNaN

public void setAllNaN()
Sets all datapoints data and wavelength to Double.NaN.


add

public void add(Wavelength1DModel that)
Adds the specified dataset to this dataset, converting the specified dataset to use existing wavelength points, then adds them to current data.

also ASSUMES that wavelength and data units are the same, no checking is done Note: Use the mergeData() method instead if the specified dataset has different wavelengths and you want use the specified dataset's wavelength to determine where to add the corresponding data value.


mergeData

public void mergeData(Wavelength1DModel inDS)
Folds all inDS point values into this dataset, checking each wavelength in inDS and add the data value to the appropriate location in this dataset.

ASSUMES that the data units are the same -- no checking is done. Note: Use the add() method if you're adding a dataset that has same wavelengths as this dataset or if you just want to add each data value directly to this dataset's data value without checking for the wavelengths.


combineData

public void combineData(Wavelength1DModel baseDs,
                        int nPts)
Used to reduce the number of data points. Every nPts will be aggregated to a single point in the new dataset. Wavelength for each new point is the "left most" wavelength of points aggregated together


alignData

public void alignData(Wavelength1DModel baseDs)
Resets the length and wavelength elements to match the input Wavelength1DArray uses the getData() method to interpolate between old wavelength values and new wavelength values


trim

public void trim()
Trims off zero value datapoints and the beginning or end of the wavelength


setNumPoints

public void setNumPoints(int newP)
Changes the length of the dataset, with a new total length, preserves the old data truncate the end if new number of points is less than current or filling with zeros if the new number is more than the current.

Parameters:
newP - the new number of points

getNumPoints

public int getNumPoints()
Returns the number of points in the array


multiply

public void multiply(double m)
Multiplies every element in the array by the parameter


parse

public void parse(java.io.InputStream istr)
           throws WavelengthArrayParseException
Deprecated. use Wavelength1DArrayParser.parse instead

Passes a null String as the units to parse( StringReader, String), causing Angstroms to be the assumed wavelength units

Parameters:
istr - an InputStream to the data to be parsed, this may includes binary FITS files or text-based data
Throws:
WavelengthArrayParseException

parse

public void parse(java.io.Reader rdr)
           throws WavelengthArrayParseException
Deprecated. use Wavelength1DArrayParser.parse instead

Passes a null String as the units to parse( StringReader, String), causing Angstroms to be the assumed wavelength units

Parameters:
rdr - a Reader to the data to be parsed, ASSUME only text-based inputs
Throws:
WavelengthArrayParseException

parse

public void parse(java.io.InputStream istr,
                  java.lang.String wlUnits)
           throws WavelengthArrayParseException
Deprecated. use Wavelength1DArrayParser.parse instead

Looks to parse data from a reader and fill the array, looking first to see if the data is a binary FITS file. Otherwise it assumes a _very_ basic variant of and ASCII fits file where it expects non-comment characters to alternate between a wavelength in Angstroms, and a data value. The parse makes some bold assumptions: all white space ignore, wavelength are monotonically ascending.

No conversion of the data value is performed For FITS binary data the wavelength units are converted from their source units. And ASCII wavelengths are assumed to be in wlUnits

Parameters:
istr - an InputStream to the data to be parsed
wlUnits - the input units for an ascii data string, ignore if reader contains binary FITS data
Throws:
WavelengthArrayParseException

parseFits

public void parseFits(java.io.InputStream istr,
                      java.lang.String wlColName,
                      java.lang.String wlUnits,
                      java.lang.String dataColName,
                      java.lang.String dataUnits)
               throws WavelengthArrayParseException
Deprecated. use Wavelength1DArrayParser.parse instead

looks to parse a FITS formated input stream. If FITS format not found, tries a basic space/tab/comma seperate ascii format

Throws:
WavelengthArrayParseException

parseAscii

public void parseAscii(java.io.Reader rdr,
                       java.lang.String wlUnits)
                throws WavelengthArrayParseException
Deprecated. use Wavelength1DArrayParser.parse instead

looks to parse a FITS formated input stream. If FITS format not found, tries a basic space/tab/comma seperate ascii format

Throws:
WavelengthArrayParseException

setFluxUnits

public void setFluxUnits(java.lang.String units)
                  throws UnitsNotSupportedException
Description copied from class: AbstractWavelength1D
a DUMMY implementation: Saves the string but does NOTHING with it.

Specified by:
setFluxUnits in interface Wavelength1DModel
Overrides:
setFluxUnits in class AbstractWavelength1D
Throws:
UnitsNotSupportedException