@@ -32,7 +32,8 @@ def __init__(self, data_path_dict, parameters_dict, apply_line_correction=False)
32
32
self .data_path_dict = data_path_dict
33
33
self .parms_dict = parameters_dict
34
34
self .line_correction = apply_line_correction
35
- self .data_dict = self .open_data ()
35
+ self .data_dict = self ._open_data ()
36
+
36
37
#process the data
37
38
self ._process_data ()
38
39
@@ -46,6 +47,14 @@ def _process_data(self):
46
47
Gx = self .parms_dict ['Gx' ]
47
48
Gy = self .parms_dict ['Gy' ]
48
49
50
+
51
+ self .data_dict ['Difference' ] = {}
52
+ self .data_dict ['Average' ] = {}
53
+ self .data_dict ['Difference' ]['Left-Right' ] = {}
54
+ self .data_dict ['Difference' ]['Past-Before' ] = {}
55
+ self .data_dict ['Average' ]['Left-Right' ] = {}
56
+ self .data_dict ['Average' ]['Past-Before' ] = {}
57
+
49
58
# Compute difference and average images for amplitude and piezoresponse
50
59
difference_left_right_amplitude = self .data_dict ["Left" ]['amplitude' ] - self .data_dict ["Right" ]['amplitude' ]
51
60
difference_past_before_amplitude = self .data_dict ["Past" ]['amplitude' ] - self .data_dict ["Before" ]['amplitude' ]
@@ -57,10 +66,96 @@ def _process_data(self):
57
66
average_left_right_piezoresponse = (self .data_dict ["Left" ]['piezoresponse' ] + self .data_dict ["Right" ]['piezoresponse' ]) / 2
58
67
average_before_past_piezoresponse = (self .data_dict ["Before" ]['piezoresponse' ] + self .data_dict ["Past" ]['piezoresponse' ]) / 2
59
68
69
+ self .data_dict ['Difference' ]['Left-Right' ]['Amplitude' ] = difference_left_right_amplitude
70
+ self .data_dict ['Difference' ]['Past-Before' ]['Amplitude' ] = difference_past_before_amplitude
71
+ self .data_dict ['Average' ]['Left-Right' ]['Amplitude' ] = average_left_right_amplitude
72
+ self .data_dict ['Average' ]['Past-Before' ]['Amplitude' ] = average_before_past_amplitude
60
73
61
- def plot_difference_data (self ):
74
+ self .data_dict ['Difference' ]['Left-Right' ]['Piezoresponse' ] = difference_left_right_piezoresponse
75
+ self .data_dict ['Difference' ]['Past-Before' ]['Piezoresponse' ] = difference_past_before_piezoresponse
76
+ self .data_dict ['Average' ]['Left-Right' ]['Piezoresponse' ] = average_left_right_piezoresponse
77
+ self .data_dict ['Average' ]['Past-Before' ]['Piezoresponse' ] = average_before_past_piezoresponse
62
78
63
- def open_data (self ):
79
+ return
80
+
81
+ def load_ibw_data (self , file , channel = 0 )-> np .ndarray :
82
+ """
83
+ Inputs:
84
+ - file: Path to ibw file
85
+ - channel: 0 is default, will return the height. 1 = amplitude, 2 = deflection, 3 = phase.
86
+ Outputs:
87
+ - image: np.ndarray image requested
88
+ """
89
+ ibw_reader = sr .IgorIBWReader (file )
90
+ datasets = ibw_reader .read ()
91
+ key = list (datasets .keys ())[channel ]
92
+ return np .array (datasets [key ])
93
+
94
+
95
+ def plot_difference_data (self )-> list :
96
+ # Plot difference and average images for amplitude and piezoresponse
97
+ fig0 = self ._plot_image (self .data_dict ['Difference' ]['Left-Right' ]['Amplitude' ], "Difference (Left - Right) - Amplitude" , cmap = 'bwr' )
98
+ fig1 = self ._plot_image (self .data_dict ['Difference' ]['Past-Before' ]['Amplitude' ], "Difference (Past - Before) - Amplitude" , cmap = 'bwr' )
99
+ fig2 = self ._plot_image (self .data_dict ['Average' ]['Left-Right' ]['Amplitude' ], "Average (Left + Right) / 2 - Amplitude" , cmap = 'viridis' )
100
+ fig3 = self ._plot_image (self .data_dict ['Average' ]['Past-Before' ]['Amplitude' ], "Average (Before + Past) / 2 - Amplitude" , cmap = 'viridis' )
101
+
102
+ fig4 = self ._plot_image (self .data_dict ['Difference' ]['Left-Right' ]['Piezoresponse' ], "Difference (Left - Right) - Piezoresponse" , cmap = 'Blues' ,vmin = - 2e-12 , vmax = 2e-12 )
103
+ fig5 = self ._plot_image (self .data_dict ['Difference' ]['Past-Before' ]['Piezoresponse' ], "Difference (Past - Before) - Piezoresponse" , cmap = 'Greens' ,vmin = - 2e-12 , vmax = 2e-12 )
104
+ fig6 = self ._plot_image (self .data_dict ['Average' ]['Left-Right' ]['Piezoresponse' ], "Average (Left + Right) / 2 - Piezoresponse" , cmap = 'Reds' ,vmin = - 8e-12 , vmax = 8e-12 )
105
+ fig7 = self ._plot_image (self .data_dict ['Average' ]['Past-Before' ]['Piezoresponse' ], "Average (Before + Past) / 2 - Piezoresponse" , cmap = 'Reds' ,vmin = - 4e-12 , vmax = 4e-12 )
106
+
107
+ return [fig0 ,fig1 ,fig2 ,fig3 ,fig4 ,fig5 ,fig6 ,fig7 ]
108
+
109
+ def plot_data (self )-> list :
110
+ # Plot individual amplitude and piezoresponse images
111
+ figure_handles = []
112
+ for label , data in self .data_dict .items ():
113
+ if 'amplitude' in data .keys () and 'piezoresponse' in data .keys ():
114
+ fig0 = self ._plot_image (data ['amplitude' ], f"{ label } Amplitude" , cmap = 'bwr' )
115
+ fig1 = self ._plot_image (data ['piezoresponse' ], f"{ label } Piezoresponse" , cmap = 'Greens' )
116
+ figure_handles .append ([fig0 ,fig1 ])
117
+ return figure_handles
118
+
119
+ def normalize_to_minus_one_one (data )-> np .ndarray :
120
+ """
121
+ Normalize the input data to the range [-1, 1].
122
+
123
+ Args:
124
+ data (np.array): 2D array to normalize.
125
+
126
+ Returns:
127
+ np.array: Normalized data in range [-1, 1].
128
+ """
129
+ data_min = np .min (data )
130
+ data_max = np .max (data )
131
+
132
+ print (f"Original data range: min={ data_min } , max={ data_max } " )
133
+
134
+ # Normalize to range [-1, 1]
135
+ normalized_data = 2 * ((data - data_min ) / (data_max - data_min )) - 1
136
+
137
+ print (f"Normalized data range: min={ np .min (normalized_data )} , max={ np .max (normalized_data )} " )
138
+
139
+ return normalized_data
140
+
141
+ def plot_normalized_data (data , title ):
142
+ """
143
+ Plot the normalized data using a color scale that reflects negative to positive range.
144
+
145
+ Args:
146
+ data (np.array): 2D normalized data.
147
+ title (str): Title for the plot.
148
+ """
149
+ plt .figure (figsize = (6 , 6 ))
150
+ plt .imshow (np .rot90 (data ), cmap = 'bwr' , vmin = - 1 , vmax = 1 )
151
+ plt .colorbar (label = "Normalized Value (-1 to 1)" )
152
+ plt .title (title )
153
+ plt .xlabel ("X Axis" )
154
+ plt .ylabel ("Y Axis" )
155
+ plt .show ()
156
+
157
+
158
+ def _open_data (self ):
64
159
"""
65
160
Opens data pointed to by self.data_path_dict, converts to piezoresponse, and adds it to a data dictionary
66
161
"""
@@ -73,12 +168,11 @@ def open_data(self):
73
168
if amplitude_data is not None and phase_data is not None :
74
169
piezoresponse_data = self .compute_piezoresponse (amplitude_data , phase_data )
75
170
if self .line_correction :
76
-
77
- data_dict [label ] = {
78
- 'amplitude' : amplitude_data ,
79
- 'phase' : phase_data ,
80
- 'piezoresponse' : piezoresponse_data
81
- }
171
+ data_dict [label ] = {
172
+ 'amplitude' : self .line_by_line_offset_correction (amplitude_data ),
173
+ 'phase' : self .line_by_line_offset_correction (phase_data ),
174
+ 'piezoresponse' : self .line_by_line_offset_correction (piezoresponse_data )
175
+ }
82
176
else :
83
177
print (f"Failed to load data for { label } ." )
84
178
@@ -109,8 +203,11 @@ def line_by_line_offset_correction(self, image)->np.ndarray:
109
203
Input: - image (np.ndarray).
110
204
Output: - corrected_image: image after offset correction
111
205
"""
206
+ new_image = np .zeros (image .shape )
207
+ for ind in range (image .shape [0 ]):
208
+ new_image [ind ,:] = image [ind ,:] - np .mean (image [ind ,:])
112
209
113
- return
210
+ return new_image
114
211
115
212
def _plot_image (self , data , title , cmap = 'viridis' , vmin = None , vmax = None )-> matplotlib .figure .Figure :
116
213
"""
0 commit comments