Skip to content

Commit

Permalink
Merge pull request #143 from rolfverberg/main
Browse files Browse the repository at this point in the history
fix: fixed issues with EDD non interactive without saving figs
  • Loading branch information
rolfverberg authored Oct 10, 2024
2 parents 45d6efc + 767465a commit a04f187
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
16 changes: 8 additions & 8 deletions CHAP/edd/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
28 changes: 18 additions & 10 deletions CHAP/edd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit a04f187

Please sign in to comment.