Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time budget analysis using observation time interval #832

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

florianduclot
Copy link
Contributor

This PR proposes to add an option in the Time budget analyses (with timebins or not) to use the observation's defined time interval as the time interval for the time budget analysis.

For instance, when tested with the following observations...

{'file': {'1': ['test_video.mp4'], '2': [], '3': [], '4': [], '5': [], '6': [], '7': [], '8': []}, 'type': 'MEDIA', 'date': '2025-02-20T15:27:51.580', 'description': '', 'time offset': Decimal('-10.0'), 'events': [[Decimal('0.667'), '', 'beh1', '', '', 160], [Decimal('3.400'), '', 'beh1', '', '', 201]], 'observation time interval': [10.0, 25.0], 'independent_variables': {}, 'visualize_spectrogram': False, 'visualize_waveform': False, 'media_creation_date_as_offset': False, 'media_scan_sampling_duration': 0, 'image_display_duration': 1, 'close_behaviors_between_videos': False, 'media_info': {'length': {'test_video.mp4': 600.6}, 'fps': {'test_video.mp4': 15.0}, 'hasVideo': {'test_video.mp4': True}, 'hasAudio': {'test_video.mp4': False}, 'offset': {'1': 0.0}}}

{'file': {'1': ['test_video.mp4'], '2': [], '3': [], '4': [], '5': [], '6': [], '7': [], '8': []}, 'type': 'MEDIA', 'date': '2025-02-20T18:17:24.824', 'description': '', 'time offset': Decimal('0.0'), 'events': [[Decimal('0.867'), '', 'beh1', '', '', 13], [Decimal('3.332'), '', 'beh1', '', '', 'NA'], [Decimal('3.333'), '', 'beh2', '', '', 50], [Decimal('5.867'), '', 'beh2', '', '', 88]], 'observation time interval': [0, 0], 'independent_variables': {}, 'visualize_spectrogram': False, 'visualize_waveform': False, 'media_creation_date_as_offset': False, 'media_scan_sampling_duration': 0, 'image_display_duration': 1, 'close_behaviors_between_videos': False, 'media_info': {'length': {'test_video.mp4': 600.6}, 'fps': {'test_video.mp4': 15.0}, 'hasVideo': {'test_video.mp4': True}, 'hasAudio': {'test_video.mp4': False}, 'offset': {'1': 0.0}}}

... with the following of interest...

{
'time offset': Decimal('-10.0'),
'events': [[Decimal('0.667'), '', 'beh1', '', '', 160], [Decimal('3.400'), '', 'beh1', '', '', 201]],
'observation time interval': [10.0, 25.0]
}

{
'time offset': Decimal('0.0'),
'events': [[Decimal('0.867'), '', 'beh1', '', '', 13], [Decimal('3.332'), '', 'beh1', '', '', 'NA'], [Decimal('3.333'), '', 'beh2', '', '', 50], [Decimal('5.867'), '', 'beh2', '', '', 88]],
'observation time interval': [0, 0]
}

... we end up with the following output (only select columns are pasted here, for clarity):

Subjects: No focal subject No focal subject No focal subject No focal subject
Behaviors: beh1 beh1 beh2 beh2
Observations id Total length (s) Time interval (s) Total duration Number of occurrences Total duration Number of occurrences
video1 15 0.000-15.000 2.733 1 0 0
video2 600.6 0.000-600.600 2.465 1 2.534 1

Note the first observation (video1) uses a different interval than the 2nd observation (video2). The latter was not created with a restricted time interval for the scoring.

A new radio button in created at the bottom of the dialog window:
image

When only 1 observation is selected, the start and end of the interval that was set during the creation of the observation is displayed:
image

If no time interval was used then, the display follows the same as if the "media duration" option was selected:
image

I thought I would upstream this change here in case it is of interest to you. I'm sorry for not asking first if such feature would interest you; I wanted to see if that was possible without too many changes, and ended up with what seems to be functional so far. I tried to run the pytest suite of tests, but it seems some of them were failing before hand so I'm not sure whether you are interested in updating these/adding coverage for the new bits. I'm not familiar with pytest or PySide, but I can have a look at adding that if required.

Thanks in advance for your time considering this PR.

Add a fourth time option for the time budget
analyses that uses the time interval defined in
the observation itself. If no time interval is
defined for some observations, use the media
duration instead.
@olivierfriard
Copy link
Owner

Hi Florian,

thank you for this PR. It is a good idea to implement this function.
I have to fix an error on your code before merging:

File "/home/olivier/projects/BORIS/boris/param_panel.py", line 96, in rb_time_interval_selection
   self.start_time.set_time(self.start_interval)
 File "/home/olivier/projects/BORIS/boris/dialog.py", line 412, in set_time
   self.pb_sign.setText("-" if new_time < 0 else "+")
                               ^^^^^^^^^^^^
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

@florianduclot
Copy link
Contributor Author

Thanks, @olivierfriard!

I apparently did not realize that this dialog window was so ubiquitous; my apologies. I should have tested a lot more than that. I have now fixed it for the following in the "Analysis" menu:

  • Time budget
  • Time budget by behavioral category
  • Synthetic time budget (already in the PR)
  • Synthetic time budget with time bins (already in PR)

If I'm correct, I would also need to update pretty much all other options in the Analysis menu, correct? From a quick search & glance, I see the following that would need updating:
advanced_event_filtering.py
behavior_binary_table.py
core.plot_events_triggered
core.behaviors_bar_plot
core.create_subtitles
export_events.export_events_as_behavioral_sequences
export_events.export_tabular_events
export_events.export_aggregated_events
export_events.export_events_as_text_grid
... as well as the 3 plugins.

Most instances of the select_subj_behav dialog window
were not able to process the observation intervals
as time interval. This commit implements this for all such instances.
@florianduclot
Copy link
Contributor Author

@olivierfriard,

I have now implemented this for all the instances calling this dialog window I could find by looking for the use of select_subj_behav.choose_obs_subj_behav_category(). I hope I didn't miss anything.
It really made me realize how much I missed in the first commit of this, sorry again about that botched one.

Hope it's in much better shape now. I touched many parts of BORIS I've never interacted with before, so I hope I didn't affect their original intent or functions. It still seems OK in my testing but I could miss something given I'm not that familiar with them.

Cheers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants