{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "dab18dbb", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from scipy.misc import face\n", "from scipy.ndimage import zoom\n", "from scipy.special import logsumexp\n", "import torch\n", "import matplotlib.pyplot as plt\n", "import pickle\n", "import scipy.io\n", "import cv2\n", "import os\n", "import pandas as pd\n", "from scipy.stats import pearsonr, spearmanr" ] }, { "cell_type": "code", "execution_count": null, "id": "b48a6642", "metadata": {}, "outputs": [], "source": [ "def load_images_from_folder(folder):\n", " images = []\n", " img_name = []\n", " for filename in os.listdir(folder):\n", " img = cv2.imread(os.path.join(folder,filename))\n", " if img is not None:\n", " images.append(img)\n", " img_name.append(filename)\n", " return images, img_name" ] }, { "cell_type": "code", "execution_count": null, "id": "a79f3e8f", "metadata": {}, "outputs": [], "source": [ "imgs, img_name = load_images_from_folder('stimuli')" ] }, { "cell_type": "code", "execution_count": null, "id": "c2d3ff2c", "metadata": {}, "outputs": [], "source": [ "img_name" ] }, { "cell_type": "code", "execution_count": null, "id": "d00d5fcb", "metadata": {}, "outputs": [], "source": [ "len(scipy.io.loadmat(fn)['Results']['Disp'])" ] }, { "cell_type": "code", "execution_count": null, "id": "6957bb28", "metadata": {}, "outputs": [], "source": [ "fn = '/home/pranjul/DeepGaze/Bachelorarbeit_Christine_Huschens/results/S04/FA_Block1.mat'" ] }, { "cell_type": "code", "execution_count": null, "id": "6af13d03", "metadata": { "scrolled": true }, "outputs": [], "source": [ "len(scipy.io.loadmat(fn)['Results']['FixData'][0][0][0][63][0])" ] }, { "cell_type": "code", "execution_count": null, "id": "67e9c2eb", "metadata": {}, "outputs": [], "source": [ "fn = '/home/pranjul/DeepGaze/Bachelorarbeit_Christine_Huschens/results/S04/FA_Block1.mat'\n", "\n", "for i in range(64):\n", " gavx, gavy, sttime, entime = [], [], [], []\n", " \n", " for j in range(len(scipy.io.loadmat(fn)['Results']['FixData'][0][0][0][i][0])):\n", " gavx.append(scipy.io.loadmat(fn)['Results']['FixData'][0][0][0][i][0][j][18][0][0])\n", " gavy.append(scipy.io.loadmat(fn)['Results']['FixData'][0][0][0][i][0][j][19][0][0])\n", " sttime.append(scipy.io.loadmat(fn)['Results']['FixData'][0][0][0][i][0][j][4][0][0])\n", " entime.append(scipy.io.loadmat(fn)['Results']['FixData'][0][0][0][i][0][j][5][0][0])\n", "\n", " fixendtimes = scipy.io.loadmat(fn)['Results']['FixEndTimes'][0][0][0][i][0]\n", " stim_image_name = scipy.io.loadmat(fn)['Results']['ImPath'][0][0][0][i][0].split('\\\\')[-1]\n", " stim_folder_name = scipy.io.loadmat(fn)['Results']['ImPath'][0][0][0][i][0].split('\\\\')[-2]\n", "\n", " break\n", "\n", "gavx = np.array(gavx)\n", "gavy = np.array(gavy)\n", "sttime = np.array(sttime)\n", "entime = np.array(entime)\n", "\n", "res_width = scipy.io.loadmat(fn)['Results']['Disp'][0][0][0][0][2][0][0][0][0][0]\n", "res_height = scipy.io.loadmat(fn)['Results']['Disp'][0][0][0][0][2][0][0][1][0][0]\n", "ImWidth = scipy.io.loadmat(fn)['Results']['ImWidth'][0][0][0][0]\n", "ImHeight = scipy.io.loadmat(fn)['Results']['ImHeight'][0][0][0][0]\n", "\n", "FixX = np.round(gavx) - (res_width/2) + (ImWidth/2)\n", "FixY = np.round(gavy) - (res_height/2) + (ImHeight/2)\n", "FixDur = entime - sttime\n", "FixOnset = fixendtimes - FixDur + FixDur*.999\n", "\n", "exclude_ind = np.unique([np.where(FixDur < 100)[0][0], np.where(FixOnset < 0)[0][0]])\n", "FixX = np.delete(FixX, exclude_ind)\n", "FixY = np.delete(FixY, exclude_ind)\n", "FixDur = np.delete(FixDur, exclude_ind)\n", "FixOnset = np.delete(FixOnset, exclude_ind)\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "87e18819", "metadata": {}, "outputs": [], "source": [ "image = cv2.imread('/home/pranjul/DeepGaze/Bachelorarbeit_Christine_Huschens/stimuli/' + stim_folder_name + '/' + stim_image_name)\n", "image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n", "image = cv2.resize(image, (ImWidth, ImHeight))\n", "plt.imshow(image)\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "e07be79d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "17977642", "metadata": {}, "outputs": [], "source": [ "image.shape" ] }, { "cell_type": "code", "execution_count": null, "id": "aad511e9", "metadata": {}, "outputs": [], "source": [ "scipy.io.loadmat(fn)['Results']['ImPath'][0][0][0][i][0].split('\\\\')[-2]" ] }, { "cell_type": "code", "execution_count": null, "id": "6396d916", "metadata": {}, "outputs": [], "source": [ "\n", "#fixation_history_x = fix_X[i]/3\n", "#print(fixation_history_x)\n", "#fixation_history_y = fix_Y[i]/3\n", "#radius_history = radius[i]/5\n", "\n", "#print(fixation_history_x, fixation_history_y, radius_history)\n", "\n", "# Create a 2D matrix filled with zeros of size (600, 800)\n", "matrix_size = (1200, 1200)\n", "matrix = np.zeros(matrix_size, dtype=int)\n", "\n", "# Call the function to add circles to the matrix\n", "result_matrix = add_circles(matrix, FixY, FixX, FixDur/5)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "6f396faf", "metadata": {}, "outputs": [], "source": [ "plt.imshow(result_matrix)" ] }, { "cell_type": "code", "execution_count": null, "id": "7c35bf1b", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "2b9b0899", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "e52c9c1a", "metadata": {}, "outputs": [], "source": [ "FixX(iFix) = round(FixData(iFix).gavx - Results.Disp.Resolution.width./2 + Results.ImWidth/2); \n", "FixY(iFix) = round(FixData(iFix).gavy - Results.Disp.Resolution.height./2 + Results.ImHeight/2);\n", "FixDur(iFix) = FixData(iFix).entime - FixData(iFix).sttime;\n", "FixOnset(iFix) = Results.FixEndTimes{iIm}(iFix) - FixDur(iFix);\n", "% Bug fix to correct error in fixation onsets\n", "FixOnset(iFix) = FixOnset(iFix) + FixDur(iFix)*.999;" ] }, { "cell_type": "code", "execution_count": null, "id": "8e8787a9", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "412324a5", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "d2ebb782", "metadata": {}, "outputs": [], "source": [ "def load_fix_from_folder(folder):\n", " fix_X = []\n", " fix_Y = []\n", " radius = []\n", " img_name = []\n", " for filename in os.listdir(folder):\n", " fix_X.append(scipy.io.loadmat(os.path.join(folder,filename))['currImData'][:,4])\n", " fix_Y.append(scipy.io.loadmat(os.path.join(folder,filename))['currImData'][:,5])\n", " radius.append(scipy.io.loadmat(os.path.join(folder,filename))['currImData'][:,6])\n", " img_name.append(str(scipy.io.loadmat(os.path.join(folder,filename))['currImName'][0][0]) + '.jpg')\n", " #print(filename)\n", " #print(img_name)\n", " return fix_X, fix_Y, radius, img_name" ] }, { "cell_type": "code", "execution_count": null, "id": "78ddfb7d", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "def create_folder(folder_path):\n", " try:\n", " os.mkdir(folder_path)\n", " print(f\"Folder '{folder_path}' created successfully.\")\n", " except FileExistsError:\n", " print(f\"Folder '{folder_path}' already exists.\")\n", " except Exception as e:\n", " print(f\"An error occurred: {e}\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "585be960", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "def folder_exists(folder_path):\n", " return os.path.exists(folder_path) and os.path.isdir(folder_path)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "25fa0752", "metadata": {}, "outputs": [], "source": [ "def add_circles(matrix, x_list, y_list, r_list):\n", " for x, y, r in zip(x_list, y_list, r_list):\n", " x, y, r = int(x), int(y), int(r)\n", " for i in range(max(0, y - r), min(matrix.shape[0], y + r + 1)):\n", " for j in range(max(0, x - r), min(matrix.shape[1], x + r + 1)):\n", " if (i - y) ** 2 + (j - x) ** 2 <= r ** 2:\n", " matrix[i][j] += 1\n", " return matrix" ] }, { "cell_type": "code", "execution_count": null, "id": "bd2da5f7", "metadata": { "scrolled": true }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from scipy.misc import face\n", "from scipy.ndimage import zoom\n", "from scipy.special import logsumexp\n", "import torch\n", "\n", "import deepgaze_pytorch\n", "\n", "DEVICE = 'cuda'\n", "\n", "# you can use DeepGazeI or DeepGazeIIE\n", "model = deepgaze_pytorch.DeepGazeIII(pretrained=True).to(DEVICE)\n", "\n", "#image = face()\n", "\n", "n_f = '/home/pranjul/DeepGaze/Bachelorarbeit_Christine_Huschens_(1)/results/S'\n", "\n", "for q in range(30, 41):\n", " \n", " x = []\n", " \n", " # Replace 'path/to/your/folder' with the folder path you want to check\n", " folder_path = n_f + str(q)\n", " \n", " if folder_exists(folder_path):\n", " \n", " #fix_X, fix_Y, radius, img_name = load_fix_from_folder('S_fix/S'+ str(q) +'_fix')\n", "\n", " # Replace 'path/to/your/folder' with the desired folder path\n", " folder_path = '/home/pranjul/DeepGaze/Bachelorarbeit_Christine_Huschens/DG3_HG_heatmaps_c/S'+ str(q) +'_fix_c'\n", " create_folder(folder_path)\n", "\n", " for file in sorted(os.listdir(n_f + str(q))):\n", " if 'Block' in file:\n", " print(file) \n", "\n", " fn = n_f + str(q) + '/' + file\n", "\n", " for i in range(64):\n", " gavx, gavy, sttime, entime = [], [], [], []\n", "\n", " for j in range(len(scipy.io.loadmat(fn)['Results']['FixData'][0][0][0][i][0])):\n", " gavx.append(scipy.io.loadmat(fn)['Results']['FixData'][0][0][0][i][0][j][18][0][0])\n", " gavy.append(scipy.io.loadmat(fn)['Results']['FixData'][0][0][0][i][0][j][19][0][0])\n", " sttime.append(scipy.io.loadmat(fn)['Results']['FixData'][0][0][0][i][0][j][4][0][0])\n", " entime.append(scipy.io.loadmat(fn)['Results']['FixData'][0][0][0][i][0][j][5][0][0])\n", "\n", " fixendtimes = scipy.io.loadmat(fn)['Results']['FixEndTimes'][0][0][0][i][0]\n", " stim_image_name = scipy.io.loadmat(fn)['Results']['ImPath'][0][0][0][i][0].split('\\\\')[-1]\n", " stim_folder_name = scipy.io.loadmat(fn)['Results']['ImPath'][0][0][0][i][0].split('\\\\')[-2]\n", "\n", " #break\n", "\n", " gavx = np.array(gavx)\n", " gavy = np.array(gavy)\n", " sttime = np.array(sttime)\n", " entime = np.array(entime)\n", "\n", " res_width = scipy.io.loadmat(fn)['Results']['Disp'][0][0][0][0][2][0][0][0][0][0]\n", " res_height = scipy.io.loadmat(fn)['Results']['Disp'][0][0][0][0][2][0][0][1][0][0]\n", " ImWidth = scipy.io.loadmat(fn)['Results']['ImWidth'][0][0][0][0]\n", " ImHeight = scipy.io.loadmat(fn)['Results']['ImHeight'][0][0][0][0]\n", "\n", " FixX = np.round(gavx) - (res_width/2) + (ImWidth/2)\n", " FixY = np.round(gavy) - (res_height/2) + (ImHeight/2)\n", " FixDur = entime - sttime\n", " FixOnset = fixendtimes - FixDur + FixDur\n", " \n", " #print(FixDur)\n", " #print(FixOnset)\n", " dur_indices = np.where(FixDur < 100)[0]\n", " onset_indices = np.where(FixOnset < 0)[0]\n", "\n", " exclude_ind = np.unique(np.concatenate([dur_indices, onset_indices]))\n", " \n", " print(exclude_ind)\n", " FixX = np.delete(FixX, exclude_ind)\n", " FixY = np.delete(FixY, exclude_ind)\n", " FixDur = np.delete(FixDur, exclude_ind)\n", " FixOnset = np.delete(FixOnset, exclude_ind) \n", " \n", " image = cv2.imread('/home/pranjul/DeepGaze/Bachelorarbeit_Christine_Huschens/stimuli/' + stim_folder_name + '/' + stim_image_name)\n", " create_folder(os.path.join(folder_path, stim_folder_name))\n", " \n", " #image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n", " image = cv2.resize(image, (ImWidth, ImHeight)) \n", " \n", " if image is not None and len(FixX) > 3 and len(FixY > 3):\n", "\n", " # location of previous scanpath fixations in x and y (pixel coordinates), starting with the initial fixation on the image.\n", " #fixation_history_x = np.array([1024//2, 300, 500, 200, 200, 700])\n", " #fixation_history_y = np.array([768//2, 300, 100, 300, 100, 500])\n", "\n", " #print(img_name[i])\n", "\n", " fixation_history_x = FixX\n", " #print(fixation_history_x)\n", " fixation_history_y = FixY\n", " #radius_history = radius[i]/5\n", "\n", " #print(fixation_history_x, fixation_history_y, radius_history)\n", "\n", " # Create a 2D matrix filled with zeros of size (600, 800)\n", " matrix_size = (ImWidth, ImHeight)\n", " matrix = np.zeros(matrix_size, dtype=int)\n", "\n", " # Call the function to add circles to the matrix\n", " result_matrix = add_circles(matrix, FixX, FixY, FixDur/5)\n", "\n", " #plt.imshow(result_matrix)\n", " #plt.plot(fixation_history_x, fixation_history_y, 'o-', color='red')\n", " #plt.axis('on')\n", " #plt.colorbar(fraction=0.046, pad=0.04) # Adjust fraction and pad values as needed\n", " #plt.tight_layout()\n", "\n", " # load precomputed centerbias log density (from MIT1003) over a 1024x1024 image\n", " # you can download the centerbias from https://github.com/matthias-k/DeepGaze/releases/download/v1.0.0/centerbias_mit1003.npy\n", " # alternatively, you can use a uniform centerbias via `centerbias_template = np.zeros((1024, 1024))`.\n", " centerbias_template = np.load('centerbias_mit1003.npy')\n", "\n", " # rescale to match image size\n", " centerbias = zoom(centerbias_template, (image.shape[0]/centerbias_template.shape[0], image.shape[1]/centerbias_template.shape[1]), order=0, mode='nearest')\n", " # renormalize log density\n", " centerbias -= logsumexp(centerbias)\n", "\n", " image_tensor = torch.tensor([image.transpose(2, 0, 1)]).to(DEVICE)\n", " centerbias_tensor = torch.tensor([centerbias]).to(DEVICE)\n", " x_hist_tensor = torch.tensor([fixation_history_x[model.included_fixations]]).to(DEVICE)\n", " y_hist_tensor = torch.tensor([fixation_history_y[model.included_fixations]]).to(DEVICE)\n", "\n", " log_density_prediction = model(image_tensor, centerbias_tensor, x_hist_tensor, y_hist_tensor)\n", "\n", " # Scale factor\n", " #scale_factor = 3\n", "\n", " # Calculate the new width and height\n", " #new_width = image.shape[1] * scale_factor\n", " #new_height = image.shape[0] * scale_factor\n", "\n", " # Resize the image using cv2.resize()\n", " #image = cv2.resize(image, (new_width, new_height))\n", "\n", " image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n", "\n", " x.append((log_density_prediction.detach().cpu().numpy()[0, 0], str(stim_folder_name), str(stim_image_name.split('.')[0]),\n", " 'S' + str(q), result_matrix))\n", "\n", " f, axs = plt.subplots(nrows=1, ncols=3, figsize=(16, 9))\n", " axs[0].imshow(image)\n", " axs[0].plot(fixation_history_x, fixation_history_y, 'o-', color='red')\n", " axs[0].scatter(fixation_history_x[-1], fixation_history_y[-1], 100, color='white', zorder=100)\n", " axs[0].set_axis_off()\n", " axs[1].matshow(log_density_prediction.detach().cpu().numpy()[0, 0]) # first image in batch, first (and only) channel\n", " axs[1].plot(fixation_history_x, fixation_history_y, 'o-', color='red')\n", " axs[1].scatter(fixation_history_x[-1], fixation_history_y[-1], 100, color='white', zorder=100)\n", " axs[1].set_axis_off()\n", " axs[2].matshow(result_matrix)\n", " axs[2].plot(fixation_history_x, fixation_history_y, 'o-', color='red')\n", " axs[2].scatter(fixation_history_x[-1], fixation_history_y[-1], 100, color='white', zorder=100)\n", " axs[2].set_axis_off()\n", " plt.tight_layout()\n", " plt.savefig(os.path.join(folder_path, stim_folder_name, stim_image_name.split('.')[0] + '.png'))\n", " #plt.show()\n", " plt.close()\n", " #break\n", "\n", " # Open a file in binary write mode\n", " with open(folder_path + '/' + 'S' + str(q) + '.pkl', 'wb') as file:\n", " pickle.dump(x, file)\n", "\n", " #break\n", " #break" ] }, { "cell_type": "code", "execution_count": null, "id": "d083b6bf", "metadata": {}, "outputs": [], "source": [ "np.shape(x)" ] }, { "cell_type": "code", "execution_count": null, "id": "3b1a8ba5", "metadata": {}, "outputs": [], "source": [ "32*8" ] }, { "cell_type": "code", "execution_count": 2, "id": "970201dc", "metadata": {}, "outputs": [], "source": [ "x_loaded = {}" ] }, { "cell_type": "code", "execution_count": 7, "id": "072a0b13", "metadata": {}, "outputs": [], "source": [ "for q in range(10, 41):\n", "\n", " # Replace 'path/to/your/folder' with the folder path you want to check\n", " folder_path = '/raid/pranjul/DG3_HG_heatmaps_c/S'+ str(q) +'_fix_c'\n", " \n", " if folder_exists(folder_path):\n", " # Open a file in binary write mode\n", " with open('/raid/pranjul/DG3_HG_heatmaps_c/S'+ str(q) +'_fix_c/' + 'S'+ str(q) + '.pkl', 'rb') as file:\n", " x_loaded[q] = pickle.load(file)\n", "\n", "#x_loaded = [x.tolist() for x in x_loaded]" ] }, { "cell_type": "code", "execution_count": 8, "id": "eef8a427", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "37" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(x_loaded)" ] }, { "cell_type": "code", "execution_count": null, "id": "532e15cd", "metadata": {}, "outputs": [], "source": [ "x_loaded" ] }, { "cell_type": "code", "execution_count": null, "id": "a4e0f88c", "metadata": { "scrolled": true }, "outputs": [], "source": [ "x_loaded[4]" ] }, { "cell_type": "code", "execution_count": null, "id": "4d0b7c18", "metadata": {}, "outputs": [], "source": [ "plt.imshow(x_loaded[4][0][0])" ] }, { "cell_type": "code", "execution_count": null, "id": "7253f70f", "metadata": {}, "outputs": [], "source": [ "plt.imshow(x_loaded[4][0][4])" ] }, { "cell_type": "code", "execution_count": 10, "id": "48886c2d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "9472" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "256*37" ] }, { "cell_type": "code", "execution_count": null, "id": "fb4e8b68", "metadata": {}, "outputs": [], "source": [ "for i in range(2):\n", " print(f\"Iter:{i+1}\")\n" ] }, { "cell_type": "code", "execution_count": 9, "id": "9743923c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " dg3 stim_folder \\\n", "0 [[-21.89091177095421, -21.89091177095421, -21.... pareidolia \n", "1 [[-23.752590900618024, -23.752590900618024, -2... pareidolia_inv \n", "2 [[-22.717763718089778, -22.717763718089778, -2... faces \n", "3 [[-23.13883206422637, -23.13883206422637, -23.... objects \n", "4 [[-20.465820021512595, -20.465820021512595, -2... pareidolia_inv \n", "... ... ... \n", "9204 [[-22.03320704181483, -22.03320704181483, -22.... objects_inv \n", "9205 [[-19.347162311089896, -19.347162311089896, -1... pareidolia_inv \n", "9206 [[-21.903870228837253, -21.903870228837253, -2... objects \n", "9207 [[-19.344542363086855, -19.344542363086855, -1... faces_inv \n", "9208 [[-24.540417387594943, -24.540417387594943, -2... pareidolia_inv \n", "\n", " stim_name sub hg \n", "0 64 S04 [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... \n", "1 56_inv S04 [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... \n", "2 face31 S04 [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... \n", "3 16_match S04 [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... \n", "4 46_inv S04 [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... \n", "... ... ... ... \n", "9204 74_match_inv S40 [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... \n", "9205 15_inv S40 [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... \n", "9206 39_match S40 [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... \n", "9207 face12_inv S40 [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... \n", "9208 06_inv S40 [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,... \n", "\n", "[9209 rows x 5 columns]\n" ] } ], "source": [ "import pandas as pd\n", "\n", "# Assuming x_loaded is a dictionary\n", "data_frames = []\n", "\n", "for key, value in x_loaded.items():\n", " df = pd.DataFrame(value, columns=['dg3', 'stim_folder', 'stim_name', 'sub', 'hg'])\n", " data_frames.append(df)\n", "\n", "# Concatenate DataFrames\n", "df = pd.concat(data_frames, ignore_index=True)\n", "\n", "# Display the resulting DataFrame\n", "print(df)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "4d51aabe", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 11, "id": "9fc92e53", "metadata": {}, "outputs": [], "source": [ "df_agg_hg = df.groupby(['stim_folder', 'stim_name'])['hg'].apply(lambda x: np.mean(x.tolist(), axis=0)).reset_index()\n" ] }, { "cell_type": "code", "execution_count": 12, "id": "2e9d4054", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | stim_folder | \n", "stim_name | \n", "hg | \n", "
---|---|---|---|
0 | \n", "faces | \n", "face01 | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
1 | \n", "faces | \n", "face02 | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
2 | \n", "faces | \n", "face03 | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
3 | \n", "faces | \n", "face04 | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
4 | \n", "faces | \n", "face05 | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
251 | \n", "pareidolia_inv | \n", "75_inv | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
252 | \n", "pareidolia_inv | \n", "78_inv | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
253 | \n", "pareidolia_inv | \n", "80_inv | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
254 | \n", "pareidolia_inv | \n", "81_inv | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
255 | \n", "pareidolia_inv | \n", "83_inv | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
256 rows × 3 columns
\n", "\n", " | stim_folder | \n", "stim_name | \n", "hg | \n", "
---|---|---|---|
0 | \n", "faces | \n", "face01 | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
1 | \n", "faces | \n", "face02 | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
2 | \n", "faces | \n", "face03 | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
3 | \n", "faces | \n", "face04 | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
4 | \n", "faces | \n", "face05 | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
251 | \n", "pareidolia_inv | \n", "75_inv | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
252 | \n", "pareidolia_inv | \n", "78_inv | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
253 | \n", "pareidolia_inv | \n", "80_inv | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
254 | \n", "pareidolia_inv | \n", "81_inv | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
255 | \n", "pareidolia_inv | \n", "83_inv | \n", "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,... | \n", "
256 rows × 3 columns
\n", "