示例#1
0
def generate_distribution_violin(data_path: str, num_ranks: int,
                                 timesteps: int, bw_value: float):
    num_ranks = 2
    vpic_reader = VPICReader(data_path, num_ranks=num_ranks)
    fig = go.Figure()

    for tsidx in range(0, timesteps):
        data = vpic_reader.read_global(tsidx)
        print(len(data))
        # plotted_data = np.random.choice(data, 50000)
        plotted_data = np.random.choice(data, 500)

        head_cutoff = 0.5
        head_cutoff_2 = 4
        tail_cutoff = 10

        head_data = len([i for i in plotted_data if i < head_cutoff])
        head_data_2 = len([i for i in plotted_data if i < head_cutoff_2])
        tail_data = len([i for i in plotted_data if i > tail_cutoff])

        percent_head = head_data * 100.0 / len(plotted_data)
        percent_head_2 = head_data_2 * 100.0 / len(plotted_data)
        percent_tail = tail_data * 100.0 / len(plotted_data)

        print('TS {0}, < {1}: {2:.2f}'.format(tsidx, head_cutoff,
                                              percent_head))
        print('TS {0}, < {1}: {2:.2f}'.format(tsidx, head_cutoff_2,
                                              percent_head_2))
        print('TS {0}, > {1}: {2:.2f}'.format(tsidx, tail_cutoff,
                                              percent_tail))

        plotted_data = list(map(lambda x: log_tailed(x, 10), plotted_data))

        ts_name = 'Timestep {0}'.format(vpic_reader.get_ts(tsidx), )

        violin_data = go.Violin(y=plotted_data,
                                box_visible=False,
                                meanline_visible=False,
                                name=ts_name,
                                side='positive',
                                points=False,
                                bandwidth=bw_value,
                                scalemode='width',
                                line=dict(width=1))

        fig.add_trace(violin_data)

    fig.update_traces(width=1.8)
    fig.update_layout(
        title_text='Energy distribution from 4 timesteps of a VPIC simulation'
        ' (tail is logarithmic)',
        yaxis=dict(tickmode='array',
                   tickvals=list(range(0, 18, 2)),
                   ticktext=[
                       '{0:.0f}'.format(log_tailed_reverse(x, 10))
                       for x in range(0, 18, 2)
                   ]),
    )

    fig.show()
示例#2
0
def generate_distribution_box(data_path: str, num_ranks: int, timesteps: int):
    # num_ranks = 4
    vpic_reader = VPICReader(data_path, num_ranks=num_ranks)
    fig = go.Figure()

    for tsidx in range(0, timesteps):
        data = vpic_reader.read_global(tsidx)
        print(len(data))
        plotted_data = np.random.choice(data, 50000)

        head_cutoff = 2
        tail_cutoff = 10

        head_data = len([i for i in plotted_data if i < head_cutoff])
        tail_data = len([i for i in plotted_data if i > tail_cutoff])

        percent_head = head_data * 100.0 / len(plotted_data)
        percent_tail = tail_data * 100.0 / len(plotted_data)

        print('TS {0}, < {1}: {2:.2f}'.format(tsidx, head_cutoff,
                                              percent_head))
        print('TS {0}, > {1}: {2:.2f}'.format(tsidx, tail_cutoff,
                                              percent_tail))

        plotted_data = list(map(lambda x: log_tailed(x, 10), plotted_data))

        ts_name = 'Timestep {0}'.format(vpic_reader.get_ts(tsidx), )

        box_data = go.Box(y=plotted_data,
                          name=ts_name,
                          line_width=1,
                          marker=dict(size=4, line=dict(width=0)))
        fig.add_trace(box_data)

    fig.update_layout(
        title_text='Energy distribution from 4 timesteps of a VPIC simulation'
        ' (tail is logarithmic)',
        yaxis=dict(tickmode='array',
                   tickvals=list(range(0, 18, 2)),
                   ticktext=[
                       '{0:.0f}'.format(log_tailed_reverse(x, 10))
                       for x in range(0, 18, 2)
                   ]),
    )

    # fig.show()
    fig.write_image('../vis/poster/vpic32.distrib.box.pdf')