Phantom config
Phantom config files: parse, convert, modify, and generate.
phantomconfig can read Phantom .in and .setup files. (They have the same format.) You can, for example:
- modify config values,
- add new variables,
- write the config as a JSON file,
- generate a config file from a dictionary.
Usage
Basic usage
Import phantomconfig as pc.
>>> import phantomconfig as pc
To read in a Phantom config file
>>> input_file = pc.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
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 = pc.read_json('prefix-in.json')
Check that the configs are equal
>>> input_file.config == json_file.config
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')
Examples
Generate a config from a dictionary
You can create a Phantom .setup file from a Python dictionary. First create the dictionary
>>> setup = {
... 'cs': [cs, 'sound speed', 'gas properties'],
... 'npart': [npart, 'number of particles in x direction', 'gas properties'],
... 'rhozero': [rhozero, 'initial density', 'gas properties'],
... 'ilattice': [ilattice, 'lattice type', 'gas properties'],
... }
Then you can read the dictionary with phantomconfig, and write to a Phantom .setup file
>>> setup_config = pc.read_dict(setup)
>>> setup_config.header = ['input file for some particular setup routine']
>>> setup_config.write_phantom('filename.setup')
This writes a file like
# input file for some particular setup routine
# 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
- reads the template file
- loops over a list of
alphavalues, writing a new.infile for each value in the list
alphas = [0.1, 0.2, 0.3]
infile = pc.read_config('template.in')
for alpha in alphas:
infile.change_value('alpha', alpha)
infile.write_phantom(f'alpha={alpha}.in')
Release files for phantomconfig 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| phantomconfig-0.1.0.tar.gz | 7.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| phantomconfig-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.8 kB
Release files / phantomconfig-0.1.0.tar.gz
| Download URL | phantomconfig-0.1.0.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b9cd2976845fea7bccfccf9549b3284a54b0454f3beb3ebabc8fc4afc59abbf
|
|
BLAKE2b-256 checksum How to use checksums |
ca127ba461786634908bf7a3a352c4c8e9804568bf96df784119d097e0a6eb1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Release files / phantomconfig-0.1.0-py3-none-any.whl
| Download URL | phantomconfig-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fea906388fcdd438d72ddce4fd0b10d17b8650993600b1dba42aaf874f5f2341
|
|
BLAKE2b-256 checksum How to use checksums |
0bea2f2743be15c01eb8a6699d921ca1050149c62fd78e21ccdc4bfbbc502043
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|