Skip to content

Commit 20becc2

Browse files
author
Brian Jones
committed
attempt to fix changes. failing locally on dataframe compare because of issues how pandas versions set types
1 parent f2cb1ab commit 20becc2

7 files changed

Lines changed: 30 additions & 21 deletions

File tree

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extracts from OTN.
99
Abacus Plot
1010
-----------
1111

12-
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.
12+
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`` (or `dateCollectedUTC` ~ for the new extract format) is used as the x axis. ``color_column`` is used to group detections together and assign them a color.
1313

1414

1515

resonate/determine_format.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,22 @@ def detect(dataframe: pd.DataFrame) -> dict:
3131
"col_longitude": "decimalLongitude",
3232
"col_latitude": "decimalLatitude",
3333
"col_station": "station",
34-
"col_catalognumber": "catalogNumber"},
34+
"col_catalognumber": "catalogNumber",
35+
"col_unique_id": "unqDetecID"},
3536
{ "col_datecollected": "datecollected",
3637
"col_longitude": "longitude",
3738
"col_latitude": "latitude",
3839
"col_station": "station",
39-
"col_catalognumber": "catalognumber"}
40+
"col_catalognumber": "catalognumber",
41+
"col_unique_id": "unqdetecid",},
42+
{"col_datecollected": 'datecollected',
43+
"col_fieldnumber": 'fieldnumber',
44+
"col_scientificname": "scientificname",
45+
"col_station":"station",
46+
'col_latitude' :'latitude',
47+
'col_longitude': 'longitude'},
48+
{"col_catalognumber":"catalognumber",
49+
"col_station":"station"}
4050
]
4151

4252
columns = dataframe.columns

