Skip to content

Commit b2661fe

Browse files
committed
MNT update notebooks
1 parent c1ac59a commit b2661fe

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

tutorials/notebooks/movies_3T/06_extract_motion_energy.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
},
7474
"outputs": [],
7575
"source": [
76-
"import numpy as np\nfrom moten.io import imagearray2luminance\n\nfrom voxelwise_tutorials.progress_bar import bar\nfrom voxelwise_tutorials.io import load_hdf5_array\n\n\ndef compute_luminance(run_name, size=(96, 96)):\n\n stimuli_file = os.path.join(directory, 'stimuli', run_name)\n\n # get the list of batches in the stimuli file\n with h5py.File(stimuli_file, 'r') as f:\n keys = list(f.keys())\n keys.sort() # sort the batches\n\n # compute the luminance on each batch\n luminance = []\n for key in bar(keys, title=f'compute_luminance({run_name})'):\n # load the batch of images\n images = load_hdf5_array(stimuli_file, key=key)\n\n # ``imagearray2luminance`` uses uint8 arrays\n if images.dtype != 'uint8':\n images = np.int_(np.clip(images, 0, 1) * 255).astype(np.uint8)\n\n # convert RGB images to a single luminance channel\n luminance.append(imagearray2luminance(images, size=size))\n\n return np.concatenate(luminance)\n\n\nluminance_train = np.concatenate(\n [compute_luminance(f\"train_{ii:02d}.hdf\") for ii in range(12)])\nluminance_test = compute_luminance(\"test.hdf\")"
76+
"import numpy as np\nfrom moten.io import imagearray2luminance\n\nfrom voxelwise_tutorials.progress_bar import bar\nfrom voxelwise_tutorials.io import load_hdf5_array\n\n\ndef compute_luminance(run_name, size=(96, 96), batch_size=100):\n\n stimuli_file = os.path.join(directory, 'stimuli', run_name)\n\n # get the number of images in the stimuli file\n with h5py.File(stimuli_file, 'r') as f:\n n_images = f['stimuli'].shape[0]\n\n # compute the luminance on each batch\n luminance = np.zeros((n_images, *size))\n for start in bar(range(0, n_images, batch_size),\n title=f'compute_luminance({run_name})'):\n # load the batch of images\n batch = slice(start, start + batch_size)\n images = load_hdf5_array(stimuli_file, key='stimuli', slice=batch)\n\n # ``imagearray2luminance`` uses uint8 arrays\n if images.dtype != 'uint8':\n images = np.int_(np.clip(images, 0, 1) * 255).astype(np.uint8)\n\n # convert RGB images to a single luminance channel\n luminance[batch] = imagearray2luminance(images, size=size)\n\n return luminance\n\n\nluminance_train = np.concatenate(\n [compute_luminance(f\"train_{ii:02d}.hdf\") for ii in range(12)])\nluminance_test = compute_luminance(\"test.hdf\")"
7777
]
7878
},
7979
{
@@ -109,7 +109,7 @@
109109
},
110110
"outputs": [],
111111
"source": [
112-
"from voxelwise_tutorials.io import save_hdf5_dataset\n\nfeatures_directory = os.path.join(directory, \"features\")\nif not os.path.exists(features_directory):\n os.makedirs(features_directory)\n\nsave_hdf5_dataset(\n os.path.join(features_directory, \"motion_energy_recomputed.hdf\"),\n dataset=dict(X_train=motion_energy_train, X_test=motion_energy_test))"
112+
"from voxelwise_tutorials.io import save_hdf5_dataset\n\nfeatures_directory = os.path.join(directory, \"features\")\nif not os.path.exists(features_directory):\n os.makedirs(features_directory)\n\nsave_hdf5_dataset(\n os.path.join(features_directory, \"motion_energy_recomputed.hdf\"),\n dataset=dict(X_train=motion_energy_train, X_test=motion_energy_test,\n run_onsets=np.arange(0, 3600, 300)))"
113113
]
114114
},
115115
{

0 commit comments

Comments
 (0)