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
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")
"""
Get the 'sapphire_total_fluence' model.
"""
sapphire_total_fluence = nom_client.get_model(model_name='sapphire-total-fluence')
"""
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_total_fluence.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_total_fluence)
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_total_fluence.get_external_inputs())
"""
The output describes that we need to give the sapphire model an input of quantity (type) 'trajectory' and label it 'trajectoy'
if you look at the model documentation for the pipelineing of the sapphire model:
https://nom.esa.int/models/sapphire-total-fluence/flow
it lists the valid models that produce an output of quantity (type) 'trajectory'
We will use the 'Trajectory Tool'
"""
"""
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_total_fluence' model can now be run after setting the external input.
"""
sapphire_total_fluence.set_external_input(external_input_name="trajectory", external_input=trajectory_model_result)
run = nom_client.run_model(model=sapphire_total_fluence)
print(run)