import pyauric
auric = pyauric.AURICManager()
# reset the parameters to a default setting
with open(auric.pathto('param.inp'),'w') as f:
    f.writelines(pyauric._param_format)

"""
Explanation: pyauric features

Manage AURIC batch runs
Read data from AURIC output files

The AURIC environment is handled through AURICManager. It will assume that you either have an AURIC_ROOT environment variable or that you keep auric in ~/auric. If this is not the case or you want to run use another dierctory as the root, pass it as an argument.
End of explanation
"""


print("AURIC input parameters:\n")
for line in auric.params.items():
    print("    ",line)

auric.runbatch();
print("\n\nLines computed in AURIC batch run:\n")
print("   ",auric.load("dayglo.ver").columns)

"""
Explanation: AURIC batch run
pyauric can be used to set the input parameters for an AURIC batch run, which end up in the various .inp files. For example, here are some example parameters which produce a nightglow batch run.
End of explanation
"""


auric.set_params({"UTSEC":0*3600})
print(auric.params['UTSEC'])

"""
Explanation: Change parameters
Suppose we meant to do a nighttime run instead. We can change the UTC to midnight like this:
End of explanation
"""


print(auric.params['F10AVE'], auric.params['AP(1)'])
auric.run_geoparm(True)
print(auric.params['F10AVE'], auric.params['AP(1)'])

"""
Explanation: In order to compute the derived parameters, use auric.run_geoparm. It takes an argument to tell it whether to compute F10.7 and Ap or to leave whatever is already in param.inp alone. This allows the user to manually specify F10.7 or Ap.
End of explanation
"""


auric.runbatch();
print("Lines computed in AURIC batch run:")
print("   ",auric.load("niteglo.ver").columns)

"""
Explanation: Running the batch script again will produce dayglow instead.
End of explanation
"""


ni = auric.load("niteglo.int")
nv = auric.load("niteglo.ver")

"""
Explanation: Reading AURIC files
AURIC's files can be loaded into a dictionary or data frame with AURICManager.load(filename). Filenames should be relative to the AURIC root.
End of explanation
"""


%matplotlib inline
import matplotlib.pyplot as plt
def outside_legend(ax):
    return ax.legend(loc='center right', bbox_to_anchor=(1.7, 0.5))

nv.plot()
lgd = outside_legend(plt.gca())
plt.yscale('log')
plt.title(nv.title)
plt.ylabel(nv.ylabel);

"""
Explanation: Data loaded in this way will define a title and ylabel for plotting.
End of explanation
"""


herzberg = [ c for c in nv.columns if "Herzberg" in c ]

nv[herzberg].plot()
plt.yscale('log')
outside_legend(plt.gca())
plt.ylabel(nv.ylabel)
plt.title("O2 Herzberg lines");

thin_O = [ c for c in nv.columns if "O2" not in c and "final" not in c ]

nv[thin_O].plot()
plt.yscale('log')
outside_legend(plt.gca())
plt.ylabel(nv.ylabel)
plt.title("Optically thin atomic oxygen nightglow");

"""
Explanation: We can use list comprehensions to pick out different types features to look at.
End of explanation
"""


