# IPython session run with --pylab=inline; "import matplotlib.pyplot as plt" was run during startup import pandas as pd # ERDDAP data request URL's (decided in advance), selecting only a subset of variables # Each request returns a csv table with 2 header rows: variable names and units willdet_url = "http://MYSERVER/erddap/tabledap/otnnepWILLDetects.csv?time,transmittername,platform_name,platform_latitude,platform_longitude" antag_url = "http://MYSERVER/erddap/tabledap/otnnepAnTags.csv?transmittername,vernacularname,project_reference" # read detection data from "will" receivers (Willapa Bay) into pandas dataframe willdet = pd.read_csv(willdet_url, skiprows=[1], parse_dates=['time']) # read all animal tags into pandas dataframe antag = pd.read_csv(antag_url, skiprows=[1]) # create month variable on will det, then merge the two dataframes willdet['month'] = willdet['time'].apply(lambda dt: dt.month) willdetantag = pd.merge(willdet, antag, how='left') willdetantag # create new dataframe where records without an identified tagging project are removed d = willdetantag[willdetantag.project_reference.notnull()] d.vernacularname.value_counts() # total number of detections, by tagging project d.project_reference.value_counts() # aggregate (count) detections by calendar month (1-12), and split off by tagging project dvogl = d[d.project_reference=='VOGL'].groupby('month').time.count() dlind = d[d.project_reference=='LIND'].groupby('month').time.count() dmoser = d[d.project_reference=='MOSER'].groupby('month').time.count() dvogl # plot number of detected Vogl tags vs month (plotted independently of year) dvogl.plot() # now compare the number of detected tags vs month (independent of year), for each of the 3 tagging projects # blue line is Vogl (same plot as above) plt.plot(dvogl.index,dvogl.values,'b-', dlind.index,dlind.values,'r-', dmoser.index,dmoser.values,'g-')