Running a model, basic tutorial
Run a solar particle model and explore the models requirements to run.
trajectory sapphire-1-in-n-peak-flux list_models validate_to_run set_external_input

# coding=utf-8
"""
title: Running a model, basic tutorial
description: Run a solar particle model and explore the models requirements to run.
keywords: trajectory, sapphire-1-in-n-peak-flux, list_models, validate_to_run, set_external_input
"""
from pprint import pprint

from nom_client.nom_client import NoMClient

"""
Initialise the NoM Client with a project name (optional) and the configuation data.
"""
nom_client = NoMClient(project_name="Model running example")

"""
Determine the status of the NoM Server(s) specified in the configuration.
"""
print(nom_client.status())

"""
List the solar particle models available.
"""
pprint(nom_client.list_models(categories=["model/environment/radiation/solar_particle"]))

"""
Get the 'sapphire-1-in-n-peak-flux' model.
"""
sapphire_1_in_n_peak_flux = nom_client.get_model(model_name='sapphire-1-in-n-peak-flux')

"""
We can test if we can run this model. The 'validate_to_run' method returns a tuple containing:
boolean: True or False if the model can run
message: If there is an error, a message
"""
model_valid = sapphire_1_in_n_peak_flux.validate_to_run()
print(model_valid)

"""
The message explains that there is a missing external input 'trajectory'
If this model is run now, a ModelRun object is returned repeating this error
"""

if model_valid['valid'] == 'true':
    run = nom_client.run_model(model=sapphire_1_in_n_peak_flux)
    print(run)
else:
    print("Invalid model")

"""
The model documentation page describes the external input this model requires, or it can be printed.
This meta data states that the external input needs the result from either the 'sapre' or 'trajectory' trajectory models.
"""
pprint(sapphire_1_in_n_peak_flux.get_external_inputs())

"""
Run the 'trajectory' model
"""
trajectory_model = nom_client.get_model(model_name='trajectory')

trajectory_model_result = nom_client.run_model(model=trajectory_model)
print(trajectory_model_result)

"""
The 'sapphire-1-in-n-peak-flux' model can now be run after setting the external input.
"""
sapphire_1_in_n_peak_flux.set_external_input(external_input_name="trajectory", external_input=trajectory_model_result)

run = nom_client.run_model(model=sapphire_1_in_n_peak_flux)
print(run)