Coder Social home page Coder Social logo

christophermayes / openpmd-beamphysics Goto Github PK

View Code? Open in Web Editor NEW
16.0 5.0 15.0 263.03 MB

Tools for analyzing and viewing particle data in the openPMD standard, extension beamphysics.

Home Page: https://christophermayes.github.io/openPMD-beamphysics/

License: Apache License 2.0

Python 99.82% HTML 0.09% Shell 0.09%
fields particles openpmd phase-space twiss

openpmd-beamphysics's Introduction

openPMD-beamphysics

Documentation
Documentation

Tools for analyzing and viewing particle data in the openPMD standard, extension beamphysics.

https://github.com/openPMD/openPMD-standard/blob/upcoming-2.0.0/EXT_BeamPhysics.md

Installing openpmd-beamphysics

Installing openpmd-beamphysics from the conda-forge channel can be achieved by adding conda-forge to your channels with:

conda config --add channels conda-forge

Once the conda-forge channel has been enabled, openpmd-beamphysics can be installed with:

conda install openpmd-beamphysics

It is possible to list all of the versions of openpmd-beamphysics available on your platform with:

conda search openpmd-beamphysics --channel conda-forge

openpmd-beamphysics's People

Contributors

christophermayes avatar colwyngulliford avatar fuhaoji avatar joeduris avatar weiyuanlou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

openpmd-beamphysics's Issues

Openpmd format for Ocelot tracking code

Dear Developers,

I recent came to know that the particle tracking code OCELOT can read openpmd data format (ocelot-collab/ocelot@55d485d).

This is a nice combination of PIC and then tracking of particles in beam line.

I am wonder if you have ever tried to use FBPIC or WarpX output data file to read in Ocelot ?

This may be interesting for many users.

Thanks.

Upload to PyPI

Hello,

This is a nice package. It would be great if this package was also on PyPI so one could include it in a setup.py easily. I understand that there are alternative methods like linking directly within the setup.py to some asset associated with this github repository, but it would nevertheless be easier to just have it on PyPI like the main openPMD repository and its friends.

matplotlib cmap warning/ depreciation

I'm getting a matplotlib/colarmap warning when loading openPMD-beamphysics in plot.py file. Looks like this behavior may not be allowed in the future.

/Users/nneveu/Code/anaconda3/envs/lume/lib/python3.7/site-packages/pmd_beamphysics/plot.py:13: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("viridis"))
cmap.set_under('white')

Add topics

Hi,
this is a nice looking package :-)

To make it easier to find, could I suggest adding some topics as well, .e.g.:

particles fields openpmd phase-space twiss` etc.?

Add a helper utility for generating gaussian data for `ParticleGroup`s

Initial attempt here:

from typing import Optional
import numpy as np


def gaussian_data(
    n_particle: int = 100,
    charge: float = 1e-9,
    p0: float = 1e9,
    mean: Optional[np.ndarray] = None,
    sigma_mat: Optional[np.ndarray] = None,
):
    """
    Makes Gaussian particle data from a Bmad-style sigma matrix.

    Parameters
    ----------
    n_particle: int, default=100
        Number of particles.
    charge : float, default=1e-9
        Charge in C.
    p0 : float
        Reference momentum in eV/c
    mean : np.ndarray of shape (6,), optional
        Mean positions. Default = None gives zeros
    sigma_mat : np.ndarray of shape (6,6), optional
        Sigma matrix in Bmad units. If default, this is the identity * 1e-3

    Returns
    -------
    dict
        ParticleGroup-compatible data dictionary:
        >>> ParticleGroup(data=gaussian_data())
    """
    if mean is None:
        mean = np.zeros(6)

    if sigma_mat is None:
        cov = np.eye(6) * 1e-3
    else:
        cov = sigma_mat

    dat = np.random.multivariate_normal(mean, cov, size=n_particle)
    x = dat[:, 0]
    px = dat[:, 1]
    y = dat[:, 2]
    py = dat[:, 3]
    z = dat[:, 4]
    pz = dat[:, 5]

    data = {
        "x": x,
        "px": px * p0,
        "y": y,
        "py": py,
        "z": z,
        "pz": (1 + pz) * p0,
        "t": np.zeros(n_particle),
        "weight": charge / n_particle,
        "status": np.ones(n_particle),
        "species": "electron",
    }

    return data

from pmd_beamphysics import ParticleGroup
P = ParticleGroup(data=gaussian_data(100_000))
P.plot('x', 'px')

Missing: GDF to openPMD format

Add Functionality for .GDF to .h5 openPMD Format Conversion

Description

The current codebase lacks functionality to convert .GDF files to a .h5 openPMD format.

Example Script for Conversion

An existing script that performs this conversion is available in this repository:
openPMD-converter-GDF

Suggested Environment for Running the Example Script

To run this script, it is recommended to set up a conda environment with Python 3.6.5. The requirements.txt file should be modified as follows to ensure compatibility:

# openPMD_to_gdf.py, gdf_to_openPMD.py
openpmd-api>=0.13.0,<0.15.0
# gdf_to_openPMD.py
matplotlib>=3.0.0
# OpenPMD_add_patches.py
h5py>=2.8.0
numpy>=1.16.0```

