-
-
Notifications
You must be signed in to change notification settings - Fork 18
Add new options to genesis4_par_to_data: wrap, z0, equal_weights, cut… #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ChristopherMayes
wants to merge
4
commits into
master
Choose a base branch
from
genesis4_particles_features
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a9aae30
Add new options to genesis4_par_to_data: wrap, z0, equal_weights, cut…
ChristopherMayes 2d05d8d
Add ParticleGroup.from_genesis4
ChristopherMayes fab4f11
Merge branch 'master' into genesis4_particles_features
ChristopherMayes 7bba584
Docs
ChristopherMayes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| &setup | ||
| rootname = genesis4 | ||
| lattice = genesis4.lat | ||
| beamline = LAT | ||
| gamma0 = 1000.0 | ||
| lambda0 = 1e-07 | ||
| delz = 0.026 | ||
| seed = 123456 | ||
| npart = 128 | ||
| &end | ||
|
|
||
| &time | ||
| slen = 7.175993210500245e-05 | ||
| sample = 10 | ||
| &end | ||
|
|
||
| # 100 pC | ||
| &profile_gauss | ||
| label = beamcurrent | ||
| c0 = 1000.0 | ||
| s0 = 3.5879966052501225e-05 | ||
| sig = 1.1959988684167075e-05 | ||
| &end | ||
|
|
||
| &beam | ||
| gamma = 1000.0 | ||
| delgam = 1.0 | ||
| current = @beamcurrent | ||
| &end | ||
|
|
||
| &track | ||
| zstop = 1.0 | ||
| &end | ||
|
|
||
| &write | ||
| beam=end | ||
| &end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| D1: drift = {l=1.0}; | ||
| LAT: LINE = {D1}; |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| genesis4 genesis4.in | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,166 +11,187 @@ | |||||
| "cell_type": "code", | ||||||
| "execution_count": null, | ||||||
| "metadata": { | ||||||
| "execution": { | ||||||
| "iopub.execute_input": "2024-10-17T23:18:26.404727Z", | ||||||
| "iopub.status.busy": "2024-10-17T23:18:26.404338Z", | ||||||
| "iopub.status.idle": "2024-10-17T23:18:26.431800Z", | ||||||
| "shell.execute_reply": "2024-10-17T23:18:26.431113Z" | ||||||
| }, | ||||||
| "tags": [] | ||||||
| }, | ||||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "# Useful for debugging\n", | ||||||
| "%load_ext autoreload\n", | ||||||
| "%autoreload 2" | ||||||
| "from pmd_beamphysics import ParticleGroup\n", | ||||||
| "from pmd_beamphysics.interfaces.elegant import elegant_h5_to_data" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "markdown", | ||||||
| "metadata": {}, | ||||||
| "source": [ | ||||||
| "# elegant hdf5 format" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "markdown", | ||||||
| "metadata": {}, | ||||||
| "source": [ | ||||||
| "This will convert to a data dict" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "code", | ||||||
| "execution_count": null, | ||||||
| "metadata": { | ||||||
| "execution": { | ||||||
| "iopub.execute_input": "2024-10-17T23:18:26.434439Z", | ||||||
| "iopub.status.busy": "2024-10-17T23:18:26.434222Z", | ||||||
| "iopub.status.idle": "2024-10-17T23:18:27.006225Z", | ||||||
| "shell.execute_reply": "2024-10-17T23:18:27.005886Z" | ||||||
| }, | ||||||
| "tags": [] | ||||||
| }, | ||||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "from pmd_beamphysics import ParticleGroup" | ||||||
| "data = elegant_h5_to_data(\"data/elegant_raw.h5\")\n", | ||||||
| "data" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "markdown", | ||||||
| "metadata": {}, | ||||||
| "source": [ | ||||||
| "# elegant hdf5 format" | ||||||
| "Create `ParticleGroup` and plot:" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "code", | ||||||
| "execution_count": null, | ||||||
| "metadata": { | ||||||
| "execution": { | ||||||
| "iopub.execute_input": "2024-10-17T23:18:27.007895Z", | ||||||
| "iopub.status.busy": "2024-10-17T23:18:27.007692Z", | ||||||
| "iopub.status.idle": "2024-10-17T23:18:27.018400Z", | ||||||
| "shell.execute_reply": "2024-10-17T23:18:27.018161Z" | ||||||
| }, | ||||||
| "tags": [] | ||||||
| }, | ||||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "from pmd_beamphysics.interfaces.elegant import elegant_h5_to_data" | ||||||
| "P = ParticleGroup(data=data)\n", | ||||||
| "P.plot(\"delta_t\", \"delta_pz\")" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "markdown", | ||||||
| "metadata": {}, | ||||||
| "source": [ | ||||||
| "This will convert to a data dict" | ||||||
| "# Genesis4 HDF5 format\n", | ||||||
| "\n", | ||||||
| "Genesis4 stores particles in `z` slices in its HDF5 file format. Each slice has a `z` length equal to the reference wavelength `lambda0`. In order to speed up the simulation, Genesis4 also has an integer parameter [`sample`](https://github.com/svenreiche/Genesis-1.3-Version4/blob/master/manual/MAIN_INPUT.md#time) that essentially skips adjacent slices, defined in the input file:\n" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "code", | ||||||
| "execution_count": null, | ||||||
| "metadata": { | ||||||
| "execution": { | ||||||
| "iopub.execute_input": "2024-10-17T23:18:27.019838Z", | ||||||
| "iopub.status.busy": "2024-10-17T23:18:27.019749Z", | ||||||
| "iopub.status.idle": "2024-10-17T23:18:27.038539Z", | ||||||
| "shell.execute_reply": "2024-10-17T23:18:27.038287Z" | ||||||
| }, | ||||||
| "tags": [] | ||||||
| }, | ||||||
| "metadata": {}, | ||||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "data = elegant_h5_to_data(\"data/elegant_raw.h5\")\n", | ||||||
| "data" | ||||||
| "# Input\n", | ||||||
| "!cat data/genesis4/genesis4.in" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "code", | ||||||
| "execution_count": null, | ||||||
| "metadata": {}, | ||||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "# Lattice\n", | ||||||
| "!cat data/genesis4/genesis4.lat" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "markdown", | ||||||
| "metadata": {}, | ||||||
| "source": [ | ||||||
| "Create `ParticleGroup` and plot:" | ||||||
| "Running Genesis4 on this input (`genesis4 genesis4.in`) produces the raw particle file `end.par.h5` with slice particle." | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "code", | ||||||
| "execution_count": null, | ||||||
| "metadata": { | ||||||
| "execution": { | ||||||
| "iopub.execute_input": "2024-10-17T23:18:27.060724Z", | ||||||
| "iopub.status.busy": "2024-10-17T23:18:27.060588Z", | ||||||
| "iopub.status.idle": "2024-10-17T23:18:27.383511Z", | ||||||
| "shell.execute_reply": "2024-10-17T23:18:27.383284Z" | ||||||
| }, | ||||||
| "tags": [] | ||||||
| }, | ||||||
| "metadata": {}, | ||||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "P = ParticleGroup(data=data)\n", | ||||||
| "P.plot(\"delta_t\", \"delta_pz\")" | ||||||
| "parfile = \"data/genesis4/end.par.h5\"" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "markdown", | ||||||
| "metadata": {}, | ||||||
| "source": [ | ||||||
| "# Genesis4 HDF5 format" | ||||||
| "By default `ParticleGroup.from_genesis4` will load these particles relative to their slice position. Because `sample=10` we see a comb-like distribution:" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "code", | ||||||
| "execution_count": null, | ||||||
| "metadata": { | ||||||
| "execution": { | ||||||
| "iopub.execute_input": "2024-10-17T23:18:27.385069Z", | ||||||
| "iopub.status.busy": "2024-10-17T23:18:27.384959Z", | ||||||
| "iopub.status.idle": "2024-10-17T23:18:27.395330Z", | ||||||
| "shell.execute_reply": "2024-10-17T23:18:27.395103Z" | ||||||
| } | ||||||
| }, | ||||||
| "metadata": {}, | ||||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "from pmd_beamphysics.interfaces.genesis import genesis4_par_to_data" | ||||||
| "P_default = ParticleGroup.from_genesis4(parfile)\n", | ||||||
| "P_default.plot(\"z\", \"pz\", bins=200)\n", | ||||||
| "P_default" | ||||||
| ] | ||||||
| }, | ||||||
| { | ||||||
| "cell_type": "code", | ||||||
| "execution_count": null, | ||||||
| "metadata": { | ||||||
| "execution": { | ||||||
| "iopub.execute_input": "2024-10-17T23:18:27.396506Z", | ||||||
| "iopub.status.busy": "2024-10-17T23:18:27.396431Z", | ||||||
| "iopub.status.idle": "2024-10-17T23:18:27.491746Z", | ||||||
| "shell.execute_reply": "2024-10-17T23:18:27.491430Z" | ||||||
| } | ||||||
| }, | ||||||
| "metadata": {}, | ||||||
| "outputs": [], | ||||||
| "source": [ | ||||||
| "P = ParticleGroup(data=genesis4_par_to_data(\"data/genesis4.par.h5\"))\n", | ||||||
| "# ParticleGroup has a `smear` option that shifts particles in each slice by a random integer multiple of the slice spacing, so that the overall distrubution is smoother while preserving the bunching characteristics:" | ||||||
|
||||||
| "# ParticleGroup has a `smear` option that shifts particles in each slice by a random integer multiple of the slice spacing, so that the overall distrubution is smoother while preserving the bunching characteristics:" | |
| "# ParticleGroup has a `smear` option that shifts particles in each slice by a random integer multiple of the slice spacing, so that the overall distribution is smoother while preserving the bunching characteristics:" |
Copilot
AI
Mar 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in notebook text: "roughtly" → "roughly".
Suggested change
| "Normally Genesis4 populates the same number of particles in each slice, with each slice having its own weight (internally the `current`). In some cases it's simpler to have particles that have the same weight, so `ParticleGroup` further has an `equal_weights` option that samples particles from the slices according to the relative weights. Notice that there are fewer particles in this case, but that the projected densities are roughtly the same as above." | |
| "Normally Genesis4 populates the same number of particles in each slice, with each slice having its own weight (internally the `current`). In some cases it's simpler to have particles that have the same weight, so `ParticleGroup` further has an `equal_weights` option that samples particles from the slices according to the relative weights. Notice that there are fewer particles in this case, but that the projected densities are roughly the same as above." |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run.shis missing a shebang and will rely on the caller invoking it withbash. Add#!/usr/bin/env bash(and optionallyset -euo pipefail) to make it executable and less error-prone when used as a standalone script.