{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84969,"databundleVersionId":10033515,"sourceType":"competition"},{"sourceId":9983979,"sourceType":"datasetVersion","datasetId":6143877}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport random\n\n# Set the directory where your particle .npy files are stored\nparticles_directory = \"/kaggle/input/cryoet-v1\"\n\n# List all .npy files in the particles directory\nnpy_files = [f for f in os.listdir(particles_directory) if f.endswith('.npy')]\n\n# Randomly select any .npy file\ndef run_one(): \n    if npy_files:\n        random_file = random.choice(npy_files)\n        file_path = os.path.join(particles_directory, random_file)\n        volume_data = np.load(file_path)\n        print(f\"Array dimensions: {volume_data.shape}\")\n        print(f\"Loaded file: {file_path}\")\n    else:\n        print(\"No .npy files found in the particles directory.\")\n        exit()\n    \n    # Calculate and print statistical values\n    mean_value = np.mean(volume_data)\n    min_value = np.min(volume_data)\n    max_value = np.max(volume_data)\n    percentile_5 = np.percentile(volume_data, 5)\n    percentile_95 = np.percentile(volume_data, 95)\n    \n    print(f\"Mean: {mean_value}\")\n    print(f\"Min: {min_value}\")\n    print(f\"Max: {max_value}\")\n    print(f\"5th Percentile: {percentile_5}\")\n    print(f\"95th Percentile: {percentile_95}\")\n    \n    # Normalize the volume data for better visualization\n    # Clip the data to the 5th and 95th percentiles to reduce the influence of extreme values\n    volume_data = np.clip(volume_data, percentile_5, percentile_95)\n    # Rescale to range [0, 1]\n    volume_data = (volume_data - percentile_5) / (percentile_95 - percentile_5)\n    volume_data[volume_data < 0.1] = 0  # Set very small values to zero for better visualization\n    \n    # Slice the array into 8 layers along the z-axis and visualize each slice\n    z_slices = np.array_split(volume_data, 8, axis=0)\n    \n    fig, axes = plt.subplots(2, 4, figsize=(20, 10))\n    axes = axes.ravel()\n    \n    for i, z_slice in enumerate(z_slices):\n        # Summarize the slice along the z-axis\n        summarized_slice = np.sum(z_slice, axis=0)\n        \n        # Plot the summarized slice\n        axes[i].imshow(summarized_slice, cmap='viridis')\n        axes[i].set_title(f'Slice {i + 1}')\n        axes[i].axis('off')\n    \n    plt.tight_layout()\n    plt.show()\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-11-22T15:30:46.335522Z","iopub.execute_input":"2024-11-22T15:30:46.335965Z","iopub.status.idle":"2024-11-22T15:30:46.356438Z","shell.execute_reply.started":"2024-11-22T15:30:46.335922Z","shell.execute_reply":"2024-11-22T15:30:46.353510Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"run_one()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-22T15:30:54.128164Z","iopub.execute_input":"2024-11-22T15:30:54.128570Z","iopub.status.idle":"2024-11-22T15:30:55.049159Z","shell.execute_reply.started":"2024-11-22T15:30:54.128534Z","shell.execute_reply":"2024-11-22T15:30:55.047684Z"}},"outputs":[],"execution_count":null}]}