diff --git a/Notebooks/GDAL vs Matplotlib.ipynb b/Notebooks/GDAL vs Matplotlib.ipynb new file mode 100644 index 0000000..bb041ad --- /dev/null +++ b/Notebooks/GDAL vs Matplotlib.ipynb @@ -0,0 +1,159 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# GDAL vs Matplotlib\n", + "\n", + "We have in data fusion contest dataset TIFF file with 32 bit per sample. For now TRISKELE only work with less than 17 bps: `BOOST_ASSERT (bits < 17);`. I want to ensure that we can oppen such data with Python.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import gdal\n", + "from pathlib import Path\n", + "import subprocess" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "file = Path('../Data/phase1_rasters/DSM_C12/UH17c_GEF051_TR.tif')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "info = subprocess.Popen(['tiffinfo', file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n", + "print(info.communicate()[0].decode())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mat_data = plt.imread(file)\n", + "mat_data.shape, mat_data.dtype" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gdl_data = gdal.Open(str(file))\n", + "gdl_data.GetMetadata(), gdl_data.RasterCount" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gdl_data.GetRasterBand(1).ReadAsArray().shape, gdl_data.GetRasterBand(1).ReadAsArray().dtype" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## There.\n", + "\n", + "`matplotlib` is derping around with bps. \n", + "\n", + "Maybe each byte is split `[a, b, c, d]` as $V = a 2^{24} + b 2^{16} + c 2^8 + d$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "(np.power(2, (np.arange(4)[::-1] * 8)) * mat_data).sum(axis=2).shape" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "raster = gdl_data.GetRasterBand(1).ReadAsArray()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure(figsize=(32,9))\n", + "plt.imshow(raster)\n", + "plt.colorbar()\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plt.hist(raster.reshape(-1), 100, log=True)\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure(figsize=(32,9))\n", + "plt.imshow(raster * (raster < .25 * 1e38))\n", + "plt.colorbar()\n", + "plt.show()\n", + "plt.hist(raster.reshape(-1) * (raster.reshape(-1) < .25 * 1e38), 100, log=True)\n", + "plt.show()" + ] + } + ], + "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" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Notebooks/TRYSKELE Wrapper.ipynb b/Notebooks/TRYSKELE Wrapper.ipynb index d9b721e..dd2c08b 100644 --- a/Notebooks/TRYSKELE Wrapper.ipynb +++ b/Notebooks/TRYSKELE Wrapper.ipynb @@ -48,16 +48,6 @@ "print('STDOUT:\\n' + tryskele.stdout.read().decode() + '\\nSTDERR:\\n' + tryskele.stderr.read().decode())" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "area = np.array([42,100,1000])\n", - "np.savetxt(area_conf, area)" - ] - }, { "cell_type": "code", "execution_count": null, @@ -73,7 +63,7 @@ "inertia_conf = Path('../Res/inertia.txt')\n", "\n", "# Attributes definition\n", - "area = np.arange(100)#np.array([10,100,1000])\n", + "area = np.array([10,100,1000])\n", "deviation = np.array([10,100,1000])\n", "inertia = np.array([10,100,1000])\n", "np.savetxt(area_conf, area, fmt='%d')\n", @@ -88,8 +78,10 @@ " '--moment-of-inertia', inertia_conf.absolute(),\n", " '-o', outfile.absolute()]\n", "\n", + "display(' '.join(str(v) for v in process))\n", + "\n", "tryskele = subprocess.Popen(process, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n", - "print('STDOUT:\\n' + tryskele.stdout.read().decode() + '\\nSTDERR:\\n' + tryskele.stderr.read().decode())" + "print('Return code: ' + str(tryskele.returncode) + '\\nSTDOUT:\\n' + tryskele.stdout.read().decode() + '\\nSTDERR:\\n' + tryskele.stderr.read().decode())" ] }, { @@ -98,7 +90,8 @@ "metadata": {}, "outputs": [], "source": [ - "np.expand_dims(out[:,:,0] < 50, axis=2).shape" + "A = ' '\n", + "A.join(str(v) for v in process)" ] }, { diff --git a/deps.txt b/deps.txt new file mode 100644 index 0000000..86dbb1d --- /dev/null +++ b/deps.txt @@ -0,0 +1 @@ +python-pillow