Python wrapper for TestParticle.jl - trace charged particles in electromagnetic fields via Julia
Project description
testparticle
Python wrapper for TestParticle.jl - trace charged particles in electromagnetic fields via Julia.
The Julia package and its dependencies are installed automatically on first
use through JuliaCall (see juliapkg.json).
Installation
The wrapper drives the Julia package TestParticle.jl through
JuliaCall and
juliapkg. You do not need to install
TestParticle.jl yourself: the Julia environment (including TestParticle and
its dependencies) is resolved from juliapkg.json and downloaded/precompiled
automatically on first use.
Requirements
- Python 3.10 or later
- Julia 1.10 or later, installed and available on your
PATH
From PyPI
python -m pip install testparticle
From a checkout of this repository
cd bindings/python
python -m pip install -e .
By default the wrapper resolves TestParticle.jl from the Julia General
registry. To develop and test the wrapper against the local checkout of
this repository, register it as a development dependency (this writes an
environment-local override and does not modify the packaged juliapkg.json):
# from bindings/python
python -m juliapkg add TestParticle --dev --path ..
# if the CLI is unavailable: pip install "juliapkg[cli]"
# or equivalently, without the CLI extra:
python -c "from juliapkg import add; add('TestParticle', uuid='953b605b-f162-4481-8f7f-a191c2bb40e3', dev=True, path='..')"
The first time you import testparticle (or run the tests) juliapkg downloads
and precompiles the Julia environment. This can take several minutes and only
happens once.
Usage
import testparticle as tp
import numpy as np
# Uniform magnetic field of 10 nT along z.
B = 1e-8
def get_B(x):
return [0.0, 0.0, B]
# Initial position [m] and velocity [m/s].
x0 = [0.0, 0.0, 0.0]
v0 = [1e5, 0.0, 0.0]
# Trace a proton for 0.1 us with a 0.5 ns step.
res = tp.trace(x0, v0, (0.0, 1e-7), 5e-10, get_B, species="proton")
# `res` exposes numpy arrays.
t = res.t # time stamps, shape (n,)
x = res.x # positions, shape (n, 3)
v = res.v # velocities, shape (n, 3)
# Save the EM fields along the trajectory as well.
res = tp.trace(x0, v0, (0.0, 1e-7), 5e-10, get_B, species="proton", save_fields=True)
E = res.E # shape (n, 3)
B_sol = res.B # shape (n, 3)
# Guiding-center tracing.
gc = tp.trace_gc(x0, v0, (0.0, 1e-7), 5e-10, get_B, species="proton")
R = gc.R # guiding-center position, shape (n, 3)
vpar = gc.vpar # parallel velocity, shape (n,)
# Magnetic field-line tracing (arc-length parameter).
fl = tp.trace_fieldline([1.0, 0.0, 0.0], get_B, (0.0, 1.0), mode="both")
t_fwd, x_fwd = fl["forward"]
t_bwd, x_bwd = fl["backward"]
Field functions may be either time-independent f(x) or time-dependent
f(x, t), and must return a length-3 sequence. Alternatively you can pass a
Julia field object directly (e.g. a field built with the Magnetostatics
package).
API
The high-level helpers are:
trace(x0, v0, tspan, dt, B, E=None, *, species="proton", trajectories=1, savestepinterval=1, save_fields=False, save_work=False, parallel=False, alg=None, init_func=None, q=None, m=None)- Boris pusher.trace_gc(x0, v0, tspan, dt, B, E=None, *, species="proton", ..., alg="rk4")- guiding-center RK4/RK45 solver.trace_fieldline(x0, B, tspan, *, mode="both", alg="Tsit5", abstol=1e-8, reltol=1e-8)- magnetic field lines.
Raw Julia objects (prepare, TraceProblem, solve, Proton, get_gyrofrequency,
...) are re-exported under their Julia names; functions ending with ! in Julia
are available with the _b suffix (e.g. trace! -> trace_b).
See the TestParticle.jl documentation for the full description of the underlying Julia functions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file testparticle-0.1.0.tar.gz.
File metadata
- Download URL: testparticle-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4136d68c37fa3ef7a0512ddbc95b3da051bab0a27978f01f2c093399343779d8
|
|
| MD5 |
89a40b495edfddc58ee466817e1706b4
|
|
| BLAKE2b-256 |
209307f246d11371b0fd9b689b9dfbc5e73ee3c272705e9475c08de74c79f45a
|
Provenance
The following attestation bundles were made for testparticle-0.1.0.tar.gz:
Publisher:
publish-python.yml on henry2004y/TestParticle.jl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
testparticle-0.1.0.tar.gz -
Subject digest:
4136d68c37fa3ef7a0512ddbc95b3da051bab0a27978f01f2c093399343779d8 - Sigstore transparency entry: 2167129805
- Sigstore integration time:
-
Permalink:
henry2004y/TestParticle.jl@08c040eb0ca7b9feab3c4a8e5befb8fcd268dca3 -
Branch / Tag:
refs/tags/py-v0.1.0 - Owner: https://github.com/henry2004y
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@08c040eb0ca7b9feab3c4a8e5befb8fcd268dca3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file testparticle-0.1.0-py3-none-any.whl.
File metadata
- Download URL: testparticle-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5721ce0dff64347cc01d392b1d174d3d16a8546f36fd65284bfae68ff62340d7
|
|
| MD5 |
05c8db019f8ae681ea4d9b3acd709f98
|
|
| BLAKE2b-256 |
8f56f02f0a098102886f6a027974bf6a03259f7738b87d8bc8f103ba147bf649
|
Provenance
The following attestation bundles were made for testparticle-0.1.0-py3-none-any.whl:
Publisher:
publish-python.yml on henry2004y/TestParticle.jl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
testparticle-0.1.0-py3-none-any.whl -
Subject digest:
5721ce0dff64347cc01d392b1d174d3d16a8546f36fd65284bfae68ff62340d7 - Sigstore transparency entry: 2167129824
- Sigstore integration time:
-
Permalink:
henry2004y/TestParticle.jl@08c040eb0ca7b9feab3c4a8e5befb8fcd268dca3 -
Branch / Tag:
refs/tags/py-v0.1.0 - Owner: https://github.com/henry2004y
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@08c040eb0ca7b9feab3c4a8e5befb8fcd268dca3 -
Trigger Event:
release
-
Statement type: