# PEARL Procedures: pearl-scienta-countrate.ipf Source File

pearl-scienta-countrate.ipf
Go to the documentation of this file.
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
#pragma IgorVersion = 6.35
#pragma ModuleName = PearlScientaCountrate
#include "pearl-area-display"
// Copyright (c) 2019 Paul Scherrer Institut
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
function ScientaLiveDisplay(epicsname, nickname, wbRGB)
string epicsname
string nickname
string wbRGB
ad_connect(epicsname, nickname)
string df_name
sprintf df_name, "ad_display_profiles(root:pearl_epics:%s)", nickname
dfref df = $df_name
wave /sdfr=df img = image
string graphname = ad_display(img)
wbRGB = replacestring("(", wbRGB, "")
wbRGB = replacestring(")", wbRGB, "")
variable rr = str2num(StringFromList(0, wbRGB, ","))
variable gg = str2num(StringFromList(1, wbRGB, ","))
variable bb = str2num(StringFromList(2, wbRGB, ","))
ModifyGraph /w=$graphname wbRGB=(rr,gg,bb)
add_roi_controls()
ad_add_overlay(img)
end
#if igorVersion() >= 8
function check_exposure(image, outmask, dwelltime)
wave image
wave outmask
variable dwelltime
variable xbin = 1
variable ybin = 902 / dimsize(image, 1)
variable thresh = 1e5 / 900 / 900
duplicate /free image, filt
setscale /p x -dimsize(image, 0)/2, 1, "", filt // energy
setscale /p y -dimsize(image, 1)/2, 1, "", filt // angle
variable wx = sqrt(500) / xbin
variable wy = sqrt(500) / ybin
filt = exp(-((x/wx)^2 + (y/wy)^2))
variable nfilt = sum(filt)
filt /= nfilt
fft /free /dest=filt_fft filt
duplicate /free image, img
img /= dwelltime
setscale /p x -dimsize(image, 0)/2, 1, "", img
setscale /p y -dimsize(image, 1)/2, 1, "", img
fft /free /dest=img_fft img
img_fft *= filt_fft
ifft /free /dest=img_ifft img_fft
imagetransform swap img_ifft
outmask = (img_ifft < thresh) * 64
end
#endif
function check_exposure_opt(image, outmask, dwelltime, [calc_df])
wave image
wave outmask
variable dwelltime
dfref calc_df
variable xbin = 1
variable ybin = 902 / dimsize(image, 1)
variable thresh = 1e5 / 900 / 900
dfref save_df = GetDataFolderDFR()
if (ParamIsDefault(calc_df))
dfref source_df = GetWavesDataFolderDFR(image)
string calc_df_name = PearlCleanupName("psc_" + NameOfWave(image))
dfref calc_df = source_df:$calc_df_name
endif
NewDataFolder /o /s calc_df
wave /z co_filt
wave /z /c co_filt_fft
wave /z co_img
wave /z /c co_img_fft
wave /z co_img_ifft
nvar /z co_img_size_x
nvar /z co_img_size_y
variable cache = 0
if (waveexists(co_filt))
cache = (dimsize(image, 0) == co_img_size_x) && (dimsize(image, 1) == co_img_size_y)
if (!cache)
redimension /n=(dimsize(image, 0), dimsize(image, 1)) co_filt, co_filt_fft, co_img, co_img_fft, co_img_ifft
endif
else
duplicate /o image, co_filt, co_img, co_img_ifft
make /n=(dimsize(image, 0), dimsize(image, 1)) /c co_filt_fft, co_img_fft
variable /g co_img_size_x
variable /g co_img_size_y
endif
co_img_size_x = dimsize(image, 0)
co_img_size_y = dimsize(image, 1)
setscale /p x -co_img_size_x/2, 1, "", co_filt, co_filt_fft, co_img, co_img_fft, co_img_ifft
setscale /p y -co_img_size_y/2, 1, "", co_filt, co_filt_fft, co_img, co_img_fft, co_img_ifft
if (!cache)
variable wx = sqrt(500) / xbin
variable wy = sqrt(500) / ybin
co_filt = exp(-((x/wx)^2 + (y/wy)^2))
variable nfilt = sum(co_filt)
co_filt /= nfilt
fft /dest=co_filt_fft co_filt
endif
co_img /= dwelltime
fft /dest=co_img_fft co_img
co_img_fft *= co_filt_fft
ifft /dest=co_img_ifft co_img_fft
imagetransform swap co_img_ifft
redimension /n=(dimsize(co_img_ifft, 0), dimsize(co_img_ifft, 1)) outmask
outmask = (co_img_ifft < thresh) * 64
SetDataFolder save_df
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