-
Notifications
You must be signed in to change notification settings - Fork 1
Running models
HāpuaMod can be run from the commandline or from another python script. The commandline is probably the easiest way for general use but python potentially allows greater flexibility (for example if batching many model runs).
Because HāpuaMod is constructed as a python module it needs to be called with python -m i.e.
python -m hapuamod ModelConfigFile.cnf
Help is available via the -h flag
python -m hapuamod -h
The -o flag can be used to suppress the prompt regarding whether it is ok to overwrite output files.
python -m hapuamod ModelConfigFile.cnf -o
The main function to run HāpuaMod is contained in the core submodule of hapuamod so can be called by doing something like:
from hapuamod.core import main
OutputTs = main('ModelConfigFile.cnf')
or
from hapuamod.core import main
OutputTs = main('ModelConfigFile.cnf', True)
Where the second variable sets the option to suppress the prompt regarding whether it is ok to overwrite output files.
HāpuaMod uses the python logging package which allows you to have full control over the detail and format of logging if running from python. To do this you need to set up a logger in the python environment before calling HāpuaMod. For example:
RootLogger = logging.getLogger()
RootLogger.setLevel(logging.INFO)
ConsoleHandler = logging.StreamHandler()
ConsoleHandler.setLevel(logging.INFO)
RootLogger.addHandler(ConsoleHandler)
When running from the commandline logging to the console and to file is enabled by default. A log file is automatically created in the same directory as the config file with the name ConfigFileName_log.txt. By default INFO, WARNING and ERROR messages are logged but this can be changed using flags at the commandline. The -v (verbose) flag means that DEBUG messages are also logged. The -q (quiet) flag suppresses logging of INFO messages.