Ejemplo n.º 1
0
def plotTrace(paramY, paramX=None, label='', history=100, tracelen=None, name=None, group=None):
    """Plotting a trace.
    
    Args:
        :paramY(Record):   The data for the ordinate is paramY.data.ravel()

    Kwargs:
        :paramX(Record):   The data for the abscissa is paramX.data.ravel() if paramX is not None
        :label(str):    Label for param
        :history(int):  Length of history buffer
    """
    if paramY is None:
        return
    if name is None:
        name = "Trace(%s)" %paramY.name
    if(not paramY.name in traces):
        ipc.broadcast.init_data(name, data_type='vector', xlabel=label, history_length=history, group=group)
        histograms[paramY.name] = True
    if paramX is None:
        ipc.new_data(name, data_y=paramY.data.ravel())
    else:
        x = paramX.data.ravel()
        y = paramY.data.ravel()
        if tracelen is not None:
            x = x[:tracelen]
            y = y[:tracelen]
        if x.size != y.size:
            logging.warning("For %s x- and y-dimension do not match (%i, %i). Cannot plot trace." % (name,x.size,y.size))
            return
        ipc.new_data(name, data_y=np.array([x,y], copy=False)) 
Ejemplo n.º 2
0
def plotHistogram(param, hmin=None, hmax=None, bins=100, label='', density=False, vline=None, history=10000, mask=None, log10=False, name_extension="", name=None, group=None):
    """Plotting a histogram.
    
    Args:
        :param(Record):   The histogram is based on param.data.flat

    Kwargs:
        :hmin(float):   Minimum, default = record.data.min()
        :hmax(float):   Maximum, default = record.data.max()
        :bins(int):     Nr. of bins, default = 100
        :label(str):    Label for param
        :density(bool): If True, the integral of the histogram is 1
        :history(int):  Length of history buffer
    """
    if param is None:
        return
    if name is None:
        name = "Histogram(%s)%s" % (param.name, name_extension)
    if(not param.name in histograms):
        ipc.broadcast.init_data(name, data_type='vector', xlabel=label, vline=vline, history_length=history, group=group)
        histograms[param.name] = True
    data = param.data
    if mask is not None:
        data = data[mask]
    if log10:
        data=np.log10(data)
    if hmin is None: hmin = data.min()
    if hmax is None: hmax = data.max()
    H,B = np.histogram(data.flat, range=(hmin, hmax), bins=bins, density=density)
    ipc.new_data(name, H, xmin=B.min(), xmax=B.max(), vline=vline)
Ejemplo n.º 3
0
def plotTrace(paramY, paramX=None, label='', history=10000, tracelen=None, name=None, group=None):
    """Plotting a trace.
    
    Args:
        :paramY(Record):   The data for the ordinate is paramY.data.ravel()

    Kwargs:
        :paramX(Record):   The data for the abscissa is paramX.data.ravel() if paramX is not None
        :label(str):    Label for param
        :history(int):  Length of history buffer
    """
    if paramY is None:
        return
    if name is None:
        name = "Trace(%s)" %paramY.name
    if(not paramY.name in traces):
        ipc.broadcast.init_data(name, data_type='vector', xlabel=label, history_length=history, group=group)
        histograms[paramY.name] = True
    if paramX is None:
        ipc.new_data(name, data_y=paramY.data.ravel())
    else:
        x = paramX.data.ravel()
        y = paramY.data.ravel()
        if tracelen is not None:
            x = x[:tracelen]
            y = y[:tracelen]
        if x.size != y.size:
            logging.warning("For %s x- and y-dimension do not match (%i, %i). Cannot plot trace." % (name,x.size,y.size))
            return
        ipc.new_data(name, data_y=np.array([x,y], copy=False)) 
Ejemplo n.º 4
0
def plotScatter(X,
                Y,
                name=None,
                history=10000,
                xlabel=None,
                ylabel=None,
                group=None):
    """Plotting the scatter of two parameters X and Y.
    (No buffer in the backend).

    Args:
        :X(Record): An event parameter, e.g. injector position in x
        :Y(Record): An event parameter, e.g. injector position in y

    Kwargs:
        :name(str): The key that appears in the interface (default = MeanMap(X.name, Y.name))
        :xlabel(str): 
        :ylabel(str):
    """
    if name is None:
        name = "Scatter(%s,%s)" % (X.name, Y.name)
    if (not name in _existingPlots):
        if xlabel is None: xlabel = X.name
        if ylabel is None: ylabel = Y.name
        ipc.broadcast.init_data(name,
                                data_type='tuple',
                                history_length=history,
                                xlabel=xlabel,
                                ylabel=ylabel,
                                group=group)
        _existingPlots[name] = True
    ipc.new_data(name, np.array([X.data, Y.data]))
Ejemplo n.º 5
0
def plotMeanMap(X,
                Y,
                Z,
                xmin=0,
                xmax=10,
                xbins=10,
                ymin=0,
                ymax=10,
                ybins=10,
                xlabel=None,
                ylabel=None,
                msg='',
                dynamic_extent=False,
                initial_reset=False,
                name=None,
                group=None):
    """Plotting the meanmap of Z as a function of two parameters X and Y.
    (No buffer in the backend).

    Args:
        :X(Record,float): An event parameter, e.g. injector position in x
        :Y(Record,float): An event parameter, e.g. injector position in y
        :Z(Record,float): Some metric, e.g. hit rate, size, etc...
    Kwargs:
        :xmin(int):  default = 0
        :xmax(int):  default = 10
        :xbins(int): default = 10
        :ymin(int):  default = 0
        :ymax(int):  default = 10
        :ybins(int): default = 10
        :name(str): The key that appears in the interface (default = MeanMap(X.name, Y.name))
        :xlabel(str): 
        :ylabel(str):
        :msg(msg):   Any message to be displayed in the plot
    """
    if name is None:
        name = "MeanMap(%s,%s,%s)" % (X.name, Y.name, Z.name)
    if (not name in _existingPlots):
        if xlabel is None: xlabel = X.name
        if ylabel is None: ylabel = Y.name
        ipc.broadcast.init_data(name,
                                data_type='triple',
                                history_length=1,
                                xmin=xmin,
                                xmax=xmax,
                                ymin=ymin,
                                ymax=ymax,
                                xbins=xbins,
                                ybins=ybins,
                                xlabel=xlabel,
                                ylabel=ylabel,
                                flipy=True,
                                dynamic_extent=dynamic_extent,
                                initial_reset=initial_reset,
                                group=group)
        _existingPlots[name] = True
    x = X if not isinstance(X, Record) else X.data
    y = Y if not isinstance(Y, Record) else Y.data
    z = Z if not isinstance(Z, Record) else Z.data
    ipc.new_data(name, np.array([x, y, z]), msg=msg)
Ejemplo n.º 6
0
def plotNormalizedHistogram(value,
                            weight,
                            hmin=0,
                            hmax=10,
                            bins=10,
                            name=None,
                            group=None,
                            buffer_length=100):
    if name is None:
        if hasattr(value, "name"):
            name = "Normalized histogram of {0}".format(value.name)
        else:
            name = "Normalize histogram"

    if name not in normalized_histograms:
        ipc.broadcast.init_data(name,
                                data_type='normalized_histogram',
                                history_length=buffer_length,
                                hmin=hmin,
                                hmax=hmax,
                                bins=bins,
                                group=group)
        normalized_histograms[name] = True
    value = value if not isinstance(value, Record) else value.data
    weight = weight if not isinstance(weight, Record) else weight.data
    ipc.new_data(name,
                 np.array([value, weight]),
                 data_type="normalized_histogram")
Ejemplo n.º 7
0
def plotScatterBg(X,
                  Y,
                  name=None,
                  history=10000,
                  xlabel=None,
                  ylabel=None,
                  bg_filename=None,
                  bg_xmin=0.,
                  bg_xmax=1.,
                  bg_ymin=0.,
                  bg_ymax=0.,
                  bg_angle=0.,
                  group=None):
    """Plotting the scatter of two parameters X and Y.
    """
    if name is None:
        name = "ScatterBg(%s,%s)" % (X.name, Y.name)
    if (not name in _existingPlots):
        if xlabel is None: xlabel = X.name
        if ylabel is None: ylabel = Y.name
        ipc.broadcast.init_data(name,
                                data_type='tuple',
                                history_length=history,
                                xlabel=xlabel,
                                ylabel=ylabel,
                                bg_filename=bg_filename,
                                bg_xmin=bg_xmin,
                                bg_xmax=bg_xmax,
                                bg_ymin=bg_ymin,
                                bg_ymax=bg_ymax,
                                bg_angle=bg_angle,
                                group=group)
        _existingPlots[name] = True
    ipc.new_data(name, np.array([X.data, Y.data]))
Ejemplo n.º 8
0
def plotMeanMap(X,Y,Z, xmin=0, xmax=10, xbins=10, ymin=0, ymax=10, ybins=10, plotid=None, xlabel=None, ylabel=None, msg=''):
    """Plotting the meanmap of Z as a function of two parameters X and Y.
    (No buffer in the backend).

    Args:
        :X(Record,float): An event parameter, e.g. injector position in x
        :Y(Record,float): An event parameter, e.g. injector position in y
        :Z(Record,float): Some metric, e.g. hit rate, size, etc...
    Kwargs:
        :xmin(int):  default = 0
        :xmax(int):  default = 10
        :xbins(int): default = 10
        :ymin(int):  default = 0
        :ymax(int):  default = 10
        :ybins(int): default = 10
        :plotid(str): The key that appears in the interface (default = MeanMap(X.name, Y.name))
        :xlabel(str): 
        :ylabel(str):
        :msg(msg):   Any message to be displayed in the plot
    """
    if plotid is None:
        plotid = "MeanMap(%s,%s)" %(X.name, Y.name)
    if (not plotid in meanMaps):
        if xlabel is None: xlabel = X.name
        if ylabel is None: ylabel = Y.name
        ipc.broadcast.init_data(plotid, data_type='triple', history_length=1,
                                xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
                                xbins=xbins, ybins=ybins,
                                xlabel=xlabel, ylabel=ylabel, flipy=True)
    x = X if not isinstance(X, Record) else X.data
    y = Y if not isinstance(Y, Record) else Y.data
    z = Z if not isinstance(Z, Record) else Z.data
    ipc.new_data(plotid, np.array([x, y, z]), msg=msg)
