Skip to main content

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

At this development stage PyCroXe is not yet public on PyPI, hence just running pip install pycroxe won't work. You can, though, clone this repo to your machine and install PyCroXe from it:

git clone https://codeberg.org/Kruayd/PyCroXe.git
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:

  1. directly passing them as argument

    with connect(
        "mariadb+mariadbconnector://user@server.institute.org/CroXe"
    ) as conn:
        ...
    
  2. setting up the environment variable CROXE_DB

    # if using bash
    export CROXE_DB="mysql+pymysql://user@server.institute.org/CroXe"
    
  3. 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] connect can also be used outside with statements, but notice that this will return a closed instance of a CroXeConnection class 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 with statement, you can just use the CroXeConnection class instance builder, to which you can provide URLs in the same manner as to connect:

from pycroxe import CroXeConnection

conn = CroXeConnection("mysql+pymysql://user@server.institute.org/CroXe")
conn.open()
...
conn.close()

[!CAUTION] Using connect and/or CroXeConnection outside with statements 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycroxe-0.2.2.tar.gz (33.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycroxe-0.2.2-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

File details

Details for the file pycroxe-0.2.2.tar.gz.

File metadata

  • Download URL: pycroxe-0.2.2.tar.gz
  • Upload date:
  • Size: 33.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for pycroxe-0.2.2.tar.gz
Algorithm Hash digest
SHA256 5bc9f7dbd144114c9b389c37b73081e6eb0fa2763e26f648eadd424f0c219330
MD5 bcbabc2229723c8e6f8828ca954f3e9f
BLAKE2b-256 e70f70542468e215f7422e22ff665b5fec662b03f93ea47c30157a361ffdd7fb

See more details on using hashes here.

File details

Details for the file pycroxe-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pycroxe-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 37.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for pycroxe-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f515e2eafb881681fc8c20c61c2e3b6c742c414809b2e93e942a4ca722161600
MD5 1dc7609691b5583844c46b66c3edffcb
BLAKE2b-256 d31bfb11b7f3764388935f38a3b2ad9b3d2109ae14bb4f97cb42d616d869175e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page