Exemplo n.º 1
0
def extract_report_data(xFilename, data, page_index, page_count=0):
    xfield = data['x'] if 'x' in data else data[_X_FIELD]
    # x, column_names, x_def, err
    x_col = sdds_util.extract_sdds_column(xFilename, xfield, page_index)
    if x_col['err']:
        return x_col['err']
    x = x_col['values']
    if not _is_histogram_file(xFilename, x_col['column_names']):
        # parameter plot
        plots = []
        filename = {
            'y1': xFilename,
            #TODO(pjm): y2Filename, y3Filename are not currently used. Would require rescaling x value across files.
            'y2': xFilename,
            'y3': xFilename,
        }
        for f in ('y1', 'y2', 'y3'):
            if re.search(r'^none$', data[f], re.IGNORECASE) or data[f] == ' ':
                continue
            yfield = data[f]
            y_col = sdds_util.extract_sdds_column(filename[f], yfield,
                                                  page_index)
            if y_col['err']:
                return y_col['err']
            y = y_col['values']
            plots.append({
                'points': y,
                'label': _field_label(yfield, y_col['column_def'][1]),
            })
        title = ''
        if page_count > 1:
            title = 'Plot {} of {}'.format(page_index + 1, page_count)
        return {
            'title': title,
            'x_range': [min(x), max(x)],
            'y_label': '',
            'x_label': _field_label(xfield, x_col['column_def'][1]),
            'x_points': x,
            'plots': plots,
            'y_range': template_common.compute_plot_color_and_range(plots),
        }
    yfield = data['y1'] if 'y1' in data else data['y']
    y_col = sdds_util.extract_sdds_column(xFilename, yfield, page_index)
    if y_col['err']:
        return y_col['err']
    y = y_col['values']
    bins = data['histogramBins']
    hist, edges = np.histogramdd([x, y], template_common.histogram_bins(bins))
    return {
        'x_range': [float(edges[0][0]),
                    float(edges[0][-1]),
                    len(hist)],
        'y_range': [float(edges[1][0]),
                    float(edges[1][-1]),
                    len(hist[0])],
        'x_label': _field_label(xfield, x_col['column_def'][1]),
        'y_label': _field_label(yfield, y_col['column_def'][1]),
        'title': _plot_title(xfield, yfield, page_index, page_count),
        'z_matrix': hist.T.tolist(),
    }
Exemplo n.º 2
0
def _extract_evolution_plot(report, run_dir):
    filename = str(run_dir.join(_BEAM_EVOLUTION_OUTPUT_FILENAME))
    data = simulation_db.read_json(run_dir.join(template_common.INPUT_BASE_NAME))
    x_col = sdds_util.extract_sdds_column(filename, _X_FIELD, 0)
    if x_col['err']:
        return x_col['err']
    x = x_col['values']
    plots = []
    for f in ('y1', 'y2', 'y3'):
        if report[f] == 'none':
            continue
        yfield = _map_field_name(report[f])
        y_col = sdds_util.extract_sdds_column(filename, yfield, 0)
        if y_col['err']:
            return y_col['err']
        plots.append({
            'points': y_col['values'],
            'label': '{}{}'.format(_field_label(yfield, y_col['column_def']), _field_description(yfield, data)),
        })
    return {
        'title': '',
        'x_range': [min(x), max(x)],
        'y_label': '',
        'x_label': _field_label(_X_FIELD, x_col['column_def']),
        'x_points': x,
        'plots': plots,
        'y_range': template_common.compute_plot_color_and_range(plots),
    }
Exemplo n.º 3
0
def _extract_particle_plot(report, run_dir, page_index):
    xfield = _map_field_name(report['x'])
    yfield = _map_field_name(report['y'])
    bins = report['histogramBins']
    filename = _ion_files(run_dir)[page_index]
    data = simulation_db.read_json(run_dir.join(template_common.INPUT_BASE_NAME))
    settings = data.models.simulationSettings
    time = settings.time / settings.step_number * settings.save_particle_interval * page_index
    if time > settings.time:
        time = settings.time
    x_col = sdds_util.extract_sdds_column(filename, xfield, 0)
    if x_col['err']:
        return x_col['err']
    x = x_col['values']
    y_col = sdds_util.extract_sdds_column(filename, yfield, 0)
    if y_col['err']:
        return y_col['err']
    y = y_col['values']
    particle_animation = data.models.particleAnimation
    range = None
    if report['plotRangeType'] == 'fixed':
        range = [_plot_range(report, 'horizontal'), _plot_range(report, 'vertical')]
    elif report['plotRangeType'] == 'fit' and 'fieldRange' in particle_animation:
        range = [particle_animation.fieldRange[xfield], particle_animation.fieldRange[yfield]]
    hist, edges = np.histogramdd([x, y], template_common.histogram_bins(bins), range=range)
    return {
        'x_range': [float(edges[0][0]), float(edges[0][-1]), len(hist)],
        'y_range': [float(edges[1][0]), float(edges[1][-1]), len(hist[0])],
        'x_label': _field_label(xfield, x_col['column_def']),
        'y_label': _field_label(yfield, y_col['column_def']),
        'title': 'Ions at time {:.2f} [s]'.format(time),
        'z_matrix': hist.T.tolist(),
    }
Exemplo n.º 4
0
def _extract_particle_plot(report, run_dir, page_index):
    xfield = _map_field_name(report['x'])
    yfield = _map_field_name(report['y'])
    filename = _ion_files(run_dir)[page_index]
    data = simulation_db.read_json(run_dir.join(template_common.INPUT_BASE_NAME))
    settings = data.models.simulationSettings
    time = settings.time / settings.step_number * settings.save_particle_interval * page_index
    if time > settings.time:
        time = settings.time
    x_col = sdds_util.extract_sdds_column(filename, xfield, 0)
    if x_col['err']:
        return x_col['err']
    x = x_col['values']
    y_col = sdds_util.extract_sdds_column(filename, yfield, 0)
    if y_col['err']:
        return y_col['err']
    y = y_col['values']
    model = data.models.particleAnimation
    model.update(report)
    model['x'] = xfield
    model['y'] = yfield
    return template_common.heatmap([x, y], model, {
        'x_label': _field_label(xfield, x_col['column_def']),
        'y_label': _field_label(yfield, y_col['column_def']),
        'title': 'Ions at time {:.2f} [s]'.format(time),
    })
Exemplo n.º 5
0
def sim_frame_particleAnimation(frame_args):
    page_index = frame_args.frameIndex
    xfield = _map_field_name(frame_args.x)
    yfield = _map_field_name(frame_args.y)
    filename = _ion_files(frame_args.run_dir)[page_index]
    data = frame_args.sim_in
    settings = data.models.simulationSettings
    time = settings.time / settings.step_number * settings.save_particle_interval * page_index
    if time > settings.time:
        time = settings.time
    x_col = sdds_util.extract_sdds_column(filename, xfield, 0)
    if x_col['err']:
        return x_col['err']
    x = x_col['values']
    y_col = sdds_util.extract_sdds_column(filename, yfield, 0)
    if y_col['err']:
        return y_col['err']
    y = y_col['values']
    model = data.models.particleAnimation
    model.update(frame_args)
    model['x'] = xfield
    model['y'] = yfield
    return template_common.heatmap(
        [x, y], model, {
            'x_label': _field_label(xfield, x_col['column_def']),
            'y_label': _field_label(yfield, y_col['column_def']),
            'title': 'Ions at time {:.2f} [s]'.format(time),
        })
Exemplo n.º 6
0
def sim_frame_beamEvolutionAnimation(frame_args):
    filename = str(frame_args.run_dir.join(_BEAM_EVOLUTION_OUTPUT_FILENAME))
    x_col = sdds_util.extract_sdds_column(filename, _X_FIELD, 0)
    if x_col['err']:
        return x_col['err']
    x = x_col['values']
    plots = []
    for f in ('y1', 'y2', 'y3'):
        if frame_args[f] == 'none':
            continue
        yfield = _map_field_name(frame_args[f])
        y_col = sdds_util.extract_sdds_column(filename, yfield, 0)
        if y_col['err']:
            return y_col['err']
        plots.append({
            'points':
            y_col['values'],
            'label':
            '{}{}'.format(
                _field_label(yfield, y_col['column_def']),
                _field_description(yfield, frame_args.sim_in),
            ),
        })
    return {
        'title': '',
        'x_range': [min(x), max(x)],
        'y_label': '',
        'x_label': _field_label(_X_FIELD, x_col['column_def']),
        'x_points': x,
        'plots': plots,
        'y_range': template_common.compute_plot_color_and_range(plots),
    }
Exemplo n.º 7
0
def extract_report_data(xFilename, data, page_index, page_count=0):
    xfield = data['x'] if 'x' in data else data[_X_FIELD]
    # x, column_names, x_def, err
    x_col = sdds_util.extract_sdds_column(xFilename, xfield, page_index)
    if x_col['err']:
        return x_col['err']
    x = x_col['values']
    if not _is_histogram_file(xFilename, x_col['column_names']):
        # parameter plot
        plots = []
        filename = {
            'y1': xFilename,
            #TODO(pjm): y2Filename, y3Filename are not currently used. Would require rescaling x value across files.
            'y2': xFilename,
            'y3': xFilename,
        }
        for f in ('y1', 'y2', 'y3'):
            if re.search(r'^none$', data[f], re.IGNORECASE) or data[f] == ' ':
                continue
            yfield = data[f]
            y_col = sdds_util.extract_sdds_column(filename[f], yfield, page_index)
            if y_col['err']:
                return y_col['err']
            y = y_col['values']
            plots.append({
                'points': y,
                'label': _field_label(yfield, y_col['column_def'][1]),
            })
        title = ''
        if page_count > 1:
            title = 'Plot {} of {}'.format(page_index + 1, page_count)
        return {
            'title': title,
            'x_range': [min(x), max(x)],
            'y_label': '',
            'x_label': _field_label(xfield, x_col['column_def'][1]),
            'x_points': x,
            'plots': plots,
            'y_range': template_common.compute_plot_color_and_range(plots),
        }
    yfield = data['y1'] if 'y1' in data else data['y']
    y_col = sdds_util.extract_sdds_column(xFilename, yfield, page_index)
    if y_col['err']:
        return y_col['err']
    y = y_col['values']
    bins = data['histogramBins']
    hist, edges = np.histogramdd([x, y], template_common.histogram_bins(bins))
    return {
        'x_range': [float(edges[0][0]), float(edges[0][-1]), len(hist)],
        'y_range': [float(edges[1][0]), float(edges[1][-1]), len(hist[0])],
        'x_label': _field_label(xfield, x_col['column_def'][1]),
        'y_label': _field_label(yfield, y_col['column_def'][1]),
        'title': _plot_title(xfield, yfield, page_index, page_count),
        'z_matrix': hist.T.tolist(),
    }
Exemplo n.º 8
0
def _extract_report_data(xFilename, frame_args, page_count=0):
    page_index = frame_args.frameIndex
    xfield = frame_args.x if 'x' in frame_args else frame_args[_X_FIELD]
    # x, column_names, x_def, err
    x_col = sdds_util.extract_sdds_column(xFilename, xfield, page_index)
    if x_col['err']:
        return x_col['err']
    x = x_col['values']
    if not _is_histogram_file(xFilename, x_col['column_names']):
        # parameter plot
        plots = []
        filename = PKDict(
            y1=xFilename,
            #TODO(pjm): y2Filename, y3Filename are not currently used. Would require rescaling x value across files.
            y2=xFilename,
            y3=xFilename,
        )
        for f in ('y1', 'y2', 'y3'):
            if re.search(r'^none$', frame_args[f],
                         re.IGNORECASE) or frame_args[f] == ' ':
                continue
            yfield = frame_args[f]
            y_col = sdds_util.extract_sdds_column(filename[f], yfield,
                                                  page_index)
            if y_col['err']:
                return y_col['err']
            y = y_col['values']
            plots.append(
                PKDict(
                    field=yfield,
                    points=y,
                    label=_field_label(yfield, y_col['column_def'][1]),
                ))
        title = ''
        if page_count > 1:
            title = 'Plot {} of {}'.format(page_index + 1, page_count)
        return template_common.parameter_plot(
            x, plots, frame_args,
            PKDict(
                title=title,
                y_label='',
                x_label=_field_label(xfield, x_col['column_def'][1]),
            ))
    yfield = frame_args['y1'] if 'y1' in frame_args else frame_args['y']
    y_col = sdds_util.extract_sdds_column(xFilename, yfield, page_index)
    if y_col['err']:
        return y_col['err']
    return template_common.heatmap(
        [x, y_col['values']], frame_args,
        PKDict(
            x_label=_field_label(xfield, x_col['column_def'][1]),
            y_label=_field_label(yfield, y_col['column_def'][1]),
            title=_plot_title(xfield, yfield, page_index, page_count),
        ))
Exemplo n.º 9
0
def extract_report_data(xFilename, data, page_index, page_count=0):
    xfield = data['x'] if 'x' in data else data[_X_FIELD]
    # x, column_names, x_def, err
    x_col = sdds_util.extract_sdds_column(xFilename, xfield, page_index)
    if x_col['err']:
        return x_col['err']
    x = x_col['values']
    if not _is_histogram_file(xFilename, x_col['column_names']):
        # parameter plot
        plots = []
        filename = {
            'y1': xFilename,
            #TODO(pjm): y2Filename, y3Filename are not currently used. Would require rescaling x value across files.
            'y2': xFilename,
            'y3': xFilename,
        }
        for f in ('y1', 'y2', 'y3'):
            if re.search(r'^none$', data[f], re.IGNORECASE) or data[f] == ' ':
                continue
            yfield = data[f]
            y_col = sdds_util.extract_sdds_column(filename[f], yfield,
                                                  page_index)
            if y_col['err']:
                return y_col['err']
            y = y_col['values']
            plots.append({
                'field': yfield,
                'points': y,
                'label': _field_label(yfield, y_col['column_def'][1]),
            })
        title = ''
        if page_count > 1:
            title = 'Plot {} of {}'.format(page_index + 1, page_count)
        return template_common.parameter_plot(
            x, plots, data, {
                'title': title,
                'y_label': '',
                'x_label': _field_label(xfield, x_col['column_def'][1]),
            })
    yfield = data['y1'] if 'y1' in data else data['y']
    y_col = sdds_util.extract_sdds_column(xFilename, yfield, page_index)
    if y_col['err']:
        return y_col['err']
    return template_common.heatmap(
        [x, y_col['values']], data, {
            'x_label': _field_label(xfield, x_col['column_def'][1]),
            'y_label': _field_label(yfield, y_col['column_def'][1]),
            'title': _plot_title(xfield, yfield, page_index, page_count),
        })
Exemplo n.º 10
0
def sim_frame_plot2Animation(frame_args):

    x = None
    plots = []
    for f in ('x', 'y1', 'y2', 'y3'):
        name = frame_args[f].replace(' ', '_')
        if name == 'none':
            continue
        col = sdds_util.extract_sdds_column(
            str(frame_args.run_dir.join(_OPAL_SDDS_FILE)), name, 0)
        if col.err:
            return col.err
        field = PKDict(
            points=col['values'],
            label=frame_args[f],
        )
        _field_units(col.column_def[1], field)
        if f == 'x':
            x = field
        else:
            plots.append(field)
    return template_common.parameter_plot(x.points, plots, {}, {
        'title': '',
        'y_label': '',
        'x_label': x.label,
    })
Exemplo n.º 11
0
def sim_frame_plot2Animation(frame_args):
    from sirepo.template import sdds_util

    x = None
    plots = []
    for f in ('x', 'y1', 'y2', 'y3'):
        name = frame_args[f].replace(' ', '_')
        if name == 'none':
            continue
        col = sdds_util.extract_sdds_column(str(frame_args.run_dir.join(_OPAL_SDDS_FILE)), name, 0)
        if col.err:
            return col.err
        field = PKDict(
            points=col['values'],
            label=frame_args[f],
        )
        _field_units(col.column_def[1], field)
        if f == 'x':
            x = field
        else:
            plots.append(field)
    # independent reads of file may produce more columns, trim to match x length
    for p in plots:
        if len(x.points) < len(p.points):
            p.points = p.points[:len(x.points)]
    return template_common.parameter_plot(x.points, plots, {}, {
        'title': '',
        'y_label': '',
        'x_label': x.label,
    })
Exemplo n.º 12
0
def _sdds_report(frame_args, filename, x_field):
    xfield = _map_field_name(x_field)
    x_col = sdds_util.extract_sdds_column(filename, xfield, 0)
    if x_col.err:
        return x_col.err
    x = x_col['values']
    if 'fieldRange' in frame_args.sim_in.models.particleAnimation:
        frame_args.fieldRange = frame_args.sim_in.models.particleAnimation.fieldRange
    plots = []
    for f in ('y1', 'y2', 'y3'):
        if f not in frame_args or frame_args[f] == 'none':
            continue
        yfield = _map_field_name(frame_args[f])
        y_col = sdds_util.extract_sdds_column(filename, yfield, 0)
        if y_col.err:
            return y_col.err
        y = y_col['values']
        label_prefix = ''
        #TODO(pjm): the forceScale feature makes the code unmanageable
        # it might be simpler if this was done on the client
        if 'forceScale' in frame_args \
           and yfield in ('f_x', 'f_long') \
           and frame_args.forceScale == 'negative':
            y = [-v for v in y]
            label_prefix = '-'
            if 'fieldRange' in frame_args:
                r = frame_args.fieldRange[frame_args[f]]
                frame_args.fieldRange[frame_args[f]] = [-r[1], -r[0]]
        plots.append(
            PKDict(
                field=frame_args[f],
                points=y,
                label='{}{}{}'.format(
                    label_prefix,
                    _field_label(yfield, y_col.column_def),
                    _field_description(yfield, frame_args.sim_in),
                ),
            ))
    if xfield == 'V_trans':
        x = _resort_vtrans(x, plots)
    frame_args.x = x_field
    return template_common.parameter_plot(
        x, plots, frame_args,
        PKDict(
            y_label='',
            x_label=_field_label(xfield, x_col.column_def),
        ))
Exemplo n.º 13
0
def _beam_evolution_status(run_dir, settings, has_rates):
    try:
        filename = str(run_dir.join(_BEAM_EVOLUTION_OUTPUT_FILENAME))
        col = sdds_util.extract_sdds_column(filename, 't', 0)
        t_max = max(col['values'])
        if t_max and settings.time > 0:
            return {
                # use current time as frameCount for uniqueness until simulation is completed
                'frameCount': int(float(os.path.getmtime(filename))),
                'percentComplete': 100.0 * t_max / settings.time,
                'hasRates': has_rates,
            }
    except:
        pass
    return {
        'frameCount': 0,
        'percentComplete': 0,
    }
Exemplo n.º 14
0
def extract_report_data(xFilename, yFilename, data, page_index):
    xfield = data['x'] if 'x' in data else data[_X_FIELD]

    # x, column_names, x_def, err
    x_col = sdds_util.extract_sdds_column(xFilename, xfield, page_index)
    if x_col['err']:
        return x_col['err']
    x = x_col['values']
    if 'y1' in data:
        # parameter plot
        y_range = None
        plots = []
        for f in ('y1', 'y2', 'y3'):
            if data[f] == 'none':
                continue
            yfield = data[f]
            y_col = sdds_util.extract_sdds_column(yFilename, yfield,
                                                  page_index)
            if y_col['err']:
                return y_col['err']
            y = y_col['values']
            if y_range:
                y_range[0] = min(y_range[0], min(y))
                y_range[1] = max(y_range[1], max(y))
            else:
                y_range = [min(y), max(y)]
            plots.append({
                'points': y,
                'label': _field_label(yfield, y_col['column_def'][1]),
                #TODO(pjm): refactor with template_common.compute_plot_color_and_range()
                'color': _PLOT_LINE_COLOR[f],
            })
        return {
            'title': '',
            'x_range': [min(x), max(x)],
            'y_label': '',
            'x_label': _field_label(_X_FIELD, x_col['column_def'][1]),
            'x_points': x,
            'plots': plots,
            'y_range': y_range,
        }
    yfield = data['y']
    y_col = sdds_util.extract_sdds_column(yFilename, yfield, page_index)
    if y_col['err']:
        return y_col['err']
    y = y_col['values']
    if _is_2d_plot(x_col['column_names']):
        # 2d plot
        return {
            'title': _plot_title(xfield, yfield, page_index),
            'x_range': [np.min(x), np.max(x)],
            'x_label': _field_label(xfield, x_col['column_def'][1]),
            'y_label': _field_label(yfield, y_col['column_def'][1]),
            'points': y,
            'x_points': x,
        }
    bins = data['histogramBins']
    hist, edges = np.histogramdd([x, y], template_common.histogram_bins(bins))
    return {
        'x_range': [float(edges[0][0]),
                    float(edges[0][-1]),
                    len(hist)],
        'y_range': [float(edges[1][0]),
                    float(edges[1][-1]),
                    len(hist[0])],
        'x_label': _field_label(xfield, x_col['column_def'][1]),
        'y_label': _field_label(yfield, y_col['column_def'][1]),
        'title': _plot_title(xfield, yfield, page_index),
        'z_matrix': hist.T.tolist(),
    }