spv.spectrum
Class SpectrumTools

java.lang.Object
  extended by spv.spectrum.SpectrumTools

public final class SpectrumTools
extends java.lang.Object

This class acts a library where several general-purpose spectrum processing algorithms are lumped together.

Version:
1.0 - 20Apr01
Author:
Ivo Busko (Space Telescope Science Institute)

Field Summary
static java.lang.String SPECTRUM_NAME_SEPARATOR
           
 
Constructor Summary
SpectrumTools()
           
 
Method Summary
private  void addMetaParameters(Spectrum spi, SingleSpectrum spo)
           
private  void addRadialVelocities(Spectrum spi, Spectrum spo)
           
 void buildCombinedName(java.util.List spectra, CompositeSpectrum outputSpectrum)
           
private  CompositeSpectrum buildOutputSpectrum(java.util.ArrayList spectra)
           
 SingleSpectrum buildSubSetSpectrum(Spectrum spi, java.util.Enumeration list_int, java.util.Enumeration list_dq)
          Builds a spectrum object that contains only a subset of the arrays actually stored in the input spectrum.
private  boolean checkCrossNames(boolean match, java.util.ArrayList names, java.lang.String name)
           
private  java.util.Vector checkIntensityUnits(java.util.Enumeration list, java.util.List spectra)
           
private  XUnits checkOriginalXUnits(java.util.ArrayList spectra)
           
private  YUnits checkOriginalYUnits(java.util.ArrayList spectra)
           
 java.util.Vector checkUnits(java.util.List spectra, java.util.Enumeration list)
          Checks for units mismatches.
private  void checkWavelengthUnits(java.util.List spectra)
           
 Spectrum combine(java.util.List ispectra)
          Combines several Spectrum instances into a MultiSegmentSpectrum instance, or a EchelleSpectrum instance.
private  DQBits combineDQBits(java.util.List spectra)
          Combines the DQBits objects of all spectra into a single object.
private  int combineDQMasks(java.util.List spectra)
          Combine the DQ masks of all spectra inot a single mask.
private  java.util.ArrayList[] compress(java.util.ArrayList[] array)
          Compresses an array, removing empty elements.
private  java.util.Vector findCommonNames(java.util.ArrayList[] input_names)
          Finds array names that are common to all input spectra.
private  java.util.Vector getCommonDQ(java.util.ArrayList spectra)
          Builds an array that stores only the common DQ array names in all spectra in the input list.
private  java.util.Vector getCommonIntensities(java.util.ArrayList spectra)
          Builds an array that stores only the common intensity array names in all spectra in the input list.
 Spectrum getSubRange(Spectrum sp, double w1, double w2)
          Extracts spectrum in a wavelength subrange.
private  Units getUnits(java.util.List spectra, int index, java.lang.String id)
           
private  boolean isComparison(java.util.List spectra)
           
private  boolean isSED(java.util.List spectra)
           
private  boolean isSingleInstrument(java.util.ArrayList spectra)
          Finds if data comes from a single instrument.
 java.util.List openMultiSegment(java.util.List spectra)
          Searches input array for instances of MultiSegmentSpectrum.
private  void propagateTarget(java.util.List spectra, CompositeSpectrum spectrum)
           
 double[] removeDatamarkers(double[] array)
          Utility method to remove INDEFs (data markers) from arrays.
private  java.util.ArrayList removeDuplicates(java.util.ArrayList list)
           
 Spectrum toVelocity(Spectrum sp, double w0)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPECTRUM_NAME_SEPARATOR

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

SpectrumTools

public SpectrumTools()
Method Detail

removeDatamarkers

public double[] removeDatamarkers(double[] array)
Utility method to remove INDEFs (data markers) from arrays.

Parameters:
array - the array to be cleaned
Returns:
the new cleaned array

getSubRange

public Spectrum getSubRange(Spectrum sp,
                            double w1,
                            double w2)
Extracts spectrum in a wavelength subrange.

Parameters:
sp - the spectrum which to take a subrange from
w1 - the minimum wavelength
w2 - the maximum wavelength
Returns:
spectrum encompassing just the wavelength range from w1 to w2, and in SingleSpectrum format. null is returned if the intersection of the desired range and the range spanned by the input spectrum is empty.

toVelocity

public Spectrum toVelocity(Spectrum sp,
                           double w0)

combine

public Spectrum combine(java.util.List ispectra)
                 throws SpectrumException
Combines several Spectrum instances into a MultiSegmentSpectrum instance, or a EchelleSpectrum instance. This method assumes that the factory creates arrays consistently named across different instruments. If array names were arbitrary instead, we would need specific rules to combine them.

The type of the resulting object depends on the origin of the input spectra. If they all come from the same instrument, the result will be an EchelleSpectrum instance. Otherwise, it will be am instance of MultiSegmentSpectrum. The instrument identification is taken from the DQBits objects associated with each input spectrum.

This method assumes that all spectra to be combined share the same physical units in arrays of same ID. Note however that no check is performed regarding the objects' ID or target name. Thus this method can be used to combine together data from different astronomical sources into a single entity. Altough questionable (to say the least) from a strict data analysis perspective, the ability to overplot data from different sources onto a single stretch of WCS real state may be useful in some circunstances.

