<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 PhenoCam "roistats" Files
Here's a python notebook demonstrating how to read in and plot an "roistats" file (formerly referred to as the "all image" file) using python.  In this case I'm using the all image file from the alligatorriver site.  The all image files are in CSV format and can be read directly from the site using a URL.  First try reading directly from a file.
Step1:  While the data can be read directly from a URL we'll start by doing the simple thing of reading the CSV file directly from our local disk.
Step2:  Okay, that worked.  The date times seem to be a problem for plotting in pandas so I'm going to drop back to using matplotlib directly.
Step3:  That was pretty simple.  Now try to read directly from a URL to see if we get the same result.  This has the advantage that you always get the latest version of the file which is updated nightly.
Step4:  I finally figured out how to plot this using pandas.  It's pretty simple once you know what you need to do.
Step5:  Once the data frame is indexed with the datetime other values can also be plotted as a function of time.
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import os, sys
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
import requests
import StringIO
# set matplotlib  style
matplotlib.style.use('ggplot')
sitename = 'alligatorriver'
roiname = 'DB_0001'
infile = "{}_{}_roistats.csv".format(sitename, roiname)
print infile
Explanation: PhenoCam "roistats" Files
Here's a python notebook demonstrating how to read in and plot an "roistats" file (formerly referred to as the "all image" file) using python.  In this case I'm using the all image file from the alligatorriver site.  The all image files are in CSV format and can be read directly from the site using a URL.  First try reading directly from a file.
End of explanation
with open(infile,'r') as fd:
    df = pd.read_csv(fd, comment='#', parse_dates=[[0,1]])
df.head()
Explanation: While the data can be read directly from a URL we'll start by doing the simple thing of reading the CSV file directly from our local disk.
End of explanation
x = df.date_local_std_time
y = df.gcc
plt.figure(figsize=[16,4])
plt.plot_date(x, y, 'k.', markersize=.5)
Explanation: Okay, that worked.  The date times seem to be a problem for plotting in pandas so I'm going to drop back to using matplotlib directly.
End of explanation
url = "https://phenocam.sr.unh.edu/data/archive/{}/ROI/{}"
url = url.format(sitename, infile)
print url
response = requests.get(url)
fd = StringIO.StringIO(response.text)
df = pd.read_csv(fd, comment='#', parse_dates=[[0,1]])
fd.close
df[0:3]
x = df.date_local_std_time
y = df.gcc
plt.figure(figsize=[16,4])
plt.plot_date(x, y, 'k.', markersize=.5)
Explanation: That was pretty simple.  Now try to read directly from a URL to see if we get the same result.  This has the advantage that you always get the latest version of the file which is updated nightly.
End of explanation
df.index = df.date_local_std_time
df.gcc.plot(style='k.', markersize=.5, figsize=[16,4])
Explanation: I finally figured out how to plot this using pandas.  It's pretty simple once you know what you need to do.
End of explanation
df.rcc.plot(style='r.', markersize=.5, figsize=[16,4])
Explanation: Once the data frame is indexed with the datetime other values can also be plotted as a function of time.
End of explanation
<END_TASK>