Ejemplo n.º 9
0
def plotScatterColor(X,Y,Z, plotid=None, history=100, xlabel=None, ylabel=None, zlabel=None, vmin=None, vmax=None):
    """Plotting the scatter of two parameters X and Y and use Z for color.
    (No buffer in the backend).

    Args:
        :X(Record): An event parameter, e.g. injector position in x
        :Y(Record): An event parameter, e.g. injector position in y
        :Z(Record): An event parameter, e.g. injector position in z

    Kwargs:
        :plotid(str): The key that appears in the interface (default = MeanMap(X.name, Y.name))
        :xlabel(str): 
        :ylabel(str):
    """
    if plotid is None:
        plotid = "ScatterColor(%s,%s)" %(X.name, Y.name)
    if (not plotid in scatterPlots):
        if xlabel is None: xlabel = X.name
        if ylabel is None: ylabel = Y.name
        if zlabel is None: zlabel = Z.name
        if vmin is None: vmin = 0
        if vmax is None: vmax = 1
        ipc.broadcast.init_data(plotid, data_type='triple', history_length=history,
                                xlabel=xlabel, ylabel=ylabel, zlabel=zlabel,
                                vmin=vmin, vmax=vmax)
    ipc.new_data(plotid, np.array([X.data, Y.data, Z.data]))
Ejemplo n.º 10
0
def plotScatter(X, Y, plotid=None, history=100, xlabel=None, ylabel=None):
    """Plotting the scatter of two parameters X and Y.
    (No buffer in the backend).

    Args:
        :X(Record): An event parameter, e.g. injector position in x
        :Y(Record): An event parameter, e.g. injector position in y

    Kwargs:
        :plotid(str): The key that appears in the interface (default = MeanMap(X.name, Y.name))
        :xlabel(str): 
        :ylabel(str):
    """
    if plotid is None:
        plotid = "Scatter(%s,%s)" % (X.name, Y.name)
    if (not plotid in scatterPlots):
        if xlabel is None: xlabel = X.name
        if ylabel is None: ylabel = Y.name
        ipc.broadcast.init_data(
            plotid,
            data_type='tuple',
            history_length=history,
            xlabel=xlabel,
            ylabel=ylabel)
    ipc.new_data(plotid, np.array([X.data, Y.data]))
Ejemplo n.º 11
0
def plotImage(record, history=10, vmin=None, vmax=None, log=False, mask=None, msg=None, alert=False, name=None):
    """Plotting an image.

    Args:
        :record(Record): record.data is plotted as an image

    Kwargs:
        :history(int):  Length of history buffer
        :vmin(float):   Minimum value
        :vmax(float):   Maximum value
        :log(boolean):  Plot image in log scale (needs restart of GUI, only works with grayscale colormap)
        :mask(boolean or int): Multiply image with mask
    """
    if record is None:
        return
    if name is None:
        n = record.name
    else:
        n = name
    if(not n in images):
        ipc.broadcast.init_data(n, data_type='image', history_length=history, vmin=vmin, vmax=vmax, log=log)
        images[n] = True
    image = record.data
    sh = image.shape
    if (image.ndim == 3):
        image = image.reshape(sh[0]*sh[2], sh[1])
    if mask is None:
        mask = np.ones_like(image)
    ipc.new_data(n, image*mask, msg=msg, alert=alert)
Ejemplo n.º 12
0
def plotHistogram(param, hmin=None, hmax=None, bins=100, label='', density=False, vline=None, history=100, mask=None, log10=False, name_extension="", name=None, group=None):
    """Plotting a histogram.
    
    Args:
        :param(Record):   The histogram is based on param.data.flat

    Kwargs:
        :hmin(float):   Minimum, default = record.data.min()
        :hmax(float):   Maximum, default = record.data.max()
        :bins(int):     Nr. of bins, default = 100
        :label(str):    Label for param
        :density(bool): If True, the integral of the histogram is 1
        :history(int):  Length of history buffer
    """
    if param is None:
        return
    if name is None:
        name = "Histogram(%s)%s" % (param.name, name_extension)
    if(not param.name in histograms):
        ipc.broadcast.init_data(name, data_type='vector', xlabel=label, vline=vline, history_length=history, group=group)
        histograms[param.name] = True
    data = param.data
    if mask is not None:
        data = data[mask]
    if log10:
        data=np.log10(data)
    if hmin is None: hmin = data.min()
    if hmax is None: hmax = data.max()
    H,B = np.histogram(data.flat, range=(hmin, hmax), bins=bins, density=density)
    ipc.new_data(name, H, xmin=B.min(), xmax=B.max(), vline=vline)
