Skip to content

Commit

Permalink
Merge branch 'all_modifiers'
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierfriard committed Oct 7, 2024
2 parents 4a85ba9 + 7564dd4 commit 9acfa25
Show file tree
Hide file tree
Showing 28 changed files with 186 additions and 555 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dist
tests/output
boris_behav_obs.egg-info
.venv
uv.lock
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.12.3
3.12.6
4 changes: 2 additions & 2 deletions boris/advanced_event_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ def event_filtering(self):
start_coding=start_coding,
end_coding=end_coding,
maxTime=max_media_duration_all_obs,
flagShowIncludeModifiers=False,
flagShowExcludeBehaviorsWoEvents=False,
show_include_modifiers=False,
show_exclude_non_coded_behaviors=False,
by_category=False,
n_observations=len(selected_observations),
)
Expand Down
4 changes: 2 additions & 2 deletions boris/behavior_binary_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def behavior_binary_table(self):
start_coding=start_coding,
end_coding=end_coding,
maxTime=max_media_duration_all_obs,
flagShowIncludeModifiers=True,
flagShowExcludeBehaviorsWoEvents=True,
show_include_modifiers=True,
show_exclude_non_coded_behaviors=True,
by_category=False,
n_observations=len(selected_observations),
)
Expand Down
1 change: 1 addition & 0 deletions boris/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@
SELECTED_SUBJECTS = "selected subjects"
INCLUDE_MODIFIERS = "include modifiers"
EXCLUDE_BEHAVIORS = "exclude behaviors"
EXCLUDE_NON_CODED_MODIFIERS = "exclude_non_coded_modifiers"
EXCLUDED_BEHAVIORS = "excluded behaviors"
TIME_INTERVAL = "time"
START_TIME = "start time"
Expand Down
4 changes: 2 additions & 2 deletions boris/cooccurence.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def interval_len(interval: I) -> dec:
selected_observations,
window_title="Select the behaviors",
n_observations=len(selected_observations),
flagShowIncludeModifiers=False,
flagShowExcludeBehaviorsWoEvents=True,
show_include_modifiers=False,
show_exclude_non_coded_behaviors=True,
)

if parameters == {}: # cancel button pressed
Expand Down
12 changes: 6 additions & 6 deletions boris/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ def filter_behaviors(
"""

if not self.pj[cfg.ETHOGRAM]:
True, []
return True, []

behavior_type = [x.upper() for x in behavior_type]

Expand Down Expand Up @@ -2750,7 +2750,7 @@ def plot_events_triggered(self, mode: str = "list"):
start_coding=start_coding,
end_coding=end_coding,
maxTime=max_obs_length,
flagShowExcludeBehaviorsWoEvents=True,
show_exclude_non_coded_behaviors=True,
by_category=False,
n_observations=len(selected_observations),
)
Expand Down Expand Up @@ -2849,8 +2849,8 @@ def behaviors_bar_plot(self, mode: str = "list"):
start_coding=start_coding,
end_coding=end_coding,
maxTime=max_obs_length if len(selected_observations) > 1 else selectedObsTotalMediaLength,
flagShowIncludeModifiers=False,
flagShowExcludeBehaviorsWoEvents=True,
show_include_modifiers=False,
show_exclude_non_coded_behaviors=True,
n_observations=len(selected_observations),
)

Expand Down Expand Up @@ -3730,8 +3730,8 @@ def create_subtitles(self):
start_coding=start_coding,
end_coding=end_coding,
maxTime=max_media_duration_all_obs,
flagShowIncludeModifiers=False,
flagShowExcludeBehaviorsWoEvents=False,
show_include_modifiers=False,
show_exclude_non_coded_behaviors=False,
n_observations=len(selected_observations),
)
if parameters == {}:
Expand Down
2 changes: 2 additions & 0 deletions boris/db_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def load_events_in_db(
"""

db = sqlite3.connect(":memory:", isolation_level=None)

"""
import os
os.system("rm /tmp/ramdisk/events.sqlite")
Expand Down Expand Up @@ -212,6 +213,7 @@ def load_aggregated_events_in_db(
db = sqlite3.connect(":memory:")

"""
# only for debugging
import os
os.system("rm /tmp/ramdisk/aggreg.sqlite")
db = sqlite3.connect("/tmp/ramdisk/aggreg.sqlite", isolation_level=None)
Expand Down
10 changes: 5 additions & 5 deletions boris/event_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ def filter_events(self):
start_coding=dec("NaN"),
end_coding=dec("NaN"),
maxTime=None,
flagShowIncludeModifiers=False,
flagShowExcludeBehaviorsWoEvents=False,
show_include_modifiers=False,
show_exclude_non_coded_behaviors=False,
by_category=False,
)
if parameters == {}:
Expand Down Expand Up @@ -983,9 +983,9 @@ def add_frame_indexes(self):
continue
if not self.seek_mediaplayer(event[0]):
time.sleep(0.1)
self.pj[cfg.OBSERVATIONS][self.observationId][cfg.EVENTS][idx][
cfg.PJ_OBS_FIELDS[cfg.MEDIA][cfg.FRAME_INDEX]
] = self.get_frame_index()
self.pj[cfg.OBSERVATIONS][self.observationId][cfg.EVENTS][idx][cfg.PJ_OBS_FIELDS[cfg.MEDIA][cfg.FRAME_INDEX]] = (
self.get_frame_index()
)

self.seek_mediaplayer(mem_time)

Expand Down
9 changes: 4 additions & 5 deletions boris/events_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"""


import logging
import os
import pathlib as pl
Expand Down Expand Up @@ -80,8 +79,8 @@ def events_snapshots(self):
selected_observations,
start_coding=dec("NaN"),
end_coding=dec("NaN"),
flagShowIncludeModifiers=False,
flagShowExcludeBehaviorsWoEvents=False,
show_include_modifiers=False,
show_exclude_non_coded_behaviors=False,
n_observations=len(selected_observations),
)

Expand Down Expand Up @@ -346,8 +345,8 @@ def extract_events(self):
selected_observations,
start_coding=dec("NaN"),
end_coding=dec("NaN"),
flagShowIncludeModifiers=False,
flagShowExcludeBehaviorsWoEvents=False,
show_include_modifiers=False,
show_exclude_non_coded_behaviors=False,
)
if parameters == {}:
return
Expand Down
20 changes: 10 additions & 10 deletions boris/export_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def export_events_as_behavioral_sequences(self, separated_subjects=False, timed=
start_coding=start_coding,
end_coding=end_coding,
maxTime=max_media_duration_all_obs,
flagShowIncludeModifiers=True,
flagShowExcludeBehaviorsWoEvents=False,
show_include_modifiers=True,
show_exclude_non_coded_behaviors=False,
n_observations=len(selected_observations),
)

Expand Down Expand Up @@ -171,8 +171,8 @@ def export_tabular_events(self, mode: str = "tabular") -> None:
start_coding=start_coding,
end_coding=end_coding,
maxTime=max_media_duration_all_obs,
flagShowIncludeModifiers=False,
flagShowExcludeBehaviorsWoEvents=False,
show_include_modifiers=False,
show_exclude_non_coded_behaviors=False,
n_observations=len(selected_observations),
)
if parameters == {}:
Expand Down Expand Up @@ -283,7 +283,7 @@ def export_aggregated_events(self):
- select subjects and behaviors
- export events in aggregated format
Formats can be SQL (sql), SDIS (sds) or Tabular format (tsv, csv, ods, xlsx, xls, html)
Formats can be SQL (sql), SDIS (sds), Tabular format (tsv, csv, ods, xlsx, xls, html) or Pandas dataframe
"""

def fields_type(max_modif_number: int) -> dict:
Expand Down Expand Up @@ -366,14 +366,14 @@ def fields_type(max_modif_number: int) -> dict:
start_coding=start_coding,
end_coding=end_coding,
maxTime=max_media_duration_all_obs,
flagShowIncludeModifiers=False,
flagShowExcludeBehaviorsWoEvents=False,
show_include_modifiers=False,
show_exclude_non_coded_behaviors=False,
n_observations=len(selected_observations),
)
if parameters == {}:
return
if not parameters[cfg.SELECTED_SUBJECTS] or not parameters[cfg.SELECTED_BEHAVIORS]:
QMessageBox.warning(None, cfg.programName, "Select subject(s) and behavior(s) to analyze")
QMessageBox.warning(None, cfg.programName, "Select subject(s) and behavior(s) to export")
return

# check for grouping results
Expand Down Expand Up @@ -660,8 +660,8 @@ def export_events_as_textgrid(self) -> None:
selected_observations,
start_coding=start_coding,
end_coding=end_coding,
flagShowIncludeModifiers=False,
flagShowExcludeBehaviorsWoEvents=False,
show_include_modifiers=False,
show_exclude_non_coded_behaviors=False,
maxTime=max_obs_length,
n_observations=len(selected_observations),
)
Expand Down
2 changes: 1 addition & 1 deletion boris/export_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def dataset_write(dataset: tablib.Dataset, file_name: str, output_format: str, d
try:
if output_format in (cfg.PANDAS_DF_EXT, cfg.RDS_EXT):
# build pandas dataframe from the tsv export of tablib dataset
date_type = []
date_type: list = []
for field_name in dtype:
if dtype[field_name] == dt.datetime:
date_type.append(field_name)
Expand Down
8 changes: 4 additions & 4 deletions boris/irr.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ def irr_cohen_kappa(self):
selected_observations,
start_coding=dec("NaN"),
end_coding=dec("NaN"),
flagShowIncludeModifiers=True,
flagShowExcludeBehaviorsWoEvents=False,
show_include_modifiers=True,
show_exclude_non_coded_behaviors=False,
n_observations=len(selected_observations),
)
if parameters == {}:
Expand Down Expand Up @@ -581,8 +581,8 @@ def needleman_wunch(self):
selected_observations,
start_coding=dec("NaN"),
end_coding=dec("NaN"),
flagShowIncludeModifiers=True,
flagShowExcludeBehaviorsWoEvents=False,
show_include_modifiers=True,
show_exclude_non_coded_behaviors=False,
n_observations=len(selected_observations),
)

