Skip to content

Receiver removal during localization crashes in edge cases #1207

@rhine3

Description

@rhine3

I found a bug that happens when receivers are removed from localization at both of these steps:

  • (1) A receiver is removed due to its audio file being shorter than the requested time window, then
  • (2) A second receiver is removed due to not meeting the cross-correlation max threshold

OPSO crashes for two reasons when this happens:

First, this line fails:

receiver_files=self.receiver_files[rec_mask],

Because self.receiver_files isn't cast as a numpy array when we delete receivers in step (1):

Producing this error:

Traceback (most recent call last):
  File "/ix/jkitzes/ter38/alberta/1_test_parameters/C_localization/0_localize_test_source_sep.py", line 195, in <module>
    events = array.localize_detections(
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/opensoundscape/localization/synchronized_recorder_array.py", line 260, in localize_detections
    position_estimates = localize_events_parallel(
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/opensoundscape/localization/spatial_event.py", line 505, in localize_events_parallel
    return Parallel(n_jobs=num_workers)(
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/joblib/parallel.py", line 1986, in __call__
    return output if self.return_generator else list(output)
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/joblib/parallel.py", line 1914, in _get_sequential_output
    res = func(*args, **kwargs)
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/opensoundscape/localization/spatial_event.py", line 162, in estimate_location
    return self._localize_after_cross_correlation(
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/opensoundscape/localization/spatial_event.py", line 363, in _localize_after_cross_correlation
    receiver_files=self.receiver_files[rec_mask],
TypeError: only integer scalar arrays can be converted to a scalar index

Second, this line fails because self.receiver_start_time_offsets still contains the offset from the additional receiver removed in step (1)

receiver_start_time_offsets=self.receiver_start_time_offsets[rec_mask],

Producing this error:

Traceback (most recent call last):
  File "/ix/jkitzes/ter38/alberta/1_test_parameters/C_localization/0_localize_test_source_sep.py", line 195, in <module>
    events = array.localize_detections(
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/opensoundscape/localization/synchronized_recorder_array.py", line 260, in localize_detections
    position_estimates = localize_events_parallel(
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/opensoundscape/localization/spatial_event.py", line 506, in localize_events_parallel
    return Parallel(n_jobs=num_workers)(
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/joblib/parallel.py", line 1986, in __call__
    return output if self.return_generator else list(output)
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/joblib/parallel.py", line 1914, in _get_sequential_output
    res = func(*args, **kwargs)
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/opensoundscape/localization/spatial_event.py", line 162, in estimate_location
    return self._localize_after_cross_correlation(
  File "/bgfs/jkitzes/ter38/.conda/envs/opso-0.12.0/lib/python3.10/site-packages/opensoundscape/localization/spatial_event.py", line 369, in _localize_after_cross_correlation
    receiver_start_time_offsets=self.receiver_start_time_offsets[rec_mask],
IndexError: boolean index did not match indexed array along dimension 0; dimension is 5 but corresponding boolean dimension is 4

To fix this, we remove the extra receiver from self.receiver_start_time_offsets in the same place that the bug from above is fixed, too - where we remove the bad receivers from self.receiver_files and self.receiver_locations.

I tested both of these fixes and they solve my issues - I'll submit a PR with the fixes shortly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions