PEARL Procedures rev-distro-2.1.1-1-gf419e92-dirty Igor procedures for the analysis of PEARL data

pearl-otf-import.ipf
Go to the documentation of this file.
1 #pragma rtGlobals=1 // Use modern global access method.
2 #pragma IgorVersion = 6.1
3 #pragma ModuleName = PearlOtfImport
4 #pragma version = 1.01
5
6 // procedures for importing on-the-fly (OTF) scans
7 // OTF scans are saved as ITX files
8 // matthias muntwiler, 2013-02-22
9 // $Id$
10
11 // introduction
12 // the latest version of the PEARL OTF server saves data in igor text (ITX)
13 // the files contain code which saves all data from one file into one data folder with a unique name
14 // multiple files can be selected in the explorer and loaded by a double click
15
16 // description
17 // OTF data folder names have the format otf_date_time_suffix, where only suffix is user-defined
18 // thus, raw data folder names are unique
19 // data folder names can be converted to a shorter format
20 // an OTF data folder contains a wave for each measured quantity (detector)
21 // and the IN, ID, IV, and IU waves for additional beamline parameters
22 // detector waves must have a wave note containing the following key=value pairs:
23 // PV=name of EPICS process variable
24 // PhysicalType=physical type of the quantity in the same way as used by pearl-optics-import
25 // Axis1=wave name of principal X axis
26
27 // convergence
28 // while the file formats may be different, data files generated by the OTF and EPICS scan tools
29 // shall ultimately produce the same data structures in an Igor experiment
30
31 function otf_load_itx_all(pathname)
32 // loads all OTF files from a given path
33 // this function is for older files (before 2013-03-01) which do not specify a destination data folder
34 // newer files can be loaded by double click from the explorer
35 // without the danger of overwriting data from other files
36 string pathname
37 string filename
38
39 if (strlen(pathname) <= 0)
40 newpath /o/q otf_load_itx
41 pathname = "otf_load_itx"
42 endif
43 string filelist = IndexedFile($pathname, -1, ".itx")
44 filelist = ListMatch(filelist, "otf*.itx", ";")
45 variable nfile = ItemsInList(filelist, ";")
46 variable ifile
47 for (ifile = 0; ifile < nfile; ifile += 1)
48 filename = StringFromList(ifile, filelist, ";")
49 otf_load_itx(pathname, filename)
50 endfor
51 end
52
53 function otf_load_itx_match(pathname, matchstr)
54 // loads all OTF files from a given path whose names match a given string
55 // this function is for older files (before 2013-03-01) which do not specify a destination data folder
56 // newer files can be loaded by double click from the explorer
57 // without the danger of overwriting data from other files
58 string pathname
59 string matchstr
60 string filename
61
62 if (strlen(pathname) <= 0)
63 newpath /o/q otf_load_itx
64 pathname = "otf_load_itx"
65 endif
66 string filelist = IndexedFile($pathname, -1, ".itx")
67 filelist = ListMatch(filelist, matchstr, ";")
68 variable nfile = ItemsInList(filelist, ";")
69 variable ifile
70 for (ifile = 0; ifile < nfile; ifile += 1)
71 filename = StringFromList(ifile, filelist, ";")
72 otf_load_itx(pathname, filename)
73 endfor
74 end
75
76 function otf_load_itx(pathname, filename)
77 // loads a specific OTF file
78 // this function is for older files (before 2013-03-01) which do not specify a destination data folder
79 // newer files can be loaded by double click from the explorer
80 // without the danger of overwriting data from other files
81 string pathname
82 string filename
83
84 dfref savedf = GetDataFolderDFR()
85 setdatafolder root:
86
87 newdatafolder /s/o otf_load_itx_temp
88 if (strlen(pathname) > 0)
89 LoadWave /O/P=$pathname/Q/T filename
90 else
91 LoadWave /O/Q/T filename
92 endif
93 if (v_flag)
94 string foldername
95 foldername = ParseFilePath(3, s_filename, "/", 0, 0)
96 foldername = foldername[0,16]
97 foldername = CleanupName(foldername, 0)
98 //foldername = UniqueName(foldername, 11, 0)
99 renamedatafolder root:otf_load_itx_temp, $foldername
100 printf "loaded otf data from file %s into folder %s\r", s_filename, foldername
101 endif
102
103 setdatafolder savedf
104 end
105
106 function otf_gather_iterator(df, sdata)
107 // data folder iterator used by otf_gather_batch
108 dfref df
109 string &sdata // key=value list of parameters
110 // xwavematch
111 // ywavematch
112 // destfolder
113
114 string src_name
115 string dst_name
116 string src_folder
117 string dst_folder
118 string df_id
119 string prefix, sdate, stime
120
121 setdatafolder df
122 src_folder = GetDataFolder(0, df)
123 sscanf src_folder, "%[^_]_%[0-9]_%[0-9]", prefix, sdate, stime
124 df_id = ""
125 if (strlen(sdate) > 0)
126 df_id += "_" + sdate
127 endif
128 if (strlen(stime) > 0)
129 df_id += "_" + stime
130 endif
131 dst_folder = StringByKey("destfolder", sdata)
132
133 src_name = StringByKey("xwavematch", sdata)
134 src_name = WaveList(src_name, "", "")
135 if (ItemsInList(src_name) >= 1)
136 src_name = StringFromList(0, src_name)
137 dst_name = dst_folder + src_name + df_id
138 //print src_name, dst_name
139 duplicate $src_name, $dst_name
140 endif
141
142 src_name = StringByKey("ywavematch", sdata)
143 src_name = WaveList(src_name, "", "")
144 if (ItemsInList(src_name) >= 1)
145 src_name = StringFromList(0, src_name)
146 dst_name = dst_folder + src_name + df_id
147 //print src_name, dst_name
148 duplicate $src_name, $dst_name
149 endif
150 end
151
152 function otf_gather_batch(ywavematch, xwavematch, destfolder)
153 // gathers (copies) OTF datasets in one data folder
154 // can be used for example for the Igor batch curve fitting tool
155 string ywavematch // match string identifies the y wave to be copied
156 string xwavematch // match string identifies the x wave to be copied
157 string destfolder // name of the destination data folder. folder does not have to exist.
158
159 return gather_batch("otf*", ywavematch, xwavematch, destfolder)
160 end
161
162 function gather_batch(foldermatch, ywavematch, xwavematch, destfolder)
163 // gathers (copies) OTF datasets in one data folder
164 // can be used for example for the Igor batch curve fitting tool
165 string foldermatch // match string to select data folders, e.g. "otf*"
166 string ywavematch // match string identifies the y wave to be copied
167 string xwavematch // match string identifies the x wave to be copied
168 string destfolder // name of the destination data folder. folder does not have to exist.
169
170 dfref savedf = GetDataFolderDFR()
171 newdatafolder /o/s $destfolder
172 destfolder = GetDataFolder(1)
173
174 string iteratordata = ""
175 iteratordata = ReplaceStringByKey("xwavematch", iteratordata, xwavematch)
176 iteratordata = ReplaceStringByKey("ywavematch", iteratordata, ywavematch)
177 iteratordata = ReplaceStringByKey("destfolder", iteratordata, destfolder)
178
179 setdatafolder savedf
180 iteratordata = IterateDataFolders(foldermatch, otf_gather_iterator, iteratordata)
181
182 setdatafolder savedf
183 end
184
185 function otf_rename_folders_iterator(df, sdata)
186 // data folder iterator used by otf_rename_folders
187 dfref df
188 string &sdata // key=value list of parameters
189
190 string pattern = StringByKey("pattern", sdata)
191 variable unique_index = NumberByKey("unique_index", sdata)
192 string new_suffix = StringByKey("new_suffix", sdata)
193
194 string src_folder
195 string dst_folder
196 string sprefix, sdate, stime, ssuffix
197
198 setdatafolder df
199 src_folder = GetDataFolder(0, df)
200 sprefix = "otf"
201 sscanf src_folder, "otf_%[0-9]_%[0-9]%s", sdate, stime, ssuffix
202 // return early if folder name does not match the expected pattern
203 if ((strlen(sdate) == 0) || (strlen(stime) == 0))
204 return 1
205 endif
206
207 dst_folder = sprefix
208 if (cmpstr(pattern[0], "0") != 0)
209 dst_folder += "_" + sdate
210 endif
211 if (cmpstr(pattern[1], "0") != 0)
212 dst_folder += "_" + stime
213 endif
214 if (cmpstr(pattern[2], "0") != 0)
215 if (strlen(new_suffix) > 0)
216 ssuffix = "_" + new_suffix
217 endif
218 dst_folder += ssuffix
219 endif
220
221 if ((unique_index > 0) || (CheckName(dst_folder, 11) != 0))
222 dst_folder = UniqueName(dst_folder + "_", 11, unique_index)
223 endif
224
225 setdatafolder ::
226 print src_folder + " -> " + dst_folder
227 RenameDataFolder $src_folder, $dst_folder
228 return 0
229 end
230
231 function otf_rename_folders(pattern, [unique_index, new_suffix, match_str])
232 // renames OTF data folders by omitting parts of the file name
233 string pattern // string of zeros and ones indicates which name parts to keep
234 // pos 1: date
235 // pos 2: time
236 // pos 3: custom suffix
237 variable unique_index // if you remove date and time,
238 // this start index will be used to make names unique
239 // if non-zero, new names will be forced to include a unique index
240 // if zero (default), new names will get a unique index only in case of a conflict
241 // optional, defaults to 0
242 string new_suffix
243 // replace old suffix by this one
244 // if empty (default), the old suffix will be kept
245 // optional, defaults to empty string
246 string match_str // match folder name to rename
247 // optional, defaults to "otf*" (matches all OTF folders)
248
249 dfref savedf = GetDataFolderDFR()
250
251 if (ParamIsDefault(unique_index))
252 unique_index = 0
253 endif
254 if (ParamIsDefault(new_suffix))
255 new_suffix = ""
256 endif
257 if (ParamIsDefault(match_str))
258 match_str = "otf*"
259 endif
260
261 string iteratordata = ""
262 iteratordata = ReplaceStringByKey("pattern", iteratordata, pattern)
263 iteratordata = ReplaceNumberByKey("unique_index", iteratordata, unique_index)
264 iteratordata = ReplaceStringByKey("new_suffix", iteratordata, new_suffix)
265
266 iteratordata = IterateDataFolders(match_str, otf_rename_folders_iterator, iteratordata)
267
268 setdatafolder savedf
269 end
270
271 function otf_interp(e1, e2, npts, smo)
272 variable e1
273 variable e2
274 variable npts
275 variable smo
276
277 wave ch1 = current_ch1
278 wave ch2 = current_ch2
279 wave pe = photonenergy
280 wave cff
281 wave rc = ringcurrent
282
283 duplicate /o ch1, current_ch1_int
284 wave ch1i = current_ch1_int
285 duplicate /o ch2, current_ch2_int
286 wave ch2i = current_ch2_int
287 duplicate /o pe, photonenergy_int
288 wave pei = photonenergy_int
289 duplicate /o cff, cff_int
290 wave cffi = cff_int
291 duplicate /o rc, ringcurrent_int
292 wave rci = ringcurrent_int
293
294 redimension /n=(npts) ch1i, ch2i, pei, cffi, rci
295 setscale /i x e1, e2, "eV", ch1i, ch2i, pei, cffi, rci
296
297 otf_smo_int(ch1, ch1i, pe, smo)
298 otf_smo_int(ch2, ch2i, pe, smo)
299 otf_smo_int(pe, pei, pe, smo)
300 otf_smo_int(cff, cffi, pe, smo)
301 otf_smo_int(rc, rci, pe, smo)
302 end
303
304 function otf_smo_int(win, wout, wpe, smo)
305 wave win
306 wave wout
307 wave wpe
308 variable smo
309
310 //duplicate /o win, wtmp
311 duplicate /free win, wtmp
312 smooth /b /e=3 smo, wtmp
313 wout = interp(x, wpe, wtmp)
314 end
otf_gather_iterator
variable otf_gather_iterator(dfref df, string *sdata)
Definition: pearl-otf-import.ipf:106
IterateDataFolders
string IterateDataFolders(string matchStr, funcref iterator, string sdata, string progress_title=defaultValue)
Definition: pearl-tools.ipf:79
otf_load_itx
variable otf_load_itx(string pathname, string filename)
Definition: pearl-otf-import.ipf:76
otf_interp
variable otf_interp(variable e1, variable e2, variable npts, variable smo)
Definition: pearl-otf-import.ipf:271
gather_batch
variable gather_batch(string foldermatch, string ywavematch, string xwavematch, string destfolder)
Definition: pearl-otf-import.ipf:162
otf_load_itx_match
variable otf_load_itx_match(string pathname, string matchstr)
Definition: pearl-otf-import.ipf:53
otf_gather_batch
variable otf_gather_batch(string ywavematch, string xwavematch, string destfolder)
Definition: pearl-otf-import.ipf:152
otf_rename_folders
variable otf_rename_folders(string pattern, variable unique_index=defaultValue, string new_suffix=defaultValue, string match_str=defaultValue)
Definition: pearl-otf-import.ipf:231
otf_rename_folders_iterator
variable otf_rename_folders_iterator(dfref df, string *sdata)
Definition: pearl-otf-import.ipf:185
otf_load_itx_all
variable otf_load_itx_all(string pathname)
Definition: pearl-otf-import.ipf:31
otf_smo_int
variable otf_smo_int(wave win, wave wout, wave wpe, variable smo)
Definition: pearl-otf-import.ipf:304