proc_shift.py
2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
title = "Shift"
tip = "shifts a map"
onein = 2
import numpy as np
import copy as cp
import scipy.ndimage as spi
from guidata.qt.QtGui import QMessageBox
from guidata.dataset.datatypes import DataSet
from guidata.dataset.dataitems import (IntItem, FloatArrayItem, StringItem,
ChoiceItem, FloatItem, DictItem,
BoolItem)
from guiqwt.config import _
from nodfitting import gaussian, correlate
from nodmath import nan_interpolation, subpixel_shift
#from nodmath import nan_interpolation, map_zoom, same_size, register_translation, center_of_gravity
def nextpow2(i):
n = 1
while n < i: n *= 2
return n
class NOD3_App:
def __init__(self, parent):
self.parent = parent
self.parent.activateWindow()
def Error(self, msg):
QMessageBox.critical(self.parent.parent(), title,
_(u"Error:")+"\n%s" % str(msg))
def compute_app(self, **args):
class FuncParam(DataSet):
clip = FloatItem('Cutoff', default=0.1, min=0.0)
name = title.replace(" ", "")
if args == {}:
param = FuncParam(_(title), "Percent of maximum:")
else:
param = self.parent.ScriptParameter(name, args)
# if no parameter needed set param to None. activate next line
#param = None
self.parent.compute_11(name, lambda m, p: self.function(m, p), param, onein)
def function(self, ms, p):
hpbw = []
i = 0
m1 = ms[0]
m2 = ms[1]
mask1 = ~np.isnan(m1.data)
mask2 = ~np.isnan(m2.data)
m1.data = nan_interpolation(m1.data)
m2.data = nan_interpolation(m2.data)
dx, dy, m2.data = subpixel_shift(m1.data, m2.data, clip=p.clip)
m1.data = np.where(mask1, m1.data, np.nan)
m2.data = np.where(mask2, m2.data, np.nan)
progress = self.parent.imagewidget.Progress
progress.showMessage(_("image shift: dx = %f dy = %f" % (dx, dy)))
return [m1, m2], p