Creating model grids

This module provides routines to generate simple (and small)
ProDiMo
model
grids.
Please also look at the command line tool
pgrid
see
Command-line utilities
or just type
pgrid
-h
in your command line.
You can make your own pythong script to generate the grid, however, usually it easier to use
pgrid
and a JSON file to define
the parameters and ranges used for the grid. The example shows the different optioncs
Examples

JSON file

Here is an example for the content of JSON file that can be used with
pgrid
(or with the grid utilities in general).
[
[
"Lstar"
,
100
,
300
,
3
,
"lin"
],
[
"env_Mdot"
,
1e-06
,
0.0001
,
3
,
"log"
],
[
"Rout"
,
3000
,
6000
,
4
,
"lin"
],
[
"new_escape"
],
[
"ABS_CRI"
,
[
1
,
3
,
4
]]
]
This JSON file is equivalent to the code in the Python script below. To generate a grid with this JSON file called
gridparams.json
type in the command line
pgrid
make
grid1
gridparams.json
Init
For more details use
pgrid
-h
(i.e. how to run the grid etc.).
Python script

import
prodimopy.grid
as
pgrid
# the grid name
gridname
=
"grid1"
# A director with the initial model (e.g. a normal ProDiMo model with the required input files.)
indir
=
"Init"
# Create a Parameter list.
# The grid will be the same one, as for the example JSON file shown above.
params
=
list
()
params
.
append
([
"Lstar"
,
100
,
300
,
3
,
"lin"
])
params
.
append
([
"env_Mdot"
,
1.e-6
,
1.e-4
,
3
,
"log"
])
params
.
append
([
"Rout"
,
3000
,
6000
,
4
,
"lin"
])
# a boolean value, just the name is required
params
.
append
([
"new_escape"
])
# use values from a list, that also works with strings
params
.
append
([
"ABS_CRI"
,(
1
,
3
,
4
)])
# make the grid. One gets a list of modelnames (directories), and a tuple with the values for each parameter
modelnames
,
paramvalues
=
pgrid
.
make_grid
(
gridname
,
params
,
indir
)
# print the Parameter values
for
param
,
val
in
zip
(
params
,
paramvalues
):
print
(
f
"
{
param
[
0
]
:
20s
}
:
{
val
.
flatten
()
}
"
)
# Run the grid, please not ParameterGrid.in as added automatically to the end of the command string
# $MODELNAME$ is replaced by the model directory name
pgrid
.
run_grid
(
gridname
,
"sbatch -J $MODELNAME$ -p short ../../prodimo.slurm"
)
prodimopy.grid.
GRIDINPUTFILE
=
'ParameterGrid.in'

The additional input file which includes all the parameters that are included in the grid.
prodimopy.grid.
chgriddir
(
gridname
)
[source]

Changes the current working directory to the grid directory.
Parameters
:
gridname
(
str
) – The name of the grid (the directory with the models).
prodimopy.grid.
genparamentry
(
name
,
value
)
[source]

Generates one Parameter entry in the ProDiMo Parameter.in format.
If name is
fcarbon
then it it is assumed that the DIANA standard
opacities are used,and a proper
!
NDUST
entry is created (with a fixed vacuum fraction of 0.25).
Parameters
:
name
(
str
) – The name of the ProDiMo parameter.
value
(
Any
) – The value of the Parameter, is converted to a string.
Returns
:
The full str that can be written to a file in Parameter.in format.
Return type
:
str
prodimopy.grid.
genvalues
(
param
)
[source]

Generates the values for the given parameter, depending on type.
Parameters
:
param
(
tuple
) – A tuple with x entries depending on type. see
make_grid()
.
Returns
:
A numpy array with the generated values for that
param
. Can be of any type (str,float,int,boolean).
Return type
:
NDArray[Any]
prodimopy.grid.
get_modeldirs
(
modeldirs
=
None
,
gridname
=
None
)
[source]

Returns all grid models of the current grid (current directory) or for the grid given by
gridname
.
Parameters
:
modeldirs
(
list
|
None
) – The list of model directories. If
None
all directories within the current directory starting with
model
will be selected.
gridname
(
str
|
None
) – The name of the grid (it’s directoryname to be precise). If gridname is given search is done with
gridname+"/model*/"
Returns
:
If
modeldirs
is not
None
modeldirs
is returned (so nothing is done).
Otherwise all directory names staring with
[gridname/]model*/
are returned.
Return type
:
list
prodimopy.grid.
make_grid
(
gridname
,
params
,
indir
=
None
)
[source]

Generates a grid of prodimo models.
A directory with the name
gridname
is created. Within this directory for
each parameter combination a directory is created. This directory is initially
copied from the directory given by
indir
, where certain files (
.out,
.log,*.fits) are ignored.
The generated parameters are added to a
ParameterGrid.in
file. If
ParameterGrid.in
does not exist
it will be created.
Parameters
:
gridname
(
str
) – The name of the grid (the directory with the models).
params
(
list
) –
The list of parameters. Depending of the type different entries per Parameter are required.
numeric: Entry has to be like
(paramname,startvalue,endvalue,numberofsteps,type)
.
type
can either be
"lin"
or
"log"
for linear or logarithmic spacing
boolean: Entry is simply
(paramname)
Special parameters:
fcarbon: Only works if DIANA opacities are used. Changes the carbon fraction and the silicate part accordingly.
indir
(
str
|
None
) –
an input or starting directory containing the usual
ProDiMo
input
files. This directory is copied into a new model.
If it is
None
only the ParameterGrid.in are created
Returns
:
First entry is the list of modelnames (director values). Second one is a tuple with an entry for each
parameter, giving the generated values for this parameter.
Return type
:
tuple[list,tuple]
prodimopy.grid.
run_grid
(
gridname
,
runProDiMo
,
modeldirs
=
None
)
[source]

Runs the grid.
Changes to the grid directory and runs each model by either calling
a passed python function or a system command string (see parameters).
Parameters
:
gridname
(
str
) – The name of the grid (the directory with the models).
runProDiMo
(
str
|
Callable
) –
If it is a
str
the string is interpreted as a system command.
Any occurrence of
$MODELNAME$
in the given string is replaced by the actual model name (model directory).
If the parameter is a python function (a
Callable
). This function is called with the
modeldir
as a parameter.
modeldirs
(
list
|
None
) – A list of all models in the grid (the directory name of each model).
If
None
the list is created automatically using
prodimop.grid.get_modeldirs()
.
Only useful to run a selection of models from the grid (i.e. the failed ones).
prodimopy.grid.
check_grid
(
gridname
,
modeldirs
=
None
)
[source]

Checks if all models look okay.
This routine checks if finished.out exists for all models of the grid.
Parameters
:
gridname
(
str
) – The name of the grid (the directory with the models).
modeldirs
(
list
) –
a list of all models in the grid (directory name of each model).
If
modeldirs
is
None
all directories with names starting with
model
are
considered as potential grid models.
prodimopy.grid.
sel_lowest_chisquare
(
gridname
,
modeldirs
=
None
,
tolerance
=
None
)
[source]

Selects the model(s) with the lowest chi squared. If a tolerance is
given all models within this tolerance, measured relative to the minimum
chi square are selected.
Parameters
:
gridname
(
str
) – The name of the grid (the directory with the models).
modeldirs
(
list
|
None
) –
a list of all models in the grid (directory name of each model).
If
modeldirs
is
None
all directories with names starting with
model
are
considered as potential grid models.
tolerance
(
float
|
None
)
Return type
:
tuple[list, list]
prodimopy.grid.
sel_param_val
(
gridname
,
param
,
value
,
modeldirs
=
None
)
[source]

Very primitive and inefficient method to select models having a certain
value of a parameter. It only searches in
grid.GRIDINPUTFILE
.
Parameters
:
gridname
(
str
) – The (directory) name of the grid.
param
(
str
) – The parameter name to search for.
value
(
float
|
int
|
str
) – The value to search for. In case of numbers the read value from the grid Parameter file
is converted to the type of
value
.
modeldirs
(
list
[
str
]
|
None
) – List of model directories of the grid. If
None
get_modeldirs()
is used.
Return type
:
list[str]