Ejemplo n.º 13
0
def plotHistogram(value, hmin=0, hmax=10, bins=10, name=None, group=None, buffer_length=100):
    if name is None:
        name = "Histogram of {0}".format(value.name)
    if (name not in histograms):
        ipc.broadcast.init_data(name, data_type='histogram', history_length=buffer_length,
                                hmin=hmin, hmax=hmax, bins=bins, group=group)
        histograms[name] = True
    value = value if not isinstance(value, Record) else value.data
    ipc.new_data(name, value)
Ejemplo n.º 14
0
def plotTimestamp(timestamp, name=None, group=None, **kwargs):
    if name is None:
        name = "History(Fiducial)"
    if not name in histories:
        ipc.broadcast.init_data(name,
                                data_type='scalar',
                                group=group,
                                **kwargs)
    ipc.new_data(name, timestamp.fiducials, **kwargs)
Ejemplo n.º 15
0
def plotMeanMapDynamic(X, Y, Z, norm=1., msg='', update=100, xmin=0, xmax=100, ymin=0, ymax=100, step=10, \
                       localRadius=100, overviewStep=100, xlabel=None, ylabel=None, name=None, group=None):
    """Plotting the mean of parameter Z as a function of parameters X and Y.
    (Using a buffer in the backend).

    Args:
       :X(Record):     An event parameter e.g. Motor position in X
       :Y(Record):     An event parameter e.g. Motor position in Y
       :Z(Record):     An event parameter e.g. Intensity

    Kwargs:
        :norm(int):    Z is normalized by a given value, e.g. gmd (default = 1)
        :msg (str):    A message to be displayed in the plot
        :update (int): After how many new data points, an update is send to the frontend (default = 100)
        :xmin (int):   (default = 0)
        :xmax (int):   (default = 100)
        :ymin (int):   (default = 0)
        :ymax (int):   (default = 100)
        :step (int):   The resolution of the map in units of x,y (default = 10)
        :xlabel (str): (default = X.name) 
        :ylabel (str): (default = Y.name)
        :localRadius (int):  The radius of a square neighborehood around the current position (X.data, Y.data) (default = 100)
        :overviewStep (int): The resolution of the overiew map (default = 100)
    """
    if name is None:
        name = "%s(%s,%s)" % (Z.name, X.name, Y.name)
    if (not name in _existingPlots):
        if xlabel is None: xlabel = X.name
        if ylabel is None: ylabel = Y.name
        _existingPlots[name] = _MeanMap(name,
                                        xmin,
                                        xmax,
                                        ymin,
                                        ymax,
                                        step,
                                        localRadius,
                                        overviewStep,
                                        xlabel,
                                        ylabel,
                                        group=group)
    m = existingPlots[name]
    m.append(X, Y, Z, norm)
    if (not m.counter % update):
        m.gatherSumsAndNorms()
        m.gatherOverview()
        if (ipc.mpi.is_main_worker()):
            m.updateCenter(X, Y)
            m.updateLocalLimits()
            m.updateLocalMap()
            m.updateOverviewMap(X, Y)
            print m.localXmin, m.localXmax, m.localYmin, m.localYmax
            ipc.new_data(name+' -> Local', m.localMap, msg=msg, \
                         xmin=m.localXmin, xmax=m.localXmax, ymin=m.localYmin, ymax=m.localYmax)
            ipc.new_data(name + ' -> Overview', m.overviewMap)
Ejemplo n.º 16
0
def plotImage(record,
              history=10,
              vmin=None,
              vmax=None,
              log=False,
              mask=None,
              msg=None,
              alert=False,
              name=None,
              group=None,
              send_rate=None,
              roi_center=None,
              roi_diameters=None):
    """Plotting an image.

    Args:
        :record(Record): record.data is plotted as an image

    Kwargs:
        :history(int):  Length of history buffer
        :vmin(float):   Minimum value
        :vmax(float):   Maximum value
        :log(boolean):  Plot image in log scale (needs restart of GUI, only works with grayscale colormap)
        :mask(boolean or int): Multiply image with mask
    """
    if record is None:
        return
    if name is None:
        n = record.name
    else:
        n = name
    if (not n in images):
        ipc.broadcast.init_data(n,
                                data_type='image',
                                history_length=history,
                                vmin=vmin,
                                vmax=vmax,
                                log=log,
                                group=group)
        images[n] = True
    image = record.data
    sh = image.shape
    if (image.ndim == 3):
        image = image.reshape(sh[0] * sh[2], sh[1])
    if mask is None:
        mask = np.ones_like(image)
    ipc.new_data(n,
                 image * mask,
                 msg=msg,
                 alert=alert,
                 send_rate=send_rate,
                 center=roi_center,
                 diameters=roi_diameters)