resonate/interval_data_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
def interval_data(compressed_df: pd.DataFrame, dist_matrix_df: pd.DataFrame, station_radius_df: pd.DataFrame=None, col_catalognumber:str='catalogNumber',
6-
col_station:str='station'):
6+
col_station:str='station', **kwargs):
77
"""Creates a detection interval file from a compressed detection, distance matrix and station detection radius DataFrames
88
99
Args:

resonate/residence_index.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ def get_days(dets: pd.DataFrame, calculation_method='kessel'):
178178
return days
179179

180180

181-
def get_station_location(station: str, detections: pd.DataFrame, col_catalognumber:str='catalogNumber',
182-
col_station:str='station', col_latitude:str='decimalLatitude', col_longitude:str='decimalLongitude',
183-
col_datecollected:str='dateCollectedUTC', col_unique_id:str='unqDetecID'):
181+
def get_station_location(station: str, detections: pd.DataFrame,
182+
col_station:str='station', col_latitude:str='decimalLatitude', col_longitude:str='decimalLongitude'):
184183
"""Returns the longitude and latitude of a station/receiver given the station
185184
and the table name.
186185
@@ -366,7 +365,7 @@ def residency_index(detections: pd.DataFrame, calculation_method='kessel', col_c
366365
for station in dets[col_station].unique():
367366
st_dets = pd.DataFrame(dets[dets[col_station] == station])
368367
total = get_days(st_dets.copy(), calculation_method)
369-
location = get_station_location(station, detections)
368+
location = get_station_location(station, detections, col_longitude=col_longitude, col_station=col_station, col_latitude=col_latitude)
370369
# Determine the RI and add the station to the list
371370
station_dict = {
372371
'days_detected': total,

tests/rei_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pandas.testing as pt
66
from colorama import Fore as c
77
from resonate.receiver_efficiency import REI
8-
8+
from resonate.determine_format import detect
99

1010
class REITest(unittest.TestCase):
1111

@@ -15,7 +15,7 @@ def test_rei(self):
1515
detections = pd.read_csv('tests/assertion_files/hfx_detections.csv')
1616
deployments = pd.read_csv('tests/assertion_files/hfx_deployments.csv')
1717

18-
dfa = REI(detections, deployments)
18+
dfa = REI(detections, deployments, **detect(detections))
1919
dfb = pd.read_csv('tests/assertion_files/hfx_rei.csv')
2020
pt.assert_frame_equal(dfa, dfb)
2121
print(c.GREEN + 'OK!\n' + c.RESET)

tests/residence_index_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import pandas.testing as pt
66
import resonate.residence_index as ri
77
from colorama import Fore as c
8-
8+
from resonate.determine_format import detect
99

1010
class ResidenceIndexTest(unittest.TestCase):
1111

1212
def test_kessel(self):
1313
print(c.YELLOW + 'Testing Kessel RI...' + c.RESET)
14-
dfa = ri.residency_index(pd.read_csv(
15-
'tests/assertion_files/nsbs.csv'), calculation_method='kessel')
14+
input_file = pd.read_csv('tests/assertion_files/nsbs.csv')
15+
dfa = ri.residency_index(input_file, calculation_method='kessel', **detect(input_file))
1616
dfb = pd.read_csv('tests/assertion_files/nsbs_kessel_ri.csv')
1717
dfa.sort_values(['station', 'days_detected'], inplace=True)
1818
dfb.sort_values(['station', 'days_detected'], inplace=True)
@@ -23,8 +23,8 @@ def test_kessel(self):
2323

2424
def test_timedelta(self):
2525
print(c.YELLOW + 'Testing Timedelta RI...' + c.RESET)
26-
dfa = ri.residency_index(pd.read_csv(
27-
'tests/assertion_files/nsbs.csv'), calculation_method='timedelta')
26+
input_file = pd.read_csv('tests/assertion_files/nsbs.csv')
27+
dfa = ri.residency_index(input_file, calculation_method='timedelta', **detect(input_file))
2828
dfb = pd.read_csv('tests/assertion_files/nsbs_timedelta_ri.csv')
2929
dfa.sort_values(['station', 'days_detected'], inplace=True)
3030
dfb.sort_values(['station', 'days_detected'], inplace=True)
@@ -35,8 +35,8 @@ def test_timedelta(self):
3535

3636
def test_aggregate_with_overlap(self):
3737
print(c.YELLOW + 'Testing Aggregate With Overlap RI...' + c.RESET)
38-
dfa = ri.residency_index(pd.read_csv(
39-
'tests/assertion_files/nsbs.csv'), calculation_method='aggregate_with_overlap')
38+
input_file = pd.read_csv('tests/assertion_files/nsbs.csv')
39+
dfa = ri.residency_index(input_file, calculation_method='aggregate_with_overlap',**detect(input_file))
4040
dfb = pd.read_csv(
4141
'tests/assertion_files/nsbs_aggregate_with_overlap_ri.csv')
4242
dfa.sort_values(['station', 'days_detected'], inplace=True)
@@ -48,8 +48,8 @@ def test_aggregate_with_overlap(self):
4848

4949
def test_aggregate_no_overlap(self):
5050
print(c.YELLOW + 'Testing Aggregate No Overlap RI...' + c.RESET)
51-
dfa = ri.residency_index(pd.read_csv(
52-
'tests/assertion_files/nsbs.csv'), calculation_method='aggregate_no_overlap')
51+
input_file = pd.read_csv('tests/assertion_files/nsbs.csv')
52+
dfa = ri.residency_index(input_file, calculation_method='aggregate_no_overlap',**detect(input_file))
5353
dfb = pd.read_csv(
5454
'tests/assertion_files/nsbs_aggregate_no_overlap_ri.csv')
5555
dfa.sort_values(['station', 'days_detected'], inplace=True)

tests/unqid_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class UniqueDetectionIdTest(unittest.TestCase):
1010

1111
def test_add_unqdetecid_file(self):
1212
print(c.YELLOW+'Testing Unique ID file...'+c.RESET)
13-
dfa = add_unqdetecid('tests/assertion_files/nsbs_nounq.csv')
13+
dfa = add_unqdetecid('tests/assertion_files/nsbs_nounq.csv', column_name="unqdetecid")
1414
dfb = pd.read_csv('tests/assertion_files/nsbs_unqid.csv')
1515
pt.assert_frame_equal(dfa, dfb, check_like=True)
1616
print( c.GREEN+'OK!\n'+c.RESET)
1717

1818
def test_add_unqdetecid_file(self):
1919
print( c.YELLOW+'Testing Unique ID DataFrame...'+c.RESET)
20-
dfa = add_unqdetecid(pd.read_csv('tests/assertion_files/nsbs_nounq.csv'))
20+
dfa = add_unqdetecid(pd.read_csv('tests/assertion_files/nsbs_nounq.csv'), column_name="unqdetecid")
2121
dfb =pd.read_csv('tests/assertion_files/nsbs_unqid.csv')
2222
pt.assert_frame_equal(dfa, dfb, check_like=True)
2323
print( c.GREEN+'OK!\n'+c.RESET)

0 commit comments

Comments
 (0)