pf_grid
This is a program that is designed to expand a .pf file into a grid of .pf files.
Usage:
Use:
pf_grid.py base.pfwhere base.pf is a correctly formatted parameter file, with variables that one wishes to grid indicated by ?
Description:
This program was written for creating grids of models with python, although it should work with any .pf file in the case where one wants to run a grid of models. As an example this should be a reasonable way to do much of the setup work for runing a bunch of ISM calculations.
To use the program take a .pf file which is correctly formatted to run with python. This is going to be the basis of all of the .pf files. Replace the values of those variables you want to grid with $
Run the program. It will ask for the .pf file, herafter grid.pf, to use, and a basename for all of the output files. It will read through grid.pf and will ask the user to give the values of each of the variables to grid.
The format of the inputs is very specific, and not particularly user-friendly! (The lines are read with the input or using the raw_input command in python, the scripting language’.
The two possibities that are supported by the program are:
a list format which means one must enclose everything in [], e.g. [14,27,32] which would say that for this variable you want values of 14, 27, and 32.
a special format to create a logarithminc grid of variables, e.g. log_ints(xmin,xmax,n) where xmin and xmax are the minimum and maximum values of the variable in question and n is the number of variables. Note that you enter the actual values of xmin and xmax and not the log of this. For example:
log_ints(1.e16.,1.e18.,3)will end up produciing a list with variables [1.e16,1.e17,1.e18]
Note also that this input is treated within the routine as a function, and so here the inputs have to be enclosed in parentheses.
- returns:
a file which lists what was varied and the values for them. The name of this file is the same as basename, with a .ls extensition attached, e.g vwhyi.ls This is intended for use with a fitting program:
# Variable Disk.mdot(msol/yr) # Variable Wind.mdot(msol/yr) PYGRID/vwhyi_0000.spec 1e-08 1e-09 PYGRID/vwhyi_0001.spec 1e-08 2.2e-09 PYGRID/vwhyi_0002.spec 1e-08 4.6e-09 ...
a file which can run python for the grid, one model after another. This has the prefix Run_ and the remainder is the basename, e.g something like, Run_vwhyi. It begins something like:
#!/usr/bin/env bash py vwhyi_0000 py vwhyi_0001 py vwhyi_0002 py vwhyi_0003 py vwhyi_0100 ...
A number of .pf files, that are like the original pf files, but now the $ have been replaced with the variables associated with the grid.
- rtype:
The program produces a lot of files
Notes
If the program finds .pf files that seems to have been created earlier, it will ask you if you want to delete them
History:
- 0709 ksl
Coded and debugged
- 1701 ksl
Updated for python3. It should be backward compatible. I have partially but not completely updated the style to the way I would write this program today.
Functions
|
Remove a preexistigng set of files with the same name |
|
Actually create the paameter files |
|
Create a file which can be sourced to run all the models |
|
Generate a set of parameter files from a pre-existing one with at least one entry ($) for interactive input |
|
Expand the the arrays containing the items to ve varied to individual runs |
|
Write out the results |
|
normal usage answer=get_input(question,answer) |
|
This generates a set of logarithmic intervals beween xmin and xmax inclusive |