Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions .github/workflows/github-actions-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
name: Lint
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: flake8 linting
run: |
pip install flake8
Expand All @@ -43,28 +43,30 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["macos-latest", "windows-latest", "ubuntu-latest"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: ["ubuntu-latest"]
python-version: ["3.10", "3.13"]
include:
- os: "macos-latest"
python-version: "3.13"
- os: "windows-latest"
python-version: "3.13"
fail-fast: false
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
activate-environment: test-env
cache: pip
cache-dependency-path: |
requirements.txt
test_requirements.txt
- name: Install
run: |
conda activate test-env
pip install codecov
pip install -r test_requirements.txt
pip install .
- name: Test
run: |
py.test --cov=allensdk -n 4
python -m pytest -n 4 ${{ (matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13') && '--cov=allensdk' || '' }}

onprem:
name: python ${{ matrix.image }} on-prem test
Expand All @@ -73,7 +75,7 @@ jobs:
matrix:
image: ["allensdk_local_py38:latest"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: run test in docker
run: |
docker run \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
image: ["allensdk_local_py38:latest"]
branch: ["master", "rc/**"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
- name: run test in docker
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/notebook_runner.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
name: Notebooks
on:
pull_request:
push:
branches:
- master
jobs:
run_notebooks:
name: Notebook runner
strategy:
matrix:
os: ["ubuntu-latest"]
python-version: ["3.8"]
python-version: ["3.13"]
fail-fast: false
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest-8x
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
requirements.txt
dev_requirements.txt
notebook_requirements.txt
- name: Install
run: |
pip install -r requirements.txt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _get_ophys_session_table(self):
df = sanitize_data_columns(session_table_path, {"mouse_id": str})
# Add UTC to match DateOfAcquisition object.
df["date_of_acquisition"] = pd.to_datetime(
df["date_of_acquisition"], utc="True"
df["date_of_acquisition"], format="ISO8601", utc=True
)
df = enforce_df_int_typing(
input_df=df, int_columns=VBO_INTEGER_COLUMNS, use_pandas_type=True
Expand Down Expand Up @@ -217,7 +217,7 @@ def _get_behavior_session_table(self):
df = sanitize_data_columns(session_table_path, {"mouse_id": str})
# Add UTC to match DateOfAcquisition object.
df["date_of_acquisition"] = pd.to_datetime(
df["date_of_acquisition"], utc="True"
df["date_of_acquisition"], format="ISO8601", utc=True
)
df = enforce_df_int_typing(
input_df=df, int_columns=VBO_INTEGER_COLUMNS, use_pandas_type=True
Expand Down Expand Up @@ -252,7 +252,7 @@ def _get_ophys_experiment_table(self):
df = sanitize_data_columns(experiment_table_path, {"mouse_id": str})
# Add UTC to match DateOfAcquisition object.
df["date_of_acquisition"] = pd.to_datetime(
df["date_of_acquisition"], utc="True"
df["date_of_acquisition"], format="ISO8601", utc=True
)
df = enforce_df_int_typing(
input_df=df, int_columns=VBO_INTEGER_COLUMNS, use_pandas_type=True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def get_ophys_session_table(self) -> pd.DataFrame:
)
# Make date time explicitly UTC.
table["date_of_acquisition"] = pd.to_datetime(
table["date_of_acquisition"], utc=True
table["date_of_acquisition"], format="ISO8601", utc=True
)

# Fill NaN values of imaging_plane_group_count with zero to match
Expand Down Expand Up @@ -554,7 +554,7 @@ def get_ophys_experiment_table(self) -> pd.DataFrame:
"""
df = self._get_ophys_experiment_table()
df["date_of_acquisition"] = pd.to_datetime(
df["date_of_acquisition"], utc=True
df["date_of_acquisition"], format="ISO8601", utc=True
)
# Set type to pandas.Int64 to enforce integer typing and not revert to
# float.
Expand All @@ -581,7 +581,7 @@ def get_behavior_session_table(self) -> pd.DataFrame:
summary_tbl = self._get_behavior_summary_table()
# Add UTC time zone to match timezone from DateOfAcquisition object.
summary_tbl["date_of_acquisition"] = pd.to_datetime(
summary_tbl["date_of_acquisition"], utc=True
summary_tbl["date_of_acquisition"], format="ISO8601", utc=True
)
# Query returns float typing of age_in_days. Convert to int to match
# typing of the Age data_object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class BehaviorSessionMetadataSchema(RaisingSchema):
def convert_date_time(self, data, **kwargs):
"""Change date_of_acquisition to a date time type from string."""
data["date_of_acquisition"] = pd.to_datetime(
data["date_of_acquisition"], utc=True
data["date_of_acquisition"], format="ISO8601", utc=True
)
return data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,13 +857,13 @@ def _validate_traces(
if traces is None:
continue
# validate traces contain expected roi ids
if not np.in1d(traces.value.index, cell_roi_ids).all():
if not np.isin(traces.value.index, cell_roi_ids).all():
raise RuntimeError(
f"{traces.name} contains ROI IDs that "
f"are not in "
f"cell_specimen_table.cell_roi_id"
)
if not np.in1d(cell_roi_ids, traces.value.index).all():
if not np.isin(cell_roi_ids, traces.value.index).all():
raise RuntimeError(
f"cell_specimen_table contains ROI IDs "
f"that are not in {traces.name}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def get_task_parameters(data: Dict) -> Dict:
# displayed stimuli (no flashes).

if stim_duration is None:
stim_duration = np.NaN
stim_duration = np.nan
else:
stim_duration = stim_duration[0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def from_nwb(
cls,
nwbfile: NWBFile
) -> "RunningAcquisition":
running_module = nwbfile.modules['running']
running_module = nwbfile.processing['running']
dx_interface = running_module.get_data_interface('dx')

dx = dx_interface.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def from_nwb(
nwbfile: NWBFile,
filtered=True
) -> "RunningSpeed":
running_module = nwbfile.modules['running']
running_module = nwbfile.processing['running']
interface_name = 'speed' if filtered else 'speed_unfiltered'
running_interface = running_module.get_data_interface(interface_name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _add_image_index_to_nwb(
image_index = IndexSeries(
name=nwb_template.name,
data=stimulus_index['image_index'].values,
unit='None',
unit='N/A',
indexed_timeseries=nwb_template,
timestamps=stimulus_index['start_time'].values)
nwbfile.add_stimulus(image_index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _parse_stimulus_key():
# displayed stimuli (no flashes).

if stim_duration is None:
stim_duration = np.NaN
stim_duration = np.nan
else:
stim_duration = stim_duration[0]
return stim_duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def add_change_time(self, trial_dict: dict) -> Tuple[dict, float]:
"""
change_frame = trial_dict['change_frame']
if np.isnan(change_frame):
change_time = np.NaN
change_time = np.nan
else:
change_frame = int(change_frame)
change_time = self._stimulus_timestamps.value[change_frame]
Expand Down
12 changes: 6 additions & 6 deletions allensdk/brain_observatory/behavior/stimulus_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def get_images_dict(pkl) -> Dict:
meta = dict(
image_category=cat.decode("utf-8"),
image_name=img_name.decode("utf-8"),
orientation=np.NaN,
phase=np.NaN,
spatial_frequency=np.NaN,
orientation=np.nan,
phase=np.nan,
spatial_frequency=np.nan,
image_index=ii,
)

Expand Down Expand Up @@ -341,9 +341,9 @@ def get_stimulus_metadata(pkl) -> pd.DataFrame:
"image_category": ["omitted"],
"image_name": ["omitted"],
"image_set": ["omitted"],
"orientation": np.NaN,
"phase": np.NaN,
"spatial_frequency": np.NaN,
"orientation": np.nan,
"phase": np.nan,
"spatial_frequency": np.nan,
"image_index": len(stimulus_index_df),
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def get_stimulus_templates(self):
# What we really want is a dict with image_name as key
template_dict = {}
image_index_names = self.get_image_index_names()
for image_index, image_name in image_index_names.iteritems():
for image_index, image_name in image_index_names.items():
if image_name != 'omitted':
template_dict.update(
{image_name: stimulus_template_array[image_index, :, :]})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_extended_stimulus_presentations(session):
)
block_repetition_number = np.copy(block_inds)

for image_name, image_blocks in blocks_per_image.iteritems():
for image_name, image_blocks in blocks_per_image.items():
if image_name != "omitted":
for ind_block, block_number in enumerate(image_blocks):
# block_rep_number starts as a copy of block_inds, so we can
Expand Down
2 changes: 1 addition & 1 deletion allensdk/brain_observatory/chisquare_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def compute_chi_shuffle(
def stim_table_to_categories(stim_table, columns, verbose=False):
# get the categories for all sweeps with each unique combination of
# parameters in 'columns' being one category
# sweeps with non-finite values in ANY column (e.g. np.NaN) are labeled
# sweeps with non-finite values in ANY column (e.g. np.nan) are labeled
# as blank sweeps (category = -1)
# TODO: Replace with EcephysSession.get_stimulus_conditions

Expand Down
2 changes: 2 additions & 0 deletions allensdk/brain_observatory/demixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def _demix_point(source_frame: np.ndarray, mask_traces: np.ndarray,
overlap = flat_masks.dot(weighted_masks.T).toarray()
try:
demix_traces = linalg.solve(overlap, mask_weighted_trace)
if not np.all(np.isfinite(demix_traces)):
raise linalg.LinAlgError("non-finite result")
except linalg.LinAlgError:
logging.warning("Singular matrix, using least squares to solve.")
x, _, _, _ = linalg.lstsq(overlap, mask_weighted_trace)
Expand Down
2 changes: 1 addition & 1 deletion allensdk/brain_observatory/dff.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def noise_std(x, noise_kernel_length=31, positive_peak_scale=1.5,
"""Robust estimate of the standard deviation of the trace noise."""
_check_kernel(noise_kernel_length, len(x))
if any(np.isnan(x)):
return np.NaN
return np.nan
x = x - median_filter(x, noise_kernel_length, mode='constant')
# first pass removing big pos peak outliers
x = x[x < positive_peak_scale*np.abs(x.min())]
Expand Down
6 changes: 3 additions & 3 deletions allensdk/brain_observatory/drifting_gratings.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ def get_peak(self):
np.abs(subset_stat[str(nc)].mean()))

else:
peak.p_run_dg.iloc[nc] = np.NaN
peak.run_modulation_dg.iloc[nc] = np.NaN
peak.p_run_dg.iloc[nc] = np.nan
peak.run_modulation_dg.iloc[nc] = np.nan

# reliability
subset = self.sweep_response[
Expand All @@ -264,7 +264,7 @@ def get_peak(self):
for i in range(len(subset)):
for j in range(len(subset)):
if i >= j:
mask[i, j] = np.NaN
mask[i, j] = np.nan
corr_matrix *= mask
peak.reliability_dg.iloc[nc] = np.nanmean(corr_matrix)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def align_timestamps(args):
min_time = probe_split_times[idx]

if idx == (len(probe_split_times) - 1):
max_time = np.Inf
max_time = np.inf
else:
max_time = probe_split_times[idx + 1]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def get_barcode_table(self, **barcode_kwargs):

"""
warnings.warn(
np.VisibleDeprecationWarning(
"""This function is deprecated as unecessary (and slated for
removal). Instead, simply use extract_barcodes."""
)
"""This function is deprecated as unecessary (and slated for
removal). Instead, simply use extract_barcodes.""",
DeprecationWarning,
stacklevel=2,
)

barcode_times, barcodes = self.extract_barcodes(**barcode_kwargs)
Expand Down
2 changes: 1 addition & 1 deletion allensdk/brain_observatory/ecephys/data_objects/trials.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def add_change_time(self, trial_dict: dict) -> Tuple[dict, float]:
"""
change_frame = trial_dict['change_frame']
if np.isnan(change_frame):
change_time = np.NaN
change_time = np.nan
else:
no_delay = self._stimulus_timestamps.subtract_monitor_delay()
change_frame = int(change_frame)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,20 @@ def __init__(

super(AsyncHttpEngine, self).__init__(scheme, host, **kwargs)

self._session = None
if session:
self.session = session
self._session = session
warnings.warn(
"Recieved preconstructed session, ignoring timeout parameter."
)
else:
self.session = aiohttp.ClientSession(

@property
def session(self):
if self._session is None:
self._session = aiohttp.ClientSession(
timeout=aiohttp.client.ClientTimeout(self.timeout)
)
return self._session

async def _stream_coroutine(
self,
Expand Down Expand Up @@ -169,10 +174,10 @@ def stream(
return functools.partial(self._stream_coroutine, route)

def __del__(self):
if hasattr(self, "session"):
if getattr(self, "_session", None) is not None:
nest_asyncio.apply()
loop = asyncio.get_event_loop()
loop.run_until_complete(self.session.close())
loop.run_until_complete(self._session.close())

@staticmethod
def write_bytes(
Expand Down
Loading
Loading