All Projects → dmentipl → phantom-config

dmentipl / phantom-config

Licence: MIT license
Parse, convert, modify, and generate Phantom config files.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to phantom-config

sunraster
A SunPy-affiliated package which provides tools to analyze data from spectral data from any solar mission.
Stars: ✭ 19 (+58.33%)
Mutual labels:  astronomy
nightlight
Nightlight: Astronomic Image Processing
Stars: ✭ 25 (+108.33%)
Mutual labels:  astronomy
Nasa-And-Spacex-Cooperation
Theme Outer Space
Stars: ✭ 41 (+241.67%)
Mutual labels:  astronomy
nmmn
Miscellaneous methods for: astronomy, dealing with arrays, statistical distributions, computing goodness-of-fit, numerical simulations and much more
Stars: ✭ 16 (+33.33%)
Mutual labels:  astronomy
cygrid
Cygrid is a cython-powered convolution-based gridding module for astronomy
Stars: ✭ 32 (+166.67%)
Mutual labels:  astronomy
ha skyfield
See the apparent positions of the Sun, Moon, and planets in this home assistant custom component
Stars: ✭ 26 (+116.67%)
Mutual labels:  astronomy
fritz
Astronomical data platform for the Zwicky Transient Facility.
Stars: ✭ 20 (+66.67%)
Mutual labels:  astronomy
pyuvdata
A pythonic interface for radio astronomy interferometry data (uvfits, miriad, others)
Stars: ✭ 62 (+416.67%)
Mutual labels:  astronomy
curvit
Create light curves from UVIT data.
Stars: ✭ 14 (+16.67%)
Mutual labels:  astronomy
kosmorro
A program to calculate your ephemerides.
Stars: ✭ 53 (+341.67%)
Mutual labels:  astronomy
pydl
Library of IDL astronomy routines converted to Python.
Stars: ✭ 20 (+66.67%)
Mutual labels:  astronomy
indi-allsky
Software to manage a Linux-based All Sky Camera.
Stars: ✭ 59 (+391.67%)
Mutual labels:  astronomy
PyNeb devel
PyNeb development repository
Stars: ✭ 22 (+83.33%)
Mutual labels:  astronomy
starclass
Stellar Classification
Stars: ✭ 15 (+25%)
Mutual labels:  astronomy
planisphere
Make your own cardboard model planisphere
Stars: ✭ 28 (+133.33%)
Mutual labels:  astronomy
apod chrome extension
Astronomy Picture of the Day (APOD) Chrome Extension for the new tab screen
Stars: ✭ 16 (+33.33%)
Mutual labels:  astronomy
api-rest
API - The Solar System OpenData
Stars: ✭ 18 (+50%)
Mutual labels:  astronomy
MOSFiT
Modular Open Source Fitter for Transients
Stars: ✭ 27 (+125%)
Mutual labels:  astronomy
ephemeris-compute-de405
A command-line tool for producing tables of the positions of solar system objects over time.
Stars: ✭ 14 (+16.67%)
Mutual labels:  astronomy
marvin
Data access and visualization for MaNGA. http://sdss-marvin.readthedocs.io/en/latest/
Stars: ✭ 48 (+300%)
Mutual labels:  astronomy

Phantom config

phantom-config: parse, convert, modify, and generate Phantom config files

phantom-config can read Phantom .in and .setup files. (They have the same format.) You can, for example:

  • modify config values or comment strings,
  • add new variables or delete old ones,
  • write the config to a JSON or TOML file,
  • generate a config file from a Python dictionary.

Build Status Coverage Status PyPI

Installation

Install phantom-config with pip

python -m pip install phantomconfig

Requirements

Python 3.7+ only. Optionally tomlkit for read/write to TOML format.

Usage

Basic usage

Import phantom-config.

>>> import phantomconfig

To read in a Phantom config file

>>> input_file = phantomconfig.read_config('prefix.in')

Print a summary

>>> input_file.summary()

The variables, with their values, comment string, and the block they are a member of, are stored in a dictionary accessed by the .config method.

>>> dtmax = input_file.config['dtmax']

The keys of this dictionary correspond to the variable name, and values are a ConfigVariable named tuple with the variable name, value, comment, and block.

>>> dtmax.name
>>> dtmax.value
>>> dtmax.comment
>>> dtmax.block

You can just get the value if you want.

input_file.get_value('dtmax')

If you like, you can write the Phantom config as a JSON file, and you can read the JSON file.

>>> input_file.write_json('prefix-in.json')
>>> json_file = phantomconfig.read_json('prefix-in.json')

Check that the configs are equal

>>> input_file.config == json_file.config

You can also read and write TOML files.

>>> input_file.write_toml('prefix-in.toml')
>>> toml_file = phantomconfig.read_toml('prefix-in.toml')

You can add a new variable, remove a variable, and change the value of a variable.

# Add new variable
>>> input_file.add_variable(
...     'new_var',
...     12345678,
...     comment='Sets thing',
...     block='options controlling things',
... )

# Remove a variable
>>> input_file.remove_variable('dtmax')

# Change the value of a variable
>>> input_file.change_value('dumpfile', 'new_dumpfile_name')

Then you can write the Phantom config file with the modified values.

>>> input_file.write_phantom('new.in')

Examples

Generate a config from a dictionary

You can create a Phantom .setup file from a Python dictionary. First create the dictionary

>>> setup = dict()
>>> setup['gas properties'] = {
...     'cs': (cs, 'sound speed'),
...     'npart': (npart, 'number of particles in x direction'),
...     'rhozero': (rhozero, 'initial density'),
...     'ilattice': (ilattice, 'lattice type'),
... }

Then you can read the dictionary with phantomconfig, and write to a Phantom .setup file

>>> setup_config = phantomconfig.read_dict(setup)
>>> setup_config.header = [
...     'input file for some particular setup routine',
...     'short description of what it does',
... ]
>>> setup_config.write_phantom('filename.setup')

This writes a file like

# input file for some particular setup routine
# short description of what it does

# gas properties
                  cs =        1.000   ! sound speed
               npart =         9999   ! number of particles in x direction
             rhozero =        0.100   ! initial density
            ilattice =            2   ! lattice type

Writing multiple configs

Say you want to write multiple configs, each with a different parameter value. For example, you have a template .in file and you want to vary the alpha parameter. The following

  1. reads the template file
  2. loops over a list of alpha values, writing a new .in file for each value in the list
alphas = [0.1, 0.2, 0.3]
infile = phantomconfig.read_config('template.in')

for alpha in alphas:
    infile.change_value('alpha', alpha)
    infile.write_phantom(f'alpha={alpha}.in')

See also

phantom-build

phantom-build is a Python package designed to make it easy to generate reproducible Phantom builds for writing reproducible papers. You can generate .in and .setup files with phantom-config and then, with phantom-build, you can compile Phantom and set up multiple runs, and schedule them via, for example, the Slurm job scheduler.

phantom-setup

phantom-setup is a (work in progress) Python package designed to set up Phantom initial conditions in pure Python, i.e. with no Fortran dependencies. It uses NumPy and Numba to achieve Fortran like performance for computationally expensive operations.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].