stella.util
Class SensorTest

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by stella.util.SensorTest
All Implemented Interfaces:
Cloneable, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying

public class SensorTest
extends PropertyBundles

This class test the behaviour of the linear prediction and the derivative properties of the sensors. It takes the raw output of a sensor stored as ascii-data in a file and performs numerical derivative calculation on it according to the KEY_DERIVE property, and linear prediction according to the KEY_DATABASE, KEY_PREDICT, and KEY_FUTURE properties. The output data are writtn together with the input data to a column-ascii file.

The aim of this test is to find the most reliable derivators and linear predictors, possibly together with read-out times, for all sensors. Prediction should only be accurate for the next two minutes (closure time of the roof).


Nested Class Summary
private static class SensorTest.Parser
          A command line parser class to allow direct parameter hand-over.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static boolean DEFBIAS
          The default bias removal.
private static int DEFCOLUMN
          The default column to read on input.
private static String DEFFORMAT
          The default data output format.
private static int DEFFUTURE
          The default number of predicted values.
private static String DEFOUTFILE
          The default output file name.
private  List derivatives
          The list to the data derived from applying the derivators.
private  NumberFormat df
          The data formatter used.
private  List extrapolations
          The list to the data derived from applying extrapolation.
private  double[] input
          The input data of the sensor raw readings.
static String KEY_BIAS
          The key pointing to bias removal at predicition.
static String KEY_COLUMN
          The key to the column number to read in the input file.
static String KEY_DATABASE
          The key pointing the number of input data used for prediction.
static String KEY_DERIVE
          The key pointing to a list of derivator files.
static String KEY_EXTRAPOLATE
          The key pointing to a list of data points used for extrapolation.
static String KEY_FORMAT
          The key to the output data formatter.
static String KEY_FUTURE
          The key pointing to the number of points to predict/extrapolate.
static String KEY_INFILE
          The key to the input file.
static String KEY_LINEAR
          If present, only linear extrapolation is done.
static String KEY_OUTFILE
          The key to the output file.
static String KEY_PREDICT
          The key pointing to a list of linear prediction coefficient-counts.
static String KEY_RESIDUAL
          If present, only residuals of the extrapolation are loaded.
static String KEY_SMOOTH
          The key pointing to a list of smoother files.
private  List predictions
          The list to the data derived from applying linear prediction.
private  List smoothers
          The list to the data derived from applying the smoothers.
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
SensorTest(Map<String,String> prop)
          Constructs a new censor tester.
 
Method Summary
 boolean applyDerivator()
          Applies the numerical derivators stated in the KEY_DERIVE property.
 boolean applyExtrapolation()
          Applies extrapolation as stated in the KEY_EXTRAPOLATE property.
 boolean applyPrediction()
          Applies linear predictions as stated in the KEY_PREDICT property.
 boolean applySmoothing()
          Applies the savitzky-goolay filters stated in the KEY_SMOOTH property.
private  double[] deriveOne(double[] indata, SavitzkyGolaySmoothing sgs)
          Numerically derives an entire data set using a savitzky-golay filter.
private  double[] extrapolateOne(double[] indata, int base, Extrapolation ext, int fut)
          Applies extrapolation to the entire data set.
static void main(String[] arg)
          The main method.
private  double[] predictOne(double[] indata, int base, int back, int fut)
          Applies linear prediction to the entire data set.
 boolean readInput()
          Reads the input data.
private  double[] readInputFile(File infile)
          Reads the input data from the given file.
private  double[] smoothOne(double[] indata, SavitzkyGolaySmoothing sgs)
          Numerically derives an entire data set using a savitzky-golay filter.
private  void writeData(BufferedWriter out)
          Writes the data sets.
private  void writeHead(BufferedWriter out)
          Writes a header to the output stream.
 void writeOutput()
          Writes the output data.
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, init, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.Initializable
init
 

Field Detail

KEY_SMOOTH

public static final String KEY_SMOOTH
The key pointing to a list of smoother files.

See Also:
Constant Field Values

KEY_DERIVE

