Skip to content

Commit

Permalink
Use PositionOutput to get data in example (LorenFrankLab#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelbray32 authored Jan 12, 2024
1 parent 07ff56c commit 4dd1d8a
Show file tree
Hide file tree
Showing 2 changed files with 347 additions and 199 deletions.
509 changes: 327 additions & 182 deletions notebooks/20_Position_Trodes.ipynb

Large diffs are not rendered by default.

37 changes: 20 additions & 17 deletions notebooks/py_scripts/20_Position_Trodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.16.0
# jupytext_version: 1.15.2
# kernelspec:
# display_name: Python 3 (ipykernel)
# language: python
Expand Down Expand Up @@ -221,7 +221,19 @@

sgp.v1.TrodesPosV1 & trodes_key

# To retrieve the results as a pandas DataFrame with time as the index, we use `TrodesPosV1.fetch1_dataframe`.
# When we populatethe `TrodesPosV1` table, we automatically create an entry in the `PositionOutput` merge table.
# Since this table supports position information from multiple methods, it's best practive to access data through here.
#
# We can view the entry in this table:

# +
from spyglass.position import PositionOutput

PositionOutput.TrodesPosV1 & trodes_key
# -

# To retrieve the results as a pandas DataFrame with time as the index, we use `PositionOutput.fetch1_dataframe`.
# When doing so, we need to restric the merge table by the
#
# This dataframe has the following columns:
#
Expand All @@ -232,12 +244,10 @@
# - `speed`: the magnitude of the change in head position over time in cm/s
#

position_info = (
sgp.v1.TrodesPosV1()
& {
"nwb_file_name": nwb_copy_file_name,
}
).fetch1_dataframe()
# get the merge id corresponding to our inserted trodes_key
merge_key = (PositionOutput.merge_get_part(trodes_key)).fetch1("KEY")
# use this to restrict PositionOutput and fetch the data
position_info = (PositionOutput & merge_key).fetch1_dataframe()
position_info

# `.index` on the pandas dataframe gives us timestamps.
Expand Down Expand Up @@ -340,15 +350,8 @@
)
sgp.v1.TrodesPosV1.populate(trodes_s_up_key)

# +
upsampled_position_info = (
sgp.v1.TrodesPosV1()
& {
"nwb_file_name": nwb_copy_file_name,
"position_info_param_name": trodes_params_up_name,
}
).fetch1_dataframe()

merge_key = (PositionOutput.merge_get_part(trodes_s_up_key)).fetch1("KEY")
upsampled_position_info = (PositionOutput & merge_key).fetch1_dataframe()
upsampled_position_info

# +
Expand Down

0 comments on commit 4dd1d8a

Please sign in to comment.