%matplotlib inline
import pandas as pd

"""
Explanation: Real-world data in a few minutes with Google Science Journal
Author: Fernando Perez (@fperez_org).
Using an Android phone and Google's new Science Journal app, it's very easy to collect real-world data. 
The first thing I did was to try their basic light example, using the phone's light sensor. I recorded for a few seconds moving my phone under a lamp, this is what the app shows:

Let's see how we can get a bit more detail with just a few lines of code.
From within the app, it takes just a couple of taps to export the data to a CSV file and put it on dropbox, from where we can pick it up with the computer and continue our experiments here.
End of explanation
"""


fname = "Untitled Experiment Trial 1.csv"
!head "$fname"

"""
Explanation: Let's have a quick peek at the data, it's always a good idea to do this, to know how to best load it:
End of explanation
"""


tc = lambda x: int(x)-1463893627134
df = pd.read_csv(fname, index_col=0, converters={0:tc}, names=["time", "lux"], header=0)
df.head()

"""
Explanation: OK, the timestamps look like miliseconds from the epoch.  
For convenience, we'll subtract the first timestamp from all of them to get 0-offset data (basically setting our "laboratory clock" at $t=0$ for data collection).  This is done by the tc function below, applied to column 0 in converters.
We can also ask Pandas to use the time directly as our data index (index_col=0) and we'll name the columns ourselves, by providing the column names and asking it to skip the header (header=0):
End of explanation
"""


df.describe()

"""
Explanation: Now let's get some quick summary statistics on the data:
End of explanation
"""


df.plot(logy=True);

"""
Explanation: This already gives us more detail that Google does (cf screenshot above), as we have more precise min/max/average values, as well as extra statistics.
We can also plot the data, but because of the sharp variation in the intensity, the linear scale provided by the app isn't too informative, a log y scale will be much more useful:
End of explanation
"""


