1
- #@+leo-ver=4
2
- #@+node:@file D:\Arbeit\SXM\SXM\Data.py
3
- #@@language python
4
- #@@tabwidth -4
5
- #@+others
6
- #@+node:Data declarations
1
+ # Copyright 2008 Felix Marczinowski <[email protected] >
2
+ #
3
+ # This file is part of PySXM.
4
+ #
5
+ # PySXM is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # PySXM is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with PySXM. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
7
19
"""Data types and functions.
8
20
@author: fm
9
21
@version: $Rev: 123 $
14
26
import FileIO
15
27
import pilutil
16
28
17
- #@-node:Data declarations
18
- #@+node:class DataField
19
29
class DataField (object ):
20
30
"""Base class for physical data.
21
31
@@ -43,8 +53,6 @@ class DataField(object):
43
53
@ivar dataLoaded: has the data been read?
44
54
@type dataLoaded: bool
45
55
"""
46
- #@ @+others
47
- #@+node:__init__
48
56
49
57
def __init__ (self ,data = None ):
50
58
super (DataField ,self ).__init__ ()
@@ -60,42 +68,30 @@ def __init__(self,data=None):
60
68
self .dataLoaded = False
61
69
self .Temperature = None
62
70
63
- #@-node:__init__
64
- #@+node:dataChanged
65
71
def dataChanged (self ):
66
72
self .updateDataRange ()
67
73
try :
68
74
super (DataField , self ).dataChanged (self )
69
75
except AttributeError :
70
76
pass
71
77
72
- #@-node:dataChanged
73
- #@+node:updateDataRange
74
78
def updateDataRange (self ):
75
79
"""Update the values of dataMax and dataMin, call this after changing the data."""
76
80
if self .d != None :
77
81
self .dataMax = self .d .max ()
78
82
self .dataMin = self .d .min ()
79
83
return self
80
84
81
- #@-node:updateDataRange
82
- #@+node:setReader
83
85
def setReader (self ,reader ):
84
86
"""Set the reader class."""
85
87
self .Reader = reader ()
86
88
87
- #@-node:setReader
88
- #@+node:findReader
89
89
def findReader (self ):
90
90
"""Find a reader class from available format plugins for our filename."""
91
91
reader = FileIO .findReaderForFilename (self .filename )
92
92
self .setReader (reader )
93
93
94
- #@-node:findReader
95
- #@+node:loadHeader
96
94
def loadHeader (self ,force = False ):
97
- #@ << docstring >>
98
- #@+node:<< docstring >>
99
95
"""Load the header.
100
96
101
97
This function reads the header information from the file given in this
@@ -109,9 +105,6 @@ def loadHeader(self,force=False):
109
105
@keyword force: Set to True if header should be read even if it was already read before.
110
106
@type force: bool
111
107
"""
112
- #@nonl
113
- #@-node:<< docstring >>
114
- #@nl
115
108
if self .Reader == None :
116
109
self .findReader ()
117
110
if force or not self .headerLoaded :
@@ -124,11 +117,7 @@ def loadHeader(self,force=False):
124
117
raise
125
118
return self
126
119
127
- #@-node:loadHeader
128
- #@+node:loadData
129
120
def loadData (self ,force = False ):
130
- #@ << docstring >>
131
- #@+node:<< docstring >>
132
121
"""Load the data.
133
122
134
123
This function reads the actual data from the file given in this
@@ -144,9 +133,6 @@ def loadData(self,force=False):
144
133
@keyword force: Set to True if data should be read even if it was already read before.
145
134
@type force: bool
146
135
"""
147
- #@nonl
148
- #@-node:<< docstring >>
149
- #@nl
150
136
if force or not self .dataLoaded :
151
137
if force or not self .headerLoaded :
152
138
self .loadHeader (force )
@@ -160,8 +146,6 @@ def loadData(self,force=False):
160
146
raise
161
147
return self
162
148
163
- #@-node:loadData
164
- #@+node:load
165
149
def load (self ):
166
150
"""Read data from file.
167
151
@@ -170,26 +154,16 @@ def load(self):
170
154
self .loadData ()
171
155
return self
172
156
173
- #@-node:load
174
- #@-others
175
- #@-node:class DataField
176
- #@+node:class G1D
177
157
class G1D (DataField ):
178
158
"""General 1-dimensional data.
179
159
180
160
This is mainly intended as a base class.
181
161
This class should implement methods common to 1-dimensional data types
182
162
"""
183
- #@ @+others
184
- #@+node:__init__
185
163
186
164
def __init__ (self ):
187
165
super (G1D ,self ).__init__ ()
188
166
189
- #@-node:__init__
190
- #@-others
191
- #@-node:class G1D
192
- #@+node:class G2D
193
167
class G2D (DataField ):
194
168
"""General 2-dimensional data.
195
169
@@ -201,16 +175,12 @@ class G2D(DataField):
201
175
@ivar YRes: Number of datapoints in Y-direction
202
176
@type YRes: number
203
177
"""
204
- #@ @+others
205
- #@+node:__init__
206
178
207
179
def __init__ (self ):
208
180
super (G2D ,self ).__init__ ()
209
181
self .XRes = 0
210
182
self .YRes = 0
211
183
212
- #@-node:__init__
213
- #@+node:bgRowwiseZOffset
214
184
def bgRowwiseZOffset (self ):
215
185
"""Subtract each row's mean value from it.
216
186
"""
@@ -221,8 +191,6 @@ def bgRowwiseZOffset(self):
221
191
self .updateDataRange ()
222
192
return self
223
193
224
- #@-node:bgRowwiseZOffset
225
- #@+node:bgColwiseZOffset
226
194
def bgColwiseZOffset (self ):
227
195
"""Subtract each column's mean value from it.
228
196
"""
@@ -233,8 +201,6 @@ def bgColwiseZOffset(self):
233
201
self .updateDataRange ()
234
202
return self
235
203
236
- #@-node:bgColwiseZOffset
237
- #@+node:bgPlaneSubtract
238
204
def bgPlaneSubtract (self ):
239
205
"""Subtract a plane.
240
206
@@ -256,51 +222,33 @@ def bgPlaneSubtract(self):
256
222
self .updateDataRange ()
257
223
return self
258
224
259
- #@-node:bgPlaneSubtract
260
- #@+node:savePNG
261
225
def savePNG (self ,cmin = None ,cmax = None ,pal = 'grey' ):
262
226
self .saveImage (self .filename + '.png' , cmin = cmin , cmax = cmax , pal = pal )
263
227
264
- #@-node:savePNG
265
- #@+node:saveImage
266
228
def saveImage (self ,fname ,cmin = None ,cmax = None ,pal = 'grey' ):
267
229
format = os .path .splitext (fname )[1 ][1 :]
268
230
savefile = open (fname ,'wb' )
269
231
self .toImage (savefile ,format = format ,cmin = cmin ,cmax = cmax ,pal = pal )
270
232
savefile .close ()
271
233
272
- #@-node:saveImage
273
- #@+node:toImage
274
234
def toImage (self ,fobj ,format = "bmp" ,cmin = None ,cmax = None ,pal = 'grey' ):
275
235
img = scipy .misc .pilutil .toimage (self .d ,cmin = cmin ,cmax = cmax )
276
236
palette = pilutil .stdpal (pal )
277
237
img .putpalette (palette )
278
238
img .save (fobj , format )
279
239
280
- #@-node:toImage
281
- #@-others
282
- #@-node:class G2D
283
- #@+node:class G3D
284
240
class G3D (DataField ):
285
241
"""General 3-dimensional data.
286
242
287
243
This is mainly intended as a base class.
288
244
This class should implement methods common to 3-dimensional data types
289
245
"""
290
- #@ @+others
291
- #@+node:__init__
292
246
293
247
def __init__ (self ):
294
248
super (G3D ,self ).__init__ ()
295
249
296
- #@-node:__init__
297
- #@-others
298
- #@-node:class G3D
299
- #@+node:class LockInData
300
250
class LockInData (object ):
301
251
"""Class for lock-in measurements."""
302
- #@ @+others
303
- #@+node:__init__
304
252
305
253
def __init__ (self ):
306
254
self .LIMod = None #: Lock-In modulation amplitude
@@ -309,27 +257,15 @@ def __init__(self):
309
257
self .LISens = None #: Lock-In sensitivity
310
258
self .LITau = None #: Lock-In time constant
311
259
312
- #@-node:__init__
313
- #@-others
314
- #@-node:class LockInData
315
- #@+node:class Spectroscopy
316
260
class Spectroscopy (object ):
317
261
"""Class for spectroscopy measurements."""
318
- #@ @+others
319
- #@+node:__init__
320
262
def __init__ (self ):
321
263
self .SamplesT = None #: samples per curve, trace
322
264
self .SamplesR = None #: samples per curve, retrace
323
265
324
- #@-node:__init__
325
- #@-others
326
- #@-node:class Spectroscopy
327
- #@+node:class Image
328
266
class Image (G2D ,LockInData ):
329
267
"""Base class for SXM images.
330
268
"""
331
- #@ @+others
332
- #@+node:__init__
333
269
334
270
def __init__ (self ):
335
271
super (Image ,self ).__init__ ()
@@ -344,27 +280,13 @@ def __init__(self):
344
280
self .ScanSpeed = 0 # nm/s
345
281
self .Angle = 0
346
282
347
- #@-node:__init__
348
- #@+node:__repr__
349
283
def __repr__ (self ):
350
284
return "<SPMImage %s %ix%inm %ix%ipx U:%.2fV I:%.2f1nA %s>" % (self .ImageType ,self .XSize ,self .YSize ,self .XRes ,self .YRes ,self .UBias ,self .ISet ,self .Name )
351
285
352
- #@-node:__repr__
353
- #@-others
354
- #@-node:class Image
355
- #@+node:class SpecField
356
286
class SpecField (G3D ,LockInData ):
357
287
"""Base class for spectroscopy fields.
358
288
"""
359
- #@ @+others
360
- #@+node:__init__
361
289
362
290
def __init__ (self ):
363
291
super (SpecField ,self ).__init__ ()
364
292
365
- #@-node:__init__
366
- #@-others
367
- #@-node:class SpecField
368
- #@-others
369
- #@-node:@file D:\Arbeit\SXM\SXM\Data.py
370
- #@-leo
0 commit comments