This file is indexed.

/usr/share/pyshared/PyMca/Plot1D.py is in pymca 4.5.0-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
"""
This module can be used for plugin testing purposes as well as for doing
the bookkeeping of actual plot windows.

It implements the Plot1D interface:

    addCurve(self, x, y, legend=None, info=None, replace=False, replot=True)
    getActiveCurve(self, just_legend=False)
    getAllCurves(self, just_legend=False)
    getGraphXLimits(self)
    getGraphYLimits(self)
    removeCurve(self, legend, replot=True)
    setActiveCurve(self)
"""
import Plot1DBase

class Plot1D(Plot1DBase.Plot1DBase):
    def __init__(self):
        Plot1DBase.Plot1DBase.__init__(self)
        self.curveList = []
        self.curveDict = {}
        self.activeCurve = None
        
    def addCurve(self, x, y, legend=None, info=None, replace=False, replot=True):
        """
        Add the 1D curve given by x an y to the graph.
        """
        if legend is None:
            key = "Unnamed curve 1.1"
        else:
            key = str(legend)
        if info is None:
            info = {}
        xlabel = info.get('xlabel', 'X')
        ylabel = info.get('ylabel', 'Y')
        info['xlabel'] = str(xlabel)
        info['ylabel'] = str(ylabel)

        if replace:
            self.curveList = []
            self.curveDict = {}
            
        if key in self.curveList:
            idx = self.curveList.index(key)
            self.curveList[idx] = key
        else:
            self.curveList.append(key)
        self.curveDict[key] = [x, y, key, info]
        if len(self.curveList) == 1:
            self.activeCurve = key
        return

    def removeCurve(self, legend, replot=True):
        """
        Remove the curve associated to the supplied legend from the graph.
        The graph will be updated if replot is true.
        """
        if legend is None:
            return        
        if legend in self.curveList:
            idx = self.curveList.index(legend)
            del self.curveList[idx]
        if legend in self.curveDict.keys(): 
            del self.curveDict[legend]
        return
    
    def getActiveCurve(self, just_legend=False):
        """
        Function to access the currently active curve.
        It returns None in case of not having an active curve.

        Default output has the form:
            xvalues, yvalues, legend, dict
            where dict is a dictionnary containing curve info.
            For the time being, only the plot labels associated to the
            curve are warranted to be present under the keys xlabel, ylabel.

        If just_legend is True:
            The legend of the active curve (or None) is returned.
        """
        if self.activeCurve not in self.curveDict.keys():
            self.activeCurve = None
        if just_legend:
            return self.activeCurve
        if self.activeCurve is None:
            return None
        else:
            return self.curveDict[self.activeCurve]

    def getAllCurves(self, just_legend=False):
        """
        If just_legend is False:
            It returns a list of the form:
                [[xvalues0, yvalues0, legend0, dict0],
                 [xvalues1, yvalues1, legend1, dict1],
                 [...],
                 [xvaluesn, yvaluesn, legendn, dictn]]
            or just an empty list.
        If just_legend is True:
            It returns a list of the form:
                [legend0, legend1, ..., legendn]
            or just an empty list.
        """
        output = []
        keys = self.curveDict.keys()
        for key in self.curveList:
            if key in keys:
                output.append(self.curveDict[key])
        return output

    def __getAllLimits(self):
        keys = self.curveDict.keys()
        if not len(keys):
            return 0.0, 0.0, 100., 100.
        xmin = None
        ymin = None
        xmax = None
        ymax = None
        for key in keys:
            x = self.curveDict[key][0]
            y = self.curveDict[key][1]
            if xmin is None:
                xmin = x.min()
            else:
                xmin = min(xmin, x.min())
            if ymin is None:
                ymin = y.min()
            else:
                ymin = min(ymin, y.min())
            if xmax is None:
                xmax = x.max()
            else:
                xmax = max(xmax, x.max())
            if ymax is None:
                ymax = y.max()
            else:
                ymax = max(ymax, y.max())
        return xmin, ymin, xmax, ymax

    def getGraphXLimits(self):
        """
        Get the graph X limits. 
        """
        xmin, ymin, xmax, ymax = self.__getAllLimits()
        return xmin, xmax
        

    def getGraphYLimits(self):
        """
        Get the graph Y (left) limits. 
        """
        xmin, ymin, xmax, ymax = self.__getAllLimits()
        return ymin, ymax

    def setActiveCurve(self, legend):
        """
        Funtion to request the plot window to set the curve with the specified
        legend as the active curve.
        It returns the active curve legend.
        """
        key = str(legend)
        if key in self.curveDict.keys():
            self.activeCurve = key
        return self.activeCurve

if __name__ == "__main__":
    import numpy
    x = numpy.arange(100.)
    y = x * x
    plot = Plot1D()
    plot.addCurve(x, y, "dummy")
    plot.addCurve(x+100, -x*x)
    print("Active curve = ", plot.getActiveCurve())
    print("X Limits = ",     plot.getGraphXLimits())
    print("Y Limits = ",     plot.getGraphYLimits())
    print("All curves = ",   plot.getAllCurves())
    plot.removeCurve("dummy")
    print("All curves = ",   plot.getAllCurves())