saaps.util
Class TimeSeries

java.lang.Object
  |
  +--saaps.util.TimeSeries
All Implemented Interfaces:
java.io.Serializable

public class TimeSeries
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Field Summary
static int aveArrDptOffset
           
static int aveArrStdvOffset
           
static int aveArrTypes
          Describes how many different types of data is in the average array.
private  java.util.Calendar cal
           
private  Jama.Matrix data
           
private  java.util.Date[] dates
           
private  java.lang.String[] fieldNames
           
private  java.lang.String[] fieldUnits
           
private  java.lang.String longDescription
           
private  int numOfData
           
private  int numOfDataFields
           
private  int numOfFields
           
private  java.lang.String shortDescription
           
private  java.util.TimeZone tz
           
 
Constructor Summary
TimeSeries(java.util.Date[] d, double[] m)
          Create a TimeSeries object from a Date vector and a double vector.
TimeSeries(java.util.Date[] d, double[][] m, java.lang.String[] fn, java.lang.String[] fu)
          Create the object from date array and the 2-D array.
TimeSeries(java.util.Date[] d, double[] m, java.lang.String fn, java.lang.String fu)
          Create a TimeSeries object from a Date vector and a double vector, and specify the data field names and units.
TimeSeries(java.util.Date[] d, Jama.Matrix m)
          Create a TimeSeries object from an array of Date objects and a Matrix.
TimeSeries(long st, long et, long si, int nodf)
          Create an empty time series object.
TimeSeries(ObjectTimeSeries ots, java.lang.String[] fn, java.lang.String[] fu)
          Create a TimeSeries object from an ObjectTimeSeries.
TimeSeries(java.util.Vector dbov)
          Create a TimeSeries object from a Vector of DatabaseObject:s
TimeSeries(java.util.Vector dbov, int fieldIndex)
          Create a TimeSeries object from a Vector of DatabaseObjects Use only the indicated data field.
TimeSeries(java.util.Vector dbov, java.lang.String[] fn, java.lang.String[] fu)
          Create a TimeSeries object from a Vector of DatabaseObject:s
 
Method Summary
 double[] average(boolean ignoreNaN)
          Get the average of a time series object.
 double[] average(java.util.Calendar date, boolean ignoreNaN)
          Gets the average of a time series object.
 int average(java.util.Date sampleTime, long wa, long wb, java.util.Date mdate, double[] mdata)
          Averages all fields in the data for the selected time interval.
 int average(int[] fields, java.util.Date sampleTime, long wa, long wb, java.util.Date mdate, double[] mdata)
          Averages the selected fields in the data for the selected time interval.
 TimeSeries averageFields()
          Average over the data fields.
 TimeSeries dailySum()
          Get the daily sum for each parameter for each day.
 TimeSeries extract(long st, long et)
          Extract a time period.
 Jama.Matrix getData()
          Get the data as a Matrix object.
 double[] getData(int i)
          Get the data for one row.
 double getData(int i, int j)
          Get one data element.
 java.util.Date getDate(int i)
          Get one Date object.
 java.util.Date[] getDates()
          Get the Date objects.
 java.lang.String[] getFieldNames()
          Gets the field names array.
 java.lang.String[] getFieldUnits()
          Gets the field units array.
 java.util.Date getLastDate()
          Get the last date in the time series.
 int getLength()
          Get the length of the TimeSeries object.
 java.lang.String getLongDescription()
          Get the long description of the data.
 int getNumOfDataFields()
          Get the number of data fields.
 long getSampleInterval()
          Get the sample interval.
 java.lang.String getShortDescription()
          Get the short description of the data.
static void main(java.lang.String[] args)
           
 TimeSeries normalize(NormParam np)
          Method to normalize the data according to a NormParam object.
 byte resample(int[] fields, long dt0, long dt, long wa, long wb)
          Resamples selected fields in the data.
 byte resample(long dt0, long dt, long wa, long wb)
          Resamples all fields in the data.
private  java.util.Calendar setCalDay(java.util.Date d)
           
 void setData(int i, double[] x)
          Set one row of data.
 void setData(int i, int j, double x)
          Set data for observation i and data field j.
private  void setDefaultMeta()
          Set the default meta data for the time series.
 void setFieldNames(java.lang.String[] fn)
          Sets the field names array.
 void setFieldUnits(java.lang.String[] fu)
          Sets the field units array.
 void setLongDescription(java.lang.String ld)
          Set the long description of the data.
 void setShortDescription(java.lang.String sd)
          Set the short description of the data.
 TimeSeries sumFields()
          Sum over the data fields.
 Jama.Matrix timeDelay(NormParam np)
          Method to create a time delay line.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

dates

private java.util.Date[] dates

data

private Jama.Matrix data

numOfData

private int numOfData

numOfFields

private int numOfFields

numOfDataFields

private int numOfDataFields

tz

private java.util.TimeZone tz

cal

private java.util.Calendar cal

shortDescription

private java.lang.String shortDescription

longDescription

private java.lang.String longDescription

fieldNames

private java.lang.String[] fieldNames

fieldUnits

private java.lang.String[] fieldUnits

aveArrDptOffset

public static final int aveArrDptOffset

aveArrStdvOffset

public static final int aveArrStdvOffset

aveArrTypes

public static final int aveArrTypes
Describes how many different types of data is in the average array. ex. data,number of data points, standard deviation
Constructor Detail

TimeSeries

public TimeSeries(java.util.Date[] d,
                  double[] m)
Create a TimeSeries object from a Date vector and a double vector.
Parameters:
d - The dates.
m - The data.

TimeSeries

public TimeSeries(java.util.Date[] d,
                  double[] m,
                  java.lang.String fn,
                  java.lang.String fu)
Create a TimeSeries object from a Date vector and a double vector, and specify the data field names and units.
Parameters:
d - The dates.
m - The data.
fn - The field name.
fu - The field unit.

TimeSeries

public TimeSeries(java.util.Date[] d,
                  double[][] m,
                  java.lang.String[] fn,
                  java.lang.String[] fu)
Create the object from date array and the 2-D array. Set also the field names.

Note: All 2-D array rows must have the same length.

Parameters:
d - date array
m - 2-D array of double data (all rows same length)
fn - field names
fu - field units

TimeSeries

public TimeSeries(java.util.Vector dbov)
Create a TimeSeries object from a Vector of DatabaseObject:s
Parameters:
dbov - The DatabaseObject vector

TimeSeries

public TimeSeries(java.util.Vector dbov,
                  java.lang.String[] fn,
                  java.lang.String[] fu)
Create a TimeSeries object from a Vector of DatabaseObject:s
Parameters:
dbov - The DatabaseObject vector
fn - Field names
fu - Field units

TimeSeries

public TimeSeries(ObjectTimeSeries ots,
                  java.lang.String[] fn,
                  java.lang.String[] fu)
Create a TimeSeries object from an ObjectTimeSeries.
Parameters:
ots - The ObjectTimeSeries
fn - Field names
fu - Field units

TimeSeries

public TimeSeries(java.util.Vector dbov,
                  int fieldIndex)
           throws TimeSeriesIndexException
Create a TimeSeries object from a Vector of DatabaseObjects Use only the indicated data field.
Parameters:
dbov - The DatabaseObject vector
fieldIndex - field number in DatabaseObject data

TimeSeries

public TimeSeries(java.util.Date[] d,
                  Jama.Matrix m)
Create a TimeSeries object from an array of Date objects and a Matrix. The number of elements in the Date array must equal the number of rows in the Matrix object.
Parameters:
d - Array of Date object
m - Matrix of data.

TimeSeries

public TimeSeries(long st,
                  long et,
                  long si,
                  int nodf)
Create an empty time series object.
Method Detail

setDefaultMeta

private void setDefaultMeta()
Set the default meta data for the time series.

setFieldNames

public void setFieldNames(java.lang.String[] fn)
Sets the field names array.
Parameters:
field - names

setFieldUnits

public void setFieldUnits(java.lang.String[] fu)
Sets the field units array.
Parameters:
field - units

setCalDay

private java.util.Calendar setCalDay(java.util.Date d)

dailySum

public TimeSeries dailySum()
Get the daily sum for each parameter for each day.

Future version should include a check that all days contain the same number of data.


normalize

public TimeSeries normalize(NormParam np)
Method to normalize the data according to a NormParam object.
Parameters:
np - A NormParam object.

timeDelay

public Jama.Matrix timeDelay(NormParam np)
Method to create a time delay line. The resulting Matrix object has m rows and n columns, where m equals the length of the delay line and n equals the length of the TimeSeries object. The first m-1 columns will contain NaNs.
Parameters:
np - A NormParam object.

