Skip to content

Commit

Permalink
for #7261 show phase space plots in one panel sharing settings (#7304)
Browse files Browse the repository at this point in the history
also fixes #7297 slice axis alignment
  • Loading branch information
moellep authored Oct 4, 2024
1 parent 5fe4bdf commit 387edee
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 79 deletions.
13 changes: 3 additions & 10 deletions sirepo/package_data/static/html/canvas-comparison.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>
<div class="col-md-6 col-xl-4">
<div data-simple-panel="simulationStatus">
<div data-sim-status-panel="comparison.simState"></div>
<div data-sim-status-panel="comparison.simState" data-start-function="comparison.startSimulation()"></div>
</div>
</div>
<div class="clearfix"></div>
Expand All @@ -16,14 +16,7 @@
<div data-report-panel="parameterWithLattice" data-model-name="twissAnimation"></div>
</div>
<div class="clearfix"></div>
<div class="col-md-4" data-ng-if="comparison.simState.hasFrames()">
<div data-report-panel="heatmap" data-model-name="bunchAnimation1"></div>
</div>
<div class="col-md-4" data-ng-if="comparison.simState.hasFrames()">
<div data-report-panel="heatmap" data-model-name="bunchAnimation2"></div>
</div>
<div class="col-md-4" data-ng-if="comparison.simState.hasFrames()">
<div data-report-panel="heatmap" data-model-name="bunchAnimation3"></div>
</div>

<div data-ng-if="comparison.simState.hasFrames()" data-phase-space-plots=""></div>
</div>
</div>
75 changes: 75 additions & 0 deletions sirepo/package_data/static/js/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var srlog = SIREPO.srlog;
var srdbg = SIREPO.srdbg;

