Ejemplo n.º 1
0
def as_html(data, fields):
    """Create HTML representation of a plot

    Parameters
    ----------
    data : Plot instance
        The plot object to display.
    fields : sequence of strings
        The fields of data to use.

    """

    # Would like a nicer way to set the summary label, but without
    # adding a per-class field for this it is safest just to use
    # the object name.

    meta = []
    for name in fields:
        # skip records which we don't know about. This indicates
        # an error in the calling code, but we don't want it to
        # stop the generation of the HTML.
        #
        try:
            val = getattr(data, name)
        except Exception as e:
            lgr.debug("Skipping field {}: {}".format(name, e))
            continue

        meta.append((name, val))

    ls = [formatting.html_section(meta, open_block=True,
                                  summary=type(data).__name__)]
    return formatting.html_from_sections(data, ls)
Ejemplo n.º 2
0
def html_data1dint(data):
    """HTML representation: Data1DInt

    If have matplotlib then plot the data, otherwise summarize it.

    """

    from sherpa.plot import DataHistogramPlot, backend

    dtype = type(data).__name__

    plotter = DataHistogramPlot()
    plotter.prepare(data)

    summary = '{} Plot'.format(dtype)
    try:
        out = backend.as_html_plot(plotter, summary)
    except AttributeError:
        out = None

    if out is not None:
        return formatting.html_from_sections(data, [out])

    # Summary properties
    #
    meta = []
    if data.name is not None and data.name != '':
        meta.append(('Identifier', data.name))

    meta.append(('Number of bins', len(data.xlo)))

    # Should this only be displayed if a filter has been applied?
    #
    fexpr = data.get_filter_expr()
    nbins = data.get_dep(filter=True).size
    meta.append(('Using', '{} with {} bins'.format(fexpr, nbins)))

    # Rely on the _fields ordering, ending at staterror
    for f in data._fields[1:]:
        if f == 'staterror':
            break

        meta.append((f.upper(), getattr(data, f)))

    if data.staterror is not None:
        meta.append(('Statistical error', data.staterror))

    if data.syserror is not None:
        meta.append(('Systematic error', data.syserror))

    ls = [formatting.html_section(meta, summary=dtype + ' Summary',
                                  open_block=True)]
    return formatting.html_from_sections(data, ls)
Ejemplo n.º 3
0
def html_data2d(data):
    """HTML representation: Data2D and derived classes

    """

    dtype = type(data).__name__

    """

    It would be nice to plot the plot, but there are several questions to
    resolve, such as:

      - do we plot each point (okay for sparse data) or binned
      - simple binning, adaptive binning, hexagonal binning?
      - do we just pick a number, like 100, to bin the data to

    """

    # Summary properties
    #
    meta = []
    if data.name is not None and data.name != '':
        meta.append(('Identifier', data.name))

    # NOTE: shape is not well defined, is it x by y or
    # the inverse, so I am not going to display it at the
    # moment.
    # if data.shape != None:
    #     meta.append(('Shape', data.shape))

    meta.append(('Number of bins', len(data.y)))

    # Rely on the _fields ordering, ending at shape
    for f in data._fields[1:]:
        if f == 'shape':
            break

        meta.append((f.upper(), getattr(data, f)))

    if data.staterror is not None:
        meta.append(('Statistical error', data.staterror))

    if data.syserror is not None:
        meta.append(('Systematic error', data.syserror))

    ls = [formatting.html_section(meta, summary=dtype + ' Summary',
                                  open_block=True)]
    return formatting.html_from_sections(data, ls)