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.
In [1]:
%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
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.
In [2]:
with open(infile,'r') as fd:
df = pd.read_csv(fd, comment='#', parse_dates=[[0,1]])
df.head()
Out[2]:
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.
In [3]:
x = df.date_local_std_time
y = df.gcc
plt.figure(figsize=[16,4])
plt.plot_date(x, y, 'k.', markersize=.5)
Out[3]:
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.
In [4]:
url = "https://phenocam.sr.unh.edu/data/archive/{}/ROI/{}"
url = url.format(sitename, infile)
print url
In [5]:
response = requests.get(url)
fd = StringIO.StringIO(response.text)
df = pd.read_csv(fd, comment='#', parse_dates=[[0,1]])
fd.close
df[0:3]
Out[5]:
In [6]:
x = df.date_local_std_time
y = df.gcc
plt.figure(figsize=[16,4])
plt.plot_date(x, y, 'k.', markersize=.5)
Out[6]:
I finally figured out how to plot this using pandas. It's pretty simple once you know what you need to do.
In [7]:
df.index = df.date_local_std_time
df.gcc.plot(style='k.', markersize=.5, figsize=[16,4])
Out[7]:
Once the data frame is indexed with the datetime other values can also be plotted as a function of time.
In [8]:
df.rcc.plot(style='r.', markersize=.5, figsize=[16,4])
Out[8]:
In [ ]:
In [ ]: