ceflib_mods.py
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /bin/env python
# coding: utf8
class cefwrite(object) :
def __init__(self, data = None, filename = 'test.cef'):
"""
Data of the form data['field1'] = numpy array, and data['epoch'] = numpy time array
"""
self.data = data
self.fichier = filename
self.initializeHeader()
variables = sorted(list(set(self.data.keys()) - set(['epoch'])))
for var in variables : self.addvariableHeader(var)
self.closeHeader()
out = open(self.fichier, 'a')
for i,t in enumerate(self.data['epoch']):
out.write(t.isoformat())
#print >> out, t.isoformat()
for var in variables :
out.write(' ')
#print >> out, str(self.data[key][i])
out.write('{:f}'.format(self.data[var][i]))
out.write('\n')
out.close()
def initializeHeader(self):
#set time variable as first variable
out = open(self.fichier, 'w')
out.write(
'START_VARIABLE = epoch \n'
' PARAMETER_TYPE = "Support_Data" \n'
' VALUE_TYPE = ISO_TIME \n'
' UNITS = "s" \n'
' DELTA_PLUS = 0 \n'
' DELTA_MINUS = 0 \n'
'END_VARIABLE = epoch \n'
' \n'
)
def addvariableHeader(self, variable):
out = open(self.fichier, 'a')
out.write(
'START_VARIABLE = '+variable +'\n'
' PARAMETER_TYPE = "Data" \n'
' VALUE_TYPE = FLOAT \n'
' FILLVAL = -1.000E+31 \n'
' DEPEND_0 = epoch \n'
' UNITS = "" \n'
' FIELDNAM = "" \n'
'END_VARIABLE = '+variable+ '\n'
' \n'
)
def closeHeader(self):
out = open(self.fichier, 'a')
out.write(
'DATA_UNTIL = EOF \n'
)