Skip to content

Commit 0ff55d5

Browse files
author
Brian Jones
committed
update abacus_plot to work with any format of detection file
1 parent d207de9 commit 0ff55d5

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

py_notebooks/abacus_plot.ipynb

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,23 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Abacus Plot\n",
7+
"# 📈 Abacus Plot\n",
88
"\n",
9-
"The abacus plot is a way to plot annimal along time. The function uses Plotly to place your points on a scatter plot. ``ycolumn`` is used as the y axis and ``datecollected`` is used as the x axis. ``color_column`` is used to group detections together and assign them a color.\n",
10-
"\n",
11-
"<span style=\"color:red\">Warning:</span> \n",
12-
"\n",
13-
" Input files must include ``datecollected`` as a column."
9+
"The abacus plot is a way to plot annimal along time. The function uses Plotly to place your points on a scatter plot. ``ycolumn`` is used as the y axis and ``datecollected`` is used as the x axis. ``color_column`` is used to group detections together and assign them a color."
1410
]
1511
},
1612
{
1713
"cell_type": "code",
1814
"execution_count": null,
19-
"metadata": {
20-
"collapsed": true
21-
},
15+
"metadata": {},
2216
"outputs": [],
2317
"source": [
2418
"from resonate.abacus_plot import abacus_plot\n",
2519
"import pandas as pd\n",
2620
"\n",
27-
"df = pd.read_csv('/path/to/detections.csv')"
21+
"df = pd.read_csv('/path/to/detections.csv') # read csv\n",
22+
"# or\n",
23+
"# df = pd.read_parquet('/path/to/detections.parquet') # parquet file"
2824
]
2925
},
3026
{
@@ -40,7 +36,7 @@
4036
"metadata": {},
4137
"outputs": [],
4238
"source": [
43-
"abacus_plot(df, ycolumn='catalognumber', color_column='receiver_group')"
39+
"abacus_plot(df, date_column='dateCollectedUTC',ycolumn='catalogNumber', color_column='station', uniqueid_column='unqDetecID')"
4440
]
4541
},
4642
{
@@ -58,20 +54,11 @@
5854
"source": [
5955
"abacus_plot(df, ipython_display=False, filename='example.html')"
6056
]
61-
},
62-
{
63-
"cell_type": "code",
64-
"execution_count": null,
65-
"metadata": {
66-
"collapsed": true
67-
},
68-
"outputs": [],
69-
"source": []
7057
}
7158
],
7259
"metadata": {
7360
"kernelspec": {
74-
"display_name": "Python [default]",
61+
"display_name": "Python 3 (ipykernel)",
7562
"language": "python",
7663
"name": "python3"
7764
},
@@ -84,8 +71,8 @@
8471
"mimetype": "text/x-python",
8572
"name": "python",
8673
"nbconvert_exporter": "python",
87-
"pygments_lexer": "python",
88-
"version": "3.6.3"
74+
"pygments_lexer": "ipython3",
75+
"version": "3.9.21"
8976
},
9077
"varInspector": {
9178
"cols": {

resonate/abacus_plot.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from resonate.library.exceptions import GenericException
55

66

7-
def abacus_plot(detections: pd.DataFrame, ycolumn:str='catalognumber', color_column:str=None, ipython_display=True, title:str='Abacus Plot', filename:str=None):
7+
def abacus_plot(detections: pd.DataFrame, date_column='datecollected', uniqueid_column='unqdetecid',
8+
ycolumn:str='catalognumber', color_column:str=None, ipython_display=True, title:str='Abacus Plot', filename:str=None):
89
"""Creates a plotly abacus plot from a pandas dataframe
910
1011
Args:
@@ -31,14 +32,14 @@ def abacus_plot(detections: pd.DataFrame, ycolumn:str='catalognumber', color_col
3132
if not isinstance(detections, pd.DataFrame):
3233
raise GenericException('input parameter must be a Pandas dataframe')
3334

34-
mandatory_columns = set(['datecollected', ycolumn])
35+
mandatory_columns = set([date_column, ycolumn])
3536

3637
if color_column is not None:
3738
mandatory_columns.add(color_column)
3839

3940
if mandatory_columns.issubset(detections.columns):
4041

41-
detections = detections[~detections.unqdetecid.str.contains(
42+
detections = detections[~detections[uniqueid_column].str.contains(
4243
'release')].reset_index(drop=True)
4344

4445
if color_column is not None:
@@ -47,7 +48,7 @@ def abacus_plot(detections: pd.DataFrame, ycolumn:str='catalognumber', color_col
4748
for group in detections.groupby(color_column):
4849
data.append(
4950
{
50-
'x': group[1].datecollected.tolist(),
51+
'x': group[1][date_column].tolist(),
5152
'y': group[1][ycolumn].tolist(),
5253
'mode': 'markers',
5354
'name': group[0]
@@ -56,7 +57,7 @@ def abacus_plot(detections: pd.DataFrame, ycolumn:str='catalognumber', color_col
5657
else:
5758
data = [
5859
{
59-
'x': detections.datecollected.tolist(),
60+
'x': detections[date_column].tolist(),
6061
'y': detections[ycolumn].tolist(),
6162
'mode': 'markers',
6263
}
@@ -66,8 +67,8 @@ def abacus_plot(detections: pd.DataFrame, ycolumn:str='catalognumber', color_col
6667
title=title,
6768
xaxis=dict(
6869
autorange=False,
69-
range=[detections.datecollected.min(
70-
), detections.datecollected.max()]
70+
range=[detections[date_column].min(
71+
), detections[date_column].max()]
7172
),
7273
yaxis=dict(
7374
autorange=True

0 commit comments

Comments
 (0)