bluenoise-raytracer/utk_experiments/plotting/.ipynb_checkpoints/plotter-checkpoint.ipynb

159 lines
4.3 KiB
Text

{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "3c65dafa-2226-4d12-a61e-f92a5f92bc97",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import math\n",
"\n",
"def load_pointset(path: str) -> ([], []):\n",
" xs = []\n",
" ys = []\n",
" \n",
" with open(path, 'r') as points_file:\n",
" for line in points_file.readlines()[1:]:\n",
" x, y = line.split(\" \")\n",
" y.replace(\"\\n\", \"\")\n",
" \n",
" xs.append(float(x))\n",
" ys.append(float(y))\n",
" return (xs, ys)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "b08c4be6-e653-499c-803b-e125f2e24f4b",
"metadata": {},
"outputs": [],
"source": [
"def load_spectrum_to_matrix(freqpath: str) -> np.ndarray:\n",
" minfreq = 1.0e36\n",
" maxfreq = 0.0\n",
" \n",
" freqs = []\n",
" \n",
" with open(freqpath, 'r') as spectrum:\n",
" dimension = int(spectrum.readline())\n",
" for line in spectrum.readlines():\n",
" freqs.append(float(line))\n",
" minfreq = min(float(line), minfreq)\n",
" maxfreq = max(float(line), maxfreq)\n",
" \n",
" matrix = np.zeros((dimension, dimension))\n",
" \n",
" for row in range(dimension):\n",
" for col in range(dimension):\n",
" frequency = freqs[row * dimension + col]\n",
" # normalize\n",
" #frequency = (frequency - minfreq) / (maxfreq - minfreq)\n",
" frequency = math.sqrt(frequency / maxfreq);\n",
" matrix[row][col] = frequency\n",
" return matrix"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "3a4fff42-a5fe-4b80-93ba-54482e755c79",
"metadata": {},
"outputs": [],
"source": [
"def load_pcf(pcfpath: str) -> ([],[]):\n",
" xs = []\n",
" ys = []\n",
" with open(pcfpath, 'r') as pcffile:\n",
" for line in pcffile.readlines():\n",
" ys.append(float(line))\n",
" xs = range(len(ys))\n",
"\n",
" return (xs, ys)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "4bc08371-8322-4f1a-b78a-8a0f94dd8a7f",
"metadata": {},
"outputs": [],
"source": [
"def load_radspec(specpath: str) -> ([], []):\n",
" xs = []\n",
" ys = []\n",
"\n",
" with open(specpath, 'r') as specfile:\n",
" for line in specfile.readlines():\n",
" x, y = line.split(\", \")\n",
" xs.append(float(x))\n",
" ys.append(float(y))\n",
" return (xs, ys)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2a1e9a6e-a307-47c8-8aa6-de7c5a3166f3",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"\n",
"spectrum = load_spectrum_to_matrix(\"../result_data/spectrum.txt\")\n",
"\n",
"(px, py) = load_pointset(\"../result_data/sampled.txt\")\n",
"\n",
"(pcfx, pcfy) = load_pcf(\"../result_data/pcf.txt\")\n",
"\n",
"(specxs, specys) = load_radspec(\"../result_data/radSpec.txt\")\n",
"\n",
"fig, ax = plt.subplots(2, 2)\n",
"plt.rcParams['figure.dpi'] = 800\n",
"ax[0][0].set_aspect(1.0)\n",
"ax[0][0].scatter(px, py, s=0.2)\n",
"ax[0][0].set_title(\"Points\")\n",
"ax[0][1].imshow(spectrum, cmap=\"gray\")\n",
"ax[1][0].plot(pcfx, pcfy, linewidth=0.5)\n",
"ax[1][1].plot(specxs, specys, linewidth=0.5)\n",
"#plt.savefig(\"fullfig_utk.png\", dpi=800)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "41753602-44bb-44a9-a050-f1887589bd96",
"metadata": {},
"outputs": [],
"source": [
"plt.close()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}