Beispiel #1
0
def save_plot(txt_file, info_file, output_file, plot_description, options):
    """
    Make plot from arguments.

    :param txt_file: Name of *.txt file
    :type txt_file: str
    :param info_file: Name of *.info file
    :type info_file: str
    :param output_file: Desired name of output file
    :type output_file: str
    :param plot_description: Type of plot
    :type plot_description: str
    :param options: plot_options style arguments
    :type options: namedtuple
    """
    assert plot_description in PLOT_CLASS.keys()

    # Fetch data

    labels, data = data_loader.load(info_file, txt_file)

    # Make file name for plot
    if output_file is None:
        name = basename(txt_file)
        prefix = splitext(name)[0]
        all_indexes = [options.xindex, options.yindex, options.zindex]
        indexes = [str(i) for i in all_indexes if i is not None]
        output_file = prefix + '_' + '_'.join(indexes) + ".pdf"

    # Fix labels with info file

    if info_file:
        if options.xlabel is None and options.xindex:
            options = options._replace(xlabel=labels[options.xindex])
        if options.ylabel is None and options.yindex:
            options = options._replace(ylabel=labels[options.yindex])
        if options.zlabel is None and options.zindex:
            options = options._replace(zlabel=labels[options.zindex])

    # Make and save plot

    figure = PLOT_CLASS[plot_description](data, options).figure()
    plt.savefig(output_file)

    print 'Output file = {}'.format(output_file)
    print 'Summary = {}'.format(figure.summary)
Beispiel #2
0
def save_plot(txt_file, info_file, output_file, plot_description, options):
    """
    Make plot from arguments.

    :param txt_file: Name of *.txt file
    :type txt_file: str
    :param info_file: Name of *.info file
    :type info_file: str
    :param output_file: Desired name of output file
    :type output_file: str
    :param plot_description: Type of plot
    :type plot_description: str
    :param options: plot_options style arguments
    :type options: namedtuple
    """
    assert plot_description in PLOT_CLASS.keys()

    # Fetch data

    labels, data = data_loader.load(info_file, txt_file)

    # Make file name for plot
    if output_file is None:
        name = basename(txt_file)
        prefix = splitext(name)[0]
        all_indexes = [options.xindex, options.yindex, options.zindex]
        indexes = [str(i) for i in all_indexes if i is not None]
        output_file = prefix + '_' + '_'.join(indexes) + ".pdf"

    # Fix labels with info file

    if info_file:
        if options.xlabel is None and options.xindex:
            options = options._replace(xlabel=labels[options.xindex])
        if options.ylabel is None and options.yindex:
            options = options._replace(ylabel=labels[options.yindex])
        if options.zlabel is None and options.zindex:
            options = options._replace(zlabel=labels[options.zindex])

    # Make and save plot

    figure = PLOT_CLASS[plot_description](data, options).figure()
    plt.savefig(output_file)

    print 'Output file = {}'.format(output_file)
    print 'Summary = {}'.format(figure.summary)
Beispiel #3
0
    
    >>> kde = kde_posterior_pdf(data[2], data[3], data[0])
    >>> bin_centers = posterior_mode(kde.pdf, kde.bin_centers_x, kde.bin_centers_y)[0]
    >>> [round(x, DOCTEST_PRECISION) for x in bin_centers]
    [-1919.3356566959, 101.1291971019]
    """
    # Find the maximum weighted count
    max_count = np.max(pdf)

    # Find the indices of bins having the max count
    max_indices = np.argwhere(pdf == max_count)

    # Issue a warning if we found more than one such bin
    if len(max_indices) > 1:
        warnings.warn("posterior mode: max count shared by {} bins".format(
            len(max_indices)))

    # Return the (x,y) bin centers of the corresponding cells
    return [[bin_centers_x[x], bin_centers_y[y]] for x, y in max_indices]


if __name__ == "__main__":

    import doctest
    import superplot.data_loader as data_loader

    GAUSS = "../example/gaussian_.txt"
    GAUSS_DATA = data_loader.load(None, GAUSS)[1]

    doctest.testmod(extraglobs={'data': GAUSS_DATA})
Beispiel #4
0
    -1984.1097853705

    >>> kde = kde_posterior_pdf(data[3], data[0])
    >>> round(posterior_mode(kde.pdf, kde.bin_centers)[0], DOCTEST_PRECISION)
    140.3991747766
    """
    # Find the maximum weighted count.
    max_count = max(pdf)

    # Find the indices of bins having the max count.
    max_indices = [i for i, j in enumerate(pdf) if j == max_count]
    assert pdf.argmax() in max_indices

    if len(max_indices) > 1:
        warnings.warn("posterior_mode: max count shared by {} bins".format(
            len(max_indices)
        ))

    return [bin_centers[i] for i in max_indices]


if __name__ == "__main__":

    import doctest
    import superplot.data_loader as data_loader

    GAUSS = "../example/gaussian_.txt"
    GAUSS_DATA = data_loader.load(None, GAUSS)[1]

    doctest.testmod(extraglobs={'data': GAUSS_DATA})