SIREPO.app.config(() => {
SIREPO.PLOTTING_SUMMED_LINEOUTS = true;
SIREPO.lattice = {
canReverseBeamline: true,
elementColor: {
Expand Down Expand Up @@ -132,6 +133,10 @@ SIREPO.app.controller('ComparisonController', function(canvasService, frameCache
self.simScope = $scope;
self.errorMessage = '';

self.startSimulation = function() {
self.simState.saveAndRunSimulation(['simulation', 'simulationSettings']);
};

self.simHandleStatus = (data) => {
self.errorMessage = data.error;
frameCache.setFrameCount(data.frameCount || 0);
Expand All @@ -141,4 +146,74 @@ SIREPO.app.controller('ComparisonController', function(canvasService, frameCache
self.simState.errorMessage = () => self.errorMessage;

canvasService.updateCodeVersions($scope);

});

SIREPO.app.directive('phaseSpacePlots', function() {
return {
restrict: 'A',
scope: {},
template: `
<div class="col-sm-12">
<div data-simple-panel="bunchAnimation" data-is-report="1">
<div class="pull-right">
<div data-ng-repeat="(b, v) in views track by $index"
style="display: inline-block; margin-right: 1ex">
<button type="button" class="btn btn-default" data-ng-class="{ 'btn-primary': isSelected(v) }"
data-ng-click="selectView(v)">{{ b }}</button>
</div>
</div>
<div class="clearfix"></div>
<div class="sr-screenshot"
style="display: grid; grid-template-columns: 33% 33% 33%; column-gap: 10px;">
<div data-ng-repeat="r in reports track by $index">
<div data-ng-if="isHeatmap(r)" data-heatmap="" data-model-name="{{ r }}"></div>
<div data-ng-if="! isHeatmap(r)" data-plot3d="" data-model-name="{{ r }}"></div>
</div>
</div>
</div>
</div>
`,
controller: function(appState, $scope) {
$scope.views = {
Horizontal: 'x-px',
Vertical: 'y-py',
'Cross-section': 'x-y',
Longitudinal: 't-pt',
};
$scope.reports = ['bunchAnimation1', 'bunchAnimation2', 'bunchAnimation3'];

$scope.isHeatmap = (report) => {
return appState.models[report].plotType == 'heatmap';
};

$scope.isSelected = (xy) => {
const b = appState.models.bunchAnimation;
return [b.x, b.y].join('-') === xy;
};

$scope.selectView = (xy) => {
const [x, y] = xy.split('-');
const b = appState.models.bunchAnimation;
b.x = x;
b.y = y;
appState.saveChanges('bunchAnimation');
};

$scope.$on('bunchAnimation.changed', (e) => {
const b = appState.models.bunchAnimation;
const updated = {};
for (const r of $scope.reports) {
const m = appState.models[r];
for (const f of ['x', 'y', 'histogramBins', 'colorMap', 'plotType']) {
if (b[f] !== m[f]) {
m[f] = b[f];
updated[r] = true;
}
}
}
appState.saveChanges(Object.keys(updated));
});
},
};
});
2 changes: 1 addition & 1 deletion sirepo/package_data/static/js/sirepo-lattice.js
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ SIREPO.app.directive('parameterWithLattice', function(appState) {
if (! isNestedSVG) {
// nest the SVG so the "download as png" gets both images
isNestedSVG = true;
var svgs = $($element).find('svg');
var svgs = $($element).find('svg.sr-plot');
$(svgs[1]).prepend(svgs[0]);
}
latticeScope.updateFixedAxis(plotScope.getXAxis(), plotScope.margin.left);
Expand Down
14 changes: 12 additions & 2 deletions sirepo/package_data/static/js/sirepo-plotting.js
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,11 @@ SIREPO.app.service('layoutService', function(mathRendering, panelState, plotting
}

function maxDomainWidth(formatInfo) {
const d = self.scale.domain();
//const d = self.scale.domain();
const d = [
formatInfo.tickValues[0],
formatInfo.tickValues[formatInfo.tickCount - 1],
];
return Math.max(
formatInfo.format(applyUnit(d[0], formatInfo.base, formatInfo.unit)).length,
formatInfo.format(applyUnit(d[1], formatInfo.base, formatInfo.unit)).length,
Expand Down Expand Up @@ -3041,6 +3045,9 @@ SIREPO.app.directive('plot3d', function(appState, focusPointService, layoutServi
if (select().empty()) {
return;
}
//TODO(pjm): double refresh required to get correct axis in some cases
// see https://github.com/radiasoft/sirepo/issues/7297
refresh();
refresh();
};

Expand Down Expand Up @@ -3491,6 +3498,9 @@ SIREPO.app.directive('heatmap', function(appState, layoutService, plotting, util
if (select().empty()) {
return;
}
//TODO(pjm): double refresh required to get correct axis in some cases
// see https://github.com/radiasoft/sirepo/issues/7297
refresh();
refresh();
};

Expand Down Expand Up @@ -3519,7 +3529,7 @@ SIREPO.app.directive('colorCircle', function() {
},
template: `
<svg width="30" height="10">
<line x1="0" y1="4" x2="30" y2="4"
<line x1="0" y1="5" x2="30" y2="5"
data-ng-attr-stroke-width="{{ plot.strokeWidth }}"
data-ng-attr-opacity="{{ plot.opacity || 1.0 }}"
data-ng-attr-stroke="{{ plot.color }}"
Expand Down
75 changes: 58 additions & 17 deletions sirepo/package_data/static/json/canvas-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@
["y", "y"],
["py", "Py"],
["t", "t"],
["pt", "Pt"],
["qm", "q"]
["pt", "Pt"]
],
"PlotType": [
["heatmap", "Heatmap"],
["3d", "Heatmap with Histograms"]
],
"Species": [
["positron", "Positron"],
Expand All @@ -75,15 +78,21 @@
],
"bunchAnimation1": [
"simCode",
"histogramBins"
"histogramBins",
"x",
"y"
],
"bunchAnimation2": [
"simCode",
"histogramBins"
"histogramBins",
"x",
"y"
],
"bunchAnimation3": [
"simCode",
"histogramBins"
"histogramBins",
"x",
"y"
]
},
"localRoutes": {
Expand Down Expand Up @@ -112,19 +121,39 @@
"beamline": {
"name": ["Name", "ValidatedString"]
},
"bunchAnimation": {
"x": ["Horizontal Value to Plot", "PhaseSpaceCoordinate", "x"],
"y": ["Vertical Value to Plot", "PhaseSpaceCoordinate", "px"],
"plotType": ["Plot Type", "PlotType", "heatmap"],
"histogramBins": ["Histogram Bins", "Integer", 60],
"colorMap": ["Color Map", "ColorMap", "viridis"],
"notes": ["Notes", "Text", ""]
},
"bunchAnimation1": {
"simCode": ["", "String", "elegant"],
"histogramBins": ["Histogram Bins", "Integer", 80],
"x": ["Horizontal Value to Plot", "PhaseSpaceCoordinate", "x"],
"y": ["Vertical Value to Plot", "PhaseSpaceCoordinate", "px"],
"plotType": ["Plot Type", "PlotType", "heatmap"],
"histogramBins": ["Histogram Bins", "Integer", 60],
"colorMap": ["Color Map", "ColorMap", "viridis"],
"notes": ["Notes", "Text", ""]
},
"bunchAnimation2": {
"simCode": ["", "String", "madx"],
"histogramBins": ["Histogram Bins", "Integer", 80],
"x": ["Horizontal Value to Plot", "PhaseSpaceCoordinate", "x"],
"y": ["Vertical Value to Plot", "PhaseSpaceCoordinate", "px"],
"plotType": ["Plot Type", "PlotType", "heatmap"],
"histogramBins": ["Histogram Bins", "Integer", 60],
"colorMap": ["Color Map", "ColorMap", "viridis"],
"notes": ["Notes", "Text", ""]
},
"bunchAnimation3": {
"simCode": ["", "String", "impactx"],
"histogramBins": ["Histogram Bins", "Integer", 80],
"x": ["Horizontal Value to Plot", "PhaseSpaceCoordinate", "x"],
"y": ["Vertical Value to Plot", "PhaseSpaceCoordinate", "px"],
"plotType": ["Plot Type", "PlotType", "heatmap"],
"histogramBins": ["Histogram Bins", "Integer", 60],
"colorMap": ["Color Map", "ColorMap", "viridis"],
"notes": ["Notes", "Text", ""]
},
"bunchReport": {
Expand Down Expand Up @@ -251,26 +280,36 @@
"name"
]
},
"bunchAnimation1": {

"bunchAnimation": {
"hasDataFile": false,
"title": "Phase Space",
"advanced": [
"plotType",
[
["Horizontal", [
"x"
]],
["Vertical", [
"y"
]]
],
"histogramBins",
"colorMap",
"notes"
]
},
"bunchAnimation1": {
"title": "Phase Space",
"advanced": []
},
"bunchAnimation2": {
"title": "Phase Space",
"advanced": [
"histogramBins",
"notes"
]
"advanced": []
},
"bunchAnimation3": {
"title": "Phase Space",
"advanced": [
"histogramBins",
"notes"
]
"advanced": []
},
"bunchReport": {
"title": "Beam Phase Space",
Expand Down Expand Up @@ -324,6 +363,7 @@
"advanced": []
},
"sigmaAnimation": {
"hasDataFile": false,
"title": "Sigma",
"advanced": [
"includeLattice",
Expand All @@ -342,6 +382,7 @@
"advanced": []
},
"twissAnimation": {
"hasDataFile": false,
"title": "Twiss",
"advanced": [
"includeLattice",
Expand Down
2 changes: 1 addition & 1 deletion sirepo/package_data/static/json/impactx-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
["py", "Py"],
["t", "t"],
["pt", "Pt"],
["qm", "q"]
["qm", "qm"]
],
"SoftSolenoidUnits": [
["0", "1/m"],
Expand Down
6 changes: 3 additions & 3 deletions sirepo/package_data/template/canvas/examples/fodo-cell.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@
"histogramBins": 80,
"notes": "",
"x": "x",
"y": "px"
"y": "y"
},
"bunchReport4": {
"colorMap": "viridis",
"histogramBins": 80,
"notes": "",
"x": "x",
"y": "px"
"x": "t",
"y": "pt"
},
"commands": [],
"distribution": {
Expand Down
2 changes: 1 addition & 1 deletion sirepo/pkcli/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def run_background(cfg_dir):
else:
template_common.exec_parameters()
f1 = str(pkio.py_path("diags/openPMD/monitor.h5"))
f2 = "beam.h5"
f2 = sirepo.template.canvas.INPUT_IMPACTX_BEAM_FILE
pkio.py_path(f1).copy(pkio.py_path(f2))
_write_madx(d, f2)
# TODO(pjm): conditional generation
Expand Down
1 change: 1 addition & 0 deletions sirepo/sim_data/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def fixup_old_data(cls, data, qcall, **kwargs):
cls._init_models(
dm,
[
"bunchAnimation",
"bunchAnimation1",
"bunchAnimation2",
"bunchAnimation3",
Expand Down
Loading

0 comments on commit 387edee

Please sign in to comment.