{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":94147,"databundleVersionId":11390004,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# ☂️ First of all, I am here to say basic things about H5PY, Matplotlib, etc.","metadata":{}},{"cell_type":"markdown","source":"## It means, if you are not beginners or interested in it, you can skip this notebook.\n\n## The second thing, you will see different approaches for the code side. 🪡\n\n> ### I didn't use any part of AI tools neither while I am writing these markdowns nor the codes I wrote. I wanted to create different ways of doing something, peculiarly.","metadata":{}},{"cell_type":"code","source":"# As all of you already know, we are starting to import these libraries using basic syntax.\n\nimport numpy as np\nimport pandas as pd\nimport h5py","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:34.231765Z","iopub.execute_input":"2025-05-17T14:08:34.232089Z","iopub.status.idle":"2025-05-17T14:08:35.614443Z","shell.execute_reply.started":"2025-05-17T14:08:34.232059Z","shell.execute_reply":"2025-05-17T14:08:35.613502Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Then, we copy our file's path and paste it to upload.\n\nh5file = h5py.File(\"/kaggle/input/el-hackathon-2025/elucidata_ai_challenge_data.h5\", \"r\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:35.618582Z","iopub.execute_input":"2025-05-17T14:08:35.619101Z","iopub.status.idle":"2025-05-17T14:08:35.636850Z","shell.execute_reply.started":"2025-05-17T14:08:35.619071Z","shell.execute_reply":"2025-05-17T14:08:35.635032Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## 🤏🏻 Let me tell you something about h5py files...\n\n### h5py is a library that we use for huge datasets. We don't want to strain our system, so when we work with huge datasets, we take files partly from our main file, not all of them.\n### In our project (Elucidata), we don't need to do it (because files are not as huge), but it's a good opportunity to practice with this library. So let's take advantage of this opportunity.","metadata":{}},{"cell_type":"code","source":"# This is a different style of printing. Let's look at what our file has:\n\nwith h5py.File(\"/kaggle/input/el-hackathon-2025/elucidata_ai_challenge_data.h5\", \"r\") as file:\n    for name in file:\n        print(name, \"/\")\n        for j in file[name]:\n            print(\"---\",j, \"//\")\n            for k in file[name][j]:\n                print(\"------\",k)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:35.639900Z","iopub.execute_input":"2025-05-17T14:08:35.640226Z","iopub.status.idle":"2025-05-17T14:08:35.714370Z","shell.execute_reply.started":"2025-05-17T14:08:35.640200Z","shell.execute_reply":"2025-05-17T14:08:35.713292Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# We can do the same thing as above, with a function. Let's see:\n\ndef get_around(group, level=0):\n    for name in group:\n        thing = group[name]\n        print(\"--\" * level + name)\n        if isinstance(thing, h5py.Group):\n            get_around(thing, level + 1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:35.715446Z","iopub.execute_input":"2025-05-17T14:08:35.715926Z","iopub.status.idle":"2025-05-17T14:08:35.732038Z","shell.execute_reply.started":"2025-05-17T14:08:35.715892Z","shell.execute_reply":"2025-05-17T14:08:35.730816Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"with h5py.File(\"/kaggle/input/el-hackathon-2025/elucidata_ai_challenge_data.h5\", \"r\") as file:\n    get_around(file)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:35.732984Z","iopub.execute_input":"2025-05-17T14:08:35.733728Z","iopub.status.idle":"2025-05-17T14:08:35.773521Z","shell.execute_reply.started":"2025-05-17T14:08:35.733699Z","shell.execute_reply":"2025-05-17T14:08:35.772647Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Okay. Let's save these things as variables to reach them easily. Normally, h5py was not created for this type of usage. But like I said before, our data is not as huge.","metadata":{}},{"cell_type":"code","source":"with h5py.File(\"/kaggle/input/el-hackathon-2025/elucidata_ai_challenge_data.h5\", \"r\") as file:\n    def load_data(file, group_path):\n        return {s_name: file[group_path][s_name][:] for s_name in file[group_path]}\n    train_images = load_data(file, \"images/Train\")\n    test_images = load_data(file, \"images/Test\")\n    train_spots = load_data(file, \"spots/Train\")\n    test_spots = load_data(file, \"spots/Test\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:35.774492Z","iopub.execute_input":"2025-05-17T14:08:35.774839Z","iopub.status.idle":"2025-05-17T14:08:37.594119Z","shell.execute_reply.started":"2025-05-17T14:08:35.774809Z","shell.execute_reply":"2025-05-17T14:08:37.593040Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# What are these file types? What do they look like?\n\nprint(type(train_images))\nprint(type(train_images[\"S_1\"]))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:37.594992Z","iopub.execute_input":"2025-05-17T14:08:37.595256Z","iopub.status.idle":"2025-05-17T14:08:37.600564Z","shell.execute_reply.started":"2025-05-17T14:08:37.595235Z","shell.execute_reply":"2025-05-17T14:08:37.599366Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_images[\"S_1\"][0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:37.601904Z","iopub.execute_input":"2025-05-17T14:08:37.602269Z","iopub.status.idle":"2025-05-17T14:08:37.632143Z","shell.execute_reply.started":"2025-05-17T14:08:37.602236Z","shell.execute_reply":"2025-05-17T14:08:37.630516Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"##### 🪩 Hmm... Every image actually was a bunch of float numbers... <br>\n\n##### ⭐ I understand that these numbers describe RGB (Red, Green, and Blue) values. So, for the first image in train_images (which is S_1), the far left and top point's values were this...","metadata":{}},{"cell_type":"code","source":"print(type(train_images[\"S_1\"].item(0)))\ntrain_images[\"S_1\"].item(0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:37.637683Z","iopub.execute_input":"2025-05-17T14:08:37.638126Z","iopub.status.idle":"2025-05-17T14:08:37.658784Z","shell.execute_reply.started":"2025-05-17T14:08:37.638095Z","shell.execute_reply":"2025-05-17T14:08:37.657768Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Let's focus on the Matplotlib part.","metadata":{}},{"cell_type":"markdown","source":"> ### 🖼️ I want to visualize these NUMBERS, maybe tear it to pieces...\n> ### 💠 I want to slide the color of the spots that an image has...\n> ### 🖲️ For instance, what is \"C35\" and what it looks like? I want to focus on it.\n> ### In summary, I want to examine this data.","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:37.659808Z","iopub.execute_input":"2025-05-17T14:08:37.660301Z","iopub.status.idle":"2025-05-17T14:08:37.677085Z","shell.execute_reply.started":"2025-05-17T14:08:37.660273Z","shell.execute_reply":"2025-05-17T14:08:37.675995Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# How many dimensions does it have?\ntrain_images[\"S_1\"].ndim","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:37.678235Z","iopub.execute_input":"2025-05-17T14:08:37.678562Z","iopub.status.idle":"2025-05-17T14:08:37.700449Z","shell.execute_reply.started":"2025-05-17T14:08:37.678533Z","shell.execute_reply":"2025-05-17T14:08:37.699531Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"##### The difference between the function \"sum\" of numpy and the Python \"sum\".","metadata":{}},{"cell_type":"code","source":"ex_arr = np.array([[1, 2], [3, 4]])\nprint(sum(ex_arr))  # result: the sum of that array is → 10","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:37.701507Z","iopub.execute_input":"2025-05-17T14:08:37.701916Z","iopub.status.idle":"2025-05-17T14:08:37.722679Z","shell.execute_reply.started":"2025-05-17T14:08:37.701886Z","shell.execute_reply":"2025-05-17T14:08:37.721660Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(ex_arr.sum())           # result: 10\nprint(ex_arr.sum(axis=0))    # result: total by column → [4, 6]\nprint(ex_arr.sum(axis=1))     # result: total by row → [3, 7]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:37.724044Z","iopub.execute_input":"2025-05-17T14:08:37.724472Z","iopub.status.idle":"2025-05-17T14:08:37.745334Z","shell.execute_reply.started":"2025-05-17T14:08:37.724443Z","shell.execute_reply":"2025-05-17T14:08:37.743815Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"##### Thus, you could identify a special behavior for the library that you use, and get relaxed.  ","metadata":{}},{"cell_type":"markdown","source":"# IMG","metadata":{}},{"cell_type":"code","source":"# The \"plot\" function of NumPy doesn't work with 2D data.\n\nkey = \"S_1\"\nimg = train_images[key]\nplt.imshow(img)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:37.746558Z","iopub.execute_input":"2025-05-17T14:08:37.746969Z","iopub.status.idle":"2025-05-17T14:08:39.315915Z","shell.execute_reply.started":"2025-05-17T14:08:37.746941Z","shell.execute_reply":"2025-05-17T14:08:39.314836Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"flattened = train_images[\"S_1\"].reshape(-1)\nplt.plot(flattened)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:39.317076Z","iopub.execute_input":"2025-05-17T14:08:39.317767Z","iopub.status.idle":"2025-05-17T14:08:42.489525Z","shell.execute_reply.started":"2025-05-17T14:08:39.317723Z","shell.execute_reply":"2025-05-17T14:08:42.488665Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"img.shape\n\n# 2000 height, 1974 width, 3 RGB colors.\n# So it has (2000 x 1974 x 3) value. -> 11.844.000","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:42.490666Z","iopub.execute_input":"2025-05-17T14:08:42.491001Z","iopub.status.idle":"2025-05-17T14:08:42.497293Z","shell.execute_reply.started":"2025-05-17T14:08:42.490979Z","shell.execute_reply":"2025-05-17T14:08:42.496075Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train_images[\"S_1\"][0].shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:42.498193Z","iopub.execute_input":"2025-05-17T14:08:42.498484Z","iopub.status.idle":"2025-05-17T14:08:42.517698Z","shell.execute_reply.started":"2025-05-17T14:08:42.498455Z","shell.execute_reply":"2025-05-17T14:08:42.516692Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# This is the first pixel of the \"height\" and it has a 1974 width value with the 3 different colors: \nprint(train_images[\"S_1\"][0])\n\nprint(\"--------------------\")\n\n# If you want to focus on RGB colors for the first pixel of the image, you could use:\nprint(train_images[\"S_1\"][0][0])\n\nprint(\"--------------------\")\n\n# If you want to focus on the RED color of the first pixel of the image, you could use:\nprint(train_images[\"S_1\"][0][0][0])\n\nprint(\"--------------------\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:42.518625Z","iopub.execute_input":"2025-05-17T14:08:42.519288Z","iopub.status.idle":"2025-05-17T14:08:42.542631Z","shell.execute_reply.started":"2025-05-17T14:08:42.519254Z","shell.execute_reply":"2025-05-17T14:08:42.541714Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# I just tried what would happen if I ran this code, nothing important here:\n\nplt.plot(img[444][1])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:42.543696Z","iopub.execute_input":"2025-05-17T14:08:42.544117Z","iopub.status.idle":"2025-05-17T14:08:42.736194Z","shell.execute_reply.started":"2025-05-17T14:08:42.544081Z","shell.execute_reply":"2025-05-17T14:08:42.735346Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(img[:,:,1])\n\n# If I choose a color to see the first image:","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:42.737062Z","iopub.execute_input":"2025-05-17T14:08:42.737362Z","iopub.status.idle":"2025-05-17T14:08:43.400599Z","shell.execute_reply.started":"2025-05-17T14:08:42.737338Z","shell.execute_reply":"2025-05-17T14:08:43.399674Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def visualizing(img):\n    fig = plt.figure(figsize=(10,7))\n\n    plt.subplot(3, 3, 1)  # 2 rows, 2 columns, first position\n    plt.imshow(img)  \n    plt.axis('off')  # Hide the axis labels\n    plt.title(\"Original\") \n    \n    # Add the second image to the figure (top-right position)\n    plt.subplot(3, 3, 2)  # 2 rows, 2 columns, second position\n    plt.imshow(img[:,:,0],cmap=\"Greens\")  \n    plt.axis('off')  # Hide the axis labels\n    plt.title(\"Green\") \n    \n    # Add the third image to the figure (bottom-left position)\n    plt.subplot(3, 3, 3)  # 2 rows, 2 columns, third position\n    plt.imshow(img[:,:,0],cmap=\"Reds\") \n    plt.axis('off')  # Hide the axis labels\n    plt.title(\"Red\")  \n    # Add the fourth image to the figure (bottom-right position)\n    plt.subplot(3, 3, 4)  # 2 rows, 2 columns, fourth position\n    plt.imshow(img[:,:,0],cmap=\"Blues\")  \n    plt.axis('off')  # Hide the axis labels\n    plt.title(\"Blue\")  \n    \n    plt.subplot(3,3,5)\n    plt.imshow(img[:,:,0], cmap=\"Purples_r\")\n    plt.axis(\"off\")\n    plt.title(\"Purple\")\n\n    plt.subplot(3,3,6)\n    plt.imshow(img[:,:,0], cmap=\"turbo\")\n    plt.title(\"Turbo\")\n    \n    # Plotlib is fun... Really.🤩","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:43.401707Z","iopub.execute_input":"2025-05-17T14:08:43.402003Z","iopub.status.idle":"2025-05-17T14:08:43.410063Z","shell.execute_reply.started":"2025-05-17T14:08:43.401982Z","shell.execute_reply":"2025-05-17T14:08:43.409083Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"visualizing(img)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:43.411101Z","iopub.execute_input":"2025-05-17T14:08:43.411392Z","iopub.status.idle":"2025-05-17T14:08:47.125592Z","shell.execute_reply.started":"2025-05-17T14:08:43.411362Z","shell.execute_reply":"2025-05-17T14:08:47.124561Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from matplotlib import colormaps\nprint(colormaps)\n# To see the colors you can use on plotlib","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:47.126944Z","iopub.execute_input":"2025-05-17T14:08:47.127266Z","iopub.status.idle":"2025-05-17T14:08:47.133387Z","shell.execute_reply.started":"2025-05-17T14:08:47.127242Z","shell.execute_reply":"2025-05-17T14:08:47.132186Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Can spots be printable? Let's examine.","metadata":{}},{"cell_type":"code","source":"spot = train_spots[key]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:47.134559Z","iopub.execute_input":"2025-05-17T14:08:47.134952Z","iopub.status.idle":"2025-05-17T14:08:47.154478Z","shell.execute_reply.started":"2025-05-17T14:08:47.134920Z","shell.execute_reply":"2025-05-17T14:08:47.153405Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"spot.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:47.155608Z","iopub.execute_input":"2025-05-17T14:08:47.155999Z","iopub.status.idle":"2025-05-17T14:08:47.175890Z","shell.execute_reply.started":"2025-05-17T14:08:47.155937Z","shell.execute_reply":"2025-05-17T14:08:47.175028Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"spot.dtype","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:47.176913Z","iopub.execute_input":"2025-05-17T14:08:47.177225Z","iopub.status.idle":"2025-05-17T14:08:47.197255Z","shell.execute_reply.started":"2025-05-17T14:08:47.177200Z","shell.execute_reply":"2025-05-17T14:08:47.196310Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 🧐\n#### Hmm.... Okay... x and y are coordinates for the spots... And their data type is \"<i8\". It means integer-8. \n\n#### The other things are the spots that we need to find... Okay... Their data type \"<f8\" is the short form of float-8.","metadata":{}},{"cell_type":"code","source":"img.dtype","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:47.202556Z","iopub.execute_input":"2025-05-17T14:08:47.202911Z","iopub.status.idle":"2025-05-17T14:08:47.217848Z","shell.execute_reply.started":"2025-05-17T14:08:47.202877Z","shell.execute_reply":"2025-05-17T14:08:47.216680Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# How many X, Y, and \"C\" values are there in a spot variable?\n\nprint(spot[\"x\"].sum())\nprint(spot[\"y\"].sum())\nprint(spot[\"C1\"].sum())\nprint(spot[\"C2\"].sum())\nprint(\"----------- \\n\")\nprint(spot[\"C35\"].sum())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:47.218823Z","iopub.execute_input":"2025-05-17T14:08:47.219139Z","iopub.status.idle":"2025-05-17T14:08:47.241192Z","shell.execute_reply.started":"2025-05-17T14:08:47.219117Z","shell.execute_reply":"2025-05-17T14:08:47.240057Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"spot[\"C1\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:47.242234Z","iopub.execute_input":"2025-05-17T14:08:47.242555Z","iopub.status.idle":"2025-05-17T14:08:47.262131Z","shell.execute_reply.started":"2025-05-17T14:08:47.242516Z","shell.execute_reply":"2025-05-17T14:08:47.260943Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 😲\n## \"Spots\" are actually 1D dots. We just mount it on our images... Well.","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,7))\n\nplt.imshow(img)  \nplt.axis('off')  # Hide the axis labels\nplt.title(\"Original\") \nplt.scatter(spot[\"x\"],spot[\"y\"])\n\n# When we put these dots on the image.. Image looks like this.. I GOT IT.","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:47.263177Z","iopub.execute_input":"2025-05-17T14:08:47.263604Z","iopub.status.idle":"2025-05-17T14:08:48.616611Z","shell.execute_reply.started":"2025-05-17T14:08:47.263560Z","shell.execute_reply":"2025-05-17T14:08:48.615691Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(img)  \nplt.axis('off')  # Hide the axis labels\nplt.title(\"Original\") \nplt.scatter(spot[\"x\"],spot[\"y\"], s=10, c=\"red\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:48.618290Z","iopub.execute_input":"2025-05-17T14:08:48.618602Z","iopub.status.idle":"2025-05-17T14:08:49.867888Z","shell.execute_reply.started":"2025-05-17T14:08:48.618574Z","shell.execute_reply":"2025-05-17T14:08:49.866932Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def imaginary(img, number, figsize, s):\n    fig = plt.figure(figsize=figsize)\n    plt.imshow(img)\n    plt.scatter(spot[\"x\"], spot[\"y\"], c=spot[f\"C{number}\"], cmap=\"coolwarm\", s=s)\n    plt.colorbar()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:49.868918Z","iopub.execute_input":"2025-05-17T14:08:49.869219Z","iopub.status.idle":"2025-05-17T14:08:49.875201Z","shell.execute_reply.started":"2025-05-17T14:08:49.869182Z","shell.execute_reply":"2025-05-17T14:08:49.874212Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"imaginary(img, 35, (20,15), 5)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:49.876363Z","iopub.execute_input":"2025-05-17T14:08:49.877124Z","iopub.status.idle":"2025-05-17T14:08:52.052286Z","shell.execute_reply.started":"2025-05-17T14:08:49.877100Z","shell.execute_reply":"2025-05-17T14:08:52.050963Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 🤠\n### Making everything a function is too fun. You just name it for once and use it later.. Whatever, let's continue :)","metadata":{}},{"cell_type":"code","source":"# Threshold filter... Print where \"C35\" is higher than \"0.5\" value... \nmask = spot[\"C35\"] > 0.5\n\n\nplt.imshow(img)\nplt.scatter(spot[\"x\"][mask], spot[\"y\"][mask], c=\"red\", s=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:52.053708Z","iopub.execute_input":"2025-05-17T14:08:52.054120Z","iopub.status.idle":"2025-05-17T14:08:53.396311Z","shell.execute_reply.started":"2025-05-17T14:08:52.054083Z","shell.execute_reply":"2025-05-17T14:08:53.395397Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# So, where are these points? What are their values?\nimg[spot[\"y\"][mask], spot[\"x\"][mask]]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:53.397166Z","iopub.execute_input":"2025-05-17T14:08:53.397422Z","iopub.status.idle":"2025-05-17T14:08:53.403843Z","shell.execute_reply.started":"2025-05-17T14:08:53.397404Z","shell.execute_reply":"2025-05-17T14:08:53.403019Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# 💐\n\n### Okay, make it more colorful and different.\n\n### Values can be changed. I choose them randomly.","metadata":{}},{"cell_type":"code","source":"def plot_it(img, number, figsize_1, figsize_2, s):\n    fig = plt.figure(figsize=(figsize_1, figsize_2))\n\n    plt.suptitle(f\"SLIDE: {key} SPOT: C{number}\")\n    plt.subplot(1, 3, 1)  \n    plt.imshow(img)  \n    plt.axis('off')  \n    plt.title(\"Original\")\n    plt.colorbar()\n\n    plt.subplot(1, 3, 2) \n    plt.imshow(img)  \n    plt.axis('off')  \n    plt.title(\"Colorized\") \n    plt.scatter(spot[\"x\"],spot[\"y\"], s=s, c=\"red\")\n    plt.colorbar()\n\n    plt.subplot(1, 3, 3)  \n    plt.imshow(img)  \n    plt.axis('off')  \n    plt.title(\"Detailed\") \n    plt.scatter(spot[\"x\"], spot[\"y\"], c=spot[f\"C{number}\"], cmap=\"coolwarm\", s=s)\n    plt.colorbar()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:53.404805Z","iopub.execute_input":"2025-05-17T14:08:53.405581Z","iopub.status.idle":"2025-05-17T14:08:53.426508Z","shell.execute_reply.started":"2025-05-17T14:08:53.405487Z","shell.execute_reply":"2025-05-17T14:08:53.425457Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"key = \"S_1\"\nimg = train_images[key]\nspot = train_spots[key]\n\n# Values can be changed. I choose them randomly.\nplot_it(img, 24, 20, 5, 1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:53.427325Z","iopub.execute_input":"2025-05-17T14:08:53.427676Z","iopub.status.idle":"2025-05-17T14:08:57.470110Z","shell.execute_reply.started":"2025-05-17T14:08:53.427655Z","shell.execute_reply":"2025-05-17T14:08:57.469156Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"key = \"S_2\"\nimg = train_images[key]\nspot = train_spots[key]\n\nplot_it(img, 35, 20, 5, 1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:08:57.471097Z","iopub.execute_input":"2025-05-17T14:08:57.471373Z","iopub.status.idle":"2025-05-17T14:09:01.628518Z","shell.execute_reply.started":"2025-05-17T14:08:57.471348Z","shell.execute_reply":"2025-05-17T14:09:01.627528Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"key = \"S_3\"\nimg = train_images[key]\nspot = train_spots[key]\n\nplot_it(img, 19, 20, 5, 1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:01.629443Z","iopub.execute_input":"2025-05-17T14:09:01.629757Z","iopub.status.idle":"2025-05-17T14:09:05.644821Z","shell.execute_reply.started":"2025-05-17T14:09:01.629735Z","shell.execute_reply":"2025-05-17T14:09:05.643740Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"key = \"S_4\"\nimg = train_images[key]\nspot = train_spots[key]\n\nplot_it(img, 7, 20, 5, 1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:05.645830Z","iopub.execute_input":"2025-05-17T14:09:05.646145Z","iopub.status.idle":"2025-05-17T14:09:09.546617Z","shell.execute_reply.started":"2025-05-17T14:09:05.646122Z","shell.execute_reply":"2025-05-17T14:09:09.545681Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"key = \"S_5\"\nimg = train_images[key]\nspot = train_spots[key]\n\nplot_it(img, 1, 20, 5, 1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:09.547839Z","iopub.execute_input":"2025-05-17T14:09:09.548184Z","iopub.status.idle":"2025-05-17T14:09:13.395182Z","shell.execute_reply.started":"2025-05-17T14:09:09.548159Z","shell.execute_reply":"2025-05-17T14:09:13.394222Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"key = \"S_6\"\nimg = train_images[key]\nspot = train_spots[key]\n\nplot_it(img, 4, 20, 5, 1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:13.396275Z","iopub.execute_input":"2025-05-17T14:09:13.396601Z","iopub.status.idle":"2025-05-17T14:09:17.205637Z","shell.execute_reply.started":"2025-05-17T14:09:13.396573Z","shell.execute_reply":"2025-05-17T14:09:17.204290Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## etc.","metadata":{}},{"cell_type":"markdown","source":"# 🧪\n# Looking for the test set?","metadata":{}},{"cell_type":"code","source":"spot_test = test_spots[\"S_7\"]\nimage_test = test_images[\"S_7\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:17.207002Z","iopub.execute_input":"2025-05-17T14:09:17.207311Z","iopub.status.idle":"2025-05-17T14:09:17.212049Z","shell.execute_reply.started":"2025-05-17T14:09:17.207287Z","shell.execute_reply":"2025-05-17T14:09:17.210942Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"spot_test.dtype","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:17.212673Z","iopub.execute_input":"2025-05-17T14:09:17.212959Z","iopub.status.idle":"2025-05-17T14:09:17.240652Z","shell.execute_reply.started":"2025-05-17T14:09:17.212937Z","shell.execute_reply":"2025-05-17T14:09:17.239629Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:17.241600Z","iopub.execute_input":"2025-05-17T14:09:17.241915Z","iopub.status.idle":"2025-05-17T14:09:17.261004Z","shell.execute_reply.started":"2025-05-17T14:09:17.241887Z","shell.execute_reply":"2025-05-17T14:09:17.259933Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig = plt.figure(figsize=(20,5))\n\nplt.suptitle(\"Test Data\")\nplt.subplot(1,3,1)\nplt.imshow(image_test)\nplt.axis(\"off\")\nplt.title(\"Orjinal\")\n\nplt.subplot(1,3,2)\nplt.imshow(image_test)\nplt.scatter(spot_test[\"x\"], spot_test[\"y\"], c=\"red\", s=1)\nplt.axis(\"off\")\nplt.title(\"Colorized\")\nplt.colorbar()\n\nplt.subplot(1,3,3)\nplt.imshow(image_test)\nplt.scatter(spot_test[\"x\"], spot_test[\"y\"], c=spot_test[\"Test_Set\"], cmap=\"coolwarm\", s=1)\nplt.axis(\"off\")\nplt.title(\"Detailed\")\nplt.colorbar()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:17.262200Z","iopub.execute_input":"2025-05-17T14:09:17.262543Z","iopub.status.idle":"2025-05-17T14:09:21.184119Z","shell.execute_reply.started":"2025-05-17T14:09:17.262518Z","shell.execute_reply":"2025-05-17T14:09:21.183131Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Lastly, let's look at the sum of C points, visualize them, and close this notebook.","metadata":{}},{"cell_type":"code","source":"# C1 to C35..\n\nx = train_spots[\"S_1\"][\"x\"]\nY = train_spots[\"S_1\"][\"y\"]\n\ntemp_spot = train_spots[\"S_1\"]\n\nc_values = np.stack([temp_spot[name] for name in temp_spot.dtype.names if name.startswith(\"C\")], axis=1)\nc_sum = c_values.sum(axis=1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:21.185307Z","iopub.execute_input":"2025-05-17T14:09:21.185612Z","iopub.status.idle":"2025-05-17T14:09:21.194436Z","shell.execute_reply.started":"2025-05-17T14:09:21.185588Z","shell.execute_reply":"2025-05-17T14:09:21.193375Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"c_sum","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:21.195577Z","iopub.execute_input":"2025-05-17T14:09:21.195844Z","iopub.status.idle":"2025-05-17T14:09:21.213961Z","shell.execute_reply.started":"2025-05-17T14:09:21.195822Z","shell.execute_reply":"2025-05-17T14:09:21.213283Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"c_sum.sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:21.215073Z","iopub.execute_input":"2025-05-17T14:09:21.215407Z","iopub.status.idle":"2025-05-17T14:09:21.234932Z","shell.execute_reply.started":"2025-05-17T14:09:21.215371Z","shell.execute_reply":"2025-05-17T14:09:21.233814Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### For example, summing in a spot, there is an 11.13 C value. I don't know if it's less or much. I just wanted to print.","metadata":{}},{"cell_type":"code","source":"print(temp_spot[0], \"\\n\")\nprint(sum(temp_spot[0]), \"\\n\")\nprint(sum(temp_spot[0]) - (temp_spot[0][\"x\"] + temp_spot[0][\"y\"]))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:21.236183Z","iopub.execute_input":"2025-05-17T14:09:21.237166Z","iopub.status.idle":"2025-05-17T14:09:21.257707Z","shell.execute_reply.started":"2025-05-17T14:09:21.237139Z","shell.execute_reply":"2025-05-17T14:09:21.256353Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"key = \"S_1\"\nimg = train_images[key]\nspot = train_spots[key]\n\nplt.imshow(img)\nplt.scatter(x, Y, c=c_sum, cmap=\"coolwarm\", s=1)\nplt.colorbar()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:21.258902Z","iopub.execute_input":"2025-05-17T14:09:21.259197Z","iopub.status.idle":"2025-05-17T14:09:22.742459Z","shell.execute_reply.started":"2025-05-17T14:09:21.259174Z","shell.execute_reply":"2025-05-17T14:09:22.741104Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.scatter(x, Y, c=c_sum, cmap=\"coolwarm\", s=1)\nplt.colorbar()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:22.743814Z","iopub.execute_input":"2025-05-17T14:09:22.744163Z","iopub.status.idle":"2025-05-17T14:09:23.215050Z","shell.execute_reply.started":"2025-05-17T14:09:22.744140Z","shell.execute_reply":"2025-05-17T14:09:23.213929Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.hist(c_sum)\n# This is nonsense. Whatever...","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-17T14:09:23.216024Z","iopub.execute_input":"2025-05-17T14:09:23.216354Z","iopub.status.idle":"2025-05-17T14:09:23.388694Z","shell.execute_reply.started":"2025-05-17T14:09:23.216327Z","shell.execute_reply":"2025-05-17T14:09:23.387751Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# THANK YOU FOR READING. ","metadata":{}}]}