Ejemplo n.º 17
0
def plotHistory(param,
                label='',
                history=100,
                hline=None,
                runningHistogram=False,
                window=20,
                bins=100,
                hmin=0,
                hmax=100,
                name_extension="",
                name=None,
                group=None,
                **kwargs):
    """Plotting history of a parameter.

    Args:
        :param(Record):  The history is based on param.data

    Kwargs:
        :label(str):     Label for param
        :history(int):   Length of history buffer
    """
    if param is None:
        return
    if name is None:
        name = "History(%s)%s" % (param.name, name_extension)

    if (not param.name in histories):
        if runningHistogram:
            data_type = 'running_hist'
            ipc.broadcast.init_data(name,
                                    data_type=data_type,
                                    ylabel=label,
                                    history_length=history,
                                    window=window,
                                    bins=bins,
                                    hmin=hmin,
                                    hmax=hmax,
                                    group=group,
                                    **kwargs)
        else:
            data_type = 'scalar'
            ipc.broadcast.init_data(name,
                                    data_type=data_type,
                                    ylabel=label,
                                    history_length=history,
                                    hline=hline,
                                    group=group,
                                    **kwargs)
        histories[param.name] = True
    ipc.new_data(name, param.data, hline=hline, **kwargs)
Ejemplo n.º 18
0
def plotHeatmap(X,
                Y,
                xmin=0,
                xmax=1,
                xbins=10,
                ymin=0,
                ymax=1,
                ybins=10,
                name=None,
                group=None):
    """Plotting the heatmap of two parameters X and Y. Has been tested in MPI mode.
    (Using a buffer in the backend).

    Args:
        :X(Record): An event parameter, e.g. hit rate
        :Y(Record): An event parameter, e.g. some motor position
    Kwargs:
        :xmin(int):  default = 0
        :xmax(int):  default = 1
        :xbins(int): default = 10
        :ymin(int):  default = 0
        :ymax(int):  default = 1
        :ybins(int): default = 10
    """
    if name is None:
        name = "Heatmap(%s,%s)" % (X.name, Y.name)
    if not (name in _existingPlots):
        # initiate (y, x) in 2D array to get correct orientation of image
        _existingPlots[name] = np.zeros((ybins, xbins), dtype=int)
        ipc.broadcast.init_data(name, data_type="image", group=group)
    deltaX = (xmax - float(xmin)) / xbins
    deltaY = (ymax - float(ymin)) / ybins
    nx = np.ceil((X.data - xmin) / deltaX)
    if (nx < 0):
        nx = 0
    elif (nx >= xbins):
        nx = xbins - 1
    ny = np.ceil((Y.data - ymin) / deltaY)
    if (ny < 0):
        ny = 0
    elif (ny >= ybins):
        ny = ybins - 1
    # assign y to row and x to col in 2D array
    _existingPlots[name][ny, nx] += 1
    current_heatmap = np.copy(heatmaps[name])
    ipc.mpi.sum(current_heatmap)
    if ipc.mpi.is_main_event_reader():
        ipc.new_data(name, current_heatmap[()])
Ejemplo n.º 19
0
def plotScatterBg(X,Y, name=None, history=100, xlabel=None, ylabel=None, bg_filename=None, bg_xmin=0., bg_xmax=1., bg_ymin=0., bg_ymax=0., bg_angle=0., group=None):
    """Plotting the scatter of two parameters X and Y.
    """
    if name is None:
        name = "ScatterBg(%s,%s)" %(X.name, Y.name)
    if (not name in _existingPlots):
        if xlabel is None: xlabel = X.name
        if ylabel is None: ylabel = Y.name
        ipc.broadcast.init_data(name, data_type='tuple', history_length=history,
                                xlabel=xlabel, ylabel=ylabel,
                                bg_filename=bg_filename,
                                bg_xmin=bg_xmin, bg_xmax=bg_xmax,
                                bg_ymin=bg_ymin, bg_ymax=bg_ymax,
                                bg_angle=bg_angle, group=group)
        _existingPlots[name] = True
    ipc.new_data(name, np.array([X.data, Y.data]))