Expand Down
4 changes: 2 additions & 2 deletions boris/latency.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_latency(self):
parameters: dict = select_subj_behav.choose_obs_subj_behav_category(
self,
selected_observations,
flagShowExcludeBehaviorsWoEvents=False,
show_exclude_non_coded_behaviors=False,
window_title="Select the marker behaviors (stimulus)",
n_observations=len(selected_observations),
)
Expand All @@ -102,7 +102,7 @@ def get_latency(self):
print(f"{marker_behaviors=} {marker_subjects=} {include_marker_modifiers=}")

parameters: dict = select_subj_behav.choose_obs_subj_behav_category(
self, selected_observations, flagShowExcludeBehaviorsWoEvents=False, window_title="Select the latency behaviors"
self, selected_observations, show_exclude_non_coded_behaviors=False, window_title="Select the latency behaviors"
)
if not parameters[cfg.SELECTED_SUBJECTS] or not parameters[cfg.SELECTED_BEHAVIORS]:
return
Expand Down
11 changes: 10 additions & 1 deletion boris/param_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""


from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog

Expand Down Expand Up @@ -61,6 +60,16 @@ def __init__(self, parent=None):
self.rb_observed_events.clicked.connect(lambda: self.rb_time_interval_selection(cfg.TIME_EVENTS))
self.rb_user_defined.clicked.connect(lambda: self.rb_time_interval_selection(cfg.TIME_ARBITRARY_INTERVAL))

self.cbIncludeModifiers.stateChanged.connect(self.cb_exclude_non_coded_modifiers_visibility)

self.cb_exclude_non_coded_modifiers.setVisible(False)

def cb_exclude_non_coded_modifiers_visibility(self):
"""
set visibility of cb_exclude_non_coded_modifiers
"""
self.cb_exclude_non_coded_modifiers.setEnabled(self.cbIncludeModifiers.isChecked())

def rb_time_interval_selection(self, button):
"""
select the time interval for operation
Expand Down
10 changes: 10 additions & 0 deletions boris/param_panel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_exclude_non_coded_modifiers">
<property name="text">
<string>Exclude non coded modifiers</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbExcludeBehaviors">
<property name="text">
Expand Down
7 changes: 6 additions & 1 deletion boris/param_panel_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'boris/param_panel.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
Expand Down Expand Up @@ -64,6 +64,10 @@ def setupUi(self, Dialog):
self.cbIncludeModifiers = QtWidgets.QCheckBox(Dialog)
self.cbIncludeModifiers.setObjectName("cbIncludeModifiers")
self.horizontalLayout_9.addWidget(self.cbIncludeModifiers)
self.cb_exclude_non_coded_modifiers = QtWidgets.QCheckBox(Dialog)
self.cb_exclude_non_coded_modifiers.setChecked(True)
self.cb_exclude_non_coded_modifiers.setObjectName("cb_exclude_non_coded_modifiers")
self.horizontalLayout_9.addWidget(self.cb_exclude_non_coded_modifiers)
self.cbExcludeBehaviors = QtWidgets.QCheckBox(Dialog)
self.cbExcludeBehaviors.setObjectName("cbExcludeBehaviors")
self.horizontalLayout_9.addWidget(self.cbExcludeBehaviors)
Expand Down Expand Up @@ -177,6 +181,7 @@ def retranslateUi(self, Dialog):
self.pbUnselectAllBehaviors.setText(_translate("Dialog", "Unselect all"))
self.pbReverseBehaviorsSelection.setText(_translate("Dialog", "Reverse selection"))
self.cbIncludeModifiers.setText(_translate("Dialog", "Include modifiers"))
self.cb_exclude_non_coded_modifiers.setText(_translate("Dialog", "Exclude non coded modifiers"))
self.cbExcludeBehaviors.setText(_translate("Dialog", "Exclude behaviors without events"))
self.lb_time_bin_size.setText(_translate("Dialog", "Time bin size (s)"))
self.lb_time_interval.setText(_translate("Dialog", "Time interval"))
Expand Down
Loading

0 comments on commit 9acfa25

Please sign in to comment.