<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <img src="images/csdms_logo.jpg">
Examine the HydroTrend output
Let's use IPython Notebook to download the model output 
from the WMT tutorial
and examine the results.
The model output is stored as a tar.gz file on the CSDMS website. Here's its name and location
Step1:  Download the output and write it to a file on your local machine
Step2:  Unpack the file
Step3:  Change to the directory containing the unpacked contents and view
Step4:  After browsing the hydrotrend directory, 
as well as consulting the 
Model
Step5:  View basic information about the data
Step6:  Next, read the discharge data
Step7:  View basic information about the data
Step8:  Prepare the data by removing the two header lines and the empty line at the end of the discharge series. Also remove the last two values in the time series. Both series now have 365 elements.
Step9:  Now we can visualize the model output as a time series
<ASSISTANT_TASK:>
Python Code:
run_id = 'addbbe35-5fd7-4d1b-a37d-3629768532b4'
download_file = run_id + '.tar.gz'
download_url = 'http://csdms.colorado.edu/pub/users/wmt/' + download_file
Explanation: <img src="images/csdms_logo.jpg">
Examine the HydroTrend output
Let's use IPython Notebook to download the model output 
from the WMT tutorial
and examine the results.
The model output is stored as a tar.gz file on the CSDMS website. Here's its name and location:
End of explanation
import requests
r = requests.get(download_url)
with open(download_file, 'w') as fp:
    fp.write(r.content)
Explanation: Download the output and write it to a file on your local machine:
End of explanation
import tarfile
tar = tarfile.open(download_file)
tar.extractall()
tar.close()
Explanation: Unpack the file:
End of explanation
import os
os.chdir(run_id)
%ls
Explanation: Change to the directory containing the unpacked contents and view:
End of explanation
with open("hydrotrend/_time.txt", "r") as fp:
    time = fp.read().split("\n")
Explanation: After browsing the hydrotrend directory, 
as well as consulting the 
Model:HydroTrend and 
Model_help:HydroTrend pages, 
the files we need are
hydrotrend/HYDRO_OUTPUT/HYDROASCII.Q
for the discharge at the river mouth [m<sup>3</sup>s<sup>-1</sup>], and
hydrotrend/_time.txt
for the model time steps [days].
Start by reading the time data from its file:
End of explanation
print "Data type: {}".format(type(time))
print "Length: {} elements".format(len(time))
print "First five elements:\n{}".format(time[0:5])
Explanation: View basic information about the data:
End of explanation
with open("hydrotrend/HYDRO_OUTPUT/HYDROASCII.Q", "r") as fp:
    discharge = fp.read().split("\n")
Explanation: Next, read the discharge data:
End of explanation
print "Data type: {}".format(type(discharge))
print "Length: {} elements".format(len(discharge))
print "First five elements:\n{}".format(discharge[0:5])
Explanation: View basic information about the data:
End of explanation
discharge = discharge[2:-1]
time = time[:-2]
print len(discharge), len(time)
Explanation: Prepare the data by removing the two header lines and the empty line at the end of the discharge series. Also remove the last two values in the time series. Both series now have 365 elements.
End of explanation
%pylab inline
plot(time, discharge)
title("HydroTrend: discharge at river mouth versus time")
xlabel("Time [$days$]")
ylabel("Q [$m^3 s^{-1}$]")
show()
Explanation: Now we can visualize the model output as a time series:
End of explanation
<END_TASK>