Skip to main content

A package for distributing the HEASOFT / XSPEC model library.

Project description

xspectrampoline

Installing the XSPEC model library can be as easy as

pip install xspectrampoline

and that's what this package provides.

Usage

This package is indented only for providing the XSPEC model binaries, and is not a wrapper around the model library. The minimal wrapper code that exists is code you would have to write anyway, but beyond that there may are too many ways the models could be put together for Python usage. That's an exercise left to the reader.

Whilst you think about that, here's how you can use xspectrampoline

# Importing calls FNINIT in the libXS
import xspectrampoline

# Get a handle to the minimal wrapper
lib_xspec = xspectrampoline.get_libraries()

# Get the function by the symbol name
powerlaw = lib_xspec.get_model("C_powerlaw")

# Setup an energy, parameter, and output arrays
energy = np.linspace(0.01, 10.0, 100, dtype=np.float64)
parameters = np.array([3.0], dtype=np.float64)
output = np.zeros(len(energy) - 1, dtype=np.float64)
error = np.zeros(len(energy) - 1, dtype=np.float64)

# Invoke the model
powerlaw(energy, parameters, output, error)

# Then do things with `output`
...

Overwriting which libraries are used

By default xspectrampoline bundles everything that is needed to use the XSPEC model library. But what if you already have HEASOFT / XSPEC installed and want to use your local version? xspectrampoline checks if the HEADAS environment variable is set and determines the library locations accordingly. If you want to use your local version, just make sure HEADAS points to the right location and your linker paths are configured via headinit.

xspectrampoline sets the HEADAS environment variable if it's not already set. You can also access the path it uses to resolve the libraries using

import xspectrampoline

headas_path = xspectrampoline.get_HEADAS()
print(headas_path)

How does it work

This package is possible all thanks to Julia's BinaryBuilder.jl who have done all the hard work for making compiled libraries relatively easy to share around. The XSPEC model library was cross compiled into LibXSPEC_jll.jl for Linux and MacOS, and xspectrampoline is basically those artifacts bundled for distribution with Python.

For developers

To bundle things locally, ensure you have setuptools, wheel, and build installed:

python3 -m pip install --upgrade setuptool wheel build

You can then use the Makefile targets to automate the build commands. The Makefile fetches the BinaryBuilder.jl artifacts, unpacks them, and runs the necessary Python packaging commands to create the wheels. Those will then be available under ./dist in your local directory.

make

You can test the packaging by installing from the wheel:

python -m pip install ./dist/xspectrampoline-0.1.0-py3-none-linux_x86_64.whl

selecting the correct platform tag as needed.

There are also handy targets for doing this:

make install    # install the wheel on your system

make clean      # delete all files (include dist) that were generating during
                # the packaging process

Testing locally

Because you need to test the locally installed version of xspectrampoline, you need to make sure you run pytest outside of the root directory. After you've installed the wheel, the easiest way to do this is

cd test && pytest -vvv .

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

xspectrampoline-0.1.1-py3-none-manylinux_2_24_x86_64.whl (62.9 MB view details)

Uploaded Python 3manylinux: glibc 2.24+ x86-64

xspectrampoline-0.1.1-py3-none-macosx_15_0_arm64.whl (9.8 MB view details)

Uploaded Python 3macOS 15.0+ ARM64

xspectrampoline-0.1.1-py3-none-macosx_14_0_x86_64.whl (11.2 MB view details)

Uploaded Python 3macOS 14.0+ x86-64

xspectrampoline-0.1.1-py3-none-macosx_14_0_arm64.whl (9.8 MB view details)

Uploaded Python 3macOS 14.0+ ARM64

File details

Details for the file xspectrampoline-0.1.1-py3-none-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for xspectrampoline-0.1.1-py3-none-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 ede40735efbdb67b4bfad6593ec4b29f5991797f96c5872e2779ed313992ea4b
MD5 5d5e32e11656c10b500317d732537536
BLAKE2b-256 ab52c319b605c2aa3eaeeb776ff3f76ac807c753b3848da9eebafc804c0d2474

See more details on using hashes here.

File details

Details for the file xspectrampoline-0.1.1-py3-none-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for xspectrampoline-0.1.1-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b2916c3628b3ee00adbea4d3150edfcb36b1a45cea48bcb73de588cfa99bd2fa
MD5 270e9f1672f3bcfcb4ff3a3ef6e6b0d8
BLAKE2b-256 958742ab0fb61c91b2d00213fa1c036dcf51f7f971b2c6d3260321bb7b642a5f

See more details on using hashes here.

File details

Details for the file xspectrampoline-0.1.1-py3-none-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for xspectrampoline-0.1.1-py3-none-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 1037b48d321230fc24e43b549bd6e5c7adb9abcd1a989ca437e5f5f7b4c9394e
MD5 597d72d9fbbd866c79cce88008d1c5ae
BLAKE2b-256 c72f9ae4e86b7f7f1b069cf3af2a2eb40dba5f60d003c7e58fa640442ce4c2dd

See more details on using hashes here.

File details

Details for the file xspectrampoline-0.1.1-py3-none-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for xspectrampoline-0.1.1-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6576cca6a1868cd809dcb15080a76120ac56276b291b82ac24ffc92e43b82139
MD5 5100039700c03e71094ee7dfaee501be
BLAKE2b-256 fce2b8394500678f49f94fc1d77c5e5f453bb51c03f2fb21dc3fd03d1a420864

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