assign_chirps
Assign chirps detected on a spectrogram to wavetracker tracks.
ChirpAssignmentData
Bases: BaseModel
Data needed for chirp assignment.
Source code in chirpdetector/assign_chirps.py
assign_chirps(ad, chirp_df, data)
Assign chirps to wavetracker tracks.
This function uses the extracted envelope troughs to assign chirps to tracks. It computes a cost function that is high when the trough prominence is high and the distance to the chirp center is low. For each chirp, the track with the highest cost function value is chosen.
Parameters
assign_data
:dict
Dictionary containing the data needed for assignmentchirp_df
:pd.dataframe
Dataframe containing the chirp bboxesdata
:gridtools.datasets.Dataset
Dataset object containing the data
Source code in chirpdetector/assign_chirps.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
|
assign_cli(path)
Assign chirps to wavetracker tracks.
this is the command line interface for the assign_chirps function.
Parameters
path
:pathlib.path
path to the directory containing the chirpdetector.toml file
Source code in chirpdetector/assign_chirps.py
clean_bboxes(data, chirp_df)
Clean up the chirp bboxes.
This is a collection of filters that remove bboxes that either overlap, are out of range or otherwise do not make sense.
Parameters
data
:gridtools.datasets.Dataset
Dataset object containing the datachirp_df
:pd.dataframe
Dataframe containing the chirp bboxes
Returns
chirp_df_tf
:pd.dataframe
Dataframe containing the chirp bboxes that overlap with the range
Source code in chirpdetector/assign_chirps.py
extract_assignment_data(data, chirp_df)
Get envelope troughs to determine chirp assignment.
This algorigthm assigns chirps to wavetracker tracks by a series of steps:
- clean the chirp bboxes
- for each fish track, filter the signal on the best electrode
- find troughs in the envelope of the filtered signal
- compute the prominence of the trough and the distance to the chirp center
- compute a cost function that is high when the trough prominence is high and the distance to the chirp center is low
- compare the value of the cost function for each track and choose the track with the highest cost function value
Parameters
data
:dataset
Dataset object containing the datachirp_df
:pd.dataframe
Dataframe containing the chirp bboxes
Source code in chirpdetector/assign_chirps.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
|
extract_envelope_trough(data, best_electrode, second_best_electrode, best_freq, indices)
Extract envelope troughs.
Extracts a snippet from the raw data around the chirp time and computes the envelope of the bandpass filtered signal. Then finds the troughs in the envelope and computes their prominences.
Parameters
data
:gridtools.datasets.Dataset
Dataset object containing the databest_electrode
:int
Index of the best electrodesecond_best_electrode
:int
Index of the second best electrodebest_freq
:float
Frequency of the chirpindices
:Tuple[int, int, int]
Tuple containing the start, center, stop indices of the chirp
Returns
peaks
:np.ndarray
Indices of the envelope troughsproms
:np.ndarray
Prominences of the envelope troughsenv
:np.ndarray
Envelope of the filtered signal
Source code in chirpdetector/assign_chirps.py
make_chirp_indices_on_raw_data(chirp_df, data, idx, chirp)
Make indices for the chirp window.
Parameters
chirp_df
:pd.dataframe
Dataframe containing the chirp bboxesdata
:gridtools.datasets.Dataset
Dataset object containing the dataidx
:int
Index of the chirp in the chirp_dfchirp
:float
Chirp time
Returns
start_idx
:int
Start index of the chirp windowstop_idx
:int
Stop index of the chirp windowcenter_idx
:int
Center index of the chirp window
Source code in chirpdetector/assign_chirps.py
non_max_suppression_fast(chirp_df, overlapthresh)
Faster implementation of non-maximum suppression.
To remove overlapping bounding boxes. Is a slightly modified version of https://pyimagesearch.com/2015/02/16/faster-non-maximum-suppression-python/ .
Parameters
chirp_df
:pd.dataframe
Dataframe containing the chirp bboxesoverlapthresh
:float
Threshold for overlap between bboxes
Returns
pick
:list
List of indices of bboxes to keep
Source code in chirpdetector/assign_chirps.py
remove_bboxes_outside_range(chirp_dataframe, min_frequency, max_frequency)
Remove chirp bboxes that do not overlap with frequency tracks.
Parameters
chirp_dataframe
:pd.dataframe
Dataframe containing the chirp bboxesmin_frequency
:float
Minimum frequency of the rangemax_frequency
:float
Maximum frequency of the range
Returns
pd.dataframe
Dataframe containing the chirp bboxes that overlap with the range