Skip to content

Commit 7583b21

Browse files
committed
Updated channel name recognition (images), new phase correction (spectra)
1 parent aa71942 commit 7583b21

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

pySNOM/images.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
import copy
3+
import re
34
from enum import Enum
45
from pySNOM.defaults import Defaults
56
from gwyfile.objects import GwyDataField
@@ -121,21 +122,26 @@ def data(self,value):
121122
raise ValueError("The provided data object does not contain 'data' attribute")
122123

123124
def type_from_channelname(channelname):
124-
if channelname[0] == 'O':
125+
channel_strings = ['M(.?)A', 'M(.?)P', 'O(.?)A', 'O(.?)P', 'Z C', 'Z raw']
126+
for pattern in channel_strings:
127+
if re.search(pattern, channelname) is not None:
128+
channel_name = re.search(pattern, channelname)[0]
129+
130+
if channel_name[0] == 'O':
125131
channeltype = ChannelTypes["Optical"]
126-
elif 'M' in channelname:
132+
elif 'M' in channel_name:
127133
channeltype = ChannelTypes["Mechanical"]
128134
else:
129135
channeltype = ChannelTypes["None"]
130136

131-
if 'Z' in channelname:
137+
if 'Z' in channel_name:
132138
order = 0
133139
else:
134-
order = int(channelname[1])
140+
order = int(channel_name[1])
135141

136-
if channelname[2] == 'A':
142+
if channel_name[2] == 'A':
137143
datatype = DataTypes["Amplitude"]
138-
elif 'Z' in channelname:
144+
elif 'Z' in channel_name:
139145
datatype = DataTypes["Topography"]
140146
else:
141147
datatype = DataTypes["Phase"]
@@ -224,6 +230,11 @@ def transform(self, data):
224230
return data / self.value
225231
else:
226232
return data - self.value
233+
case 'min':
234+
if self.datatype == DataTypes.Amplitude:
235+
return data / np.nanmin(data)
236+
else:
237+
return data - np.nanmin(data)
227238

228239
class BackgroundPolyFit(Transformation):
229240

pySNOM/spectra.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,34 @@ def transform(self, spectrum, wnaxis):
145145

146146
return np.angle(spectrum*np.exp(angles*complex(1j)))
147147

148+
class ShiftPhaseToZero(Transformation):
149+
"""
150+
Calculates and applies the phase rotation needed to get a flat, levelled phase spectrum.
151+
Two reference frequencies have to be provided.
152+
"""
153+
def __init__(self, wavenumber1=1000.0, wavenumber2=2200.0):
154+
self.wn1 = wavenumber1
155+
self.wn2 = wavenumber2
156+
157+
def transform(self, spectrum, wnaxis):
158+
if not np.iscomplex(spectrum).any():
159+
spectrum = np.exp(spectrum*complex(1j))
160+
161+
wn1idx = np.argmin(abs(wnaxis - self.wn1))
162+
wn2idx = np.argmin(abs(wnaxis - self.wn2))
163+
164+
theta1 = np.angle(spectrum[wn1idx])
165+
wn1 = wnaxis[wn1idx]
166+
spectrum = spectrum*np.exp(-theta1*complex(1j))
167+
168+
theta2 = np.angle(spectrum[wn2idx])
169+
wn2 = wnaxis[wn2idx]
170+
171+
angles = (wnaxis-wn1) * theta2 / (wn2-wn1)
172+
spectrum = np.angle(spectrum*np.exp(-1*angles*complex(1j)))
173+
174+
return spectrum
175+
148176
class NormalizeSpectrum(Transformation):
149177

150178
def __init__(self, datatype=DataTypes.Phase, dounwrap=False):

0 commit comments

Comments
 (0)