Ejemplo n.º 20
0
def plotMeanMapDynamic(X, Y, Z, norm=1., msg='', update=100, xmin=0, xmax=100, ymin=0, ymax=100, step=10, \
                localRadius=100, overviewStep=100, xlabel=None, ylabel=None, plotid=None):
    """Plotting the mean of parameter Z as a function of parameters X and Y.
    (Using a buffer in the backend).

    Args:
       :X(Record):     An event parameter e.g. Motor position in X
       :Y(Record):     An event parameter e.g. Motor position in Y
       :Z(Record):     An event parameter e.g. Intensity

    Kwargs:
        :norm(int):    Z is normalized by a given value, e.g. gmd (default = 1)
        :msg (str):    A message to be displayed in the plot
        :update (int): After how many new data points, an update is send to the frontend (default = 100)
        :xmin (int):   (default = 0)
        :xmax (int):   (default = 100)
        :ymin (int):   (default = 0)
        :ymax (int):   (default = 100)
        :step (int):   The resolution of the map in units of x,y (default = 10)
        :xlabel (str): (default = X.name) 
        :ylabel (str): (default = Y.name)
        :localRadius (int):  The radius of a square neighborehood around the current position (X.data, Y.data) (default = 100)
        :overviewStep (int): The resolution of the overiew map (default = 100)
    """
    if plotid is None:
        plotid = "%s(%s,%s)" % (Z.name, X.name, Y.name)
    if (not plotid in meanMaps):
        if xlabel is None: xlabel = X.name
        if ylabel is None: ylabel = Y.name
        meanMaps[plotid] = _MeanMap(plotid, xmin, xmax, ymin, ymax, step,
                                    localRadius, overviewStep, xlabel, ylabel)
    m = meanMaps[plotid]
    m.append(X, Y, Z, norm)
    if (not m.counter % update):
        m.gatherSumsAndNorms()
        m.gatherOverview()
        if (ipc.mpi.is_main_worker()):
            m.updateCenter(X, Y)
            m.updateLocalLimits()
            m.updateLocalMap()
            m.updateOverviewMap(X, Y)
            print m.localXmin, m.localXmax, m.localYmin, m.localYmax
            ipc.new_data(plotid+' -> Local', m.localMap, msg=msg, \
                         xmin=m.localXmin, xmax=m.localXmax, ymin=m.localYmin, ymax=m.localYmax)
            ipc.new_data(plotid + ' -> Overview', m.overviewMap)
Ejemplo n.º 21
0
def plotCorrelation(X, Y, history=100):
    """Plotting the correlation of two parameters X and Y over time.
    (Using a buffer in the backend).
    
    Args:
        :X(Record): An event parameter, e.g. hit rate
        :Y(Record): An event parameter, e.g. some motor position
    Kwargs: 
        :history(int): Buffer length
    """
    plotid = "Corr(%s,%s)" %(X.name, Y.name)
    if (not plotid in correlations):
        ipc.broadcast.init_data(plotid, history_length=100)
        correlations[plotid] = True
    x,y = (X.data, Y.data)
    xArray.append(x)
    yArray.append(y)
    correlation = x*y/(np.mean(xArray)*np.mean(yArray))
    ipc.new_data(plotid, correlation)
Ejemplo n.º 22
0
def plotCorrelation(X, Y, history=10000, name=None, group=None):
    """Plotting the correlation of two parameters X and Y over time.
    (Using a buffer in the backend).
    
    Args:
        :X(Record): An event parameter, e.g. hit rate
        :Y(Record): An event parameter, e.g. some motor position
    Kwargs: 
        :history(int): Buffer length
    """
    if name is None:
        name = "Corr(%s,%s)" % (X.name, Y.name)
    if (not name in _existingPlots):
        ipc.broadcast.init_data(name, history_length=100, group=group)
        _existingPlots[name] = True
    x, y = (X.data, Y.data)
    xArray.append(x)
    yArray.append(y)
    correlation = x * y / (np.mean(xArray) * np.mean(yArray))
    ipc.new_data(name, correlation)
Ejemplo n.º 23
0
def plotCorrelation(X, Y, history=100, name=None, group=None):
    """Plotting the correlation of two parameters X and Y over time.
    (Using a buffer in the backend).
    
    Args:
        :X(Record): An event parameter, e.g. hit rate
        :Y(Record): An event parameter, e.g. some motor position
    Kwargs: 
        :history(int): Buffer length
    """
    if name is None:
        name = "Corr(%s,%s)" %(X.name, Y.name)
    if (not name in _existingPlots):
        ipc.broadcast.init_data(name, history_length=100, group=group)
        _existingPlots[name] = True
    x,y = (X.data, Y.data)
    xArray.append(x)
    yArray.append(y)
    correlation = x*y/(np.mean(xArray)*np.mean(yArray))
    ipc.new_data(name, correlation)
Ejemplo n.º 24
0
def plotHistogram(value,
                  hmin=0,
                  hmax=10,
                  bins=10,
                  name=None,
                  group=None,
                  buffer_length=100):
    if name is None:
        name = "Histogram of {0}".format(value.name)
    if (name not in histograms):
        ipc.broadcast.init_data(name,
                                data_type='histogram',
                                history_length=buffer_length,
                                hmin=hmin,
                                hmax=hmax,
                                bins=bins,
                                group=group)
        histograms[name] = True
    value = value if not isinstance(value, Record) else value.data
    ipc.new_data(name, value)
