NSFopen 2.2.0__tar.gz → 2.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. NSFopen-2.2.1/NSFopen/_version.py +1 -0
  2. NSFopen-2.2.1/NSFopen/read/read.py +526 -0
  3. {NSFopen-2.2.0 → NSFopen-2.2.1/NSFopen.egg-info}/PKG-INFO +1 -1
  4. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen.egg-info/SOURCES.txt +2 -1
  5. {NSFopen-2.2.0/NSFopen.egg-info → NSFopen-2.2.1}/PKG-INFO +1 -1
  6. NSFopen-2.2.0/NSFopen/_version.py +0 -1
  7. {NSFopen-2.2.0 → NSFopen-2.2.1}/LICENSE +0 -0
  8. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/__init__.py +0 -0
  9. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Calculate_Roughness/Calculate_Roughness.html +0 -0
  10. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Calculate_Roughness/Calculate_Roughness.ipynb +0 -0
  11. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Calculate_Roughness/Calculate_Roughness.py +0 -0
  12. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Calculate_Roughness/__pycache__/Calculate_Roughness.cpython-310.pyc +0 -0
  13. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Calculate_Roughness/sapphire.nid +0 -0
  14. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Force_Spectroscopy/Force_Spectroscopy.html +0 -0
  15. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Force_Spectroscopy/Force_Spectroscopy.ipynb +0 -0
  16. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Force_Spectroscopy/Force_Spectroscopy.py +0 -0
  17. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Force_Spectroscopy/spectroscopy.nid +0 -0
  18. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Lateral_Force/Lateral Force Processing.html +0 -0
  19. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Lateral_Force/Lateral Force Processing.ipynb +0 -0
  20. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Lateral_Force/Lateral Force Processing.py +0 -0
  21. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Lateral_Force/SBS-PMMA.nid +0 -0
  22. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Plane_Removal/Plane_Removal.html +0 -0
  23. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Plane_Removal/Plane_Removal.ipynb +0 -0
  24. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Plane_Removal/Plane_Removal.py +0 -0
  25. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Plane_Removal/circles.nid +0 -0
  26. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Plane_Removal/circles_holes.nid +0 -0
  27. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Plane_Removal/grid.nid +0 -0
  28. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Plane_Removal/squares_holes.nid +0 -0
  29. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Plotting_Data/MoS2.nid +0 -0
  30. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Plotting_Data/Plotting Data.html +0 -0
  31. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Plotting_Data/Plotting Data.ipynb +0 -0
  32. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Plotting_Data/Plotting Data.py +0 -0
  33. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Sharpen_Image/Sharpen Image.html +0 -0
  34. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Sharpen_Image/Sharpen Image.ipynb +0 -0
  35. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Sharpen_Image/Sharpen Image.py +0 -0
  36. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Sharpen_Image/grid.nid +0 -0
  37. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Sharpen_Image/img.jpg +0 -0
  38. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Spring_Constant/Spring_Constant.html +0 -0
  39. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Spring_Constant/Spring_Constant.ipynb +0 -0
  40. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Spring_Constant/Spring_Constant.py +0 -0
  41. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Spring_Constant/__pycache__/Spring_Constant.cpython-310.pyc +0 -0
  42. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Spring_Constant/__pycache__/__init__.cpython-310.pyc +0 -0
  43. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Spring_Constant/sader.py +0 -0
  44. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Spring_Constant/thermal.nid +0 -0
  45. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/example/Spring_Constant/thermal.png +0 -0
  46. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/process/__init__.py +0 -0
  47. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/process/process.py +0 -0
  48. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen/read/__init__.py +0 -0
  49. /NSFopen-2.2.0/NSFopen/read/read.py → /NSFopen-2.2.1/NSFopen/read/read_beta.py +0 -0
  50. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen.egg-info/dependency_links.txt +0 -0
  51. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen.egg-info/entry_points.txt +0 -0
  52. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen.egg-info/not-zip-safe +0 -0
  53. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen.egg-info/requires.txt +0 -0
  54. {NSFopen-2.2.0 → NSFopen-2.2.1}/NSFopen.egg-info/top_level.txt +0 -0
  55. {NSFopen-2.2.0 → NSFopen-2.2.1}/README.md +0 -0
  56. {NSFopen-2.2.0 → NSFopen-2.2.1}/pyproject.toml +0 -0
  57. {NSFopen-2.2.0 → NSFopen-2.2.1}/setup.cfg +0 -0
  58. {NSFopen-2.2.0 → NSFopen-2.2.1}/setup.py +0 -0
@@ -0,0 +1 @@
1
+ __version__ = "2.2.1"
@@ -0,0 +1,526 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Mon Apr 23 15:17:03 2018
4
+
5
+ Copyright (c) 2018 nelson<at>nanosurf.com
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+
25
+ """
26
+
27
+
28
+ import re
29
+ import numpy as np
30
+ import h5py
31
+ import pandas as pd
32
+ import sys, os
33
+ import time
34
+
35
+ class read():
36
+ def __init__(self, filename=None, **kwargs):
37
+ self.filename = filename
38
+ self.data = None
39
+ self.param = None
40
+
41
+
42
+ if not filename:
43
+ print('\nFile required!\n')
44
+ return
45
+
46
+ _,ext = os.path.splitext(filename)
47
+ if ext == '.nid':
48
+ nid = nid_read(filename=filename, **kwargs)
49
+ self.data = nid.data
50
+ self.param = nid.param
51
+
52
+
53
+ elif ext == '.nhf':
54
+ nhf = nhf_read(filename)
55
+
56
+ self.data = nhf.data
57
+ self.param = nhf.param
58
+
59
+ else:
60
+ print("Not a valid filetype")
61
+ return
62
+
63
+ class nid_read():
64
+ def __init__(self, filename=None, dataframe=True, verbose=False):
65
+ self.filename = filename
66
+ self.data = None
67
+ self.param = None
68
+
69
+ if not filename:
70
+ print('\nFile required!\n')
71
+ return
72
+
73
+ self.__dataframe = dataframe
74
+ self.verbose = verbose
75
+ # names of the channels that can be opened. Can be added to.
76
+ self.data_names = ['Spec forward', 'Spec backward', 'Spec fwd pause', 'Spec bwd pause',
77
+ 'Scan forward', 'Scan backward', '2nd scan forward', '2nd scan backward',
78
+ 'Frequency sweep', 'Frequency sweep SHO', 'Spectrum FFT', 'Spectrum Fit']
79
+ self.data_types = [1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, 2]
80
+
81
+ self.read()
82
+
83
+ def read(self):
84
+ t = time.time()
85
+
86
+ encode = 'ANSI'
87
+ # encode = 'UTF-8'
88
+ encode = 'ISO-8859-1'
89
+
90
+ # isolates header from data file
91
+ if self.verbose:
92
+ print("Reading Header")
93
+
94
+ fid = open(self.filename, 'rb')
95
+ data_in = fid.read().split(b'\n\r\n\r')
96
+ fid.close()
97
+
98
+ head = np.array(data_in[0].split(b'\r\n'))
99
+ boo = head == b''
100
+ indices = np.nonzero(boo[1:] != boo[:-1])[0] + 1
101
+ head = np.split(head, indices)
102
+
103
+ head = [h for h in head if len(h) > 1]
104
+
105
+ header = {}
106
+ for h in head:
107
+ title = h[0].decode(encode)[1:-1]
108
+ data = h[1:]
109
+ values = {}
110
+ for d in data:
111
+ val = d.decode(encode).split('=')
112
+ values[val[0]] = val[1].rstrip()
113
+ header[title] = values
114
+
115
+ param = {}
116
+
117
+ def from_array(key, param):
118
+ return float(header[key][param].split(',')[4])
119
+
120
+ def get_values(key, param, df=False):
121
+ string = header[key][param]
122
+
123
+ ty, val, unit = re.search(r'(\S)\[(.*)\]\*\[(.*)\]', string).groups()
124
+ if ty == 'D':
125
+ val = float(val)
126
+ if ty == 'B':
127
+ val = bool(val)
128
+ if ty == 'L':
129
+ val = int(val)
130
+ if ty == 'V':
131
+ val = [float(v) for v in val.split(',')]
132
+ unit = [str(u) for u in unit.split(',')]
133
+ out = {'Value': val, 'Unit': unit}
134
+ if df:
135
+ if len(out)==1:
136
+ return pd.DataFrame(out)
137
+ else:
138
+ return pd.DataFrame(out)
139
+ else:
140
+ return out
141
+
142
+
143
+ groupNames = []
144
+ dataSet = []
145
+
146
+ ds = 'DataSet'
147
+ grCnt = int(header[ds]['GroupCount'])
148
+ for gr in range(grCnt):
149
+ groupNames.append(header[ds]['Gr' + str(gr) + '-Name'])
150
+ gc = int(header[ds]['Gr' + str(gr) + '-Count'])
151
+
152
+ for g in range(gc):
153
+ key = 'Gr' + str(gr) + '-Ch' + str(g)
154
+ if key in header[ds]:
155
+ dataSet.append(header[ds][key])
156
+
157
+ terms = ['Frame', 'Points', 'Lines', 'SaveBits',
158
+ 'Dim0Min', 'Dim0Range', 'Dim0Unit',
159
+ 'Dim1Min', 'Dim1Range', 'Dim1Unit',
160
+ 'Dim2Min', 'Dim2Range', 'Dim2Unit',
161
+ 'Dim2Name']
162
+
163
+ types = [0, 1, 1, 1,
164
+ 2, 2, 0,
165
+ 2, 2, 0,
166
+ 2, 2, 0,
167
+ 0]
168
+
169
+ # 0 = string, 1 = integer, 2 = float
170
+ typ = [lambda x:str(x), lambda x:int(x), lambda x:float(x)]
171
+
172
+ for term, ty in zip(terms, types):
173
+ val = []
174
+ for d in dataSet:
175
+ h = header[d]
176
+ if term in h:
177
+ val.append(typ[ty](h[term]))
178
+
179
+ param[term] = val
180
+
181
+ # for spectroscopy with maps
182
+ dataPoints = []
183
+ for d in dataSet:
184
+ h = header[d]
185
+ linePoints = []
186
+ if 'LineDim0Min' in h:
187
+ for key, value in h.items():
188
+ if re.match(r'LineDim\d*Points', key):
189
+ linePoints.append(int(value))
190
+ dataPoints.append(np.array(linePoints))
191
+ param['LinePoints'] = dataPoints
192
+
193
+ cantilever = {}
194
+ key = 'DataSet\\Calibration\\Cantilever'
195
+ if key in header:
196
+ cantilever = {'Manufacturer': header[key]['Manufacturer'], 'Name': header[key]['Name']}
197
+
198
+ propcount = int(header[key]['PropCount'])
199
+ for i in range(propcount):
200
+ cantilever['Prop' + str(i)] = get_values(key, 'Prop' + str(i))
201
+
202
+ key = 'DataSet\\Calibration\\Scanhead'
203
+ if key in header:
204
+ sens = from_array(key, 'In5')
205
+ cantilever['Sensitivity'] = {'Value': sens / 10, 'Unit': 'm'}
206
+
207
+ mapTable = {}
208
+ key = 'DataSet\\SpecInfos'
209
+ if key in header:
210
+ n = int(header[key]['SubSectionCount'])
211
+ secNames = [header[key]['SubSection' + str(i)] for i in range(n)]
212
+
213
+ specMode = header[key + '\\' + secNames[0]]['SpecMode']
214
+
215
+ count = int(header[key + '\\' + secNames[1]]['Count'])
216
+
217
+ mapTable = [header[key + '\\' + secNames[1]][specMode[:3] + str(i)].split(';') for i in range(count)]
218
+ mapTable = np.array(mapTable).astype(float)[0]
219
+
220
+
221
+ specParam ={}
222
+ modFw, modBw, pauseFw, pauseBw, rangeFw, rangeBw, stopFw = ([] for i in range(7))
223
+ key = 'DataSet\\Parameters\\Spectroscopy'
224
+ if key in header:
225
+ modFw = get_values(key, 'FwModTime')
226
+ modBw = get_values(key, 'BwModTime')
227
+ pauseFw = get_values(key, 'FwPauseTime')
228
+ pauseBw = get_values(key, 'BwPauseTime')
229
+ rangeFw = get_values(key, 'FwModRange')
230
+ rangeBw = get_values(key, 'BwModRange')
231
+ stopFw = get_values(key, 'FwModStopValue')
232
+
233
+
234
+ scanParam = {}
235
+ scanRange, scanTime, scanOffset, scanRotation = ([] for i in range(4))
236
+ key = 'DataSet\\Parameters\\Imaging'
237
+ if key in header:
238
+ scanRange = get_values(key, 'ScanRange')
239
+ scanTime = get_values(key, 'ScanTime')
240
+ scanOffset = get_values(key, 'ScanOffset')
241
+ scanRotation = get_values(key, 'ScanRotation')
242
+
243
+
244
+ thermal = {}
245
+ key = 'DataSet-Info'
246
+ if '-- Thermal Tuning --' in header[key]:
247
+ if 'k' in header[key]['Q Factor:']:
248
+ Q = float(header[key]['Q Factor:'][:-1])*1e3
249
+ else:
250
+ Q = float(header[key]['Q Factor:'])
251
+ Freq = header[key]['Frequency:']
252
+ SpringK = header[key]['Spring Constant:']
253
+ Peak = header[key]['Peak Value:']
254
+
255
+ gr = re.search(r'(\d+\.\d+)(\S*)', Freq).groups()
256
+ Freq = {'Value': gr[0], 'Unit': gr[1]}
257
+ try:
258
+ gr = re.search(r'(\d+\.\d+)\s(\S*)', SpringK).groups()
259
+ except:
260
+ gr = re.search(r'(\d)\s(\S*)', SpringK).groups()
261
+ SpringK = {'Value': gr[0], 'Unit': gr[1]}
262
+
263
+ try:
264
+ gr = re.search(r'(\d+\.\d+)(\S*)', Peak).groups()
265
+ except:
266
+ gr = re.search(r'(\d)(\S*)', Peak).groups()
267
+ Peak = {'Value': gr[0], 'Unit': gr[1]}
268
+
269
+ thermal = {'Frequency': Freq, 'Q Factor': Q, 'Spring Constant': SpringK, 'Peak': Peak}
270
+
271
+ required_size = int(sum([a*b*c/8 for a, b, c in zip(param['Points'],
272
+ param['Lines'],
273
+ param['SaveBits'])]))
274
+
275
+ q = float(2**param['SaveBits'][0])
276
+ z0 = float(q/2)
277
+
278
+ if param['SaveBits'][0] == 16:
279
+ dt = np.int16
280
+ elif param['SaveBits'][0] == 32:
281
+ dt = np.int32
282
+
283
+ if self.verbose:
284
+ print('Reading Data')
285
+
286
+ fid = open(self.filename, 'rb')
287
+ fid.seek(-required_size, 2)
288
+ data_in = np.fromfile(fid, count=required_size, dtype=dt).astype(float)
289
+ data_in = (data_in + z0) / q
290
+ fid.close()
291
+
292
+ data_in = np.split(data_in, np.cumsum([a * b for a, b in zip(param['Points'],
293
+ param['Lines'])]))
294
+ data_in.pop()
295
+
296
+ data = []
297
+ # reshape and rescale data
298
+ for datain, pts, lns, zran, zmin in zip(data_in,
299
+ param['Points'],
300
+ param['Lines'],
301
+ param['Dim2Range'],
302
+ param['Dim2Min']):
303
+
304
+ data.append(datain.reshape((lns, pts)).__mul__(zran).__add__(zmin))
305
+
306
+ data_crop = []
307
+ for numP, dSet in zip(param['LinePoints'], data):
308
+ if numP.any():
309
+ temp = []
310
+ for n, d in zip(numP, dSet):
311
+ temp.append(d[:n])
312
+ data_crop.append(temp)
313
+ else:
314
+ data_crop.append(dSet)
315
+ data = np.asarray(data_crop, dtype=object)
316
+
317
+ # this is the index of the channels that will be output.
318
+ idx = [idx for idx, frame in enumerate(param['Frame']) if frame in self.data_names]
319
+
320
+ # only take data from approved list in name
321
+ data = data[idx]
322
+ frames = np.array(param['Frame'])[idx]
323
+ channel = np.array(param['Dim2Name'])[idx]
324
+
325
+ frame_chan = [i + ';' + j for i,j in zip(frames,channel)]
326
+
327
+ seen = set()
328
+ new_channel = []
329
+ for x in frame_chan:
330
+ if x not in seen:
331
+ new_channel.append(x)
332
+ seen.add(x)
333
+ else:
334
+ new_channel.append(x + '2')
335
+ channel = [x.split(';')[1] for x in new_channel]
336
+
337
+
338
+ out = {}
339
+ for frame, chan, dat in zip(frames, channel, data):
340
+ if frame not in out:
341
+ out[frame] = {}
342
+ if chan not in out[frame]:
343
+ out[frame][chan] = {}
344
+ if isinstance(dat, list):
345
+ out[frame][chan] = dat
346
+ else:
347
+ out[frame][chan] = dat.astype(float)
348
+
349
+ image = {}
350
+ spec = {}
351
+ spectrum = {}
352
+
353
+ for name, value in out.items():
354
+ dt = self.data_types[self.data_names.index(name)]
355
+ if dt == 0:
356
+ if name == 'Scan forward':
357
+ image['Forward'] = value
358
+ elif name == 'Scan backward':
359
+ image['Backward'] = value
360
+ elif name == '2nd scan forward':
361
+ image['2nd Forward'] = value
362
+ elif name == '2nd scan backward':
363
+ image['2nd Backward'] = value
364
+ else:
365
+ pass
366
+ if dt == 1:
367
+ if name == 'Spec forward':
368
+ spec['Forward'] = value
369
+ elif name == 'Spec backward':
370
+ spec['Backward'] = value
371
+ elif name == 'Spec fwd pause':
372
+ spec['Pause Forward'] = value
373
+ elif name == 'Spec bwd pause':
374
+ spec['Pause Backward'] = value
375
+ else:
376
+ pass
377
+ if dt == 2:
378
+ if name == 'Spectrum FFT':
379
+ spectrum['FFT'] = value
380
+ elif name == 'Spectrum Fit':
381
+ spectrum['Fit'] = value
382
+ elif name == 'Frequency sweep':
383
+ spectrum['Sweep'] = value
384
+ elif name == 'Frequency sweep SHO':
385
+ spectrum['SHO'] = value
386
+ else:
387
+ pass
388
+
389
+ x = dict(zip(['min', 'range', 'units'],
390
+ [param['Dim0Min'], param['Dim0Range'], param['Dim0Unit']]))
391
+ y = dict(zip(['min', 'range', 'units'],
392
+ [param['Dim1Min'], param['Dim1Range'], param['Dim1Unit']]))
393
+ z = dict(zip(['min', 'range', 'units'],
394
+ [param['Dim2Min'], param['Dim2Range'], param['Dim2Unit']]))
395
+ scanParam = dict(zip(['range','time/line','offset','rotation'],
396
+ [scanRange,scanTime,scanOffset,scanRotation]))
397
+ specParam = dict(zip(['modFw','modBw','pauseFw','pauseBw','rangeFw','rangeBw','stop-by-value','maps'],
398
+ [modFw,modBw,pauseFw,pauseBw,rangeFw,rangeBw,stopFw,mapTable]))
399
+
400
+
401
+ parameters = dict(zip(['Tip', 'X', 'Y', 'Z', 'Scan', 'Spec', 'Tune', 'HeaderDump'],
402
+ [cantilever, x, y, z, scanParam, specParam, thermal, header]))
403
+
404
+ dataout = [image, spec, spectrum]
405
+ datanames = ['Image', 'Spec', 'Sweep']
406
+
407
+ valid_data = [val for num, val in enumerate(dataout) if val]
408
+ valid_names = [datanames[num] for num, val in enumerate(dataout) if val]
409
+
410
+ dataout = dict(zip(valid_names, valid_data))
411
+ t_end = time.time() - t
412
+
413
+ if self.verbose:
414
+ print('Elapsed Time: %3.2f sec\n' % t_end)
415
+
416
+ if self.__dataframe:
417
+ # import pandas as pd
418
+ self.data = toPandaDF(dataout).unstack(level=0)
419
+ self.data.dropna(inplace=True)
420
+ # self.specunits = pd.DataFrame(specUnits)
421
+ self.param = toPandaSeries(parameters)
422
+ else:
423
+ self.data = dataout
424
+ self.param = parameters
425
+
426
+
427
+ class nhf_read():
428
+ def __init__(self, filename=None):
429
+ self.filename = filename
430
+ self.data = None
431
+ self.param = None
432
+ self.read()
433
+
434
+ def read(self):
435
+ # measurement
436
+ fopen = h5py.File(self.filename, 'r')
437
+ group_name = list(fopen.keys())
438
+ # forward/backward
439
+ segment = fopen[group_name[0]]
440
+ seg_names = list(segment.keys())
441
+
442
+ s_prop = segment.attrs
443
+ prop_s = {name:s_prop[name] for name in list(s_prop)}
444
+
445
+ DAC_max = (2**31-1)
446
+
447
+
448
+ # DAC_max: dict = {0: [-(2.0**31), 2.0**31, 'dt_int32'],
449
+ # 1: [-(2.0**8), 2.0**8, 'dt_uint8'],
450
+ # 2: [-(2.0**16), 2.0**16, 'dt_uint16'],
451
+ # 3: [-(2.0**32), 2.0**32, 'dt_uint32'],
452
+ # 4: [-(2.0**64), 2.0**64, 'dt_uint64'],
453
+ # 5: [-(2.0**15), 2.0**15, 'dt_int16'],
454
+ # 6: [-(2.0**64), 2.0**64, 'dt_int64'],
455
+ # 7: [0.0, 0.0, 'dt_double']
456
+ # }
457
+
458
+ data_out = {}
459
+ prop = []
460
+
461
+ for s in seg_names:
462
+ meas = segment[s]
463
+ direction = meas.attrs['name']
464
+ data_out[direction] = {}
465
+
466
+ for m in list(meas.keys()):
467
+ data = meas[m]
468
+ d_prop = data.attrs
469
+
470
+ Nx = prop_s['image_points_per_line']
471
+ Ny = prop_s['image_number_of_lines']
472
+
473
+ prop.append({name:d_prop[name] for name in list(d_prop)})
474
+
475
+ bit = d_prop['dataset_size']
476
+ mx = d_prop['value_max']
477
+ mn= d_prop['value_min']
478
+ cal_max = d_prop['base_calibration_max']
479
+ cal_min = d_prop['base_calibration_min']
480
+
481
+ channel = d_prop['name']
482
+ scale = (cal_max-cal_min)/DAC_max/2
483
+
484
+ data_out[direction][channel] = np.reshape(data[:], [Nx, Ny])*scale
485
+
486
+ _data_out={}
487
+ _data_out['Image'] = data_out
488
+
489
+ self.data = toPandaDF(_data_out).unstack(level=0)
490
+ self.param = pd.Series(prop_s)
491
+ fopen.close()
492
+
493
+
494
+ def toPandaDF(user_dict):
495
+ df = pd.DataFrame.from_dict({(i, j): user_dict[i][j]
496
+ for i in user_dict.keys()
497
+ for j in user_dict[i].keys()}, orient='index').transpose()
498
+ return df
499
+
500
+ def toPandaSeries(user_dict):
501
+ df = pd.Series({(i, j): user_dict[i][j]
502
+ for i in user_dict.keys()
503
+ for j in user_dict[i].keys()})
504
+ return df
505
+
506
+
507
+
508
+ def checkFileType(filename, cla):
509
+ import sys, os
510
+ switch = {'nid':'nhf_read','nhf':'nid_read'}
511
+
512
+ _,ext = os.path.splitext(filename)
513
+ if ext[-3:] != cla:
514
+ print(f'\nWrong file type detected, use "%s" instead' % switch[cla])
515
+ sys.exit()
516
+ elif ext[-3:] == cla:
517
+ return filename
518
+ else:
519
+ print("\nNot a valid filetype")
520
+ exit()
521
+
522
+
523
+ if __name__=="__main__":
524
+ filename='..//example//Plane_Removal//circles.nid'
525
+ afm=read(filename,verbose=True)
526
+ print(afm.param)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: NSFopen
3
- Version: 2.2.0
3
+ Version: 2.2.1
4
4
  Summary: Python module to open Nanosurf NID and NHF files
5
5
  Author: Nanosurf AG
6
6
  Author-email: scripting@nanosurf.com
@@ -52,4 +52,5 @@ NSFopen/example/Spring_Constant/__pycache__/__init__.cpython-310.pyc
52
52
  NSFopen/process/__init__.py
53
53
  NSFopen/process/process.py
54
54
  NSFopen/read/__init__.py
55
- NSFopen/read/read.py
55
+ NSFopen/read/read.py
56
+ NSFopen/read/read_beta.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: NSFopen
3
- Version: 2.2.0
3
+ Version: 2.2.1
4
4
  Summary: Python module to open Nanosurf NID and NHF files
5
5
  Author: Nanosurf AG
6
6
  Author-email: scripting@nanosurf.com
@@ -1 +0,0 @@
1
- __version__ = "2.2.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes