Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CompNeuro_course
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GILSON Matthieu
CompNeuro_course
Commits
57202689
Commit
57202689
authored
Feb 14, 2024
by
GILSON Matthieu
Browse files
Options
Downloads
Patches
Plain Diff
add data loader ARCHIsoc
parent
9496d63d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
data/data_fMRI_ARCHIsoc/load_data.ipynb
+139
-0
139 additions, 0 deletions
data/data_fMRI_ARCHIsoc/load_data.ipynb
with
139 additions
and
0 deletions
data/data_fMRI_ARCHIsoc/load_data.ipynb
0 → 100644
+
139
−
0
View file @
57202689
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "349c8bc6-1a18-4fe2-869c-5581df684b1c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "47021efb-21dc-4ed2-8375-de1355344a16",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"base_dir = './'\n",
"\n",
"# time series\n",
"X_ts = pd.read_hdf(base_dir+'df_ts.hdf')\n",
"n_sample, n_ts = X_ts.shape\n",
"\n",
"# labels\n",
"y = np.load(base_dir+'lbl_task.npy')\n",
"\n",
"# functional connectivity\n",
"FC = np.load(base_dir+'FC.npy')\n",
"_, N, _ = X_FC.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4dd6acc5-40c8-48e2-81c6-562d518b5859",
"metadata": {},
"outputs": [],
"source": [
"print('shape of data frame for time series:', X_ts.shape)\n",
"print('shape of numpy array for FC:', FC.shape)\n",
"print('shape of labels:', y.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a6bc3926-de0a-4967-9b00-b66a5a64bd9f",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"type(X['dim_0'][0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ea059511-2df8-447e-a064-ab23a2d4b6f5",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"plt.figure()\n",
"for i in range(6):\n",
" plt.plot(X.iloc[0,i])\n",
"plt.xlabel('time')\n",
"plt.ylabel('a.u.')\n",
"plt.title('example trace')\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5c2b55ce-f85a-4800-aeed-e202bc193688",
"metadata": {},
"outputs": [],
"source": [
"plt.figure()\n",
"plt.imshow(X_FC[0,:,:])\n",
"plt.colorbar()\n",
"plt.xlabel('region index')\n",
"plt.ylabel('region index')\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "37e06d59-48b7-4d8d-8de3-c83641da7896",
"metadata": {},
"outputs": [],
"source": [
"# format FC data for scikit learn (sample x feature)\n",
"\n",
"ind_tri = np.tri(N,N,-1,dtype=bool)\n",
"print(ind_tri.sum())\n",
"\n",
"# X array for scikit learn\n",
"X_FC = FC[:,ind_tri]\n",
"print(X_FC.shape)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:code id:349c8bc6-1a18-4fe2-869c-5581df684b1c tags:
```
python
import
numpy
as
np
import
pandas
as
pd
import
matplotlib.pyplot
as
plt
```
%% Cell type:code id:47021efb-21dc-4ed2-8375-de1355344a16 tags:
```
python
base_dir
=
'
./
'
# time series
X_ts
=
pd
.
read_hdf
(
base_dir
+
'
df_ts.hdf
'
)
n_sample
,
n_ts
=
X_ts
.
shape
# labels
y
=
np
.
load
(
base_dir
+
'
lbl_task.npy
'
)
# functional connectivity
FC
=
np
.
load
(
base_dir
+
'
FC.npy
'
)
_
,
N
,
_
=
X_FC
.
shape
```
%% Cell type:code id:4dd6acc5-40c8-48e2-81c6-562d518b5859 tags:
```
python
print
(
'
shape of data frame for time series:
'
,
X_ts
.
shape
)
print
(
'
shape of numpy array for FC:
'
,
FC
.
shape
)
print
(
'
shape of labels:
'
,
y
.
shape
)
```
%% Cell type:code id:a6bc3926-de0a-4967-9b00-b66a5a64bd9f tags:
```
python
type
(
X
[
'
dim_0
'
][
0
])
```
%% Cell type:code id:ea059511-2df8-447e-a064-ab23a2d4b6f5 tags:
```
python
plt
.
figure
()
for
i
in
range
(
6
):
plt
.
plot
(
X
.
iloc
[
0
,
i
])
plt
.
xlabel
(
'
time
'
)
plt
.
ylabel
(
'
a.u.
'
)
plt
.
title
(
'
example trace
'
)
plt
.
show
()
```
%% Cell type:code id:5c2b55ce-f85a-4800-aeed-e202bc193688 tags:
```
python
plt
.
figure
()
plt
.
imshow
(
X_FC
[
0
,:,:])
plt
.
colorbar
()
plt
.
xlabel
(
'
region index
'
)
plt
.
ylabel
(
'
region index
'
)
plt
.
show
()
```
%% Cell type:code id:37e06d59-48b7-4d8d-8de3-c83641da7896 tags:
```
python
# format FC data for scikit learn (sample x feature)
ind_tri
=
np
.
tri
(
N
,
N
,
-
1
,
dtype
=
bool
)
print
(
ind_tri
.
sum
())
# X array for scikit learn
X_FC
=
FC
[:,
ind_tri
]
print
(
X_FC
.
shape
)
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment