def _run_bunch_report(data, bunch, twiss): twiss0 = twiss[0] report = data.models[data['report']] particles = bunch.get_local_particles() x = particles[:, getattr(bunch, report['x'])] y = particles[:, getattr(bunch, report['y'])] hist, edges = np.histogramdd([x, y], template_common.histogram_bins( report['histogramBins'])) 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': template.label(report['x']), 'y_label': template.label(report['y']), 'title': '{}-{}'.format(report['x'], report['y']), 'z_matrix': hist.T.tolist(), 'summaryData': { 'bunchTwiss': { 'alpha_x': template.format_float(twiss0['alpha_x']), 'alpha_y': template.format_float(twiss0['alpha_y']), 'beta_x': template.format_float(twiss0['beta_x']), 'beta_y': template.format_float(twiss0['beta_y']), }, }, }
def _run_twiss_report(data, report_name): x = None plots = [] report = data['models'][report_name] with h5py.File(template.OUTPUT_FILE[report_name], 'r') as f: x = f['s'][:].tolist() for yfield in ('y1', 'y2', 'y3'): if report[yfield] == 'none': continue name = report[yfield] plots.append({ 'name': name, 'label': template.label(report[yfield], _SCHEMA['enum']['TwissParameter']), 'points': f[name][:].tolist(), }) return { 'title': '', 'x_range': [min(x), max(x)], 'y_range': template_common.compute_plot_color_and_range(plots), 'x_label': 's [m]', 'y_label': '', 'x_points': x, 'plots': plots, }
def _run_bunch_report(data): import synergia.bunch with h5py.File(template.OUTPUT_FILE['twissReport'], 'r') as f: twiss0 = dict( map( lambda k: (k, template.format_float(f[k][0])), ('alpha_x', 'alpha_y', 'beta_x', 'beta_y'), )) report = data.models[data['report']] bunch = data.models.bunch if bunch.distribution == 'file': bunch_file = template_common.lib_file_name('bunch', 'particleFile', bunch.particleFile) else: bunch_file = template.OUTPUT_FILE['bunchReport'] with h5py.File(bunch_file, 'r') as f: x = f['particles'][:, getattr(synergia.bunch.Bunch, report['x'])] y = f['particles'][:, getattr(synergia.bunch.Bunch, report['y'])] hist, edges = np.histogramdd([x, y], template_common.histogram_bins( report['histogramBins'])) return { 'title': '{}-{}'.format(report['x'], report['y']), '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': template.label(report['x']), 'y_label': template.label(report['y']), 'z_matrix': hist.T.tolist(), 'summaryData': { 'bunchTwiss': twiss0, }, }
def _run_twiss_report(data, report, twiss): plots = [] report = data['models'][report] x = [] plots = [] y_range = None for yfield in ('y1', 'y2', 'y3'): if report[yfield] != 'none': plots.append({ 'name': report[yfield], 'points': [], 'label': template.label(report[yfield], _SCHEMA['enum']['TwissParameter']), 'color': _PLOT_LINE_COLOR[yfield], }) for row in twiss: x.append(row['s']) for plot in plots: v = row[plot['name']] plot['points'].append(v) if y_range: if v < y_range[0]: y_range[0] = v if v > y_range[1]: y_range[1] = v else: y_range = [v, v] return { 'title': '', 'x_range': [min(x), max(x)], 'y_label': '', 'x_label': 's [m]', 'x_points': x, 'plots': plots, 'y_range': y_range, }