public static final String KEY_DERIVE
The key pointing to a list of derivator files.

See Also:
Constant Field Values

KEY_BIAS

public static final String KEY_BIAS
The key pointing to bias removal at predicition.

See Also:
Constant Field Values

KEY_DATABASE

public static final String KEY_DATABASE
The key pointing the number of input data used for prediction.

See Also:
Constant Field Values

KEY_PREDICT

public static final String KEY_PREDICT
The key pointing to a list of linear prediction coefficient-counts.

See Also:
Constant Field Values

KEY_LINEAR

public static final String KEY_LINEAR
If present, only linear extrapolation is done.

See Also:
Constant Field Values

KEY_RESIDUAL

public static final String KEY_RESIDUAL
If present, only residuals of the extrapolation are loaded.

See Also:
Constant Field Values

KEY_EXTRAPOLATE

public static final String KEY_EXTRAPOLATE
The key pointing to a list of data points used for extrapolation.

See Also:
Constant Field Values

KEY_FUTURE

public static final String KEY_FUTURE
The key pointing to the number of points to predict/extrapolate.

See Also:
Constant Field Values

KEY_INFILE

public static final String KEY_INFILE
The key to the input file.

See Also:
Constant Field Values

KEY_OUTFILE

public static final String KEY_OUTFILE
The key to the output file.

See Also:
Constant Field Values

KEY_COLUMN

public static final String KEY_COLUMN
The key to the column number to read in the input file.

See Also:
Constant Field Values

KEY_FORMAT

public static final String KEY_FORMAT
The key to the output data formatter.

See Also:
Constant Field Values

DEFBIAS

private static final boolean DEFBIAS
The default bias removal.

See Also:
Constant Field Values

DEFFUTURE

private static final int DEFFUTURE
The default number of predicted values.

See Also:
Constant Field Values

DEFOUTFILE

private static final String DEFOUTFILE
The default output file name.

See Also:
Constant Field Values

DEFCOLUMN

private static final int DEFCOLUMN
The default column to read on input.

See Also:
Constant Field Values

DEFFORMAT

private static final String DEFFORMAT
The default data output format.

See Also:
Constant Field Values

input

private double[] input
The input data of the sensor raw readings.


smoothers

private List smoothers
The list to the data derived from applying the smoothers.


derivatives

private List derivatives
The list to the data derived from applying the derivators.


predictions

private List predictions
The list to the data derived from applying linear prediction.


extrapolations

private List extrapolations
The list to the data derived from applying extrapolation.


df

private NumberFormat df
The data formatter used.

Constructor Detail

SensorTest

public SensorTest(Map<String,String> prop)
Constructs a new censor tester. Default properties set are linked to the keys KEY_FUTURE, KEY_COLUMN, KEY_FORMAT, and KEY_OUTFILE.

Method Detail

readInput

public boolean readInput()
Reads the input data. The input file must be an ascii-column file with at least the number of columns stated at KEY_COLUMN. At least this column must be parsable as a double.

Returns:
True, if at least some data points could be read.

readInputFile

private double[] readInputFile(File infile)
Reads the input data from the given file. The input file must be an ascii-column file with at least the number of columns stated at KEY_COLUMN. At least this column must be parsable as a double.


applySmoothing

public boolean applySmoothing()
Applies the savitzky-goolay filters stated in the KEY_SMOOTH property. This property is a comma-separated list of smoother-definition files. Each valid entry (i.e. entries that can be used to construct a savitsky-golay smoother) produces a data set that is the smoothened of the input data. The data missing due to the necessary pre-current data points is zero.

Returns:
True, if the smootherss were sucessfully applied.

smoothOne

private double[] smoothOne(double[] indata,
                           SavitzkyGolaySmoothing sgs)
Numerically derives an entire data set using a savitzky-golay filter. The returned data is of the same dimension as the input data and contains the numerically calculated derivative of the input data at all indices. Note that the first few output data must be zero, as they are needed as the prediction-base for the filter. The amount of leading zeros depends on the filter used.


applyDerivator

