Package fieldpy :: Package core :: Module experiment_classes
[hide private]
[frames] | no frames]

Source Code for Module fieldpy.core.experiment_classes

  1  """ 
  2  Holds the parent classes for classes to evaluate experiments. 
  3  """ 
  4  import matplotlib.mlab as mlab 
  5  import pylab as plt 
  6  import numpy as np 
  7   
  8  import fieldpy.core.raw_file_readers as raw_file_readers 
  9  from fieldpy.core.extra_classes import Metadata, Data, TimeSeries 
 10  import fieldpy.core.helper_fns as helper_fns 
 11   
12 -class LoggedData(TimeSeries):
13 """Parent class for all kinds of logged data, be it by hand or by 14 logger (i.e. time series). So, LoggedData are looked at as 15 simple, i.e. there is only very minimal data processing to be done 16 to get the data, definitely not a compound of several experiments, 17 use L{ExperimentData}. 18 """
19 - def __init__(self):
20 super(LoggedData, self).__init__()
21
22 - def check(self):
23 """ 24 Does integrity checks, should be invoced at the end of 25 __init__ of the children classes. 26 27 @todo: check that units are given. 28 """ 29 super(LoggedData, self).check()
30 31
32 -class ExperimentData(Data):
33 """Parent class for all kinds of experiments which cannot easily 34 be represented as time series. For some experiments it will 35 conincide with L{LoggedData} but mostly it will be processed from 36 the logged data, e.g. filtered, pieced together, etc. 37 """
38 - def check(self):
39 """ 40 Does integrity checks, should be invoced at the end of __init__ 41 42 @todo: check that units are given. 43 """ 44 super(ExperimentData, self).check()
45
46 -class ExperimentTimeSeries(TimeSeries):
47 """Parent class for all kinds of experiments which are time 48 series. For some experiments it will conincide with L{LoggedData} 49 but mostly it will be processed from the logged data, 50 e.g. filtered, pieced together, etc. 51 """
52 - def check(self):
53 """ 54 Does integrity checks, should be invoced at the end of __init__ 55 56 @todo: check that units are given. 57 """ 58 super(ExperimentTimeSeries, self).check()
59 60
61 -class CampbellCr1000(LoggedData):
62 """Holds Cr1000 data. 63 """ 64
65 - def __init__(self, filenames, given_headers=[]):
66 """ 67 Class to hold logged data from a Cr1000 datalogger. Can take 68 several files of the same table. 69 70 @type filenames: list of strings 71 @param filenames: a list of TOA5 Campbell Cr1000 files in 72 chronological order with the same data format. 73 74 75 @type given_headers: list of stings 76 @param given_headers: A list of header stings to be used instead 77 of the ones given in the file header. 78 79 @note: Error checking is just marginal. 80 81 >>> from fieldpy.core.experiment_classes import * 82 >>> dir_ = 'test_files/' 83 >>> fielns = ['TOA5_n1.dat','TOA5_n2.dat','TOA5_n3.dat'] 84 >>> c1000 = CampbellCr1000([dir_ + fl for fl in fielns], ['time', 'stage']) 85 """ 86 super(CampbellCr1000, self).__init__() 87 self.filenames = filenames 88 self.given_headers = given_headers 89 90 datas = [] 91 self.raw_datas = [] 92 mds = [] 93 94 # read all the files 95 for filename in filenames: 96 data, raw_data, md = raw_file_readers.read_campbell_TAO5(filename, given_headers) 97 datas.append(data) 98 self.raw_datas.append(raw_data) 99 mds.append(md) 100 101 if self.given_headers==[]: 102 self.t_name = 'TIMESTAMP' 103 else: 104 self.t_name = self.given_headers[0] 105 106 self.make_time(datas) 107 self.make_data(datas)
108
109 - def make_time(self, datas):
110 """ 111 Pieces together the time row and returns an error if wrong. 112 113 @type datas: a dict of list 114 @param datas: as generated in L{__init__} 115 """ 116 time = datas[0][self.t_name] 117 for data in datas[1:]: 118 time = np.append(time, data[self.t_name], 0) 119 120 # # check that it is the same for all other tables 121 # for table in datas.keys()[1:]: 122 # time2 = datas[table][0][self.t_name] 123 # for data in datas[table][1:] 124 # time2 = np.append(time2, data[self.t_name], 0) 125 # if not np.all(time==np.array(time2)): 126 # raise ValueError('The TIMESTAMP is not equal in all given tables. Error found in table %s' % table) 127 128 # make a record array 129 self.data = np.zeros(time.shape, dtype=[('time', float)]) 130 self.data['time'] = time 131 self.check_monotonically_inc_time() 132 133 # make a masked record array 134 self.data = self.data.view(np.ma.MaskedArray)
135
136 - def make_data(self, datas):
137 """ 138 Fills the rest of self.data 139 """ 140 for recname in datas[0].dtype.names: 141 if recname==self.t_name: 142 continue 143 tmp = datas[0][recname] 144 for data in datas[1:]: 145 tmp = np.append(tmp, data[recname], 0) 146 self.data = helper_fns.append_a2mrec(self.data, tmp, recname)
147