Skip to content

Commit

Permalink
Merge pull request #226 from pynapple-org/dev
Browse files Browse the repository at this point in the history
Adding Event trigger average for all dimensions
  • Loading branch information
gviejo authored Jan 29, 2024
2 parents 36a454e + 8ddff7d commit dcf71da
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 133 deletions.
7 changes: 7 additions & 0 deletions docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ In 2018, Francesco started neuroseries, a Python package built on Pandas. It was
In 2021, Guillaume and other trainees in Adrien's lab decided to fork from neuroseries and started *pynapple*. The core of pynapple is largely built upon neuroseries. Some of the original changes to TSToolbox made by Luke were included in this package, especially the *time_support* property of all ts/tsd objects.


0.5.1 (2024-01-29)
------------------

- Implementing `event_trigger_average` for all dimensions.
- Hiding jitted functions from users.


0.5.0 (2023-12-12)
------------------

Expand Down
94 changes: 53 additions & 41 deletions docs/gen_ref_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,68 @@

io_orders = ['interface_nwb', 'interface_npz', 'folder', 'misc'] + deprecated

ignored = ['_jitted_functions']

for path in sorted(Path("pynapple").rglob("*.py")):
print(path)
module_path = path.relative_to("pynapple").with_suffix("")
doc_path = path.relative_to("pynapple").with_suffix(".md")
full_doc_path = Path("reference", doc_path)

parts = tuple(module_path.parts)

if parts[-1] == "__init__":
parts = parts[:-1]
doc_path = doc_path.with_name("index.md")
full_doc_path = full_doc_path.with_name("index.md")
elif parts[-1] == "__main__":
continue

if len(parts):
nav[parts] = doc_path.as_posix()
# if the md file name is `module.md`, generate documentation from docstrings
if full_doc_path.name != 'index.md':
# sys.exit()
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
ident = "pynapple."+".".join(parts)
fd.write(f"::: {ident}")
# if the md file name is `index.md`, add the list of modules with hyperlinks
else:
this_module_path = Path("pynapple") / path.parent.name
module_index = ""

module_order = sorted(this_module_path.rglob("*.py"))
module_order = [m.name.replace('.py', '') for m in module_order]

if module_path.name not in ignored:

doc_path = path.relative_to("pynapple").with_suffix(".md")
full_doc_path = Path("reference", doc_path)

# print(module_path, "\t", doc_path, "\t", full_doc_path)

parts = tuple(module_path.parts)

if parts[-1] == "__init__":
parts = parts[:-1]
doc_path = doc_path.with_name("index.md")
full_doc_path = full_doc_path.with_name("index.md")
elif parts[-1] == "__main__":
continue

# print(parts, doc_path)
# if str(doc_path) == "core/_jitted_functions.md":
# sys.exit()

if len(parts):
nav[parts] = doc_path.as_posix()

# if the md file name is `module.md`, generate documentation from docstrings
if full_doc_path.name != 'index.md':

with mkdocs_gen_files.open(full_doc_path, "w") as fd:
ident = "pynapple."+".".join(parts)
fd.write(f"::: {ident}")

if "io" in this_module_path.name:
module_order = io_orders
else:
this_module_path = Path("pynapple") / path.parent.name
module_index = ""

module_order = sorted(this_module_path.rglob("*.py"))
module_order = [m.name.replace('.py', '') for m in module_order]

if "io" in this_module_path.name:
module_order = io_orders

for m in module_order:
if "__init__" in m:
continue
for m in module_order:
if "__init__" in m:
continue
if m[0] == "_":
continue

module_name = m
if m in deprecated:
module_name += " (deprecated)"
module_index += f"* [{module_name}]" \
"("+m+".md)\n"
module_name = m
if m in deprecated:
module_name += " (deprecated)"
module_index += f"* [{module_name}]" \
"("+m+".md)\n"

with mkdocs_gen_files.open(full_doc_path, "w") as fd:
fd.write(module_index)
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
fd.write(module_index)


mkdocs_gen_files.set_edit_path(full_doc_path, path)
mkdocs_gen_files.set_edit_path(full_doc_path, path)

with mkdocs_gen_files.open("reference/index.md", "w") as nav_file:
nav_file.writelines(nav.build_literate_nav())
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.5.0"
__version__ = "0.5.1"
from .core import *
from .io import *
from .process import *
7 changes: 4 additions & 3 deletions pynapple/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .interval_set import *
from .time_series import *
from .ts_group import *
from .interval_set import IntervalSet
from .time_index import TsIndex
from .time_series import Ts, Tsd, TsdFrame, TsdTensor
from .ts_group import TsGroup
File renamed without changes.
6 changes: 3 additions & 3 deletions pynapple/core/interval_set.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# @Date: 2022-01-25 21:50:48
# @Last Modified by: gviejo
# @Last Modified time: 2023-10-15 16:18:42
# @Last Modified by: Guillaume Viejo
# @Last Modified time: 2024-01-29 12:16:38

"""
"""
Expand All @@ -14,7 +14,7 @@
import pandas as pd
from numba import jit

from .jitted_functions import jitdiff, jitin_interval, jitintersect, jitunion
from ._jitted_functions import jitdiff, jitin_interval, jitintersect, jitunion
from .time_index import TsIndex

all_warnings = np.array(
Expand Down
6 changes: 3 additions & 3 deletions pynapple/core/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @Author: gviejo
# @Date: 2022-01-27 18:33:31
# @Last Modified by: Guillaume Viejo
# @Last Modified time: 2024-01-08 16:09:01
# @Last Modified time: 2024-01-29 14:36:05

"""
Expand Down Expand Up @@ -35,8 +35,7 @@
from scipy import signal
from tabulate import tabulate

from .interval_set import IntervalSet
from .jitted_functions import (
from ._jitted_functions import (
jitbin,
jitbin_array,
jitcount,
Expand All @@ -49,6 +48,7 @@
jitvaluefromtensor,
pjitconvolve,
)
from .interval_set import IntervalSet
from .time_index import TsIndex


Expand Down
14 changes: 7 additions & 7 deletions pynapple/core/ts_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @Author: gviejo
# @Date: 2022-01-28 15:10:48
# @Last Modified by: Guillaume Viejo
# @Last Modified time: 2023-09-21 15:57:41
# @Last Modified time: 2024-01-29 12:16:24


import os
Expand All @@ -13,13 +13,13 @@
import pandas as pd
from tabulate import tabulate

from .interval_set import IntervalSet
from .jitted_functions import (
from ._jitted_functions import (
jitcount,
jittsrestrict_with_count,
jitunion,
jitunion_isets,
)
from .interval_set import IntervalSet

# from .time_units import format_timestamps
from .time_index import TsIndex
Expand Down Expand Up @@ -254,7 +254,7 @@ def set_info(self, *args, **kwargs):
*args
pandas.Dataframe or list of pandas.DataFrame
**kwargs
Can be either pandas.Series or numpy.ndarray
Can be either pandas.Series, numpy.ndarray, list or tuple
Raises
------
Expand Down Expand Up @@ -286,7 +286,7 @@ def set_info(self, *args, **kwargs):
1 2 pfc
2 4 ca1
To add metadata with a pd.Series or numpy.ndarray:
To add metadata with a pd.Series, numpy.ndarray, list or tuple:
>>> hd = pd.Series(index = [0,1,2], data = [0,1,1])
>>> tsgroup.set_info(hd=hd)
Expand Down Expand Up @@ -314,9 +314,9 @@ def set_info(self, *args, **kwargs):
self._metadata[k] = v
else:
raise RuntimeError("Index are not equals")
elif isinstance(v, np.ndarray):
elif isinstance(v, (np.ndarray, list, tuple)):
if len(self._metadata) == len(v):
self._metadata[k] = v
self._metadata[k] = np.asarray(v)
else:
raise RuntimeError("Array is not the same length.")
return
Expand Down
31 changes: 26 additions & 5 deletions pynapple/process/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
from .correlograms import *
from .decoding import *
from .perievent import *
from .randomize import *
from .tuning_curves import *
from .correlograms import (
compute_autocorrelogram,
compute_crosscorrelogram,
compute_eventcorrelogram,
)
from .decoding import decode_1d, decode_2d
from .perievent import (
compute_event_trigger_average,
compute_perievent,
compute_perievent_continuous,
)
from .randomize import (
jitter_timestamps,
resample_timestamps,
shift_timestamps,
shuffle_ts_intervals,
)
from .tuning_curves import (
compute_1d_mutual_info,
compute_1d_tuning_curves,
compute_1d_tuning_curves_continuous,
compute_2d_mutual_info,
compute_2d_tuning_curves,
compute_2d_tuning_curves_continuous,
compute_discrete_tuning_curves,
)
8 changes: 4 additions & 4 deletions pynapple/process/perievent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @Author: gviejo
# @Date: 2022-01-30 22:59:00
# @Last Modified by: Guillaume Viejo
# @Last Modified time: 2024-01-26 15:52:19
# @Last Modified time: 2024-01-29 12:47:56

import numpy as np

Expand Down Expand Up @@ -179,7 +179,7 @@ def compute_perievent_continuous(data, tref, minmax, ep=None, time_unit="s"):
time_idx = np.hstack((idx1, np.zeros(1), idx2))
windowsize = np.array([idx1.shape[0], idx2.shape[0]])

new_data_array = nap.jitted_functions.jitcontinuous_perievent(
new_data_array = nap._jitted_functions.jitcontinuous_perievent(
time_array, data_array, time_target_array, starts, ends, windowsize
)

Expand Down Expand Up @@ -289,7 +289,7 @@ def compute_event_trigger_average(
data_target_array = feature.values

if data_target_array.ndim == 1:
eta = nap.jitted_functions.jitperievent_trigger_average(
eta = nap._jitted_functions.jitperievent_trigger_average(
time_array,
count_array,
time_target_array,
Expand All @@ -301,7 +301,7 @@ def compute_event_trigger_average(
)
eta = np.squeeze(eta, -1)
else:
eta = nap.jitted_functions.jitperievent_trigger_average(
eta = nap._jitted_functions.jitperievent_trigger_average(
time_array,
count_array,
time_target_array,
Expand Down
Loading

0 comments on commit dcf71da

Please sign in to comment.