Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnburrows committed Jan 8, 2023
1 parent 8e88b8a commit 1a22087
Show file tree
Hide file tree
Showing 30 changed files with 27,885 additions and 1,803 deletions.
17 changes: 12 additions & 5 deletions .ipynb_checkpoints/CCM-checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def CCM_trace_save(data, name):
"""
import numpy as np
import os
import h5py

#rename for kEDM processing
Expand Down Expand Up @@ -119,14 +120,15 @@ def ccm_stats(file, mode):
Inputs:
file (str): filename - should be a '-CCMxmap.h5' file
mode (str): what data type you want:
'ccm' = matrix of ccm values - rows = effects of a timeseries, columns = causes of a timeseries (ie. cell xy = to what extent does x cause y; cell yx = to what extent does y cause x).
'c_to_sz' = cells that drive the seizure
'sz_to_c' = cells that are driven by the seizure
'e' = embedding dimension of each cell
'rd_cause' = non-linear causing neurons - mean rhodiff of neurons that are caused by neuron of interest
'rd_int' = #non-linear integration - mean rhodiff of neurons that cause neuron of interest
Returns:
(np array): 1d vector of interest (length = n cells) containing ccm stats
(np array): np array of interest (length = n cells) containing ccm stats
"""
Expand All @@ -135,10 +137,15 @@ def ccm_stats(file, mode):
import numpy as np
data = h5py.File(file)

if mode != 'c_to_sz' and mode != 'sz_to_c' and mode != 'e' and mode != 'rd_cause' and mode != 'rd_int':
if mode != 'c_to_sz' and mode != 'sz_to_c' and mode != 'e' and mode != 'rd_cause' and mode != 'rd_int' and mode != 'ccm':
print('Mode name does not match options')
return()

if mode == 'ccm':
ccm = np.array(data['ccm'])
ccm = ccm[1:,1:] #Remove mean trace
return(ccm)

if mode == 'c_to_sz':
ccm = np.array(data['ccm'])
c_to_sz = ccm[1:,0] #cells that drive the seizure
Expand All @@ -155,14 +162,14 @@ def ccm_stats(file, mode):

else:
rd_m = data['rhodiff'][1:,1:] #remove seizure values
np.fill_diagonal(rd_m,0) #remove self-ccm values
np.fill_diagonal(rd_m,np.nan) #remove self-ccm values

if mode == 'rd_cause':
rd_cause = np.apply_along_axis(np.mean,1,rd_m) #non-linear causing - mean rhodiff of neurons that are caused by neuron of interest
rd_cause = np.apply_along_axis(np.nanmean,1,rd_m) #non-linear causing - mean rhodiff of neurons that are caused by neuron of interest
return(rd_cause)

if mode == 'rd_int':
rd_int = np.apply_along_axis(np.mean,0,rd_m) #non-linear integration - mean rhodiff of neurons that cause neuron of interest
rd_int = np.apply_along_axis(np.nanmean,0,rd_m) #non-linear integration - mean rhodiff of neurons that cause neuron of interest
return(rd_int)


Expand Down
60 changes: 48 additions & 12 deletions .ipynb_checkpoints/CCM_process-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'3.7.6 (default, Jan 8 2020, 13:42:34) \\n[Clang 4.0.1 (tags/RELEASE_401/final)]'"
"'3.7.4 (default, Aug 13 2019, 15:17:50) \\n[Clang 4.0.1 (tags/RELEASE_401/final)]'"
]
},
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -98,7 +98,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -107,7 +107,7 @@
"['datNeuralSPIKFiltAndStim.npy']"
]
},
"execution_count": 23,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -117,43 +117,79 @@
"#CCM_trace_save function renames and saves trace data as: time x cells, and \n",
"# then saves the trace in the correct orientation in h5 format\n",
"\n",
"tr_l = adfn.return_files(Fdata, 'PTZ-WILDTYPE-CCM/kostas', '*.npy*')\n",
"tr_l = adfn.return_files(Fdata, 'PTZ-WILDTYPE-CCM/kostas', '*dat*.npy*')\n",
"tr_l"
]
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(13670, 6336)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.load(tr_l[0]).shape"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"%autoreload"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('datNeuralSPIKFiltAndStim.npy',\n",
" 'KOSTAS_220315-01_2photon_sess-01-6dpf_run-01_trace')"
" 'KOSTAS_220628-800_2photon_sess-01-6dpf_run-01_trace')"
]
},
"execution_count": 40,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#NB - must have datatype after 'run-XX_'\n",
"data = tr_l[0]\n",
"name = 'KOSTAS_220315-01_2photon_sess-01-6dpf_run-01_trace'\n",
"name = 'KOSTAS_220628-800_2photon_sess-01-6dpf_run-01_trace'\n",
"data, name"
]
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"#Save \n",
"cfn.CCM_trace_save(data, name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -172,7 +208,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 1a22087

Please sign in to comment.