Intensity arrays that appear only on a subset of the input spectra are not copied into the output product. DQ arrays are handled differently though. If DQ arrays with same name exist only in a subset of the input spectra, they are included in the output product, so they can be used to mask pixels locally in the output spectrum. This is relevant when data from different instruments is mixed together.

Due to lack of a better criterion, both the header and the wavelength ID of the output spectrum are arbitrarily taken from the first spectrum in the input vector. The global DQ mask of all input spectra are ORed into a single value. The DQBits object resulting from the combination contains all bit flags stored in the combined objects. The name of the combined spectrum is built by stringing together all the component's names.

This is a shallow combine operation, meaning that, if any spectrum in the list to be combined has internal structure, that structure will disappear and the spectrum will be handled as a single flat unit.

If a single spectrum is input, this method returns a reference to the input, not a new object.

Parameters:
ispectra - the spectra to be combined
Returns:
the SingleSpectrum instance, or null if the operation fails.
Throws:
SpectrumException - if there is a units mismatch

buildCombinedName

public void buildCombinedName(java.util.List spectra,
                              CompositeSpectrum outputSpectrum)

buildOutputSpectrum

private CompositeSpectrum buildOutputSpectrum(java.util.ArrayList spectra)

isSED

private boolean isSED(java.util.List spectra)

propagateTarget

private void propagateTarget(java.util.List spectra,
                             CompositeSpectrum spectrum)

isComparison

private boolean isComparison(java.util.List spectra)

openMultiSegment

public java.util.List openMultiSegment(java.util.List spectra)
Searches input array for instances of MultiSegmentSpectrum. For any such element, opens it and adds all elements of the internal structure to the output array.

Parameters:
spectra - input array with instances of Spectrum
Returns:
output array

removeDuplicates

private java.util.ArrayList removeDuplicates(java.util.ArrayList list)

isSingleInstrument

private boolean isSingleInstrument(java.util.ArrayList spectra)
Finds if data comes from a single instrument. Uses the DQBits object in each spectrum in input list to get instrument name.

Parameters:
spectra - the list with input spectra
Returns:
true if all spectra in list come from single instrument

combineDQBits

private DQBits combineDQBits(java.util.List spectra)
Combines the DQBits objects of all spectra into a single object.


combineDQMasks

private int combineDQMasks(java.util.List spectra)
Combine the DQ masks of all spectra inot a single mask.


getCommonIntensities

private java.util.Vector getCommonIntensities(java.util.ArrayList spectra)
Builds an array that stores only the common intensity array names in all spectra in the input list.

Parameters:
spectra - the input lists
Returns:
the list with the intesection

getCommonDQ

private java.util.Vector getCommonDQ(java.util.ArrayList spectra)
Builds an array that stores only the common DQ array names in all spectra in the input list. If some of the spectra have no DQ array at all, just ignore them and proceed.

Parameters:
spectra - the input lists
Returns:
the list with the intesection

compress

private java.util.ArrayList[] compress(java.util.ArrayList[] array)
Compresses an array, removing empty elements.

Parameters:
array - the array
Returns:
a compressed version of the input

findCommonNames

private java.util.Vector findCommonNames(java.util.ArrayList[] input_names)
Finds array names that are common to all input spectra.

Parameters:
input_names - list of names
Returns:
list of common names

checkCrossNames

private boolean checkCrossNames(boolean match,
                                java.util.ArrayList names,
                                java.lang.String name)

buildSubSetSpectrum

public SingleSpectrum buildSubSetSpectrum(Spectrum spi,
                                          java.util.Enumeration list_int,
                                          java.util.Enumeration list_dq)
Builds a spectrum object that contains only a subset of the arrays actually stored in the input spectrum.

Parameters:
spi - input spectrum
list_int - list with array names to be included in output
list_dq - list with DQ array names to be included in output
Returns:
the output spectrum object

addMetaParameters

private void addMetaParameters(Spectrum spi,
                               SingleSpectrum spo)

addRadialVelocities

private void addRadialVelocities(Spectrum spi,
                                 Spectrum spo)

checkUnits

public java.util.Vector checkUnits(java.util.List spectra,
                                   java.util.Enumeration list)
                            throws SpectrumException
Checks for units mismatches. A mismatch in the wavelength units throws an exception. A mismatch in any other array causes a silent return. The returned object contains the input list of array names, eventually cleaned of the offending array names.

The returned object is not an Enumeration because enumerations can be scanned only once. This method returns instead a parent Vector object from which the required enumeration can be retrieved as many times as desired.

Parameters:
spectra - the spectra to be analysed
list - the list of array names to be analysed
Returns:
revised list with mismatched array names removed
Throws:
SpectrumException

checkIntensityUnits

private java.util.Vector checkIntensityUnits(java.util.Enumeration list,
                                             java.util.List spectra)

getUnits

private Units getUnits(java.util.List spectra,
                       int index,
                       java.lang.String id)

checkWavelengthUnits

private void checkWavelengthUnits(java.util.List spectra)
                           throws SpectrumException
Throws:
SpectrumException

checkOriginalXUnits

private XUnits checkOriginalXUnits(java.util.ArrayList spectra)

checkOriginalYUnits

private YUnits checkOriginalYUnits(java.util.ArrayList spectra)