Ejemplo n.º 25
0
def plotHeatmap(X, Y, xmin=0, xmax=1, xbins=10, ymin=0, ymax=1, ybins=10, name=None, group=None):
    """Plotting the heatmap of two parameters X and Y. Has been tested in MPI mode.
    (Using a buffer in the backend).

    Args:
        :X(Record): An event parameter, e.g. hit rate
        :Y(Record): An event parameter, e.g. some motor position
    Kwargs:
        :xmin(int):  default = 0
        :xmax(int):  default = 1
        :xbins(int): default = 10
        :ymin(int):  default = 0
        :ymax(int):  default = 1
        :ybins(int): default = 10
    """
    if name is None:
        name = "Heatmap(%s,%s)" %(X.name, Y.name)
    if not(name in _existingPlots):        
        # initiate (y, x) in 2D array to get correct orientation of image
        _existingPlots[name] = np.zeros((ybins, xbins), dtype=int)
        ipc.broadcast.init_data(name, data_type="image", group=group)
    deltaX = (xmax - float(xmin))/xbins
    deltaY = (ymax - float(ymin))/ybins
    nx = np.ceil((X.data - xmin)/deltaX)
    if (nx < 0):
        nx = 0
    elif (nx >= xbins):
        nx = xbins - 1
    ny = np.ceil((Y.data - ymin)/deltaY)
    if (ny < 0):
        ny = 0
    elif (ny >= ybins):
        ny = ybins - 1
    # assign y to row and x to col in 2D array
    _existingPlots[name][ny, nx] += 1
    current_heatmap = np.copy(heatmaps[name])
    ipc.mpi.sum(current_heatmap)
    if ipc.mpi.is_main_event_reader():
        ipc.new_data(name, current_heatmap[()])
Ejemplo n.º 26
0
def plotHistory(param, label='', history=100, runningHistogram=False, window=20, bins=100, hmin=0, hmax=100, name_extension=""):
    """Plotting history of a parameter.

    Args:
        :param(Record):  The history is based on param.data

    Kwargs:
        :label(str):     Label for param
        :history(int):   Length of history buffer
    """
    if param is None:
        return
    plotid = "History(%s)%s" % (param.name, name_extension)
    if (not param.name in histories):
        if runningHistogram:
            data_type = 'running_hist'
            ipc.broadcast.init_data(plotid, data_type=data_type, ylabel=label, history_length=history, window=window, bins=bins, hmin=hmin, hmax=hmax)
        else:
            data_type = 'scalar'
            ipc.broadcast.init_data(plotid, data_type=data_type, ylabel=label, history_length=history)
        histories[param.name] = True
    ipc.new_data(plotid, param.data)
Ejemplo n.º 27
0
def plotTimestamp(timestamp, name=None, group=None, **kwargs):
    if name is None:
        name = "History(Fiducial)"
    if not name in histories:
        ipc.broadcast.init_data(name, data_type='scalar', group=group, **kwargs)
    ipc.new_data(name, timestamp.fiducials, **kwargs)
