Coverage for /Users/Newville/Codes/xraylarch/larch/qtrixs/profiletoolbar.py: 0%

35 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-11-09 10:08 -0600

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3 

4""" 

5RIXS profile toolbar 

6==================== 

7 

8A modified version of the SILX profile toolbar. 

9""" 

10from itertools import cycle 

11from silx.gui.plot.Profile import (ProfileToolBar, createProfile) 

12 

13 

14_DEFAULT_OVERLAY_COLORS = cycle(['#1F77B4', '#AEC7E8', '#FF7F0E', '#FFBB78', 

15 '#2CA02C', '#98DF8A', '#D62728', '#FF9896', 

16 '#9467BD', '#C5B0D5', '#8C564B', '#C49C94', 

17 '#E377C2', '#F7B6D2', '#7F7F7F', '#C7C7C7', 

18 '#BCBD22', '#DBDB8D', '#17BECF', '#9EDAE5']) 

19 

20 

21class RixsProfileToolBar(ProfileToolBar): 

22 """RIXS-adapted Profile (=Cuts) toolbar""" 

23 

24 def __init__(self, parent=None, plot=None, profileWindow=None, 

25 overlayColors=None, title='RIXS profile'): 

26 """Constructor""" 

27 super(RixsProfileToolBar, self).__init__(parent=parent, plot=plot, 

28 profileWindow=profileWindow, 

29 title=title) 

30 

31 self._overlayColors = overlayColors or _DEFAULT_OVERLAY_COLORS 

32 

33 def _getNewColor(self): 

34 return next(self._overlayColors) 

35 

36 def updateProfile(self): 

37 """Update the displayed profile and profile ROI. 

38 This uses the current active image of the plot and the current ROI. 

39 """ 

40 image = self.plot.getActiveImage() 

41 if image is None: 

42 return 

43 

44 self._overlayColor = self._getNewColor() 

45 

46 self._createProfile(currentData=image.getData(copy=False), 

47 origin=image.getOrigin(), scale=image.getScale(), 

48 colormap=None, z=image.getZValue(), 

49 method=self.getProfileMethod()) 

50 

51 

52 def _createProfile(self, currentData, origin, scale, colormap, z, method): 

53 """Create the profile line for the the given image. 

54 :param numpy.ndarray currentData: the image or the stack of images 

55 on which we compute the profile 

56 :param origin: (ox, oy) the offset from origin 

57 :type origin: 2-tuple of float 

58 :param scale: (sx, sy) the scale to use 

59 :type scale: 2-tuple of float 

60 :param dict colormap: The colormap to use 

61 :param int z: The z layer of the image 

62 """ 

63 if self._roiInfo is None: 

64 return 

65 

66 coords, profile, area, profileName, xLabel = createProfile( 

67 roiInfo=self._roiInfo, 

68 currentData=currentData, 

69 origin=origin, 

70 scale=scale, 

71 lineWidth=self.lineWidthSpinBox.value(), 

72 method=method) 

73 

74 profilePlot = self.getProfilePlot() 

75 plotTitle = self.plot.getGraphTitle() 

76 

77 profilePlot.setGraphTitle("Profiles") 

78 profilePlot.getXAxis().setLabel(xLabel) 

79 

80 profileName = "{0}: {1}".format(plotTitle, profileName) 

81 

82 dataIs3D = len(currentData.shape) > 2 

83 if dataIs3D: 

84 profileScale = (coords[-1] - coords[0]) / profile.shape[1], 1 

85 profilePlot.addImage(profile, 

86 legend=profileName, 

87 colormap=colormap, 

88 origin=(coords[0], 0), 

89 scale=profileScale) 

90 profilePlot.getYAxis().setLabel("Frame index (depth)") 

91 else: 

92 profilePlot.addCurve(coords, 

93 profile[0], 

94 legend=profileName, 

95 color=self.overlayColor) 

96 

97 self.plot.addItem(area[0], area[1], 

98 legend=self._POLYGON_LEGEND, 

99 color=self.overlayColor, 

100 shape='polygon', fill=True, 

101 replace=False, z=z + 1) 

102 

103 self._showProfileMainWindow() 

104 

105 

106 

107 

108if __name__ == '__main__': 

109 pass