From 767465ac81dd72f00ce588f767d6d3b605d27ece Mon Sep 17 00:00:00 2001 From: Rolf Verberg Date: Thu, 10 Oct 2024 17:39:08 -0400 Subject: [PATCH] fix: fixed issues with EDD non interactive without saving figs --- CHAP/edd/processor.py | 16 ++++++++-------- CHAP/edd/utils.py | 28 ++++++++++++++++++---------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/CHAP/edd/processor.py b/CHAP/edd/processor.py index 8b9c527..b9ee51e 100755 --- a/CHAP/edd/processor.py +++ b/CHAP/edd/processor.py @@ -309,9 +309,9 @@ def process( raise RuntimeError from exc if len(strain_analysis_config.materials) > 1: - msg = 'Not implemented for multiple materials' - self.logger.error('Not implemented for multiple materials') - raise NotImplementedError(msg) + error_msg = 'Not implemented for multiple materials' + self.logger.error(error_msg) + raise NotImplementedError(error_msg) # Collect the raw MCA data raise RuntimeError( @@ -2770,7 +2770,9 @@ def get_nxroot(self, nxentry, strain_analysis_config): self._subtract_baselines() # Adjust the material properties - self._adjust_material_props(strain_analysis_config.materials) + strain_analysis_config.materials = self._adjust_material_props( + strain_analysis_config.materials) + self.logger.debug(f'materials: {strain_analysis_config.materials}') # Get the mask and HKLs used in the strain analysis self._get_mask_hkls(strain_analysis_config.materials) @@ -2868,19 +2870,17 @@ def _adjust_material_props(self, materials): # ASK: extend to multiple detectors? detector = self._detectors[0] - tth = detector.tth_calibrated if self._save_figures: filename = os.path.join( self._outputdir, f'{detector.id}_strainanalysis_material_config.png') else: filename = None - materials = select_material_params( + return select_material_params( detector.energies, self._mean_data[0]*self._energy_masks[0], - tth, label='Sum of all spectra in the map', + detector.tth_calibrated, label='Sum of all spectra in the map', preselected_materials=materials, interactive=self._interactive, filename=filename) - self.logger.debug(f'materials: {materials}') def _create_animation( self, det_nxdata, energies, best_fits, detector_id): diff --git a/CHAP/edd/utils.py b/CHAP/edd/utils.py index f5d2b8a..c698a32 100755 --- a/CHAP/edd/utils.py +++ b/CHAP/edd/utils.py @@ -563,9 +563,9 @@ def select_material_params( :rtype: list[CHAP.edd.models.MaterialConfig] """ # Third party modules - import matplotlib.pyplot as plt if interactive or filename is not None: from hexrd.material import Material + import matplotlib.pyplot as plt from matplotlib.widgets import Button, TextBox, RadioButtons # Local modules @@ -635,6 +635,14 @@ def accept(event): """Callback function for the "Accept" button.""" plt.close() + if not interactive and filename is None: + if preselected_materials is None: + raise RuntimeError( + 'If the material properties are not explicitly provided, ' + f'{self.__class__.__name__} must be run with ' + '`interactive=True`.') + return preselected_materials + materials = [] added_material = [] removed_material = [] @@ -953,15 +961,15 @@ def on_span_select(xmin, xmax): elif removed_hkls: change_error_text( 'Removed HKL(s) outside the selected energy mask') - # If using ref_map, update the colorbar range to min / max of - # the selected data only - if ref_map is not None: - selected_data = ref_map[:,get_mask()] - ref_map_mappable = ax_map.pcolormesh( - x, np.arange(ref_map.shape[0]), ref_map, - vmin=selected_data.min(), vmax=selected_data.max()) - fig.colorbar(ref_map_mappable, cax=cax) - plt.draw() + # If using ref_map, update the colorbar range to min / max of + # the selected data only + if ref_map is not None: + selected_data = ref_map[:,get_mask()] + ref_map_mappable = ax_map.pcolormesh( + x, np.arange(ref_map.shape[0]), ref_map, + vmin=selected_data.min(), vmax=selected_data.max()) + fig.colorbar(ref_map_mappable, cax=cax) + plt.draw() def add_span(event, xrange_init=None): """Callback function for the "Add span" button."""