Skip to main content

"Python bindings for MESA (Modules for Experiments in Stellar Astrophysics)"

Project description

pyMesa logo

DOI

pyMesa

Allows python to interface with MESA stellar evolution code.

Requirements:

Note: pyMesa currently only works on linux, Macs will fail to build.

Python dependencies can be installed with:

python -m pip install -r requirements.txt

We also need the following tool from installed by you system package manager or other means:

chrpath

Installing pyMesa

The preferred way is via pip:

python -m pip install --upgrade pyMesa

Building MESA

Go to $MESA_DIR/utils/makefile_header and find USE_SHARED=no and switch that to USE_SHARED=yes

Then:

cd $MESA_DIR
./clean
./install

Supported MESA versions

Any post github version: that is a version that starts with 'r2' or is from a git checkout.

Running

Make sure you set MESA_DIR and MESASDK_ROOT before starting Python.

Usage

Here is a basic example of talking to the const module.

import pyMesa as pym

# pyMesa module defines a number of useful MESA paths as pym.SOMETHING.
print(pym.MESA_DIR) # Print MESA_DIR

# Loads the const module
const_lib,const_def = pym.loadMod("const")

# When calling a function we must either set the value we want (for intent(in/inout) variables) or an empty variable for intent(out).
ierr=0
# Calls a function
res = const_lib.const_init(pym.MESA_DIR,ierr)


# If the call was a subroutine then res is a dict with the intent out variables in there
# else it contains the result of the function call

# Accessing a variable defined in a module is simply:
const_def.mev_to_ergs

# If the variable is not a parameter then you can change it with:
const_def.standard_cgrav = 5.0

# When passing a derived type, you should pass a dict to the function (filled with anything you want set)
x = {}
# or
x = {'a':1,'b':'abc','c':{'d':1}}

# Functions accepting arrays should pass a numpy array of the size it expects (if the function allocates the array, then just pass None)
x = np.zeros(size)

The folder mesa_models shows some examples of accessing different MESA modules. Note some may not work depending on whether MESA has changed the interface since the code was written.

Procedure calls

Calling a function or a subroutine is handled the same way:

result = module.my_function(arg1, arg2)

Where every arg should be provided either with the value to be inputted (intent(in) or intent(inout)) or a dummy empty provided for intent(out) values.

The result of a procedure call is returned as a NamedTuple of (result, args). Thus a function result is accessed via:

result = module.my_function(arg1, arg2)

#Function result
result.result

While all the arguments (both those that change and those that don't) are returned via:

result = module.my_function(arg1, arg2)

#Arguments
result.args['arg1']
result.args['arg2']

Arrays

Remember that Fortran has 1-based arrays while Numpy uses 0-based. This comes up if you're accessing an array via a mesa constant:

mesa_array[mesa_module.i_mesa_const]

should instead be accessed as:

mesa_array[mesa_module.i_mesa_const-1]

Bug reports:

Bug reports should go to the issue tracker on github. Please include mesa version, gfortran version, gfort2py version and pyMesa version

Contributing

In general, most of the development should go towards the gfort2py project to add new fortran features. This repository just handles building mesa for Python support.

Bug reports, if mesa versions don't work, or new examples are welcome as either pull requests or issues on the GitHub tracker.

Citations

People who use pyMESA in papers should cite this using the zenodo link for the version they used. If you use pyMesa in a project (research or teaching), let me know and i can help advertise here (also useful for me to help with funding requests). The current version's citation is in the CITATION file.

Known Projects using pyMesa

Poelarends et al 2017

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

pyMesa-2.0.1.tar.gz (99.4 kB view details)

Uploaded Source

Built Distribution

pyMesa-2.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file pyMesa-2.0.1.tar.gz.

File metadata

  • Download URL: pyMesa-2.0.1.tar.gz
  • Upload date:
  • Size: 99.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for pyMesa-2.0.1.tar.gz
Algorithm Hash digest
SHA256 fa3b7c3c8916df65530eb1a4d5ff0ad89d30697c3848155c711d0ec799007a67
MD5 1635b93baabed32c4100de13112691f6
BLAKE2b-256 06c766c09e847430618cbf1d70d1177c2ce010a8a88c7d0563375f262d290a0f

See more details on using hashes here.

File details

Details for the file pyMesa-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyMesa-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for pyMesa-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30dee268b4aa08c70dea4318f1dec308746f5e7fb8d6e1e528ed49606960caa9
MD5 396b4f049bb93edc182f7ed46405142e
BLAKE2b-256 c8a6a4f79e550db431096669659a7bb23ccc3c4cb86d6b366e7a23f87e86b119

See more details on using hashes here.

Supported by

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