Loading py_notebooks/interval_data.ipynb +5 −0 Original line number Diff line number Diff line %% Cell type:markdown id: tags: # Interval Data <hr> ``interval_data()`` takes a compressed detections DataFrame, a distance matrix, and a detection radius DataFrame and creates an interval data DataFrame. Intervals are lengths of time in which a station detected an animal. Many consecutive detections of an animal are replaced by one interval. <span style="color:red">Warning:</span> Input files must include ``datecollected``, ``catalognumber``, and ``unqdetecid`` as columns. %% Cell type:code id: tags: ``` python from resonate.filters import get_distance_matrix from resonate.compress import compress_detections from resonate.interval_data_tool import interval_data import pandas as pd import geopy input_file = pd.read_csv("/path/to/detections.csv") compressed = compress_detections(input_file) matrix = get_distance_matrix(input_file) ``` %% Cell type:markdown id: tags: Set the station radius for each station name. %% Cell type:code id: tags: ``` python detection_radius = 400 station_det_radius = pd.DataFrame([(x, geopy.distance.Distance(detection_radius/1000.0)) for x in matrix.columns.tolist()], columns=['station','radius']) station_det_radius.set_index('station', inplace=True) station_det_radius ``` %% Cell type:markdown id: tags: You can modify individual stations if needed by using ``DatraFrame.set_value()`` from Pandas. %% Cell type:code id: tags: ``` python station_name = 'HFX001' station_detection_radius = 500 station_det_radius.at[station_name, 'radius'] = geopy.distance.Distance( station_detection_radius/1000.0 ) ``` %% Cell type:markdown id: tags: Create the interval data by passing the compressed detections, the matrix, and the station radii. %% Cell type:code id: tags: ``` python interval = interval_data(compressed_df=compressed, dist_matrix_df=matrix, station_radius_df=station_det_radius) interval ``` %% Cell type:markdown id: tags: You can use the Pandas `DataFrame.to_csv()` function to output the file to a desired location. %% Cell type:code id: tags: ``` python interval.to_csv('/path/to/output.csv', index=False) ``` %% Cell type:code id: tags: ``` python ``` tests/assertion_files/nsbs_interval.csv +142 −7584 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
py_notebooks/interval_data.ipynb +5 −0 Original line number Diff line number Diff line %% Cell type:markdown id: tags: # Interval Data <hr> ``interval_data()`` takes a compressed detections DataFrame, a distance matrix, and a detection radius DataFrame and creates an interval data DataFrame. Intervals are lengths of time in which a station detected an animal. Many consecutive detections of an animal are replaced by one interval. <span style="color:red">Warning:</span> Input files must include ``datecollected``, ``catalognumber``, and ``unqdetecid`` as columns. %% Cell type:code id: tags: ``` python from resonate.filters import get_distance_matrix from resonate.compress import compress_detections from resonate.interval_data_tool import interval_data import pandas as pd import geopy input_file = pd.read_csv("/path/to/detections.csv") compressed = compress_detections(input_file) matrix = get_distance_matrix(input_file) ``` %% Cell type:markdown id: tags: Set the station radius for each station name. %% Cell type:code id: tags: ``` python detection_radius = 400 station_det_radius = pd.DataFrame([(x, geopy.distance.Distance(detection_radius/1000.0)) for x in matrix.columns.tolist()], columns=['station','radius']) station_det_radius.set_index('station', inplace=True) station_det_radius ``` %% Cell type:markdown id: tags: You can modify individual stations if needed by using ``DatraFrame.set_value()`` from Pandas. %% Cell type:code id: tags: ``` python station_name = 'HFX001' station_detection_radius = 500 station_det_radius.at[station_name, 'radius'] = geopy.distance.Distance( station_detection_radius/1000.0 ) ``` %% Cell type:markdown id: tags: Create the interval data by passing the compressed detections, the matrix, and the station radii. %% Cell type:code id: tags: ``` python interval = interval_data(compressed_df=compressed, dist_matrix_df=matrix, station_radius_df=station_det_radius) interval ``` %% Cell type:markdown id: tags: You can use the Pandas `DataFrame.to_csv()` function to output the file to a desired location. %% Cell type:code id: tags: ``` python interval.to_csv('/path/to/output.csv', index=False) ``` %% Cell type:code id: tags: ``` python ```
tests/assertion_files/nsbs_interval.csv +142 −7584 File changed.Preview size limit exceeded, changes collapsed. Show changes