Running a pipeline of models without returning intermediate results
This example runs a series of models but instructs the NoM server not to send back potentially large intermediate results. This can improve performance when these intermediate models are large and the network slow.
trajectory sapphire-1-in-n-peak-flux return_models flag set_external_input

# coding=utf-8
"""
title: Running a pipeline of models without returning intermediate results
description: This example runs a series of models but instructs the NoM server not to send back potentially large intermediate results. This can improve performance when these intermediate models are large and the network slow.
keywords: trajectory, sapphire-1-in-n-peak-flux, return_models flag, set_external_input
"""

from nom_client.nom_client import NoMClient

"""
We set the 'return_results' flag to False. This instructs NoM to remove the data from the returned model results.
The returned results can be used in the same way as normal results, e.g. as external inputs etc. 
NoM detects the result status and uses the run_id (on the server) to get the actual results to use as external input.
"""
nom_client = NoMClient("Running models without returning results", return_results=False)

sapre_model = nom_client.get_model('sapre')
sapre_model.set_params(orbitType="GEN", missionDurationUnits=1, missionDuration=15,trajectoryDuration=9)
sapre_result = nom_client.run_model(sapre_model)
print(sapre_result)

# The 'sapre_result' contains all meta data but no actual result data values.

# Running trapped radiation model
ap8ae8_model = nom_client.get_model('ae8ap8')
ap8ae8_model.set_external_input(external_input_name="trajectory", external_input=sapre_result)
ap8ae8_results = nom_client.run_model(ap8ae8_model)
print(ap8ae8_results)

# Running GCR model
creme_96_gcr_model = nom_client.get_model('creme-96-gcr')
creme_96_gcr_model.set_external_input(external_input_name="trajectory", external_input=sapre_result)
creme_96_gcr_results = nom_client.run_model(creme_96_gcr_model)
print(creme_96_gcr_results)

# Running SEP model
sapphire_total_fluence_model = nom_client.get_model('sapphire-total-fluence')
sapphire_total_fluence_model.set_external_input(external_input_name="trajectory", external_input=sapre_result)
sapphire_total_fluence_results = nom_client.run_model(sapphire_total_fluence_model)
print(sapphire_total_fluence_results)

# Running SD2 model
sd2_model = nom_client.get_model('sd2')
sd2_model.set_external_input(external_input_name="trappedParticleSpectrum", external_input=ap8ae8_results)
sd2_model.set_external_input(external_input_name="solarParticleSpectrum", external_input=sapphire_total_fluence_results)
sd2_model.set_external_input(external_input_name="gcrSpectrum", external_input=creme_96_gcr_results)
sd2_model.set_params(detectorMaterial=1, shieldDepthValues=1,
                     userShieldDepths=[0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8, 1, 1.5, 2,
                                       2.5, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20])
sd2_result = nom_client.run_model(sd2_model)
print(sd2_result)

"""
The 'sd2_result' will also have no results data values so we need to request the full results from the server using the 'run_id'.
The 'get_model_runs' method returns a list of results, in our case we just have one, so we grab the first index

We could have run the SD2 model using the parameter, 'return_results=True' and this would overide the global value and 
return the full results, removing the need to call 'get_model_runs'.

"""

sd2_result = nom_client.get_model_runs(run_ids=sd2_result.run_id)[0]

# Explore results
dose_depth_curve = sd2_result.get_model_result_by_name(result_name="dose_depth_curve")
thickness = dose_depth_curve['thickness'].values
absorbed_dose = dose_depth_curve['absorbed_dose'].values