add example data

Could I also suggest for the docs, pointing to an example dataset that people could quickly download and play with - maybe this one?

Add string descriptors to ParticleGroup

The openPMD BeamPhysics extension has several optional str parameters that can be used label/describe a Particle Group:
For example:

latticeElementName

type: Optional (string)
description: The name of the lattice element the particle are in. This only makes sense if all particles are in the same element. [Keep in mind that if particles are lost and the lost particles are also included in the file, not all particles may be in the same element.] Also see: locationInElement.

However, these are not implemented in the ParticleGroup python class.

Marginal plot scaling

When zooming in on a phase space plot, the projections in y and x do not scale with the zoom.
They are static and always remain the same scale. See example below after zooming in, histograms do not follow:

lcls2_gun_opt_phase_space2

Include E,B fields acting on each particle

It would be convenient for some lume-GPT user if the (total) E&B fields evaluated at each particle position could be handled by openPMD-beamphysics. The user would plot the field coordinates for individual particles or average over the particles in the bunch, etc.

OpenPMD-2.0 compliance for the test/example file `bmad_particles.h5`

The test/example file bmad_particles.h5 (at openPMD-beamphysics/docs/examples/data/) is currently incompatible with the OpenPMD-1.1 standard as shown by the following errors raised by

openpmd-ls:

sasyed@MAC-140753 ~/D/p/o/d/e/data (master)> openpmd-ls bmad_particles.h5                                                                                       (openpmd-viz) 
[~Series] An error occurred: fileBased output can not be written with no iterations.
An error occurred while opening the specified openPMD series!
Read Error in frontend 
Object type:	Attribute
Error type:	UnexpectedContent
Further description:	Unexpected Attribute datatype for 'openPMDextension' (expected uint32, found STRING)
sasyed@MAC-140753 ~/D/p/o/d/e/data (master) [2]>       

openPMD_check_h5:

sasyed@MAC-140753 ~/D/p/o/d/e/data (master)> openPMD_check_h5 -i bmad_particles.h5                                                                              (openpmd-viz) 
Error: Attribute openPMDextension in `/` is not of type 'uint32' (is 'bytes_')!
Error: Attribute iterationEncoding (required) does NOT exist in `/`!
Error: Attribute iterationFormat (required) does NOT exist in `/`!
Warning: Attribute author (recommended) does NOT exist in `/`!
Error: Attribute date in `/` does not satisfy format ('2019-12-02 20:06:54' should be in format '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [\+|-][0-9]{4}$')!
Traceback (most recent call last):
  File "/Users/sasyed/Documents/packages/mambaforge/envs/openpmd-viz/bin/openPMD_check_h5", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/sasyed/Documents/packages/mambaforge/envs/openpmd-viz/lib/python3.12/site-packages/openpmd_validator/check_h5.py", line 931, in main
    result_array = check_file(file_name, verbose, force_extension_pic)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sasyed/Documents/packages/mambaforge/envs/openpmd-viz/lib/python3.12/site-packages/openpmd_validator/check_h5.py", line 917, in check_file
    extensionStates = get_extensions(f, verbose)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sasyed/Documents/packages/mambaforge/envs/openpmd-viz/lib/python3.12/site-packages/openpmd_validator/check_h5.py", line 116, in get_extensions
    if (bitmask & extensionIDs) == bitmask:
        ~~~~~~~~^~~~~~~~~~~~~~
TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
sasyed@MAC-140753 ~/D/p/o/d/e/data (master) [1]> 

Could the example file be updated so as to make it compliant with the base OpenPMD-1.1.0 specification? Thanks!

I am working (alongside @ax3l) to update the visualization tools for OpenPMD artifacts as part of the CAMPA project. We are looking to contribute a simplified backend which uses the Python bindings of openpmd-api instead of h5py to allow for the usage of ADIOS2 files in openpmd-beamphysics once the above issue is fixed so as to not break the tool for existing users.

Output to parallel elegant format (binary)

Feature request: add an option that allows elegant_write() to dump a binary format that works in parallel elegant
Something along the lines of what the pysdds module does:

import sdds
pysdds = sdds.SDDS(0)
pysdds.load(outfile)
pysdds.mode = pysdds.SDDS_BINARY #to convert from ASCII to BINARY, need binary for pelegant
pysdds.save(outfile)

sdds data module is needed from elegant page:
https://www3.aps.anl.gov/forums/elegant/viewtopic.php?f=11&t=803&p=3292&hilit=sddsdatamodule#p3292

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.