{ "cells": [ { "cell_type": "markdown", "id": "194dad49", "metadata": {}, "source": [ "From the outputs of `make_connectivity_matrices.ipynb`, generates gifs of connectivity matrices for a particular variation scheme." ] }, { "cell_type": "code", "execution_count": 1, "id": "0621ea42", "metadata": {}, "outputs": [], "source": [ "import os\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import imageio" ] }, { "cell_type": "code", "execution_count": 3, "id": "be8cc712", "metadata": {}, "outputs": [], "source": [ "# specify directory/directories with images to turn into gifs\n", "plot_dirs = ['connectivity_matrices_2021_10_27/']\n", "files = np.concatenate([[os.path.join(d, x) for x in os.listdir(d)] for d in plot_dirs])" ] }, { "cell_type": "code", "execution_count": 4, "id": "388dbb7e", "metadata": {}, "outputs": [], "source": [ "# group together matrices of a particular variation scheme\n", "# (ORN bootstrapping, LN bootstrapping, PN synapse density, etc.)\n", "ORN_conmats = [f for f in files if 'resample_ORN_conmat' in f and '.png' in f]\n", "LN_conmats = [f for f in files if 'resample_LN_conmat' in f and '.png' in f]\n", "PN_conmats = [f for f in files if 'resample_PN_conmat' in f and '.png' in f]\n", "PN_density_conmats = [f for f in files if 'resample_PN_densityconmat' in f and '.png' in f]\n", "ORN_LN_PN_conmats = [f for f in files if 'resample_ORN_LN_PN_conmat' in f and '.png' in f]\n", "ORN_LN_PN_PN_density_conmats = [f for f in files if 'resample_ORN_LN_PN_PN_densityconmat' in f and '.png' in f]" ] }, { "cell_type": "code", "execution_count": 5, "id": "8b55019f", "metadata": {}, "outputs": [], "source": [ "# make names for output gifs\n", "all_conmat_sets = [ORN_conmats, LN_conmats, PN_conmats, PN_density_conmats, ORN_LN_PN_conmats, ORN_LN_PN_PN_density_conmats]\n", "conmat_set_names = ['ORN_bootstrapping', \n", " 'LN_bootstrapping',\n", " 'PN_bootstrapping',\n", " 'PN_synapse_density',\n", " 'ORN_LN_PN_bootstrapping',\n", " 'ORN_LN_PN_bootstrapping_PN_synapse_density']" ] }, { "cell_type": "code", "execution_count": 6, "id": "d6ccfc7c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[10, 10, 10, 10, 10, 10]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# check how many will go into each gif\n", "[len(x) for x in all_conmat_sets]" ] }, { "cell_type": "code", "execution_count": 9, "id": "3d35502b", "metadata": {}, "outputs": [], "source": [ "# specify save directory\n", "save_dir = '../figures/supmovies_connectivity_matrices/'\n", "# make the directory if it doesn't exist already\n", "if not os.path.exists(save_dir):\n", " os.makedirs(save_dir)" ] }, { "cell_type": "code", "execution_count": 10, "id": "6186b9a0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "saved ORN_bootstrapping\n", "saved LN_bootstrapping\n", "saved PN_bootstrapping\n", "saved PN_synapse_density\n", "saved ORN_LN_PN_bootstrapping\n", "saved ORN_LN_PN_bootstrapping_PN_synapse_density\n" ] } ], "source": [ "frame_duration = 0.5 # seconds\n", "\n", "n_sets = len(all_conmat_sets)\n", "for i in range(n_sets):\n", " # get the set of connectivity matrices\n", " conmat_set = all_conmat_sets[i]\n", " conmat_set_name = conmat_set_names[i]\n", " \n", " # convert filenames to image arrays\n", " filenames = conmat_set\n", " images = list(map(lambda filename: imageio.imread(filename), filenames))\n", " \n", " # save gif\n", " imageio.mimsave(os.path.join(save_dir, \n", " 'movie_{}.gif'.format(conmat_set_name)), \n", " images, duration = frame_duration)\n", " \n", " print('saved {}'.format(conmat_set_name))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.13" } }, "nbformat": 4, "nbformat_minor": 5 }