Setting model inputs, array-like example
Setting array-like model inputs using short and long term SEU models
model inputs array trajectory ap8ae8 sapphire-peak-flux newupseto SEU

# coding=utf-8
"""
category: tutorial
title: Setting model inputs, array-like example
description: Setting array-like model inputs using short and long term SEU models
keywords: model inputs,array,trajectory,ap8ae8,sapphire-peak-flux,newupseto,SEU
"""

from nom_client.nom_client import NoMClient


nom_client = NoMClient("Array-like inputs example")

sapre_model_gto = nom_client.get_model('trajectory')

sapre_gto_result = nom_client.run_model(sapre_model_gto)
print(sapre_gto_result)

ap8ae8_model = nom_client.get_model('ae8ap8')
ap8ae8_model.set_external_input(external_input_name="trajectory", external_input=sapre_gto_result)
ap8ae8_results = nom_client.run_model(ap8ae8_model)
print(ap8ae8_results)


# Solar particle models
sapphire_peak_model = nom_client.get_model('sapphire-peak-flux')
sapphire_peak_model.set_external_input(external_input_name="trajectory", external_input=sapre_gto_result)
sapphire_peak_results = nom_client.run_model(sapphire_peak_model)
print(sapphire_peak_results)


# Short term SEU/LET models
newupseto_model = nom_client.get_model('newupseto')
newupseto_model.set_external_input(external_input_name="trajectory", external_input=sapre_gto_result)
newupseto_model.set_params(includeSEPSpectrum=1, includeTrappedSpectrum=0, includeGCRSpectrum=0)
newupseto_model.set_external_input(external_input_name="solarParticleSpectrum", external_input=sapphire_peak_results)

# Add two devices to the model
"""
The input parameter 'device' within the newupseto model is defined as an array-like input (mutiplicity=many) which means you can add 
multiple 'device' parameter sets. You need to add each with a unique name (unique_group_name).
"""

newupseto_model.new_input_group(input_group_name="device", unique_group_name="mydevice1", params={
    "deviceMaterial": 0,
    "deviceName": "DEFAULT1",
    "index": 0
})

newupseto_model.new_input_group(input_group_name="device", unique_group_name="mydevice2", params={
    "deviceMaterial": 3,
    "deviceName": "DEFAULT2",
    "index": 1,
    "Z": 0.1
})

newupseto_model.set_params(numberDevices=2)

# If you want to edit the parameters for a particular device use the 'set_params'
# with an input_group_name and unique_group_name.

newupseto_model.set_params(input_group_name="device",
                           unique_group_name="mydevice2",
                           params={"deviceName": "DEFAULT10000000"})
newupseto_run = nom_client.run_model(newupseto_model)
print(newupseto_run)

# Available result names
print(newupseto_run.get_result_names())

# Get the let_spectrum result
let_spectrum_result = newupseto_run.get_model_result_by_name("let_spectrum")

# Get available variable names
variable_names = let_spectrum_result.get_variable_names()
print(variable_names)

print(let_spectrum_result.describe_variable("integral_flux"))

let_data = let_spectrum_result.get_variable_data("let")
fpiu_data = let_spectrum_result.get_variable_data("integral_flux")

# Get the seu rate data
seu_rate_result = newupseto_run.get_model_result_by_name("see_rate")

variable_names = seu_rate_result.get_variable_names()
print(variable_names)

print(seu_rate_result.describe_variable("direct_upset_rate"))

direct_upset_rate_data = seu_rate_result.get_variable_data("direct_upset_rate")
proton_upset_rate_data = seu_rate_result.get_variable_data("proton_upset_rate")

# Print the direct ionisation upset rates for both devices
print(direct_upset_rate_data)

# Print the proton induced upset rates for both devices
print(proton_upset_rate_data)