TRISKELE can not read 32 bps TIFF 😭
This commit is contained in:
parent
9d63fbea43
commit
21f13dc864
159
Notebooks/GDAL vs Matplotlib.ipynb
Normal file
159
Notebooks/GDAL vs Matplotlib.ipynb
Normal file
@ -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
|
||||||
|
}
|
@ -48,16 +48,6 @@
|
|||||||
"print('STDOUT:\\n' + tryskele.stdout.read().decode() + '\\nSTDERR:\\n' + tryskele.stderr.read().decode())"
|
"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",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
@ -73,7 +63,7 @@
|
|||||||
"inertia_conf = Path('../Res/inertia.txt')\n",
|
"inertia_conf = Path('../Res/inertia.txt')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Attributes definition\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",
|
"deviation = np.array([10,100,1000])\n",
|
||||||
"inertia = np.array([10,100,1000])\n",
|
"inertia = np.array([10,100,1000])\n",
|
||||||
"np.savetxt(area_conf, area, fmt='%d')\n",
|
"np.savetxt(area_conf, area, fmt='%d')\n",
|
||||||
@ -88,8 +78,10 @@
|
|||||||
" '--moment-of-inertia', inertia_conf.absolute(),\n",
|
" '--moment-of-inertia', inertia_conf.absolute(),\n",
|
||||||
" '-o', outfile.absolute()]\n",
|
" '-o', outfile.absolute()]\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"display(' '.join(str(v) for v in process))\n",
|
||||||
|
"\n",
|
||||||
"tryskele = subprocess.Popen(process, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\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": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"np.expand_dims(out[:,:,0] < 50, axis=2).shape"
|
"A = ' '\n",
|
||||||
|
"A.join(str(v) for v in process)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user