MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / exp_data_update

Method exp_data_update

pyxrf/model/lineplot.py:460–553  ·  view source on GitHub ↗

Observer function to be connected to the fileio model in the top-level gui.py startup Parameters ---------- changed : dict This is the dictionary that gets passed to a function with the @observe decorator

(self, change)

Source from the content-addressed store, hash-verified

458 self._ax.set_ylim(self.linear_range)
459
460 def exp_data_update(self, change):
461 """
462 Observer function to be connected to the fileio model
463 in the top-level gui.py startup
464
465 Parameters
466 ----------
467 changed : dict
468 This is the dictionary that gets passed to a function
469 with the @observe decorator
470 """
471 # TODO: This function does not change the data. Instead it is expected to
472 # perform a number of operation when data is changed.
473
474 # self.data = change['value']
475 if self.io_model.data is None:
476 return
477
478 e_range = self.energy_range_fitting
479 e_range_full, e_range_selected = "full", "selected"
480 if set([e_range_full, e_range_selected]) < set(self.energy_range_names):
481 raise ValueError(
482 f"Some names for energy range {(e_range_full, e_range_selected)} are not supported. "
483 "Please report the error to the development team."
484 )
485 if e_range not in (e_range_full, e_range_selected):
486 logger.error(
487 f"Spectrum preview: Unknown option for the energy range: {e_range}\n"
488 "Please report the error to the development team."
489 )
490 # This is not a critical error, so we still can proceed
491 e_range = e_range_full
492
493 if not self.param_model.param_new:
494 return
495
496 # The number of points in the displayed dataset
497 n_dset_points = len(self.io_model.data)
498
499 if e_range == e_range_selected:
500 n_range_low, n_range_high = self.selected_range_indices(n_indexes=n_dset_points)
501 else:
502 n_range_low, n_range_high = 0, n_dset_points
503
504 n_low = int(np.clip(n_range_low, a_min=0, a_max=n_dset_points - 1))
505 n_high = int(np.clip(n_range_high, a_min=1, a_max=n_dset_points))
506
507 # Find the maximum value (skip the first and last 'limit_cut' points of the dataset
508 n1, n2 = max(self.limit_cut, n_low), min(n_dset_points - self.limit_cut, n_high)
509 if n2 <= n1: # This is just a precaution: it is expected that n_dset_points >> 2 * limit_cut
510 n1, n2 = n_low, n_high
511 self.max_v = float(np.max(self.io_model.data[n1:n2]))
512
513 try:
514 self.plot_exp_obj.remove()
515 logger.debug("Previous experimental data is removed.")
516 except AttributeError:
517 logger.debug("No need to remove experimental data.")

Callers 3

plot_experimentMethod · 0.95

Calls 6

_update_ylimitMethod · 0.95
log_linear_plotMethod · 0.95
_show_hide_exp_plotMethod · 0.95

Tested by

no test coverage detected