From 751394bf7f55a1850a6adb73f5ff3f5acb3d6e27 Mon Sep 17 00:00:00 2001 From: Christopher Mayes <31023527+ChristopherMayes@users.noreply.github.com> Date: Thu, 8 Sep 2022 18:58:45 -0700 Subject: [PATCH 1/4] Add basic particle tests and workflow --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++ pmd_beamphysics/units.py | 3 +- tests/test_particlegroup.py | 63 +++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100644 tests/test_particlegroup.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..551ee43 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: Tests + +on: [push, pull_request] + +jobs: + build: + runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash + strategy: + matrix: + os: [ubuntu-latest] + python-version: [3.9] + steps: + - uses: actions/checkout@v3 + - uses: conda-incubator/setup-miniconda@v2 + with: + python-version: ${{ matrix.python-version }} + mamba-version: "*" + channels: conda-forge + activate-environment: pmd_beamphysics-dev + environment-file: environment.yml + +# - name: flake8 +# shell: bash -l {0} +# run: | +# flake8 . + + - name: Install openPMD-beamphysics + shell: bash -l {0} + run: | + pip install --no-dependencies . + + - name: Run Tests + shell: bash -l {0} + run: | + pytest tests diff --git a/pmd_beamphysics/units.py b/pmd_beamphysics/units.py index 34b88de..3280c48 100644 --- a/pmd_beamphysics/units.py +++ b/pmd_beamphysics/units.py @@ -386,7 +386,7 @@ def nice_array(a): # Units for ParticleGroup PARTICLEGROUP_UNITS = {} -for k in ['n_particle', 'status']: +for k in ['n_particle', 'status', 'id', 'n_alive', 'n_dead']: PARTICLEGROUP_UNITS[k] = unit('1') for k in ['t']: PARTICLEGROUP_UNITS[k] = unit('s') @@ -417,6 +417,7 @@ def nice_array(a): for component in ['', 'x', 'y', 'z', 'theta', 'r']: PARTICLEGROUP_UNITS[f'E{component}'] = unit('V/m') PARTICLEGROUP_UNITS[f'B{component}'] = unit('T') + diff --git a/tests/test_particlegroup.py b/tests/test_particlegroup.py new file mode 100644 index 0000000..d759fbe --- /dev/null +++ b/tests/test_particlegroup.py @@ -0,0 +1,63 @@ +from pmd_beamphysics import ParticleGroup +import pytest +import numpy as np + + + +P = ParticleGroup('docs/examples/data/bmad_particles.h5') + + +ARRAY_KEYS = """ +x y z px py pz t status weight id +p energy kinetic_energy xp yp higher_order_energy +r theta pr ptheta +Lz +gamma beta beta_x beta_y beta_z +x_bar px_bar Jx Jy + +""".split() + + +SPECIAL_STATS = """ +norm_emit_x norm_emit_y norm_emit_4d higher_order_energy_spread +average_current +n_alive +n_dead +""".split() + + +@pytest.fixture(params=ARRAY_KEYS) +def array_key(request): + return request.param + +@pytest.fixture(params=('min_', 'max_', 'sigma_', 'delta_', 'ptp_', 'mean_')) +def operator(request): + return request.param + +def test_operator(operator, array_key): + key = f'{operator}{array_key}' + P[key] + +# This is probably uneccessary: +# @pytest.fixture(params=array_keys) +# def array_key2(request): +# return request.param +# +# def test_cov(array_key, array_key2): +# P[f'cov_{array_key}__{array_key}'] + + +@pytest.fixture(params=SPECIAL_STATS) +def special_stat(request): + return request.param + +def test_special_stat(special_stat): + x = P[special_stat] + assert np.isscalar(x) + + +def test_array_units_exist(array_key): + P.units(array_key) + +def test_special_units_exist(special_stat): + P.units(special_stat) \ No newline at end of file From c6c3d4f3bb706a5b19acdbaa375fd02723c87683 Mon Sep 17 00:00:00 2001 From: Christopher Mayes <31023527+ChristopherMayes@users.noreply.github.com> Date: Thu, 8 Sep 2022 19:19:41 -0700 Subject: [PATCH 2/4] equality and tests --- pmd_beamphysics/particles.py | 10 ++++++++++ tests/test_particlegroup.py | 26 ++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/pmd_beamphysics/particles.py b/pmd_beamphysics/particles.py index 75f5c32..7f84d80 100644 --- a/pmd_beamphysics/particles.py +++ b/pmd_beamphysics/particles.py @@ -890,6 +890,16 @@ def __contains__(self, item): """Checks internal data""" return True if item in self._data else False + def __eq__(self, other): + """Check equality of internal data""" + if isinstance(other, ParticleGroup): + for key in ['x', 'px', 'y', 'py', 'z', 'pz', 't', 'status', 'weight', 'id']: + if not np.all(self[key] == other[key]): + return False + return True + + return NotImplemented + def __len__(self): return len(self[self._settable_array_keys[0]]) diff --git a/tests/test_particlegroup.py b/tests/test_particlegroup.py index d759fbe..ed0a66b 100644 --- a/tests/test_particlegroup.py +++ b/tests/test_particlegroup.py @@ -1,9 +1,8 @@ from pmd_beamphysics import ParticleGroup import pytest import numpy as np +import os - - P = ParticleGroup('docs/examples/data/bmad_particles.h5') @@ -14,6 +13,7 @@ Lz gamma beta beta_x beta_y beta_z x_bar px_bar Jx Jy +charge """.split() @@ -26,11 +26,13 @@ """.split() +OPERATORS = ('min_', 'max_', 'sigma_', 'delta_', 'ptp_', 'mean_') + @pytest.fixture(params=ARRAY_KEYS) def array_key(request): return request.param -@pytest.fixture(params=('min_', 'max_', 'sigma_', 'delta_', 'ptp_', 'mean_')) +@pytest.fixture(params=OPERATORS) def operator(request): return request.param @@ -60,4 +62,20 @@ def test_array_units_exist(array_key): P.units(array_key) def test_special_units_exist(special_stat): - P.units(special_stat) \ No newline at end of file + P.units(special_stat) + + +def test_twiss(): + P.twiss('xy', fraction=0.95) + + +def test_write_reload(tmp_path): + h5file = os.path.join(tmp_path, 'test.h5') + P.write(h5file) + + # Equality and inequality + P2 = ParticleGroup(h5file) + assert P == P2 + + P2.x +=1 + assert P != P2 \ No newline at end of file From 7ca9662b1715aace9a5ec20f060bf9a48dbba02e Mon Sep 17 00:00:00 2001 From: Christopher Mayes <31023527+ChristopherMayes@users.noreply.github.com> Date: Thu, 8 Sep 2022 19:22:58 -0700 Subject: [PATCH 3/4] Equality example --- docs/examples/particle_examples.ipynb | 680 +++++++++----------------- 1 file changed, 242 insertions(+), 438 deletions(-) diff --git a/docs/examples/particle_examples.ipynb b/docs/examples/particle_examples.ipynb index 89f93a2..53ea862 100644 --- a/docs/examples/particle_examples.ipynb +++ b/docs/examples/particle_examples.ipynb @@ -10,14 +10,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:07.647703Z", - "iopub.status.busy": "2022-09-08T22:57:07.647139Z", - "iopub.status.idle": "2022-09-08T22:57:08.012745Z", - "shell.execute_reply": "2022-09-08T22:57:08.012480Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Useful for debugging\n", @@ -41,14 +34,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:08.014580Z", - "iopub.status.busy": "2022-09-08T22:57:08.014465Z", - "iopub.status.idle": "2022-09-08T22:57:08.116362Z", - "shell.execute_reply": "2022-09-08T22:57:08.116071Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "from pmd_beamphysics import ParticleGroup" @@ -57,19 +43,12 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:08.118044Z", - "iopub.status.busy": "2022-09-08T22:57:08.117952Z", - "iopub.status.idle": "2022-09-08T22:57:08.133517Z", - "shell.execute_reply": "2022-09-08T22:57:08.133263Z" - } - }, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 3, @@ -85,14 +64,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:08.152461Z", - "iopub.status.busy": "2022-09-08T22:57:08.152334Z", - "iopub.status.idle": "2022-09-08T22:57:08.163889Z", - "shell.execute_reply": "2022-09-08T22:57:08.163646Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -113,14 +85,7 @@ { "cell_type": "code", "execution_count": 5, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:08.165306Z", - "iopub.status.busy": "2022-09-08T22:57:08.165214Z", - "iopub.status.idle": "2022-09-08T22:57:08.176051Z", - "shell.execute_reply": "2022-09-08T22:57:08.175807Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -140,19 +105,12 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:08.177445Z", - "iopub.status.busy": "2022-09-08T22:57:08.177358Z", - "iopub.status.idle": "2022-09-08T22:57:08.197330Z", - "shell.execute_reply": "2022-09-08T22:57:08.197039Z" - } - }, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 6, @@ -167,14 +125,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:08.198814Z", - "iopub.status.busy": "2022-09-08T22:57:08.198706Z", - "iopub.status.idle": "2022-09-08T22:57:08.804946Z", - "shell.execute_reply": "2022-09-08T22:57:08.804695Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -199,14 +150,7 @@ { "cell_type": "code", "execution_count": 8, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:08.808198Z", - "iopub.status.busy": "2022-09-08T22:57:08.808085Z", - "iopub.status.idle": "2022-09-08T22:57:09.043792Z", - "shell.execute_reply": "2022-09-08T22:57:09.043534Z" - } - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -230,15 +174,147 @@ { "cell_type": "code", "execution_count": 9, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.046297Z", - "iopub.status.busy": "2022-09-08T22:57:09.046187Z", - "iopub.status.idle": "2022-09-08T22:57:09.057851Z", - "shell.execute_reply": "2022-09-08T22:57:09.057563Z" + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\u001b[0;31mType:\u001b[0m ParticleGroup\n", + "\u001b[0;31mString form:\u001b[0m ParticleGroup with 100000 particles with total charge 2.499999999999999e-10 C\n", + "\u001b[0;31mLength:\u001b[0m 100000\n", + "\u001b[0;31mFile:\u001b[0m ~/Code/GitHub/openPMD-beamphysics/pmd_beamphysics/particles.py\n", + "\u001b[0;31mDocstring:\u001b[0m \n", + "Particle Group class\n", + "\n", + "Initialized on on openPMD beamphysics particle group:\n", + "\n", + "- **h5**: open h5 handle, or `str` that is a file\n", + "- **data**: raw data\n", + "\n", + "The required bunch data is stored in `.data` with keys\n", + "\n", + "- `np.array`: `x`, `px`, `y`, `py`, `z`, `pz`, `t`, `status`, `weight`\n", + "- `str`: `species`\n", + "\n", + "where:\n", + "\n", + "- `x`, `y`, `z` are positions in units of [m]\n", + "- `px`, `py`, `pz` are momenta in units of [eV/c]\n", + "- `t` is time in [s]\n", + "- `weight` is the macro-charge weight in [C], used for all statistical calulations.\n", + "- `species` is a proper species name: `'electron'`, etc. \n", + " \n", + "Optional data:\n", + "\n", + "- `np.array`: `id`\n", + " \n", + "where `id` is a list of unique integers that identify the particles. \n", + "\n", + " \n", + "Derived data can be computed as attributes:\n", + "\n", + "- `.gamma`, `.beta`, `.beta_x`, `.beta_y`, `.beta_z`: relativistic factors [1].\n", + "- `.r`, `.theta`: cylidrical coordinates [m], [1]\n", + "- `.pr`, `.ptheta`: momenta in the radial and angular coordinate directions [eV/c]\n", + "- `.Lz`: angular momentum about the z axis [m*eV/c]\n", + "- `.energy` : total energy [eV]\n", + "- `.kinetic_energy`: total energy - mc^2 in [eV]. \n", + "- `.higher_order_energy`: total energy with quadratic fit in z or t subtracted [eV]\n", + "- `.p`: total momentum in [eV/c]\n", + "- `.mass`: rest mass in [eV]\n", + "- `.xp`, `.yp`: Slopes $x' = dx/dz = dp_x/dp_z$ and $y' = dy/dz = dp_y/dp_z$ [1].\n", + " \n", + "Normalized transvere coordinates can also be calculated as attributes:\n", + "\n", + "- `.x_bar`, `.px_bar`, `.y_bar`, `.py_bar` in [sqrt(m)]\n", + " \n", + "The normalization is automatically calculated from the covariance matrix. \n", + "See functions in `.statistics` for more advanced usage.\n", + " \n", + "Their cooresponding amplitudes are:\n", + "\n", + "`.Jx`, `.Jy` [m]\n", + "\n", + "where `Jx = (x_bar^2 + px_bar^2 )/2`.\n", + "\n", + "The momenta are normalized by the mass, so that\n", + "` = norm_emit_x`\n", + "and similar for `y`. \n", + " \n", + "Statistics of any of these are calculated with:\n", + "\n", + "- `.min(X)`\n", + "- `.max(X)`\n", + "- `.ptp(X)`\n", + "- `.avg(X)`\n", + "- `.std(X)`\n", + "- `.cov(X, Y, ...)`\n", + "- `.histogramdd(X, Y, ..., bins=10, range=None)`\n", + "\n", + "with a string `X` as the name any of the properties above.\n", + " \n", + "Useful beam physics quantities are given as attributes:\n", + "\n", + "- `.norm_emit_x`\n", + "- `.norm_emit_y`\n", + "- `.norm_emit_4d`\n", + "- `.higher_order_energy_spread`\n", + "- `.average_current`\n", + " \n", + "Twiss parameters, including dispersion, for the $x$ or $y$ plane:\n", + "\n", + "- `.twiss(plane='x', fraction=0.95, p0C=None)`\n", + "\n", + "For convenience, `plane='xy'` will calculate twiss for both planes.\n", + "\n", + "Twiss matched particles, using a simple linear transformation:\n", + "\n", + "- `.twiss_match(self, beta=None, alpha=None, plane='x', p0c=None, inplace=False)`\n", + " \n", + "The weight is required and must sum to > 0. The sum of the weights is in `.charge`.\n", + "This can also be set: `.charge = 1.234` # C, will rescale the .weight array\n", + " \n", + "All attributes can be accessed with brackets:\n", + " `[key]`\n", + "\n", + "Additional keys are allowed for convenience:\n", + " `['min_prop']` will return `.min('prop')`\n", + " `['max_prop']` will return `.max('prop')`\n", + " `['ptp_prop']` will return `.ptp('prop')`\n", + " `['mean_prop']` will return `.avg('prop')`\n", + " `['sigma_prop']` will return `.std('prop')`\n", + " `['cov_prop1__prop2']` will return `.cov('prop1', 'prop2')[0,1]`\n", + " \n", + "Units for all attributes can be accessed by:\n", + "\n", + "- `.units(key)`\n", + "\n", + "Particles are often stored at the same time (i.e. from a t-based code), \n", + "or with the same z position (i.e. from an s-based code.)\n", + "Routines: \n", + "\n", + "- `drift_to_z(z0)`\n", + "- `drift_to_t(t0)`\n", + "\n", + "help to convert these. If no argument is given, particles will be drifted to the mean.\n", + "Related properties are:\n", + "\n", + "- `.in_t_coordinates` returns `True` if all particles have the same $t$ corrdinate\n", + "- `.in_z_coordinates` returns `True` if all particles have the same $z$ corrdinate\n", + " \n", + "Convenient plotting is provided with: \n", + "\n", + "- `.plot(...)`\n", + "- `.slice_plot(...)`\n", + " \n", + "Use `help(ParticleGroup.plot)`, etc. for usage. \n", + " \n" + ] + }, + "metadata": {}, + "output_type": "display_data" } - }, - "outputs": [], + ], "source": [ "?P" ] @@ -246,14 +322,7 @@ { "cell_type": "code", "execution_count": 10, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.059431Z", - "iopub.status.busy": "2022-09-08T22:57:09.059348Z", - "iopub.status.idle": "2022-09-08T22:57:09.069868Z", - "shell.execute_reply": "2022-09-08T22:57:09.069637Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -275,14 +344,7 @@ { "cell_type": "code", "execution_count": 11, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.071288Z", - "iopub.status.busy": "2022-09-08T22:57:09.071207Z", - "iopub.status.idle": "2022-09-08T22:57:09.081676Z", - "shell.execute_reply": "2022-09-08T22:57:09.081417Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -304,14 +366,7 @@ { "cell_type": "code", "execution_count": 12, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.083075Z", - "iopub.status.busy": "2022-09-08T22:57:09.082989Z", - "iopub.status.idle": "2022-09-08T22:57:09.093438Z", - "shell.execute_reply": "2022-09-08T22:57:09.093183Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -339,14 +394,7 @@ { "cell_type": "code", "execution_count": 13, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.094965Z", - "iopub.status.busy": "2022-09-08T22:57:09.094887Z", - "iopub.status.idle": "2022-09-08T22:57:09.106140Z", - "shell.execute_reply": "2022-09-08T22:57:09.105915Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -367,14 +415,7 @@ { "cell_type": "code", "execution_count": 14, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.107522Z", - "iopub.status.busy": "2022-09-08T22:57:09.107444Z", - "iopub.status.idle": "2022-09-08T22:57:09.121436Z", - "shell.execute_reply": "2022-09-08T22:57:09.121178Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -402,14 +443,7 @@ { "cell_type": "code", "execution_count": 15, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.123073Z", - "iopub.status.busy": "2022-09-08T22:57:09.122959Z", - "iopub.status.idle": "2022-09-08T22:57:09.138766Z", - "shell.execute_reply": "2022-09-08T22:57:09.138479Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -434,14 +468,7 @@ { "cell_type": "code", "execution_count": 16, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.140478Z", - "iopub.status.busy": "2022-09-08T22:57:09.140347Z", - "iopub.status.idle": "2022-09-08T22:57:09.152807Z", - "shell.execute_reply": "2022-09-08T22:57:09.152529Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -462,14 +489,7 @@ { "cell_type": "code", "execution_count": 17, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.154440Z", - "iopub.status.busy": "2022-09-08T22:57:09.154334Z", - "iopub.status.idle": "2022-09-08T22:57:09.171840Z", - "shell.execute_reply": "2022-09-08T22:57:09.171570Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -510,14 +530,7 @@ { "cell_type": "code", "execution_count": 18, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.173536Z", - "iopub.status.busy": "2022-09-08T22:57:09.173421Z", - "iopub.status.idle": "2022-09-08T22:57:09.188607Z", - "shell.execute_reply": "2022-09-08T22:57:09.188335Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -543,14 +556,7 @@ { "cell_type": "code", "execution_count": 19, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.190252Z", - "iopub.status.busy": "2022-09-08T22:57:09.190046Z", - "iopub.status.idle": "2022-09-08T22:57:09.297371Z", - "shell.execute_reply": "2022-09-08T22:57:09.297047Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -584,14 +590,7 @@ { "cell_type": "code", "execution_count": 20, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.299233Z", - "iopub.status.busy": "2022-09-08T22:57:09.299047Z", - "iopub.status.idle": "2022-09-08T22:57:09.317586Z", - "shell.execute_reply": "2022-09-08T22:57:09.317278Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -626,14 +625,7 @@ { "cell_type": "code", "execution_count": 21, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.319393Z", - "iopub.status.busy": "2022-09-08T22:57:09.319244Z", - "iopub.status.idle": "2022-09-08T22:57:09.330785Z", - "shell.execute_reply": "2022-09-08T22:57:09.330464Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -659,14 +651,7 @@ { "cell_type": "code", "execution_count": 22, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.332389Z", - "iopub.status.busy": "2022-09-08T22:57:09.332288Z", - "iopub.status.idle": "2022-09-08T22:57:09.343047Z", - "shell.execute_reply": "2022-09-08T22:57:09.342790Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -686,14 +671,7 @@ { "cell_type": "code", "execution_count": 23, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.344660Z", - "iopub.status.busy": "2022-09-08T22:57:09.344564Z", - "iopub.status.idle": "2022-09-08T22:57:09.354973Z", - "shell.execute_reply": "2022-09-08T22:57:09.354741Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -721,14 +699,7 @@ { "cell_type": "code", "execution_count": 24, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.357388Z", - "iopub.status.busy": "2022-09-08T22:57:09.357289Z", - "iopub.status.idle": "2022-09-08T22:57:09.368163Z", - "shell.execute_reply": "2022-09-08T22:57:09.367872Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -749,14 +720,7 @@ { "cell_type": "code", "execution_count": 25, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.369736Z", - "iopub.status.busy": "2022-09-08T22:57:09.369645Z", - "iopub.status.idle": "2022-09-08T22:57:09.383638Z", - "shell.execute_reply": "2022-09-08T22:57:09.383335Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -778,14 +742,7 @@ { "cell_type": "code", "execution_count": 26, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.385219Z", - "iopub.status.busy": "2022-09-08T22:57:09.385135Z", - "iopub.status.idle": "2022-09-08T22:57:09.396602Z", - "shell.execute_reply": "2022-09-08T22:57:09.396278Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Drift all particles to this time\n", @@ -795,14 +752,7 @@ { "cell_type": "code", "execution_count": 27, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.398361Z", - "iopub.status.busy": "2022-09-08T22:57:09.398277Z", - "iopub.status.idle": "2022-09-08T22:57:09.413552Z", - "shell.execute_reply": "2022-09-08T22:57:09.413194Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -830,14 +780,7 @@ { "cell_type": "code", "execution_count": 28, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.415212Z", - "iopub.status.busy": "2022-09-08T22:57:09.415114Z", - "iopub.status.idle": "2022-09-08T22:57:09.426232Z", - "shell.execute_reply": "2022-09-08T22:57:09.425941Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -860,14 +803,7 @@ { "cell_type": "code", "execution_count": 29, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.427721Z", - "iopub.status.busy": "2022-09-08T22:57:09.427609Z", - "iopub.status.idle": "2022-09-08T22:57:09.456655Z", - "shell.execute_reply": "2022-09-08T22:57:09.456339Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -890,14 +826,7 @@ { "cell_type": "code", "execution_count": 30, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.458378Z", - "iopub.status.busy": "2022-09-08T22:57:09.458267Z", - "iopub.status.idle": "2022-09-08T22:57:09.470218Z", - "shell.execute_reply": "2022-09-08T22:57:09.469909Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Copy is a deep copy\n", @@ -907,14 +836,7 @@ { "cell_type": "code", "execution_count": 31, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.471850Z", - "iopub.status.busy": "2022-09-08T22:57:09.471742Z", - "iopub.status.idle": "2022-09-08T22:57:09.482562Z", - "shell.execute_reply": "2022-09-08T22:57:09.482259Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -939,14 +861,7 @@ { "cell_type": "code", "execution_count": 32, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.484060Z", - "iopub.status.busy": "2022-09-08T22:57:09.483955Z", - "iopub.status.idle": "2022-09-08T22:57:09.494395Z", - "shell.execute_reply": "2022-09-08T22:57:09.494161Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -967,14 +882,7 @@ { "cell_type": "code", "execution_count": 33, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.495871Z", - "iopub.status.busy": "2022-09-08T22:57:09.495788Z", - "iopub.status.idle": "2022-09-08T22:57:09.506406Z", - "shell.execute_reply": "2022-09-08T22:57:09.506111Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -1002,14 +910,7 @@ { "cell_type": "code", "execution_count": 34, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.508053Z", - "iopub.status.busy": "2022-09-08T22:57:09.507943Z", - "iopub.status.idle": "2022-09-08T22:57:09.517910Z", - "shell.execute_reply": "2022-09-08T22:57:09.517673Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "import h5py\n", @@ -1019,14 +920,7 @@ { "cell_type": "code", "execution_count": 35, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.519344Z", - "iopub.status.busy": "2022-09-08T22:57:09.519268Z", - "iopub.status.idle": "2022-09-08T22:57:09.536816Z", - "shell.execute_reply": "2022-09-08T22:57:09.536554Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "\n", @@ -1042,14 +936,7 @@ { "cell_type": "code", "execution_count": 36, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.538481Z", - "iopub.status.busy": "2022-09-08T22:57:09.538400Z", - "iopub.status.idle": "2022-09-08T22:57:09.549870Z", - "shell.execute_reply": "2022-09-08T22:57:09.549629Z" - } - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -1078,14 +965,28 @@ { "cell_type": "code", "execution_count": 37, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:09.551373Z", - "iopub.status.busy": "2022-09-08T22:57:09.551227Z", - "iopub.status.idle": "2022-09-08T22:57:10.035787Z", - "shell.execute_reply": "2022-09-08T22:57:10.035462Z" + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" } - }, + ], + "source": [ + "# This does the same check\n", + "P2 == P" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, "outputs": [], "source": [ "# Write Astra-style particles\n", @@ -1094,30 +995,23 @@ }, { "cell_type": "code", - "execution_count": 38, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:10.037561Z", - "iopub.status.busy": "2022-09-08T22:57:10.037474Z", - "iopub.status.idle": "2022-09-08T22:57:10.165302Z", - "shell.execute_reply": "2022-09-08T22:57:10.164728Z" - } - }, + "execution_count": 39, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - " 5.358867254236e-07 -2.266596025469e-08 2.743173452837e-13 5.432293116193e+02 1.634894200076e+01 7.974939693676e+09 5.163879459127e+03 0.000000000000e+00 1 -1\r\n", - " -1.208904511904e-05 2.743402818288e-05 -5.473095269153e-06 -7.699432808273e+03 1.073320266862e+04 2.538945179648e+07 -1.818989403546e-12 2.500000000000e-06 1 -1\r\n", - " 2.500557812617e-05 1.840484451196e-06 -6.071970122807e-06 2.432464253407e+04 -2.207080331882e+03 -8.584659148073e+05 -1.818989403546e-12 2.500000000000e-06 1 -1\r\n", - " 1.840224855502e-06 2.319774542484e-05 -1.983837488548e-06 1.761897150333e+04 -4.269379756219e+03 -1.555244938371e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\r\n", - " 1.282953228685e-05 2.807375273984e-06 7.759268653990e-06 1.898440718152e+04 -5.303751910566e+03 -2.614389107333e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\r\n", - " 3.362374691900e-06 4.796982704111e-06 -1.006752695161e-06 1.012222041635e+04 1.266876546973e+04 -1.818436067077e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\r\n", - " -1.441736363766e-05 7.420644576948e-06 1.697647381418e-06 -8.598453241915e+03 -9.693787540264e+02 -4.437182519667e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\r\n", - " -1.715615894267e-05 -2.489925517264e-05 8.689767207313e-06 -1.817734573652e+04 1.917720905016e+04 -4.674564930124e+05 -1.818989403546e-12 2.500000000000e-06 1 -1\r\n", - " 5.700269218746e-06 4.764024833770e-05 2.167342605243e-05 8.662840216364e+03 -7.175141639811e+03 -3.156898311773e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\r\n", - " 9.426699454873e-07 -5.785285707147e-06 6.353982932653e-06 -1.498628620111e+04 -1.222058411806e+03 -3.802046580825e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\r\n" + " 5.358867254236e-07 -2.266596025469e-08 2.743173452837e-13 5.432293116193e+02 1.634894200076e+01 7.974939693676e+09 5.163879459127e+03 0.000000000000e+00 1 -1\n", + " -1.208904511904e-05 2.743402818288e-05 -5.473095269153e-06 -7.699432808273e+03 1.073320266862e+04 2.538945179648e+07 -1.818989403546e-12 2.500000000000e-06 1 -1\n", + " 2.500557812617e-05 1.840484451196e-06 -6.071970122807e-06 2.432464253407e+04 -2.207080331882e+03 -8.584659148073e+05 -1.818989403546e-12 2.500000000000e-06 1 -1\n", + " 1.840224855502e-06 2.319774542484e-05 -1.983837488548e-06 1.761897150333e+04 -4.269379756219e+03 -1.555244938371e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\n", + " 1.282953228685e-05 2.807375273984e-06 7.759268653990e-06 1.898440718152e+04 -5.303751910566e+03 -2.614389107333e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\n", + " 3.362374691900e-06 4.796982704111e-06 -1.006752695161e-06 1.012222041635e+04 1.266876546973e+04 -1.818436067077e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\n", + " -1.441736363766e-05 7.420644576948e-06 1.697647381418e-06 -8.598453241915e+03 -9.693787540264e+02 -4.437182519667e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\n", + " -1.715615894267e-05 -2.489925517264e-05 8.689767207313e-06 -1.817734573652e+04 1.917720905016e+04 -4.674564930124e+05 -1.818989403546e-12 2.500000000000e-06 1 -1\n", + " 5.700269218746e-06 4.764024833770e-05 2.167342605243e-05 8.662840216364e+03 -7.175141639811e+03 -3.156898311773e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\n", + " 9.426699454873e-07 -5.785285707147e-06 6.353982932653e-06 -1.498628620111e+04 -1.222058411806e+03 -3.802046580825e+06 -1.818989403546e-12 2.500000000000e-06 1 -1\n" ] } ], @@ -1127,15 +1021,8 @@ }, { "cell_type": "code", - "execution_count": 39, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:10.168584Z", - "iopub.status.busy": "2022-09-08T22:57:10.168144Z", - "iopub.status.idle": "2022-09-08T22:57:10.193449Z", - "shell.execute_reply": "2022-09-08T22:57:10.193094Z" - } - }, + "execution_count": 40, + "metadata": {}, "outputs": [], "source": [ "# Optionally, a string can be given\n", @@ -1153,15 +1040,8 @@ }, { "cell_type": "code", - "execution_count": 40, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:10.195428Z", - "iopub.status.busy": "2022-09-08T22:57:10.195289Z", - "iopub.status.idle": "2022-09-08T22:57:10.212429Z", - "shell.execute_reply": "2022-09-08T22:57:10.212128Z" - } - }, + "execution_count": 41, + "metadata": {}, "outputs": [], "source": [ "import matplotlib\n", @@ -1173,15 +1053,8 @@ }, { "cell_type": "code", - "execution_count": 41, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:10.214079Z", - "iopub.status.busy": "2022-09-08T22:57:10.213992Z", - "iopub.status.idle": "2022-09-08T22:57:10.890702Z", - "shell.execute_reply": "2022-09-08T22:57:10.890422Z" - } - }, + "execution_count": 42, + "metadata": {}, "outputs": [ { "data": { @@ -1206,15 +1079,8 @@ }, { "cell_type": "code", - "execution_count": 42, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:10.892371Z", - "iopub.status.busy": "2022-09-08T22:57:10.892242Z", - "iopub.status.idle": "2022-09-08T22:57:11.171211Z", - "shell.execute_reply": "2022-09-08T22:57:11.170882Z" - } - }, + "execution_count": 43, + "metadata": {}, "outputs": [ { "data": { @@ -1239,15 +1105,8 @@ }, { "cell_type": "code", - "execution_count": 43, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:11.173679Z", - "iopub.status.busy": "2022-09-08T22:57:11.173559Z", - "iopub.status.idle": "2022-09-08T22:57:11.744150Z", - "shell.execute_reply": "2022-09-08T22:57:11.743868Z" - } - }, + "execution_count": 44, + "metadata": {}, "outputs": [ { "data": { @@ -1272,15 +1131,8 @@ }, { "cell_type": "code", - "execution_count": 44, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:11.747897Z", - "iopub.status.busy": "2022-09-08T22:57:11.747787Z", - "iopub.status.idle": "2022-09-08T22:57:12.400545Z", - "shell.execute_reply": "2022-09-08T22:57:12.400252Z" - } - }, + "execution_count": 45, + "metadata": {}, "outputs": [ { "data": { @@ -1288,7 +1140,7 @@ "(-50.0, 50.0)" ] }, - "execution_count": 44, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" }, @@ -1318,23 +1170,16 @@ }, { "cell_type": "code", - "execution_count": 45, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:12.402145Z", - "iopub.status.busy": "2022-09-08T22:57:12.402039Z", - "iopub.status.idle": "2022-09-08T22:57:12.572816Z", - "shell.execute_reply": "2022-09-08T22:57:12.572511Z" - } - }, + "execution_count": 46, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 45, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" }, @@ -1376,15 +1221,8 @@ }, { "cell_type": "code", - "execution_count": 46, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:12.575171Z", - "iopub.status.busy": "2022-09-08T22:57:12.575064Z", - "iopub.status.idle": "2022-09-08T22:57:13.064841Z", - "shell.execute_reply": "2022-09-08T22:57:13.064533Z" - } - }, + "execution_count": 47, + "metadata": {}, "outputs": [ { "data": { @@ -1408,23 +1246,16 @@ }, { "cell_type": "code", - "execution_count": 47, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:13.067258Z", - "iopub.status.busy": "2022-09-08T22:57:13.067176Z", - "iopub.status.idle": "2022-09-08T22:57:13.361806Z", - "shell.execute_reply": "2022-09-08T22:57:13.361487Z" - } - }, + "execution_count": 48, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 47, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" }, @@ -1464,15 +1295,8 @@ }, { "cell_type": "code", - "execution_count": 48, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:13.363631Z", - "iopub.status.busy": "2022-09-08T22:57:13.363507Z", - "iopub.status.idle": "2022-09-08T22:57:13.376541Z", - "shell.execute_reply": "2022-09-08T22:57:13.376241Z" - } - }, + "execution_count": 49, + "metadata": {}, "outputs": [ { "data": { @@ -1480,7 +1304,7 @@ "['/screen/0/./', '/screen/1/./']" ] }, - "execution_count": 48, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -1499,15 +1323,8 @@ }, { "cell_type": "code", - "execution_count": 49, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:13.378141Z", - "iopub.status.busy": "2022-09-08T22:57:13.378033Z", - "iopub.status.idle": "2022-09-08T22:57:13.388958Z", - "shell.execute_reply": "2022-09-08T22:57:13.388717Z" - } - }, + "execution_count": 50, + "metadata": {}, "outputs": [ { "data": { @@ -1526,7 +1343,7 @@ " 'weight']" ] }, - "execution_count": 49, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -1539,15 +1356,8 @@ }, { "cell_type": "code", - "execution_count": 50, - "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:13.390382Z", - "iopub.status.busy": "2022-09-08T22:57:13.390294Z", - "iopub.status.idle": "2022-09-08T22:57:13.402300Z", - "shell.execute_reply": "2022-09-08T22:57:13.402047Z" - } - }, + "execution_count": 51, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -1577,14 +1387,8 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 52, "metadata": { - "execution": { - "iopub.execute_input": "2022-09-08T22:57:13.403787Z", - "iopub.status.busy": "2022-09-08T22:57:13.403707Z", - "iopub.status.idle": "2022-09-08T22:57:13.414639Z", - "shell.execute_reply": "2022-09-08T22:57:13.414371Z" - }, "tags": [] }, "outputs": [], From eb61d182ec7ad142edd9a9bf4871316ad1de3665 Mon Sep 17 00:00:00 2001 From: Christopher Mayes <31023527+ChristopherMayes@users.noreply.github.com> Date: Thu, 8 Sep 2022 19:28:20 -0700 Subject: [PATCH 4/4] remove docstring printout in notebook --- docs/examples/particle_examples.ipynb | 296 +++++++------------------- 1 file changed, 74 insertions(+), 222 deletions(-) diff --git a/docs/examples/particle_examples.ipynb b/docs/examples/particle_examples.ipynb index 53ea862..1fe9e0b 100644 --- a/docs/examples/particle_examples.ipynb +++ b/docs/examples/particle_examples.ipynb @@ -48,7 +48,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 3, @@ -110,7 +110,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 6, @@ -175,154 +175,6 @@ "cell_type": "code", "execution_count": 9, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "\u001b[0;31mType:\u001b[0m ParticleGroup\n", - "\u001b[0;31mString form:\u001b[0m ParticleGroup with 100000 particles with total charge 2.499999999999999e-10 C\n", - "\u001b[0;31mLength:\u001b[0m 100000\n", - "\u001b[0;31mFile:\u001b[0m ~/Code/GitHub/openPMD-beamphysics/pmd_beamphysics/particles.py\n", - "\u001b[0;31mDocstring:\u001b[0m \n", - "Particle Group class\n", - "\n", - "Initialized on on openPMD beamphysics particle group:\n", - "\n", - "- **h5**: open h5 handle, or `str` that is a file\n", - "- **data**: raw data\n", - "\n", - "The required bunch data is stored in `.data` with keys\n", - "\n", - "- `np.array`: `x`, `px`, `y`, `py`, `z`, `pz`, `t`, `status`, `weight`\n", - "- `str`: `species`\n", - "\n", - "where:\n", - "\n", - "- `x`, `y`, `z` are positions in units of [m]\n", - "- `px`, `py`, `pz` are momenta in units of [eV/c]\n", - "- `t` is time in [s]\n", - "- `weight` is the macro-charge weight in [C], used for all statistical calulations.\n", - "- `species` is a proper species name: `'electron'`, etc. \n", - " \n", - "Optional data:\n", - "\n", - "- `np.array`: `id`\n", - " \n", - "where `id` is a list of unique integers that identify the particles. \n", - "\n", - " \n", - "Derived data can be computed as attributes:\n", - "\n", - "- `.gamma`, `.beta`, `.beta_x`, `.beta_y`, `.beta_z`: relativistic factors [1].\n", - "- `.r`, `.theta`: cylidrical coordinates [m], [1]\n", - "- `.pr`, `.ptheta`: momenta in the radial and angular coordinate directions [eV/c]\n", - "- `.Lz`: angular momentum about the z axis [m*eV/c]\n", - "- `.energy` : total energy [eV]\n", - "- `.kinetic_energy`: total energy - mc^2 in [eV]. \n", - "- `.higher_order_energy`: total energy with quadratic fit in z or t subtracted [eV]\n", - "- `.p`: total momentum in [eV/c]\n", - "- `.mass`: rest mass in [eV]\n", - "- `.xp`, `.yp`: Slopes $x' = dx/dz = dp_x/dp_z$ and $y' = dy/dz = dp_y/dp_z$ [1].\n", - " \n", - "Normalized transvere coordinates can also be calculated as attributes:\n", - "\n", - "- `.x_bar`, `.px_bar`, `.y_bar`, `.py_bar` in [sqrt(m)]\n", - " \n", - "The normalization is automatically calculated from the covariance matrix. \n", - "See functions in `.statistics` for more advanced usage.\n", - " \n", - "Their cooresponding amplitudes are:\n", - "\n", - "`.Jx`, `.Jy` [m]\n", - "\n", - "where `Jx = (x_bar^2 + px_bar^2 )/2`.\n", - "\n", - "The momenta are normalized by the mass, so that\n", - "` = norm_emit_x`\n", - "and similar for `y`. \n", - " \n", - "Statistics of any of these are calculated with:\n", - "\n", - "- `.min(X)`\n", - "- `.max(X)`\n", - "- `.ptp(X)`\n", - "- `.avg(X)`\n", - "- `.std(X)`\n", - "- `.cov(X, Y, ...)`\n", - "- `.histogramdd(X, Y, ..., bins=10, range=None)`\n", - "\n", - "with a string `X` as the name any of the properties above.\n", - " \n", - "Useful beam physics quantities are given as attributes:\n", - "\n", - "- `.norm_emit_x`\n", - "- `.norm_emit_y`\n", - "- `.norm_emit_4d`\n", - "- `.higher_order_energy_spread`\n", - "- `.average_current`\n", - " \n", - "Twiss parameters, including dispersion, for the $x$ or $y$ plane:\n", - "\n", - "- `.twiss(plane='x', fraction=0.95, p0C=None)`\n", - "\n", - "For convenience, `plane='xy'` will calculate twiss for both planes.\n", - "\n", - "Twiss matched particles, using a simple linear transformation:\n", - "\n", - "- `.twiss_match(self, beta=None, alpha=None, plane='x', p0c=None, inplace=False)`\n", - " \n", - "The weight is required and must sum to > 0. The sum of the weights is in `.charge`.\n", - "This can also be set: `.charge = 1.234` # C, will rescale the .weight array\n", - " \n", - "All attributes can be accessed with brackets:\n", - " `[key]`\n", - "\n", - "Additional keys are allowed for convenience:\n", - " `['min_prop']` will return `.min('prop')`\n", - " `['max_prop']` will return `.max('prop')`\n", - " `['ptp_prop']` will return `.ptp('prop')`\n", - " `['mean_prop']` will return `.avg('prop')`\n", - " `['sigma_prop']` will return `.std('prop')`\n", - " `['cov_prop1__prop2']` will return `.cov('prop1', 'prop2')[0,1]`\n", - " \n", - "Units for all attributes can be accessed by:\n", - "\n", - "- `.units(key)`\n", - "\n", - "Particles are often stored at the same time (i.e. from a t-based code), \n", - "or with the same z position (i.e. from an s-based code.)\n", - "Routines: \n", - "\n", - "- `drift_to_z(z0)`\n", - "- `drift_to_t(t0)`\n", - "\n", - "help to convert these. If no argument is given, particles will be drifted to the mean.\n", - "Related properties are:\n", - "\n", - "- `.in_t_coordinates` returns `True` if all particles have the same $t$ corrdinate\n", - "- `.in_z_coordinates` returns `True` if all particles have the same $z$ corrdinate\n", - " \n", - "Convenient plotting is provided with: \n", - "\n", - "- `.plot(...)`\n", - "- `.slice_plot(...)`\n", - " \n", - "Use `help(ParticleGroup.plot)`, etc. for usage. \n", - " \n" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "?P" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, "outputs": [ { "data": { @@ -331,7 +183,7 @@ " -1.87135206e-06, 1.19494768e-06, -1.04551798e-05])" ] }, - "execution_count": 10, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -343,7 +195,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -353,7 +205,7 @@ " 15607.30607107, 15600.10233296, 15600.23563914])" ] }, - "execution_count": 11, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -365,7 +217,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -374,7 +226,7 @@ "(100000, 100000)" ] }, - "execution_count": 12, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -393,7 +245,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -402,7 +254,7 @@ "(15606.56770446094, 7440511.955100455)" ] }, - "execution_count": 13, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -414,7 +266,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -430,7 +282,7 @@ " 5.53617715e+13]])" ] }, - "execution_count": 14, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -442,7 +294,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -455,7 +307,7 @@ " 2.448488847479861e-13)" ] }, - "execution_count": 15, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -467,7 +319,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -476,7 +328,7 @@ "-3.9484106461190653" ] }, - "execution_count": 16, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -488,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -503,7 +355,7 @@ " 36247954.62263375, 42995111.31607628])])" ] }, - "execution_count": 17, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -529,7 +381,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -544,7 +396,7 @@ " 'norm_emit_x': 4.877958608683611e-07}" ] }, - "execution_count": 18, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -555,7 +407,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -577,7 +429,7 @@ " 'norm_emit_y': 3.656364435837357e-07}" ] }, - "execution_count": 19, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -589,7 +441,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -604,7 +456,7 @@ " 'norm_emit_x': 4.877958608785177e-07}" ] }, - "execution_count": 20, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -624,7 +476,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -637,7 +489,7 @@ " pmd_unit('(m)^2', 1, (2, 0, 0, 0, 0, 0, 0)))" ] }, - "execution_count": 21, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -650,7 +502,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -659,7 +511,7 @@ "pmd_unit('eV', 1.602176634e-19, (2, 1, -2, 0, 0, 0, 0))" ] }, - "execution_count": 22, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -670,7 +522,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -679,7 +531,7 @@ "'m*eV'" ] }, - "execution_count": 23, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -698,7 +550,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -707,7 +559,7 @@ "(0.0, 2.4466662184814374e-14)" ] }, - "execution_count": 24, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -719,7 +571,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -728,7 +580,7 @@ "5.163879459127423e-06" ] }, - "execution_count": 25, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -741,7 +593,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -751,7 +603,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -760,7 +612,7 @@ "(7.334920780350132e-06, 5.163879459127425e-06, {5.163879459127423e-06})" ] }, - "execution_count": 27, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -779,7 +631,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -788,7 +640,7 @@ "(array([0, 0, 0, ..., 1, 1, 1], dtype=int32), 99990, 10)" ] }, - "execution_count": 28, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -802,7 +654,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -811,7 +663,7 @@ "(10, 2.4999999999999994e-14, 2.4997499999999996e-10)" ] }, - "execution_count": 29, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -825,7 +677,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -835,7 +687,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -846,7 +698,7 @@ " 9.876499999999997e-12)" ] }, - "execution_count": 31, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -860,7 +712,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -869,7 +721,7 @@ "False" ] }, - "execution_count": 32, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -881,7 +733,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -890,7 +742,7 @@ "(array([ 1, 2, 3, ..., 99988, 99989, 99990]), True)" ] }, - "execution_count": 33, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -909,7 +761,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -919,7 +771,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -935,7 +787,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -964,7 +816,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -973,7 +825,7 @@ "True" ] }, - "execution_count": 37, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -985,7 +837,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ @@ -995,7 +847,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 38, "metadata": {}, "outputs": [ { @@ -1021,7 +873,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ @@ -1040,7 +892,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ @@ -1053,7 +905,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -1079,7 +931,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 42, "metadata": {}, "outputs": [ { @@ -1105,7 +957,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 43, "metadata": {}, "outputs": [ { @@ -1131,7 +983,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 44, "metadata": {}, "outputs": [ { @@ -1140,7 +992,7 @@ "(-50.0, 50.0)" ] }, - "execution_count": 45, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" }, @@ -1170,16 +1022,16 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 46, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" }, @@ -1221,7 +1073,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 46, "metadata": {}, "outputs": [ { @@ -1246,16 +1098,16 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 48, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" }, @@ -1295,7 +1147,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 48, "metadata": {}, "outputs": [ { @@ -1304,7 +1156,7 @@ "['/screen/0/./', '/screen/1/./']" ] }, - "execution_count": 49, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } @@ -1323,7 +1175,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 49, "metadata": {}, "outputs": [ { @@ -1343,7 +1195,7 @@ " 'weight']" ] }, - "execution_count": 50, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -1356,7 +1208,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 50, "metadata": {}, "outputs": [ { @@ -1387,7 +1239,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 51, "metadata": { "tags": [] },