Ejemplo n.º 28
0
def onEvent(evt):

    # Processing rate
    analysis.event.printProcessingRate()

    # Detector statistics
    analysis.pixel_detector.printStatistics(evt["photonPixelDetectors"])

    # Count Nr. of Photons
    analysis.pixel_detector.totalNrPhotons(evt, "photonPixelDetectors", "CCD")
    plotting.line.plotHistory(evt["analysis"]["nrPhotons - CCD"], label="Nr of photons / frame", history=50)

    # Simple hitfinding (Count Nr. of lit pixels)
    analysis.hitfinding.countLitPixels(
        evt, "photonPixelDetectors", "CCD", aduThreshold=25, hitscoreThreshold=1000, mask=mask
    )

    # Compute the hitrate
    analysis.hitfinding.hitrate(evt, evt["analysis"]["isHit - CCD"], history=10000)

    # Plot the hitscore
    plotting.line.plotHistory(evt["analysis"]["hitscore - CCD"], label="Nr. of lit pixels")

    # Plot the hitrate
    plotting.line.plotHistory(evt["analysis"]["hitrate"], label="Hit rate [%]")

    # Plot injector position in x
    plotting.line.plotHistory(evt["parameters"]["injector_posx"], label="Position in X [um]")

    # Plot injector position in y
    plotting.line.plotHistory(evt["parameters"]["injector_posz"], label="Position in Z [um]")

    # Perform sizing on hits
    if not evt["analysis"]["isHit - CCD"]:
        D.append(evt["photonPixelDetectors"]["CCD"].data)
        global iD
        global nD
        global bg
        iD += 1
        if (iD % nD) == 0:
            print "Calculating new background average."
            bg = numpy.array(D).mean(axis=0)
            ipc.new_data("background average", bg)
    else:

        print "It's a hit"

        if mode in ["default", "radial"]:
            ccd_type = "photonPixelDetectors"
            ccd_key = "CCD"
            m = mask
        elif mode == "bin":
            t0 = time.time()
            analysis.pixel_detector.bin(evt, "photonPixelDetectors", "CCD", binning, mask=mask)
            t_bin = time.time() - t0
            binnedMask = evt["analysis"]["binned mask - CCD"].data
            ccd_type = "analysis"
            ccd_key = "binned image - CCD"
            m = binnedMask

        t0 = time.time()
        # Find the center of diffraction
        analysis.sizing.findCenter(evt, ccd_type, ccd_key, mask=m, maxshift=40 / binning, threshold=13, blur=4)
        t_center = time.time() - t0

        if mode in ["default", "bin"]:
            # Fitting sphere model to get size and intensity
            t0 = time.time()
            analysis.sizing.fitSphere(evt, ccd_type, ccd_key, mask=m, **dict(modelParams, **sizingParams))
            t_size = time.time() - t0
        elif mode == "radial":
            # Calculate radial average
            t0 = time.time()
            cx = evt["analysis"]["offCenterX"].data + (sim.nx - 1) / 2.0
            cy = evt["analysis"]["offCenterY"].data + (sim.ny - 1) / 2.0
            analysis.pixel_detector.radial(evt, ccd_type, ccd_key, mask=m, cx=cx, cy=cy)
            # Fitting sphere model to get size and intensity
            analysis.sizing.fitSphereRadial(
                evt, "analysis", "radial distance - CCD", "radial average - CCD", **dict(modelParams, **sizingParams)
            )
            t_size = time.time() - t0

        # Fitting model
        analysis.sizing.sphereModel(
            evt, "analysis", "offCenterX", "offCenterY", "diameter", "intensity", m.shape, poisson=True, **modelParams
        )

        if mode == "radial":
            analysis.pixel_detector.radial(evt, "analysis", "fit", mask=m, cx=cx, cy=cy)
            # 1D arrays have to have same length, otherwise histoty keeping gets messed up
            rlen = 100
            ipc.new_data(
                "radial fit",
                numpy.array(
                    [
                        evt["analysis"]["radial distance - fit"].data.ravel()[:rlen],
                        evt["analysis"]["radial average - fit"].data.ravel()[:rlen],
                    ],
                    copy=False,
                ),
            )
            ipc.new_data(
                "radial CCD",
                numpy.array(
                    [
                        evt["analysis"]["radial distance - CCD"].data.ravel()[:rlen],
                        evt["analysis"]["radial average - CCD"].data.ravel()[:rlen],
                    ],
                    copy=False,
                ),
                msg="BLA",
            )

        t_all = t_center + t_size
        print "Time: %e sec (center / size : %.2f%% / %.2f%%)" % (
            t_all,
            100.0 * t_center / t_all,
            100.0 * t_size / t_all,
        )

        # Error parameter
        diff = (evt[ccd_type][ccd_key].data - evt["analysis"]["fit"].data)[m].sum() / float(
            evt[ccd_type][ccd_key].data[m].sum()
        )
        ipc.new_data("fit diff", diff)
        ipc.new_data("fit error", evt["analysis"]["fit error"].data)
        ipc.new_data("fit mean error 1", evt["analysis"]["fit mean error 1"].data)
        ipc.new_data("fit mean error 3", evt["analysis"]["fit mean error 3"].data)

        plotting.line.plotHistory(evt["analysis"]["offCenterX"])
        plotting.line.plotHistory(evt["analysis"]["offCenterY"])
        plotting.line.plotHistory(evt["analysis"]["diameter"])
        plotting.line.plotHistory(evt["analysis"]["intensity"])
        # plotting.line.plotHistory(evt["analysis"]["error"])

        # Attach a message to the plots
        s0 = evt["analysis"]["diameter"].data
        I0 = evt["analysis"]["intensity"].data
        msg_glo = "diameter = %.2f nm, \nintensity = %.2f mJ/um2" % (s0, I0)
        msg_fit = "Fit result: \ndiameter = %.2f nm, \nintensity = %.2f mJ/um2 \nerr=%f, merr1=%f, merr3=%f" % (
            s0,
            I0,
            evt["analysis"]["fit error"].data,
            evt["analysis"]["fit mean error 1"].data / evt["analysis"]["radial average - CCD"].data.sum(),
            evt["analysis"]["fit mean error 3"].data,
        )

        # Plot the glorious shots
        plotting.image.plotImage(evt[ccd_type][ccd_key], msg=msg_glo, log=True, mask=m)

        # Plot the fitted model
        plotting.image.plotImage(evt["analysis"]["fit"], msg=msg_fit, log=True, mask=m)

        # Plot heatmap of injector pos in x vs. diameter
        plotting.correlation.plotHeatmap(
            evt["parameters"]["injector_posx"], evt["analysis"]["diameter"], **heatmapInjector
        )

        # Plot heatmap of center positions
        plotting.correlation.plotHeatmap(
            evt["analysis"]["offCenterX"], evt["analysis"]["offCenterY"], **heatmapCenterPos
        )
Ejemplo n.º 29
0
def plotTimestamp(timestamp):
    ipc.new_data('History(Fiducial)', timestamp.fiducials)
Ejemplo n.º 30
0
def onEvent(evt):
    analysis.event.printProcessingRate()
    ipc.new_data("TOF", evt["ionTOFs"]["tof"].data)
    if numpy.random.randint(100) == 0:
        time.sleep(1)