Python API for CroXe: a relational database of cross-sections and rate coefficients for atomic processes and alike.
Project description
Welcome to PyCroXe
The Python API that let you import data from CroXe, with intuitive calls and minimal effort.
If you are looking for the database itself, visit: https://codeberg.org/Kruayd/CroXe.
Table of contents
Installation
PyCroXe is publicly available on PyPI, so you can just:
pip install pycroxe
[!IMPORTANT] PyCroXe requires Python 3.12 or newer!
[!IMPORTANT] PyCroXe uses MariaDB Python Connector which, with the current 1.1.14 release, still requires the MariaDB C Connector to successfully install. With the shortly upcoming next release, 2.0, it will be possible to install MariaDB Python Connector without any external dependency. If you are trying to install PyCroXe and MariaDB Python Connector is still in its 1.1.14 release, please install MariaDB C Connector!
Example usage
tl;dr
import numpy as np
from pycroxe import connect, get_species_properties
from pycroxe.beam import get_cross_sections_by_projectiles
energies = np.geomspace(10, 1e5, 200) # energies in eV
with connect() as conn:
sigma = get_cross_sections_by_projectiles(
conn,
energies,
initial_projectiles=["H3+", "H2+", "H+"],
target="H2",
)
species_data = get_species_properties(
conn,
symbols=sigma.coords["product"].to_numpy().tolist(),
)
But please, find some time to read the rest of this README or the official docs!
Connecting
PyCroXe provides a connect function that can be used, as the name obviously
suggests, to connect to any network-reachable instance of CroXe.
The intended usage is within a with statement; this will make connect, if
no argument is provided, return an instance of a CroXeConnection class,
acting as a context manager, with an open connection pointing towards the
default URL mariadb+mariadbconnector://croxe-guest@localhost/CroXe:
from pycroxe import connect
with connect() as conn:
...
PyCroXe URLs follow the
SQLAlchemy pattern
(dialect+driver://username@host:port/database) and can be provided to the
connect function, in order of descending precedence, by:
-
directly passing them as argument
with connect( "mariadb+mariadbconnector://user@server.institute.org/CroXe" ) as conn: ...
-
setting up the environment variable
CROXE_DB# if using bash export CROXE_DB="mysql+pymysql://user@server.institute.org/CroXe"
-
changing specific parts of the default URL with keyword arguments
with connect( host="server.institute.org", user="user", connector="mariadb+mariadbconnector", database="CroXe_2_electric_boogaloo" ) as conn: ...
[!NOTE]
connectcan also be used outsidewithstatements, but notice that this will return a closed instance of aCroXeConnectionclass that must be opened and closed manually with the corresponding methods:from pycroxe import connect conn = connect() conn.open() ... conn.close()At this point, if you really wish not to use a
withstatement, you can just use theCroXeConnectionclass instance builder, to which you can provide URLs in the same manner as toconnect:from pycroxe import CroXeConnection conn = CroXeConnection("mysql+pymysql://user@server.institute.org/CroXe") conn.open() ... conn.close()
[!CAUTION] Using
connectand/orCroXeConnectionoutsidewithstatements is strongly discouraged!
Retrieving species properties
Function get_species_properties will return a xarray Dataset
of properties of all the species stored in CroXe. If given the symbols
keyword argument, data will be limited only to the chosen species:
from pycroxe import connect, get_species_properties
with connect() as conn:
species_data = get_species_properties(
conn,
symbols=["H+", "H2"],
)
Retrieving beam-on-target processes cross-sections
PyCroXe provides the beam module, which in turn provides the
get_cross_sections_by_projectiles function.
get_cross_sections_by_projectiles will first recursively find all processes
that may derive from the given list of initial projectile species, and then
return a 3D tensor of evaluated cross-sections, in the form of a
xarray DataArray,
with first dimension indexing energy values, the second indexing product
species, and the last one indexing projectiles:
import numpy as np
from pycroxe import connect
from pycroxe.beam import get_cross_sections_by_projectiles
energies = np.geomspace(10, 1e5, 200) # energies in eV
with connect() as conn:
sigma = get_cross_sections_by_projectiles(
conn,
energies,
initial_projectiles=["H3+", "H2+", "H+"],
target="H2",
)
Full documentation
You can find the full documentation at https://pycroxe.readthedocs.io.
Contributing
Right now you can suggest changes through e-mail, but soon some more standard ways of contributing will be available.
License
PyCroXe is free as in freedom and licensed under the GPL v3.
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 pycroxe-0.3.0.tar.gz.
File metadata
- Download URL: pycroxe-0.3.0.tar.gz
- Upload date:
- Size: 33.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c46333cbd5d20087a5772c4e06862c511dd67507d84f0c73c0e6abbad87779e1
|
|
| MD5 |
66d13fcf3fed3d851cbb2b42575eff0d
|
|
| BLAKE2b-256 |
10234b2a7ff2394638371a0021600a99ff3f67913262271b39631fa77cf19c0e
|
File details
Details for the file pycroxe-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pycroxe-0.3.0-py3-none-any.whl
- Upload date:
- Size: 37.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fd213f7f3a198a6afae554084978359ec1d15a405bdcd8f8428da8b121b7309
|
|
| MD5 |
acf83dbe36e730c4a7895e308e082d17
|
|
| BLAKE2b-256 |
16e15b885ac0391b4fc6191130f2ce716fcfbd941d8c471a3e82b7c21f251e0c
|