Skip to content

Commit

Permalink
isort+black
Browse files Browse the repository at this point in the history
  • Loading branch information
morriscb committed Aug 21, 2023
1 parent b950704 commit 584144c
Show file tree
Hide file tree
Showing 6 changed files with 830 additions and 644 deletions.
24 changes: 12 additions & 12 deletions allensdk/brain_observatory/behavior/behavior_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def from_json(
path=session_data["stim_table_file"],
behavior_session_id=session_data["behavior_session_id"],
exclude_columns=stimulus_presentation_exclude_columns,
trials=trials
trials=trials,
),
templates=Templates.from_stimulus_file(
stimulus_file=stimulus_file_lookup.behavior_stimulus_file
Expand Down Expand Up @@ -358,7 +358,7 @@ def from_lims(
date_of_acquisition: Optional[DateOfAcquisition] = None,
eye_tracking_z_threshold: float = 3.0,
eye_tracking_dilation_frames: int = 2,
load_stimulus_movie: bool = True
load_stimulus_movie: bool = True,
) -> "BehaviorSession":
"""
Expand Down Expand Up @@ -454,7 +454,7 @@ def from_lims(
project_code=ProjectCode.from_lims(
behavior_session_id=behavior_session_id.value, lims_db=lims_db
),
load_stimulus_movie=load_stimulus_movie
load_stimulus_movie=load_stimulus_movie,
)

if date_of_acquisition is None:
Expand Down Expand Up @@ -1115,8 +1115,10 @@ def stimulus_presentations(self) -> pd.DataFrame:
table = table.drop(columns=["image_set", "index"], errors="ignore")
table = table.rename(columns={"stop_time": "end_time"})

if "trials_id" not in table.columns \
and 'stimulus_block' in table.columns:
if (
"trials_id" not in table.columns
and "stimulus_block" in table.columns
):
table["trials_id"] = compute_trials_id_for_stimulus(
table, self.trials
)
Expand Down Expand Up @@ -1173,9 +1175,7 @@ def stimulus_natural_movie_template(self) -> Optional[pd.DataFrame]:
if self._stimuli.templates.fingerprint_movie_template_key is not None:
return self._stimuli.templates.value[
self._stimuli.templates.fingerprint_movie_template_key
].to_dataframe(
index_name='frame_number',
index_type='int')
].to_dataframe(index_name="frame_number", index_type="int")
else:
return None

Expand Down Expand Up @@ -1413,7 +1413,7 @@ def _read_stimuli(
trials: Trials,
stimulus_presentation_columns: Optional[List[str]] = None,
project_code: Optional[ProjectCode] = None,
load_stimulus_movie: bool = False
load_stimulus_movie: bool = False,
) -> Stimuli:
"""
Construct the Stimuli data object for this session
Expand All @@ -1432,7 +1432,7 @@ def _read_stimuli(
presentation_columns=stimulus_presentation_columns,
project_code=project_code,
trials=trials,
load_stimulus_movie=load_stimulus_movie
load_stimulus_movie=load_stimulus_movie,
)

@classmethod
Expand Down Expand Up @@ -1512,7 +1512,7 @@ def _read_data_from_stimulus_file(
include_stimuli: bool = True,
stimulus_presentation_columns: Optional[List[str]] = None,
project_code: Optional[ProjectCode] = None,
load_stimulus_movie: bool = False
load_stimulus_movie: bool = False,
):
"""Helper method to read data from stimulus file"""

Expand Down Expand Up @@ -1549,7 +1549,7 @@ def _read_data_from_stimulus_file(
trials=trials,
stimulus_presentation_columns=stimulus_presentation_columns,
project_code=project_code,
load_stimulus_movie=load_stimulus_movie
load_stimulus_movie=load_stimulus_movie,
)
else:
stimuli = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(
columns_to_rename: Optional[Dict[str, str]] = None,
column_list: Optional[List[str]] = None,
sort_columns: bool = True,
trials: Optional[Trials] = None
trials: Optional[Trials] = None,
):
"""
Expand Down Expand Up @@ -102,13 +102,11 @@ def __init__(
if "active" not in presentations.columns:
# Add column marking where the mouse is engaged in active,
# trained behavior.
presentations = add_active_flag(
presentations, trials.data
)
presentations = add_active_flag(presentations, trials.data)
if "trials_id" not in presentations.columns:
# Add trials_id to presentations df to allow for joining of the
# two tables.
presentations['trials_id'] = compute_trials_id_for_stimulus(
presentations["trials_id"] = compute_trials_id_for_stimulus(
presentations, trials.data
)
if "is_sham_change" not in presentations.columns:
Expand Down Expand Up @@ -271,9 +269,9 @@ def from_nwb(
if add_trials_dependent_values and nwbfile.trials is not None:
trials = Trials.from_nwb(nwbfile)

return Presentations(presentations=table,
column_list=column_list,
trials=trials)
return Presentations(
presentations=table, column_list=column_list, trials=trials
)

@classmethod
def from_stimulus_file(
Expand Down Expand Up @@ -324,7 +322,8 @@ def from_stimulus_file(
)
raw_stim_pres_df = raw_stim_pres_df.drop(columns=["index"])
raw_stim_pres_df = cls._check_for_errant_omitted_stimulus(
input_df=raw_stim_pres_df)
input_df=raw_stim_pres_df
)

# Fill in nulls for image_name
# This makes two assumptions:
Expand Down Expand Up @@ -428,9 +427,7 @@ def from_stimulus_file(
)

return Presentations(
presentations=stim_pres_df,
column_list=column_list,
trials=trials
presentations=stim_pres_df, column_list=column_list, trials=trials
)

@classmethod
Expand All @@ -441,7 +438,7 @@ def from_path(
exclude_columns: Optional[List[str]] = None,
columns_to_rename: Optional[Dict[str, str]] = None,
sort_columns: bool = True,
trials: Optional[Trials] = None
trials: Optional[Trials] = None,
) -> "Presentations":
"""
Reads the table directly from a precomputed csv
Expand Down Expand Up @@ -578,7 +575,7 @@ def _postprocess(

@staticmethod
def _check_for_errant_omitted_stimulus(
input_df: pd.DataFrame
input_df: pd.DataFrame,
) -> pd.DataFrame:
"""Check if the first entry in the DataFrame is an omitted stimulus.
Expand Down
Loading

0 comments on commit 584144c

Please sign in to comment.