getLength

public int getLength()
Get the length of the TimeSeries object.

getDates

public java.util.Date[] getDates()
Get the Date objects.

getDate

public java.util.Date getDate(int i)
Get one Date object.

getData

public Jama.Matrix getData()
Get the data as a Matrix object.

getData

public double getData(int i,
                      int j)
Get one data element.

getData

public double[] getData(int i)
Get the data for one row.

getNumOfDataFields

public int getNumOfDataFields()
Get the number of data fields.

getShortDescription

public java.lang.String getShortDescription()
Get the short description of the data.
Returns:
The short description

getLongDescription

public java.lang.String getLongDescription()
Get the long description of the data.
Returns:
The long description

getFieldNames

public java.lang.String[] getFieldNames()
Gets the field names array.
Returns:
field names

getFieldUnits

public java.lang.String[] getFieldUnits()
Gets the field units array.
Returns:
field units

setShortDescription

public void setShortDescription(java.lang.String sd)
Set the short description of the data.
Parameters:
sd - The short description

setLongDescription

public void setLongDescription(java.lang.String ld)
Set the long description of the data.
Parameters:
ld - The short description

setData

public void setData(int i,
                    double[] x)
Set one row of data.

setData

public void setData(int i,
                    int j,
                    double x)
Set data for observation i and data field j.
Parameters:
i - The index for one observation
j - The index of the data field
x - The value to be set

average

public double[] average(boolean ignoreNaN)
Get the average of a time series object.

average

public double[] average(java.util.Calendar date,
                        boolean ignoreNaN)
Gets the average of a time series object. The returned array contains the averaged data, then the number of datapoints used in the average for every datapoint, then the standard deviation for every data point.
Parameters:
date - centre time of data interval is returned here
ignoreNaN - if true ignore NaN data
Returns:
averaged data and additional information about the average

average

public int average(java.util.Date sampleTime,
                   long wa,
                   long wb,
                   java.util.Date mdate,
                   double[] mdata)
Averages all fields in the data for the selected time interval. The data is returned in mdate and mdata. The time is set to the sample time.
Parameters:
sampleTime - time of the resulting data.
wa - time offset 1 (negative value means before sampleTime)
wb - time offset 2 (positive value means after sampleTime)
Returns:
the averaged object

average

public int average(int[] fields,
                   java.util.Date sampleTime,
                   long wa,
                   long wb,
                   java.util.Date mdate,
                   double[] mdata)
Averages the selected fields in the data for the selected time interval. The data is returned in mdate and mdata. The time is set to the sample time.
Parameters:
fields - which are included in the average
sampleTime - time of the resulting data.
wa - time offset 1 (negative value means before sampleTime)
wb - time offset 2 (positive value means after sampleTime)
Returns:
the averaged object

extract

public TimeSeries extract(long st,
                          long et)
Extract a time period.

sumFields

public TimeSeries sumFields()
Sum over the data fields.

averageFields

public TimeSeries averageFields()
Average over the data fields.

getLastDate

public java.util.Date getLastDate()
Get the last date in the time series.
Returns:
The last date.

getSampleInterval

public long getSampleInterval()
Get the sample interval.
Returns:
The sample interval.

resample

public byte resample(long dt0,
                     long dt,
                     long wa,
                     long wb)
Resamples all fields in the data. XXX The list has to be scanned through for every new sample. XXX Should throw an Exception if it fails ! Fix it !!
Parameters:
dt0 - offset time from the first time in the series [ms]
dt - new sample interval (timestep [ms])
wa - time offset where resampling begins [ms]
wb - time offset where resampling ends [ms]
Returns:
-1 if failed 0 when normal operation.

resample

public byte resample(int[] fields,
                     long dt0,
                     long dt,
                     long wa,
                     long wb)
Resamples selected fields in the data. XXX The list has to be scanned through for every new sample. XXX Should throw an Exception if it fails ! Fix it !!
Parameters:
fields - which will be included in the result
dt0 - offset time from the first time in the series [ms]
dt - new sample interval (timestep [ms])
wa - time offset where resampling begins [ms]
wb - time offset where resampling ends [ms]
Returns:
-1 if failed 0 when normal operation.

main

public static void main(java.lang.String[] args)