Skip to content

Commit

Permalink
Merge pull request #412 from pynapple-org/dev
Browse files Browse the repository at this point in the history
Bumping 0.8.4
  • Loading branch information
gviejo authored Feb 6, 2025
2 parents 0d81009 + 9dc3e30 commit 8108206
Show file tree
Hide file tree
Showing 20 changed files with 163 additions and 178 deletions.
7 changes: 7 additions & 0 deletions doc/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ of the Flatiron institute.

## Releases

### 0.8.4 (2025-02-07)

- Fix value printing of IntervalSet when rows are collapsed
- Backward compatibility fix for loading npz files with TsGroup
- Fix indexing of IntervalSet to be able to use -1
- Add column names for compute_wavelet_transform

### 0.8.3 (2025-01-24)

- `compute_mean_power_spectral_density` computes the mean periodogram.
Expand Down
2 changes: 1 addition & 1 deletion pynapple/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.8.3"
__version__ = "0.8.4"
from .core import (
IntervalSet,
Ts,
Expand Down
10 changes: 5 additions & 5 deletions pynapple/core/_core_functions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
This module holds the core function of pynapple as well as
the dispatch between numba and jax.
This module holds the core function of pynapple as well as
the dispatch between numba and jax.
If pynajax is installed and `nap.nap_config.backend` is set
to `jax`, the module will call the functions within pynajax.
Otherwise the module will call the functions within `_jitted_functions.py`.
If pynajax is installed and `nap.nap_config.backend` is set
to `jax`, the module will call the functions within pynajax.
Otherwise the module will call the functions within `_jitted_functions.py`.
"""

Expand Down
2 changes: 1 addition & 1 deletion pynapple/core/base_class.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Abstract class for `core` time series.
Abstract class for `core` time series.
"""

Expand Down
8 changes: 4 additions & 4 deletions pynapple/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
## Backend configuration
By default, pynapple core functions are compiled with [Numba](https://numba.pydata.org/).
It is possible to change the backend to [Jax](https://jax.readthedocs.io/en/latest/index.html)
By default, pynapple core functions are compiled with [Numba](https://numba.pydata.org/).
It is possible to change the backend to [Jax](https://jax.readthedocs.io/en/latest/index.html)
through the [pynajax package](https://github.com/pynapple-org/pynajax).
While numba core functions runs on CPU, the `jax` backend allows pynapple to use GPU accelerated core functions.
For some core functions, the `jax` backend offers speed gains (provided that Jax runs on the GPU).
For some core functions, the `jax` backend offers speed gains (provided that Jax runs on the GPU).
See the example below to update the backend. Don't forget to install [pynajax](https://github.com/pynapple-org/pynajax).
Expand All @@ -16,7 +16,7 @@
import numpy as np
nap.nap_config.set_backend("jax") # Default option is 'numba'.
You can view the current backend with
You can view the current backend with
>>> print(nap.nap_config.backend)
'jax'
Expand Down
27 changes: 15 additions & 12 deletions pynapple/core/interval_set.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
"""
The class `IntervalSet` deals with non-overlaping epochs. `IntervalSet` objects can interact with each other or with the time series objects.
"""

Expand Down Expand Up @@ -294,7 +294,7 @@ def __init__(
self._class_attributes = self.__dir__() # get list of all attributes
self._class_attributes.append("_class_attributes") # add this property
self._initialized = True
if drop_meta is False:
if (drop_meta is False) and (metadata is not None):
self.set_info(metadata)

def __repr__(self):
Expand Down Expand Up @@ -336,7 +336,7 @@ def __repr__(self):
np.hstack(
(
self.index[-n_rows:, None],
self.values[0:n_rows],
self.values[-n_rows:],
_convert_iter_to_str(metadata.values[-n_rows:]),
),
dtype=object,
Expand Down Expand Up @@ -406,11 +406,6 @@ def __setitem__(self, key, value):
)

def __getitem__(self, key):
try:
metadata = _MetadataMixin.__getitem__(self, key)
except Exception:
metadata = pd.DataFrame(index=self.index)

if isinstance(key, str):
# self[str]
if key == "start":
Expand All @@ -435,9 +430,15 @@ def __getitem__(self, key):
elif isinstance(key, Number):
# self[Number]
output = self.values.__getitem__(key)
metadata = self._metadata.iloc[key]
return IntervalSet(start=output[0], end=output[1], metadata=metadata)
elif isinstance(key, (slice, list, np.ndarray, pd.Series)):
# self[array_like]
elif isinstance(key, (slice, list, np.ndarray)):
# self[array_like], use iloc for metadata
output = self.values.__getitem__(key)
metadata = self._metadata.iloc[key].reset_index(drop=True)
return IntervalSet(start=output[:, 0], end=output[:, 1], metadata=metadata)
elif isinstance(key, pd.Series):
# use loc for metadata
output = self.values.__getitem__(key)
metadata = _MetadataMixin.__getitem__(self, key).reset_index(drop=True)
return IntervalSet(start=output[:, 0], end=output[:, 1], metadata=metadata)
Expand Down Expand Up @@ -487,7 +488,7 @@ def __getitem__(self, key):
if key[1] == slice(None, None, None):
# self[Any, :]
output = self.values.__getitem__(key[0])
metadata = _MetadataMixin.__getitem__(self, key[0])
metadata = self._metadata.iloc[key[0]]

if isinstance(key[0], Number):
return IntervalSet(
Expand All @@ -500,7 +501,9 @@ def __getitem__(self, key):
metadata=metadata.reset_index(drop=True),
)

elif key[1] == slice(0, 2, None):
elif (key[1] == slice(0, 2, None)) or (
key[1] == slice(None, 2, None)
):
# self[Any, :2]
# allow number indexing for start and end times for backward compatibility
output = self.values.__getitem__(key[0])
Expand Down
2 changes: 1 addition & 1 deletion pynapple/core/metadata_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def get_info(self, key):
)
)
):
# assume key is index, or tupe of index and column name
# assume key is index, or tuple of index and column name
# metadata[Number], metadata[array_like], metadata[Any, str], or metadata[Any, [*str]]
return self._metadata.loc[key]

Expand Down
14 changes: 7 additions & 7 deletions pynapple/core/time_index.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
Similar to pandas.Index, `TsIndex` holds the timestamps associated with the data of a time series.
This class deals with conversion between different time units for all pynapple objects as well
as making sure that timestamps are property sorted before initializing any objects.
- `us`: microseconds
- `ms`: milliseconds
- `s`: seconds (overall default)
Similar to pandas.Index, `TsIndex` holds the timestamps associated with the data of a time series.
This class deals with conversion between different time units for all pynapple objects as well
as making sure that timestamps are property sorted before initializing any objects.
- `us`: microseconds
- `ms`: milliseconds
- `s`: seconds (overall default)
"""

from warnings import warn
Expand Down
20 changes: 10 additions & 10 deletions pynapple/core/time_series.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""
Pynapple time series are containers specialized for neurophysiological time series.
They provides standardized time representation, plus various functions for manipulating times series with identical sampling frequency.
Pynapple time series are containers specialized for neurophysiological time series.
Multiple time series object are avaible depending on the shape of the data.
They provides standardized time representation, plus various functions for manipulating times series with identical sampling frequency.
- `TsdTensor` : for data with of more than 2 dimensions, typically movies.
- `TsdFrame` : for column-based data. It can be easily converted to a pandas.DataFrame. Columns can be labelled and selected similar to pandas.
- `Tsd` : One-dimensional time series. It can be converted to a pandas.Series.
- `Ts` : For timestamps data only.
Multiple time series object are avaible depending on the shape of the data.
Most of the same functions are available through all classes. Objects behaves like numpy.ndarray. Slicing can be done the same way for example
`tsd[0:10]` returns the first 10 rows. Similarly, you can call any numpy functions like `np.mean(tsd, 1)`.
- `TsdTensor` : for data with of more than 2 dimensions, typically movies.
- `TsdFrame` : for column-based data. It can be easily converted to a pandas.DataFrame. Columns can be labelled and selected similar to pandas.
- `Tsd` : One-dimensional time series. It can be converted to a pandas.Series.
- `Ts` : For timestamps data only.
Most of the same functions are available through all classes. Objects behaves like numpy.ndarray. Slicing can be done the same way for example
`tsd[0:10]` returns the first 10 rows. Similarly, you can call any numpy functions like `np.mean(tsd, 1)`.
"""

import abc
Expand Down
26 changes: 22 additions & 4 deletions pynapple/core/ts_group.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
The class `TsGroup` helps group objects with different timestamps
The class `TsGroup` helps group objects with different timestamps
(i.e. timestamps of spikes of a population of neurons).
"""
Expand Down Expand Up @@ -1419,13 +1419,31 @@ def _from_npz_reader(cls, file):

tsgroup = cls(group, time_support=time_support, bypass_check=True)

# do we need to enforce that these keys are not in metadata?
# not_info_keys = {"start", "end", "t", "index", "d", "rate", "keys"}

if "_metadata" in file: # load metadata if it exists
if file["_metadata"]: # check that metadata is not empty
metainfo = pd.DataFrame.from_dict(file["_metadata"].item())
tsgroup.set_info(metainfo)

metainfo = {}
not_info_keys = {
"start",
"end",
"t",
"index",
"d",
"rate",
"keys",
"_metadata",
"type",
}

for k in set(file.keys()) - not_info_keys:
tmp = file[k]
if len(tmp) == len(tsgroup):
metainfo[k] = tmp

tsgroup.set_info(**metainfo)

return tsgroup

@add_meta_docstring("set_info")
Expand Down
2 changes: 1 addition & 1 deletion pynapple/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Utility functions
Utility functions
"""

import os
Expand Down
10 changes: 5 additions & 5 deletions pynapple/process/_process_functions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
This module holds some process function of pynapple that can be
called with numba or pynajax as backend
This module holds some process function of pynapple that can be
called with numba or pynajax as backend
If pynajax is installed and `nap.nap_config.backend` is set
to `jax`, the module will call the functions within pynajax.
Otherwise the module will call the functions within `_jitted_functions.py`.
If pynajax is installed and `nap.nap_config.backend` is set
to `jax`, the module will call the functions within pynajax.
Otherwise the module will call the functions within `_jitted_functions.py`.
"""

Expand Down
4 changes: 1 addition & 3 deletions pynapple/process/perievent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Functions to realign time series relative to a reference time.
"""
"""Functions to realign time series relative to a reference time."""

import numpy as np

Expand Down
5 changes: 4 additions & 1 deletion pynapple/process/wavelets.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def compute_wavelet_transform(

if len(output_shape) == 2:
return nap.TsdFrame(
t=sig.index, d=np.squeeze(cwt, axis=1), time_support=sig.time_support
t=sig.index,
d=np.squeeze(cwt, axis=1),
time_support=sig.time_support,
columns=freqs,
)
else:
return nap.TsdTensor(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pynapple"
version = "0.8.3"
version = "0.8.4"
description = "PYthon Neural Analysis Package Pour Laboratoires d’Excellence"
readme = "README.md"
authors = [{ name = "Guillaume Viejo", email = "[email protected]" }]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/pynapple-org/pynapple',
version='v0.8.3',
version='v0.8.4',
zip_safe=False,
long_description_content_type='text/markdown',
download_url='https://github.com/pynapple-org/pynapple/archive/refs/tags/v0.8.3.tar.gz'
Expand Down
Loading

0 comments on commit 8108206

Please sign in to comment.