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

pearl-scienta-countrate.ipf
Go to the documentation of this file.
1 #pragma rtGlobals=3 // Use modern global access method and strict wave access.
2 #pragma IgorVersion = 6.35
3 #pragma ModuleName = PearlScientaCountrate
4 #include "pearl-area-display"
5
6 // Copyright (c) 2019 Paul Scherrer Institut
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
12
26
31
43 function ScientaLiveDisplay(epicsname, nickname, wbRGB)
44 string epicsname
45 string nickname
46 string wbRGB
47
48 ad_connect(epicsname, nickname)
49 string df_name
50 sprintf df_name, "ad_display_profiles(root:pearl_epics:%s)", nickname
51 dfref df = $df_name
52 wave /sdfr=df img = image
53 string graphname = ad_display(img)
54 wbRGB = replacestring("(", wbRGB, "")
55 wbRGB = replacestring(")", wbRGB, "")
56 variable rr = str2num(StringFromList(0, wbRGB, ","))
57 variable gg = str2num(StringFromList(1, wbRGB, ","))
58 variable bb = str2num(StringFromList(2, wbRGB, ","))
59 ModifyGraph /w=$graphname wbRGB=(rr,gg,bb)
60 add_roi_controls()
61 ad_add_overlay(img)
62 end
63
64 #if igorVersion() >= 8
65 function check_exposure(image, outmask, dwelltime)
88 wave image
89 wave outmask
90 variable dwelltime
91
92 variable xbin = 1
93 variable ybin = 902 / dimsize(image, 1)
94 variable thresh = 1e5 / 900 / 900
95
96 duplicate /free image, filt
97 setscale /p x -dimsize(image, 0)/2, 1, "", filt // energy
98 setscale /p y -dimsize(image, 1)/2, 1, "", filt // angle
99 variable wx = sqrt(500) / xbin
100 variable wy = sqrt(500) / ybin
101 filt = exp(-((x/wx)^2 + (y/wy)^2))
102 variable nfilt = sum(filt)
103 filt /= nfilt
104 fft /free /dest=filt_fft filt
105
106 duplicate /free image, img
107 img /= dwelltime
108 setscale /p x -dimsize(image, 0)/2, 1, "", img
109 setscale /p y -dimsize(image, 1)/2, 1, "", img
110 fft /free /dest=img_fft img
111 img_fft *= filt_fft
112 ifft /free /dest=img_ifft img_fft
113 imagetransform swap img_ifft
114
115 outmask = (img_ifft < thresh) * 64
116 end
117 #endif
118
150 function check_exposure_opt(image, outmask, dwelltime, [calc_df])
151 wave image
152 wave outmask
153 variable dwelltime
154 dfref calc_df
155
156 variable xbin = 1
157 variable ybin = 902 / dimsize(image, 1)
158 variable thresh = 1e5 / 900 / 900
159
160 dfref save_df = GetDataFolderDFR()
161 if (ParamIsDefault(calc_df))
162 dfref source_df = GetWavesDataFolderDFR(image)
163 string calc_df_name = PearlCleanupName("psc_" + NameOfWave(image))
164 dfref calc_df = source_df:$calc_df_name
165 endif
166 NewDataFolder /o /s calc_df
167
168 wave /z co_filt
169 wave /z /c co_filt_fft
170 wave /z co_img
171 wave /z /c co_img_fft
172 wave /z co_img_ifft
173 nvar /z co_img_size_x
174 nvar /z co_img_size_y
175
176 variable cache = 0
177 if (waveexists(co_filt))
178 cache = (dimsize(image, 0) == co_img_size_x) && (dimsize(image, 1) == co_img_size_y)
179 if (!cache)
180 redimension /n=(dimsize(image, 0), dimsize(image, 1)) co_filt, co_filt_fft, co_img, co_img_fft, co_img_ifft
181 endif
182 else
183 duplicate /o image, co_filt, co_img, co_img_ifft
184 make /n=(dimsize(image, 0), dimsize(image, 1)) /c co_filt_fft, co_img_fft
185 variable /g co_img_size_x
186 variable /g co_img_size_y
187 endif
188
189 co_img_size_x = dimsize(image, 0)
190 co_img_size_y = dimsize(image, 1)
191 setscale /p x -co_img_size_x/2, 1, "", co_filt, co_filt_fft, co_img, co_img_fft, co_img_ifft
192 setscale /p y -co_img_size_y/2, 1, "", co_filt, co_filt_fft, co_img, co_img_fft, co_img_ifft
193
194 if (!cache)
195 variable wx = sqrt(500) / xbin
196 variable wy = sqrt(500) / ybin
197 co_filt = exp(-((x/wx)^2 + (y/wy)^2))
198 variable nfilt = sum(co_filt)
199 co_filt /= nfilt
200 fft /dest=co_filt_fft co_filt
201 endif
202
203 co_img /= dwelltime
204 fft /dest=co_img_fft co_img
205 co_img_fft *= co_filt_fft
206 ifft /dest=co_img_ifft co_img_fft
207 imagetransform swap co_img_ifft
208
209 redimension /n=(dimsize(co_img_ifft, 0), dimsize(co_img_ifft, 1)) outmask
210 outmask = (co_img_ifft < thresh) * 64
211
212 SetDataFolder save_df
213 end
check_exposure_opt
variable check_exposure_opt(wave image, wave outmask, variable dwelltime, dfref calc_df=defaultValue)
optimized check exposure and calculate overexposure indicator mask
Definition: pearl-scienta-countrate.ipf:150
PearlCleanupName
string PearlCleanupName(string name)
Definition: pearl-compat.ipf:47
ad_display
string ad_display(wave image)
open a new graph window with a 2D image.
Definition: pearl-area-display.ipf:85
ad_add_overlay
wave ad_add_overlay(wave image, string rgba=defaultValue)
add an overlay on top of the displayed image
Definition: pearl-area-display.ipf:329
ScientaLiveDisplay
variable ScientaLiveDisplay(string epicsname, string nickname, string wbRGB)
open live display of most recent scienta measurement
Definition: pearl-scienta-countrate.ipf:43