-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrendPane.lua
166 lines (147 loc) · 5.56 KB
/
trendPane.lua
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
-- Copyright (c) 2016 Thermo Fisher Scientific
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
-- (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
-- merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished
-- to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
-- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- trendPane.lua
-- A zPane with the ability to plot header/trailer/status data
-- Load necessary libraries
local zPane = require("zPane")
-- Get assemblies
luanet.load_assembly ("System.Drawing")
luanet.load_assembly ("ZedGraph")
-- Get constructors
local plotCtor = luanet.import_type("ZedGraph.ZedGraphControl")
local pointPairListCtor = luanet.import_type("ZedGraph.PointPairList")
local GraphPane = luanet.import_type("ZedGraph.GraphPane")
-- Get enumerations
local Color = luanet.import_type("System.Drawing.Color")
local SymbolType = luanet.import_type("ZedGraph.SymbolType") -- This is an enum
-- local variables
-- forward declarations for local functions
-- local functions
-- Start of the zPane object
local trendPane = {}
trendPane.__index = trendPane
setmetatable(trendPane, {
__index = zPane, -- this is the inheritance
__call = function (cls, ...)
local self = setmetatable({}, cls)
self:_init(...)
return self
end,})
---Create a new object of the class
function trendPane:_init(args)
args = args or {}
zPane._init(self, args)
self.rawFile = args.rawFile
self.filter = ""
self.label = ""
self.paneControl.Title.Text = "trendPane"
-- Add properties, zPane already called properties.Inherit()
self:AddProperty({key = "filter", label = "Filter"})
self:AddProperty({key = "label", label = "Label"})
end
-- I could cache the labels, but speed isn't really critical
-- so don't bother
function trendPane:IsHeader(label)
local rf = self.rawFile
local header = rf:GetScanHeader(rf.FirstSpectrumNumber)
return header[label] ~= nil
end
function trendPane:IsStatus(label)
local rf = self.rawFile
local trailer = rf:GetStatusLog(rf.FirstSpectrumNumber)
return trailer[label] ~= nil
end
function trendPane:IsTrailer(label)
local rf = self.rawFile
local trailer = rf:GetScanTrailer(rf.FirstSpectrumNumber)
return trailer[label] ~= nil
end
function trendPane:Plot(label)
label = label or self.label
local rf = self.rawFile
if self:IsHeader(label) then
return self:PlotGeneric(label, rf.GetScanHeader)
elseif self:IsTrailer(label) then
return self:PlotGeneric(label, rf.GetScanTrailer)
elseif self:IsStatus(label) then
return self:PlotStatus(label)
else
print (string.format("Label '%s' not valid", label))
return nil
end
end
function trendPane:PlotGeneric(label, accessFunction)
local rf = self.rawFile
local xyData = {}
local header
local scanFilter = self.filter or ""
if scanFilter:len() > 0 then
scanFilter = " " .. scanFilter .. " "
else
scanFilter = nil
end
for i = rf.FirstSpectrumNumber, rf.LastSpectrumNumber do
if not scanFilter or
string.find(rf:GetScanFilter(i), scanFilter) then
data = accessFunction(rf, i)
if not data[label] then
print (string.format("Label '%s' not found for scan %d", label, i))
return nil
end
table.insert(xyData, {x = rf:GetRetentionTime(i), y = data[label]})
end
end
local pane = self.paneControl
self:Clear() -- Clear all data from the pane
pane.Title.Text = label
pane.XAxis.Title.Text = "Retention Time (min)"
pane.YAxis.Title.Text = "Value"
self:AddXYTable({data = xyData, xKey = "x", yKey = "y"})
self.label = label
return true
end
-- Status only updates about once a second, so no need
-- to fetch from every scan
function trendPane:PlotStatus(label)
local rf = self.rawFile
local xyData = {}
local scanNumber, statusLog
local startTime = rf:GetRetentionTime(rf.FirstSpectrumNumber)
local endTime = rf:GetRetentionTime(rf.LastSpectrumNumber)
local currentTime = startTime
local increment = 1 / 60 -- increment by one second
while currentTime < endTime do
scanNumber = rf:GetScanNumberFromRT(currentTime)
statusLog = rf:GetStatusLog(scanNumber)
if not statusLog[label] then
print (string.format("Label '%s' not found in status log for scan %d", label, i))
return nil
end
table.insert(xyData, {x = currentTime, y = statusLog[label]})
currentTime = currentTime + increment
end
local pane = self.paneControl
self:Clear() -- Clear all data from the pane
pane.Title.Text = label
pane.XAxis.Title.Text = "Retention Time (min)"
pane.YAxis.Title.Text = "Value"
self:AddXYTable({data = xyData, xKey = "x", yKey = "y"})
self.label = label
return true
end
-- This overrides the default method
function trendPane:SetPropertiesFinalize()
self:Plot()
end
return trendPane