-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc3data.py
More file actions
101 lines (82 loc) · 2.8 KB
/
c3data.py
File metadata and controls
101 lines (82 loc) · 2.8 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# C3data version 1.0.0
#
# Abstract data class for CEOS tableau calculations
# Contains measurement data in a dictionary and the associated date in a string
#
# Initializes with a string or list
# Exposes: getData() and getDate()
class C3data:
__paramsList = ('Date', 'C1', 'A1', 'A2', 'B2', 'C3', 'A3', 'S3', 'A4', 'D4', 'B4', 'C5', 'A5') # Params to search for
def __init__(self, measurements = ''):
self.__data = {}
self.__date = ''
if measurements:
if isinstance(measurements, str):
self.__loadData(measurements.split('\n'))
elif isinstance(measurements, list):
self.__loadData(measurements)
else:
raise TypeError('A string or a list of strings is required')
# __loadData(data)
#
# @api: private
# @params: data{list}
#
# load data into the __data dictionary and __date str
def __loadData(self, data):
lineBuffer = []
for item in data:
for val in self.__paramsList:
# if the __paramsList item exists (followed by a ':'') and is not preceded by a '#''
# parse out the pieces we want
if item.find(val + ":") != -1 and item.find("#") == -1:
item = item[item.find(val):]
lineBuffer = item.split(":")
# Different handling if the param is a date vs. a abberation value
if lineBuffer[0] == "Date":
# If the first value for the line list is 'Date', build a proper date for the second value
self.__date = str(lineBuffer[1] + ':' + lineBuffer[2] + ':' + lineBuffer[3]).strip()
else:
measurements = []
values = {}
# All non date items should be of the following structure:
# ['C1', ' -6.835nm (95%: 1.61nm)']
# ['A1', ' 12.26nm / +21.2deg (95%', ' 4.3nm)']
# Strip any whitespace on the second item, split it on spaces, and take
# the first element (ex. -6.835nm)
measurements = lineBuffer[1].split("/")
if len(measurements) > 1:
values['angle'] = measurements[1].strip().split(" ")[0]
values['measurement'] = self.__normalize(measurements[0].strip())
#lineBuffer[1] = self.__normalize(lineBuffer[1].strip().split(" ")[0])
self.__data[val] = values
# __normalize
#
# @api: private
# @params: value{str}
#
# normalize data to mm
def __normalize(self, value):
factors = {'mm': 1, 'um': 0.001, 'nm': 0.000001, 'pm': 0.000000001}
# check for one of the keys in the data
for key in factors.keys():
if key in value:
value = value.split(key)[0]
return str(float(value) * factors[key])
# getData
#
# @api: public
#
# getter for the __data dictionary
def getData(self):
return self.__data
# getDate
#
# @api: public
#
# getter for the __date str
def getDate(self):
return self.__date
# def toString(self, delimitor = ' '):
# #print some string representation of the data object using the specified delimitor
# return ''