-
Notifications
You must be signed in to change notification settings - Fork 149
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
Ticket/2594/dev #2609
Ticket/2594/dev #2609
Changes from all commits
73db183
9378347
19bc3bc
92b1629
cbc6a75
6b61dea
656d617
97fe065
6cb56d0
03ac5a7
25c055d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
import warnings | ||
from collections.abc import Collection | ||
from collections import defaultdict | ||
from collections.abc import Collection | ||
from typing import Optional | ||
|
||
import xarray as xr | ||
import numpy as np | ||
import pandas as pd | ||
import scipy.stats | ||
import xarray as xr | ||
|
||
from allensdk.core.lazy_property import LazyPropertyMixin | ||
from allensdk.core.utilities import literal_col_eval, df_list_to_tuple | ||
from allensdk.brain_observatory.ecephys.ecephys_session_api import ( | ||
EcephysSessionApi, | ||
EcephysNwbSessionApi, | ||
EcephysNwb1Api) | ||
EcephysNwb1Api, | ||
EcephysNwbSessionApi, | ||
EcephysSessionApi, | ||
) | ||
from allensdk.brain_observatory.ecephys.stimulus_table import naming_utilities | ||
from allensdk.brain_observatory.ecephys.stimulus_table._schemas import ( | ||
default_column_renames, | ||
default_stimulus_renames, | ||
default_column_renames) | ||
) | ||
from allensdk.core.lazy_property import LazyPropertyMixin | ||
|
||
# stimulus_presentation column names not describing a parameter of a stimulus | ||
NON_STIMULUS_PARAMETERS = tuple([ | ||
|
@@ -356,16 +359,17 @@ def get_current_source_density(self, probe_id): | |
Returns | ||
------- | ||
xr.DataArray : | ||
dimensions are channel (id) and time (seconds, relative to stimulus | ||
onset). Values are current source density assessed on that | ||
channel at that time (V/m^2) | ||
dimensions are channel (id) and time (seconds, relative to | ||
stimulus onset). Values are current source density assessed | ||
on that channel at that time (V/m^2) | ||
|
||
""" | ||
|
||
return self.api.get_current_source_density(probe_id) | ||
|
||
def get_lfp(self, probe_id, mask_invalid_intervals=True): | ||
''' Load an xarray DataArray with LFP data from channels on a single probe | ||
''' Load an xarray DataArray with LFP data from channels on a | ||
single probe | ||
|
||
Parameters | ||
---------- | ||
|
@@ -979,8 +983,8 @@ def get_parameter_values_for_stimulus( | |
self, | ||
stimulus_name, | ||
drop_nulls=True): | ||
""" For each stimulus parameter, report the unique values taken on by that | ||
parameter while a named stimulus was presented. | ||
""" For each stimulus parameter, report the unique values taken | ||
on by that parameter while a named stimulus was presented. | ||
|
||
Parameters | ||
---------- | ||
|
@@ -1004,8 +1008,8 @@ def get_stimulus_parameter_values( | |
self, | ||
stimulus_presentation_ids=None, | ||
drop_nulls=True): | ||
''' For each stimulus parameter, report the unique values taken on by that | ||
parameter throughout the course of the session. | ||
''' For each stimulus parameter, report the unique values taken | ||
on by that parameter throughout the course of the session. | ||
|
||
Parameters | ||
---------- | ||
|
@@ -1036,7 +1040,6 @@ def get_stimulus_parameter_values( | |
|
||
non_null = np.array(uniques[uniques != "null"]) | ||
non_null = non_null | ||
non_null = np.sort(non_null) | ||
|
||
if not drop_nulls and "null" in uniques: | ||
non_null = np.concatenate([non_null, ["null"]]) | ||
|
@@ -1124,12 +1127,29 @@ def _build_stimulus_presentations( | |
# pandas groupby ops ignore nans, so we need a new "nonapplicable" | ||
# value that pandas does not recognize as null ... | ||
stimulus_presentations.replace("", nonapplicable, inplace=True) | ||
stimulus_presentations.fillna(nonapplicable, inplace=True) | ||
|
||
stimulus_presentations['duration'] = \ | ||
stimulus_presentations['stop_time'] - \ | ||
stimulus_presentations['start_time'] | ||
|
||
# pandas does not automatically convert boolean cols for fillna | ||
boolean_colnames = stimulus_presentations.dtypes[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pandas 1.1 introduced I also don't know what the use case is here, but I'm surprised we want to group by a missing key There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call with the dropna. Although this would require a refactor since several parts of the code and notebook refer to the NA value as 'null'. I changed those to check for nan instead. Some of these old files can require a good amount of linting once they're touched. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, after doing more testing, I discovered one cell of the notebook had a change in results. Apparently, there's an unresolved pandas bug with dropna in the groupby function when used with MultiIndex groupings. pandas-dev/pandas#36470 I reverted everything back to 'null' |
||
stimulus_presentations.dtypes == "boolean"].index | ||
col_type_map = {colname: "object" for colname in boolean_colnames} | ||
stimulus_presentations = stimulus_presentations.astype( | ||
col_type_map).fillna(nonapplicable) | ||
mikejhuang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# eval str(numeric) and str(lists) | ||
# convert lists to tuple for hashability | ||
# Rationale: pd dataframe reads values as str from nwb files | ||
# where they are expected to be float | ||
col_list = ["phase, size, spatial_frequency"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the logic here to eval/tuple by specifying columns instead of creating rules. |
||
stimulus_presentations = literal_col_eval( | ||
stimulus_presentations, | ||
columns=col_list) | ||
stimulus_presentations = df_list_to_tuple( | ||
stimulus_presentations, | ||
columns=col_list) | ||
stimulus_presentations["duration"] = ( | ||
stimulus_presentations["stop_time"] | ||
- stimulus_presentations["start_time"] | ||
) | ||
# TODO: database these | ||
stimulus_conditions = {} | ||
presentation_conditions = [] | ||
|
@@ -1241,7 +1261,10 @@ def _build_mean_waveforms(self, mean_waveforms): | |
|
||
channel_id_lut = defaultdict(lambda: -1) | ||
for cid, row in self.channels.iterrows(): | ||
channel_id_lut[(row["local_index"], row["probe_id"])] = cid | ||
channel_id_lut[( | ||
row["probe_channel_number"], | ||
row["probe_id"], | ||
)] = cid | ||
|
||
probe_id_lut = { | ||
uid: row['probe_id'] for uid, row in self._units.iterrows() | ||
|
@@ -1438,7 +1461,8 @@ def is_distinct_from(left, right): | |
|
||
|
||
def array_intervals(array): | ||
""" find interval bounds (bounding consecutive identical values) in an array | ||
""" find interval bounds (bounding consecutive identical values) | ||
in an array | ||
|
||
Parameters | ||
----------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this function to utilities.py and removed the default values for columns