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
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 """
21
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
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 """
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
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 """
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
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
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
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
121
122
123
124
125
126
127
128
129 self.data = np.zeros(time.shape, dtype=[('time', float)])
130 self.data['time'] = time
131 self.check_monotonically_inc_time()
132
133
134 self.data = self.data.view(np.ma.MaskedArray)
135
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