Skip to content

Commit

Permalink
swapped create_stimulation_timeseries for neuroconv version
Browse files Browse the repository at this point in the history
  • Loading branch information
pauladkisson committed May 24, 2024
1 parent 4ce8212 commit e357309
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 56 deletions.
13 changes: 8 additions & 5 deletions frozen_dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ aiobotocore==2.11.1
aiohttp==3.9.2
aioitertools==0.11.0
aiosignal==1.3.1
annotated-types==0.7.0
appdirs==1.4.4
appnope==0.1.4
arrow==1.3.0
Expand All @@ -23,11 +24,12 @@ comm==0.2.1
contourpy==1.2.0
cycler==0.12.1
dandi==0.59.1
dandischema==0.8.4
dandischema==0.8.2
debugpy==1.8.1
decorator==5.1.1
distlib==0.3.8
dnspython==2.5.0
docstring_parser==0.16
email-validator==2.1.0.post1
entrypoints==0.4
et-xmlfile==1.1.0
Expand All @@ -44,7 +46,7 @@ fsspec==2023.12.2
gast==0.4.0
h5py==3.10.0
hdmf==3.13.0
hdmf_zarr==0.5.0
hdmf_zarr==0.7.0
humanize==4.9.0
identify==2.5.33
idna==3.6
Expand Down Expand Up @@ -93,7 +95,7 @@ ndx-photometry @ git+https://github.com/catalystneuro/ndx-photometry.git@c1284c9
ndx-spectrum==0.2.2
nest-asyncio==1.6.0
networkx==3.2.1
neuroconv==0.4.7
neuroconv @ git+https://github.com/catalystneuro/neuroconv.git@f45e77e152369916459a764c918d4c5cbbf1fad1
nodeenv==1.8.0
numcodecs==0.11.0
numpy==1.26.3
Expand All @@ -116,9 +118,10 @@ ptyprocess==0.7.0
pure-eval==0.2.2
py2vega==0.6.1
pycryptodomex==3.20.0
pydantic==1.10.14
pydantic==2.7.1
pydantic_core==2.18.2
Pygments==2.17.2
pynwb==2.6.0
pynwb==2.7.0
pyout==0.7.3
pyparsing==3.1.1
pytest==8.1.1
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
hdmf
neuroconv
neuroconv @ git+https://github.com/catalystneuro/neuroconv.git@main
nwbwidgets
nwbinspector
dandi
pre-commit
pytest
ndx-events
ndx-fiber-photometry @ git+https://github.com/catalystneuro/ndx-fiber-photometry.git@add_fiber_photometry_lab_meta_data
ndx-fiber-photometry @ git+https://github.com/catalystneuro/ndx-fiber-photometry.git@main
ipykernel
tdt
openpyxl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pynwb.ogen import OptogeneticSeries
from neuroconv.basedatainterface import BaseDataInterface
from neuroconv.utils import DeepDict
from neuroconv.tools.optogenetics import create_optogenetic_stimulation_timeseries
from typing import Literal
from hdmf.backends.hdf5.h5_utils import H5DataIO
from datetime import datetime, time
Expand Down Expand Up @@ -157,7 +158,7 @@ def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict):
location=f"Injection location: {opto_metadata['injection_location']} \n Stimulation location: {opto_metadata['stimulation_location']}",
excitation_lambda=opto_metadata["excitation_lambda"],
)
timestamps, data = self.create_stimulation_timeseries(
timestamps, data = create_optogenetic_stimulation_timeseries(
stimulation_onset_times=stim_times,
duration=opto_metadata["duration"],
frequency=opto_metadata["frequency"],
Expand All @@ -172,51 +173,3 @@ def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict):
description=opto_metadata["ogen_series_description"],
)
nwbfile.add_stimulus(ogen_series)

def create_stimulation_timeseries( # TODO: Move to neuroconv
self, stimulation_onset_times: np.ndarray, duration: float, frequency: float, pulse_width: float, power: float
) -> tuple[np.ndarray, np.ndarray]:
"""Create a continuous stimulation time series from stimulation onset times and parameters.
In the resulting data array, the offset time of each pulse is represented by a 0 power value.
Parameters
----------
stimulation_onset_times : np.ndarray
Array of stimulation onset times.
duration : float
Duration of stimulation in seconds.
frequency : float
Frequency of stimulation in Hz.
pulse_width : float
Pulse width of stimulation in seconds.
power : float
Power of stimulation in W.
Returns
-------
np.ndarray
Stimulation timestamps.
np.ndarray
Instantaneous stimulation power.
Notes
-----
For continuous stimulation of a desired duration, simply set
```
pulse_width = duration
frequency = 1 / duration
```
"""
num_pulses = int(duration * frequency)
inter_pulse_interval = 1 / frequency
timestamps, data = [0], [0]
for onset_time in stimulation_onset_times:
for i in range(num_pulses):
pulse_onset_time = onset_time + i * inter_pulse_interval
timestamps.append(pulse_onset_time)
data.append(power)
pulse_offset_time = pulse_onset_time + pulse_width
timestamps.append(pulse_offset_time)
data.append(0)
return np.array(timestamps, dtype=np.float64), np.array(data, dtype=np.float64)

0 comments on commit e357309

Please sign in to comment.