|
143 | 143 | tstop_ns = scale_time * tstop |
144 | 144 | tstart_ns = scale_time * tstart |
145 | 145 |
|
146 | | -for time_value in original_data_value[plot_name].index: |
147 | | - if tstart_ns <= time_value[0]: |
148 | | - start_index_original_data = time_value[0] |
149 | | - break |
150 | | -for time_value in original_data_value[plot_name][start_index_original_data:].index: |
151 | | - if time_value[0] >= tstop_ns: |
152 | | - stop_index_original_data = time_value[0] |
153 | | - break |
154 | | -for time_value in sample_waveform[0].index: |
155 | | - if tstart <= time_value: |
156 | | - sample_index = sample_waveform[0].index == time_value |
157 | | - start_index_waveform = sample_index.tolist().index(True) |
158 | | - break |
159 | | -for time_value in sample_waveform[0].index: |
160 | | - if time_value >= tstop: |
161 | | - sample_index = sample_waveform[0].index == time_value |
162 | | - stop_index_waveform = sample_index.tolist().index(True) |
163 | | - break |
164 | | - |
165 | | -original_data_zoom = original_data_value[ |
| 146 | +orig_times = np.array([row[0] for row in original_data_value[plot_name]]) |
| 147 | +start_index_original_data = int(np.searchsorted(orig_times, tstart_ns, side="left")) |
| 148 | +if start_index_original_data >= orig_times.size: |
| 149 | + start_index_original_data = orig_times.size - 1 |
| 150 | +stop_index_original_data = int(np.searchsorted(orig_times, tstop_ns, side="left")) |
| 151 | +if stop_index_original_data >= orig_times.size: |
| 152 | + stop_index_original_data = orig_times.size - 1 |
| 153 | + |
| 154 | +sample_index_array = np.array(sample_waveform[0].index) |
| 155 | +start_index_waveform = int(np.searchsorted(sample_index_array, tstart, side="left")) |
| 156 | +if start_index_waveform >= sample_index_array.size: |
| 157 | + start_index_waveform = sample_index_array.size - 1 |
| 158 | +stop_index_waveform = int(np.searchsorted(sample_index_array, tstop, side="left")) |
| 159 | +if stop_index_waveform >= sample_index_array.size: |
| 160 | + stop_index_waveform = sample_index_array.size - 1 |
| 161 | + |
| 162 | +original_data_zoom = original_data_value[plot_name][ |
166 | 163 | start_index_original_data:stop_index_original_data |
167 | 164 | ] |
168 | 165 | sampled_data_zoom = ( |
|
175 | 172 | fig, ax = plt.subplots() |
176 | 173 | ax.plot(sampled_time_zoom, sampled_data_zoom, "r*") |
177 | 174 | ax.plot( |
178 | | - np.array(list(original_data_zoom.index.values)), |
179 | | - original_data_zoom.values, |
| 175 | + np.array(list(original_data_zoom[:,0])), |
| 176 | + original_data_zoom[:,1], |
180 | 177 | color="blue", |
181 | 178 | ) |
182 | 179 | ax.set_title("WaveAfterProbe") |
|
190 | 187 | # Create the plot from a start time to stop time in seconds. |
191 | 188 |
|
192 | 189 | fig, ax2 = plt.subplots() |
193 | | -ax2.plot(sample_waveform[0].index, sample_waveform[0].values, "r*") |
| 190 | +ax2.plot(sample_waveform[0].index, np.concatenate(sample_waveform[0].values), "r*") |
194 | 191 | ax2.set_title("Slicer Scatter: WaveAfterProbe") |
195 | 192 | ax2.set_xlabel("s") |
196 | 193 | ax2.set_ylabel("V") |
|
202 | 199 |
|
203 | 200 | fig, ax4 = plt.subplots() |
204 | 201 | ax4.set_title("Slicer Histogram: WaveAfterProbe") |
205 | | -ax4.hist(sample_waveform[0].values, orientation="horizontal") |
| 202 | +ax4.hist(np.concatenate(sample_waveform[0].values), orientation="horizontal") |
206 | 203 | ax4.set_ylabel("V") |
207 | 204 | ax4.grid() |
208 | 205 | plt.show() |
|
226 | 223 |
|
227 | 224 | # + |
228 | 225 | original_data.enable_pandas_output = False |
229 | | -original_data_value = original_data.data_real() |
| 226 | +original_data_value = original_data.get_expression_data(formula="real")[1] |
230 | 227 | original_data_sweep = original_data.primary_sweep_values |
231 | 228 | waveform_unit = original_data.units_data[plot_name] |
| 229 | + |
232 | 230 | waveform_sweep_unit = original_data.units_sweeps["Time"] |
233 | 231 | tics = np.arange(20e-9, 100e-9, 1e-10, dtype=float) |
234 | 232 |
|
|
260 | 258 | tstop_ns = scale_time * tstop |
261 | 259 | tstart_ns = scale_time * tstart |
262 | 260 |
|
263 | | -for time_value in original_data_sweep: |
264 | | - if tstart_ns <= time_value: |
265 | | - start_index_original_data = original_data_sweep.index(time_value.value) |
266 | | - break |
267 | | -for time_value in original_data_sweep[start_index_original_data:]: |
268 | | - if time_value >= tstop_ns: |
269 | | - stop_index_original_data = original_data_sweep.index(time_value.value) |
270 | | - break |
| 261 | +start_index_original_data = int(np.searchsorted(original_data_sweep, tstart_ns, side="left")) |
| 262 | +if start_index_original_data >= original_data_sweep.size: |
| 263 | + start_index_original_data = original_data_sweep.size - 1 |
| 264 | + |
| 265 | +stop_index_original_data = int(np.searchsorted(original_data_sweep, tstop_ns, side="left")) |
| 266 | +if stop_index_original_data >= original_data_sweep.size: |
| 267 | + stop_index_original_data = original_data_sweep.size - 1 |
| 268 | + |
271 | 269 | cont = 0 |
272 | 270 | for frame in sample_waveform: |
273 | 271 | if tstart <= frame[0]: |
|
290 | 288 | list(map(list, zip(original_sweep_zoom, original_data_zoom))) |
291 | 289 | ) |
292 | 290 | original_data_zoom_array[:, 0] *= 1 |
293 | | -sampled_data_zoom_array = np.array( |
294 | | - sample_waveform[start_index_waveform:stop_index_waveform] |
295 | | -) |
296 | | -sampled_data_zoom_array[:, 0] *= scale_time |
297 | | -sampled_data_zoom_array[:, 1] *= scale_data |
| 291 | +sampled_slice = sample_waveform[start_index_waveform:stop_index_waveform] |
| 292 | +# Build a homogeneous Nx2 array [time, value] from the sliced frames, with a guard for empty slices. |
| 293 | +if len(sampled_slice): |
| 294 | + sampled_data_zoom_array = np.array( |
| 295 | + [ |
| 296 | + [ |
| 297 | + float(np.asarray(frame[0]).ravel()[0]), |
| 298 | + float(np.asarray(frame[1]).ravel()[0]), |
| 299 | + ] |
| 300 | + for frame in sampled_slice |
| 301 | + ], |
| 302 | + dtype=float, |
| 303 | + ) |
| 304 | + sampled_data_zoom_array[:, 0] *= scale_time |
| 305 | + sampled_data_zoom_array[:, 1] *= scale_data |
| 306 | +else: |
| 307 | + sampled_data_zoom_array = np.empty((0, 2)) |
298 | 308 |
|
299 | 309 | fig, ax = plt.subplots() |
300 | 310 | ax.plot(sampled_data_zoom_array[:, 0], sampled_data_zoom_array[:, 1], "r*") |
|
309 | 319 | # |
310 | 320 | # Create the plot from a start time to stop time in seconds. |
311 | 321 |
|
312 | | -sample_waveform_array = np.array(sample_waveform) |
| 322 | +sample_waveform_array = np.array( |
| 323 | + [ |
| 324 | + [float(frame[0]), float(np.asarray(frame[1]).ravel()[0])] |
| 325 | + for frame in sample_waveform |
| 326 | + ], |
| 327 | + dtype=float, |
| 328 | +) |
| 329 | + |
313 | 330 | fig, ax2 = plt.subplots() |
314 | 331 | ax2.plot(sample_waveform_array[:, 0], sample_waveform_array[:, 1], "r*") |
315 | 332 | ax2.set_title("Slicer Scatter: " + plot_name) |
|
0 commit comments