public boolean applyDerivator()
Applies the numerical derivators stated in the KEY_DERIVE property. This property is a comma-separated list of derivator-definition files. Each valid entry (i.e. entries that can be used to construct a savitsky-golay derivator) produces a data set that is the first derivative of the input data. The data missing due to the necessary pre-current data points is zero.

Returns:
True, if the derivators were sucessfully applied.

deriveOne

private double[] deriveOne(double[] indata,
                           SavitzkyGolaySmoothing sgs)
Numerically derives an entire data set using a savitzky-golay filter. The returned data is of the same dimension as the input data and contains the numerically calculated derivative of the input data at all indices. Note that the first few output data must be zero, as they are needed as the prediction-base for the filter. The amount of leading zeros depends on the filter used.


applyPrediction

public boolean applyPrediction()
Applies linear predictions as stated in the KEY_PREDICT property. This property is a comma-separated list of integers. Each integer corresponds to the number of linear-prediction coefficients used for the particular prediction. The input data base is constructed from the sensor readings and narrowed down to the KEY_DATABASE data-points back from the current sensor reading. Then, the linear prediction coefficients according to the KEY_PREDICT numbers are calculated. The linear prediction is then carried out for KEY_FUTURE data points starting from the current data point. This yields a single predicted value, stored in the output file. The data (sum of KEY_DATABASE and KEY_FUTURE) missing due to the necessary pre-current data points are zero.

Returns:
True, if the predicitons were sucessfully applied.

predictOne

private double[] predictOne(double[] indata,
                            int base,
                            int back,
                            int fut)
Applies linear prediction to the entire data set. Predictions can only start after the requested input-data base length. From there, again a certain number of values (the number of predicted values) are missing. From there, each input data is represented as a linear predicted value on output.
The prediction procedure is as follows:


applyExtrapolation

public boolean applyExtrapolation()
Applies extrapolation as stated in the KEY_EXTRAPOLATE property. This property is a comma-separated list of integers. Each integer corresponds to the number of measurements used for the particular prediction. The input data base is constructed from the sensor readings and narrowed down. Then, the extrapolating polynom is calculated. If the KEY_LINEAR switch is present, linear extrapolation is used, otherwise fitting to a parabolic is done. The extrapolation is then carried out for the single KEY_FUTURE data point, starting from the current data point. This yields a single predicted value, stored in the output file. The data (sum of KEY_EXTRAPOLATE and KEY_FUTURE) missing due to the necessary pre-current data points are zero.

Returns:
True, if the extrapolation were sucessfully applied.

extrapolateOne

private double[] extrapolateOne(double[] indata,
                                int base,
                                Extrapolation ext,
                                int fut)
Applies extrapolation to the entire data set. Extrapolation can only start after the requested input-data base length. From there, again a certain number of values (the number of predicted values) are missing. From there, each input data is represented as an extrapolated value on output.
The extrapolation procedure is as follows:


writeOutput

public void writeOutput()
Writes the output data. The output data is an ascii-file with columned data. The first column is the input data, followed by the derivative data. Each derivative column corresponds to a derivator named in the KEY_DERIVE property. After all derivative data, the linear predicted data is added. Each predicted column corresponds to a number of prediction coefficients, as stated in the KEY_PREDICT property.


writeHead

private void writeHead(BufferedWriter out)
                throws IOException
Writes a header to the output stream. The header starts with a '#' char to indicate a comment line. After that, the keyword ' in' follows. Each derivative data set present in the derivatives list adds a ' D#' entry, where '#' indicates the index of the derivator used. Using the predicted data sets in the predictions list, similar ' P#' character sequences are added.

Parameters:
out - The stream to write to
Throws:
IOException

writeData

private void writeData(BufferedWriter out)
                throws IOException
Writes the data sets. First data column is the input data, followed by the derivatives data, again followed by the data predictions.

Throws:
IOException

main

public static void main(String[] arg)
                 throws ParseException
The main method. Reads tthe command line arguments and parses them according to SensorTest.Parser. Note that the input file may only be specified with a switch, a command line argument is always a properties file.

Throws:
ParseException