Package PyFoam :: Package Basics :: Module SpreadsheetData :: Class SpreadsheetData
[hide private]
[frames] | no frames]

Class SpreadsheetData

source code


Collects data that could go into a spreadsheet. The focus of this class is on storing all the data at once

Instance Methods [hide private]
 
__add__(self, other)
Convinience function for joining data
source code
 
__call__(self, t, name, time=None, invalidExtend=False, noInterpolation=False)
'Evaluate' the data at a specific time by linear interpolation
source code
 
__init__(self, timeName=None, validData=None, validMatchRegexp=False, csvName=None, txtName=None, excelName=None, data=None, names=None, title=None)
Either this is constructed from a file or from the data and the column headers
source code
 
addTimes(self, times, time=None, interpolate=False, invalidExtend=False)
Extend the data so that all new times are represented (add rows if they are not there)
source code
 
append(self, name, data, allowDuplicates=False)
Add another column to the data.
source code
 
compare(self, other, name, otherName=None, time=None, common=False, minTime=None, maxTime=None)
Compare this data-set with another.
source code
 
getData(self, reindex=True)
Return a dictionary of the data in the DataFrame format of pandas
source code
 
getSeries(self, reindex=True)
Return a dictionary of the data-columns in the Series format of pandas
source code
 
join(self, other, time=None, prefix=None)
Join this object with another.
source code
 
metrics(self, name, time=None, minTime=None, maxTime=None)
Calculates the metrics for a data set.
source code
 
names(self) source code
 
recalcData(self, name, expr, create=False)
Recalc or add a column to the data
source code
 
resample(self, other, name, otherName=None, time=None, invalidExtend=False, extendData=False, noInterpolation=False)
Calculate values from another dataset at the same times as in this data-set
source code
 
size(self) source code
 
tRange(self, time=None)
Return the range of times
source code
 
validName(self, n, validData, validMatchRegexp=False) source code
 
writeCSV(self, fName, delimiter=',')
Write data to a CSV-file
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__call__(self, t, name, time=None, invalidExtend=False, noInterpolation=False)
(Call operator)

source code 

'Evaluate' the data at a specific time by linear interpolation

Parameters:
  • t - the time at which the data should be evaluated
  • name - name of the data column to be evaluated. Assumes that that column is ordered in ascending order
  • time - name of the time column. If none is given then the first column is assumed
  • invalidExtend - if t is out of the valid range then use the smallest or the biggest value. If False use nan
  • noInterpolation - if t doesn't exactly fit a data-point return 'nan'

__init__(self, timeName=None, validData=None, validMatchRegexp=False, csvName=None, txtName=None, excelName=None, data=None, names=None, title=None)
(Constructor)

source code 

Either this is constructed from a file or from the data and the column headers

Parameters:
  • timeName - the data colum that is to be considered the time in this file
  • validData - names of the valid data columns (all others should be discarded)
  • validMatchRegexp - Should the validData be interpreted as regular expressions
  • csvName - name of the CSV-file the data should be constructed from,
  • txtName - name of a file the data should be constructed from,
  • excelName - name of a Excel-file the data should be constructed from (uses the first sheet in the file),
  • data - the actual data to use
  • names - the names for the column header
  • title - a name that is used to make unique heades names
Overrides: object.__init__

addTimes(self, times, time=None, interpolate=False, invalidExtend=False)

source code 

Extend the data so that all new times are represented (add rows if they are not there)

Parameters:
  • time - the name of the column with the time
  • times - the times that shoild be there
  • interpolate - interpolate the data in new rows. Otherwise insert 'nan'
  • invalidExtend - if t is out of the valid range then use the smallest or the biggest value. If False use nan

append(self, name, data, allowDuplicates=False)

source code 

Add another column to the data. Assumes that the number of rows is right

Parameters:
  • name - the name of the column
  • data - the actual data
  • allowDuplicates - If the name already exists make it unique by appending _1, _2 ...

compare(self, other, name, otherName=None, time=None, common=False, minTime=None, maxTime=None)

source code 

Compare this data-set with another. The time-points of this dataset are used as a reference. Returns a dictionary with a number of norms: maximum absolute difference, average absolute difference on all timepoints, average absolute difference weighted by time

Parameters:
  • other - the other data-set
  • name - name of the data column to be evaluated. Assumes that that column is ordered in ascending order
  • time - name of the time column. If none is given then the first column is assumed
  • common - cut off the parts where not both data sets are defined
  • minTime - first time which should be compared
  • maxTime - last time to compare

join(self, other, time=None, prefix=None)

source code 

Join this object with another. Assume that they have the same amount of rows and that they have one column that designates the time and is called the same and has the same values

Parameters:
  • other - the other array
  • time - name of the time. If None the first column is used
  • prefix - String that is added to the other names. If none is given then the title is used

metrics(self, name, time=None, minTime=None, maxTime=None)

source code 

Calculates the metrics for a data set. Returns a dictionary with a number of norms: minimum, maximum, average, average weighted by time

Parameters:
  • name - name of the data column to be evaluated. Assumes that that column is ordered in ascending order
  • time - name of the time column. If none is given then the first column is assumed
  • minTime - first time to take metrics from
  • maxTime - latest time to take matrics from

recalcData(self, name, expr, create=False)

source code 

Recalc or add a column to the data

Parameters:
  • name - the colum (must exist if it is not created. Otherwise it must not exist)
  • expr - the expression to calculate. All present column names are usable as variables. There is also a variable data for subscripting if the data is not a valid variable name. If the column is not create then there is also a variable this that is an alias for the name
  • create - whether a new data item should be created

resample(self, other, name, otherName=None, time=None, invalidExtend=False, extendData=False, noInterpolation=False)

source code 

Calculate values from another dataset at the same times as in this data-set

Parameters:
  • other - the other data-set
  • name - name of the data column to be evaluated. Assumes that that column is ordered in ascending order
  • time - name of the time column. If none is given then the first column is assumed
  • invalidExtend - see __call__
  • extendData - if the time range of x is bigger than the range then extend the range before resampling
  • noInterpolation - if t doesn't exactly fit a data-point return 'nan'

tRange(self, time=None)

source code 

Return the range of times

Parameters:
  • time - name of the time. If None the first column is used

writeCSV(self, fName, delimiter=',')

source code 

Write data to a CSV-file

Parameters:
  • fName - Name of the file
  • delimiter - Delimiter to be used in the CSV-file