Reference on jhuki.simfactory¶
The simfactory
module provides functions to interface with
SimFactory.
The available functions are:
simfactory_option()
, which helps setting up options that are
controllable by SimFactory.
write_parfile()
, which write the .par file from a template
when the file is executed as .rpar by SimFactory.
- jhuki.simfactory.simfactory_option(name, default)[source]¶
Set a variable to a SimFactory-controllable parameter.
SimFactory can define arbitrary parameters using the
--define
keyword. With this function, you can define a variable that takes a specified default value, unless the keyword is used.For example:
par_b is a Python variable with the value 6.5 unless
--define PARB=XX
is passed to SimFactory. The way this works is that SimFactory performs a substitution of objects with the double @ symbols. For this reason, the name parameter to this function has to be surrounded by @.We convert all the numbers to floats, so if you need integers, you have to explicitly cast the variable to int, for example:
- Parameters
name (str) – Name of the SimFactory define key. It has to be with surrounded by @, for example, @XMAX@.
default (int, float, or str) – Default value that the variable has to have if define is not specified.
- Returns
The default value if the define key is not passed to SimFactory, otherwise the value defined with SimFactory.
- Return type
float or str (integers are converted)
- jhuki.simfactory.write_parfile(template: str, file_name=None) None [source]¶
Write parfile from given template using locals() as substitution dictionary.
The variables in template get substituted with the values in the local scope of the calling function. So, you can safely put this function at the end of your rpar file to have the template substituted with the variables you have defined there.
- Parameters
template (str) – Template of parfile to write. See
write_one_parfile_from_template()
file_name (str) – Name of the file that is calling this function. (Used only for debug purposes.)