Writing triskele wrapper in Notebook
This commit is contained in:
parent
ea29c16f2a
commit
9d63fbea43
@ -1,11 +1,153 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# TRYSKELE Wrapper\n",
|
||||
"\n",
|
||||
"Dependence \n",
|
||||
"--\n",
|
||||
"\n",
|
||||
"`tryskele` project folder (compiled) in jupyter's root directory. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"from pathlib import Path\n",
|
||||
"import subprocess\n",
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import pandas as pd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"triskele_bin = Path('../triskele/build/out/apGenerator')\n",
|
||||
"triskele_bin.exists()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"process = [triskele_bin.absolute(),\n",
|
||||
" '']\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())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Files\n",
|
||||
"infile = Path('../Data/phase1_rasters/DEM_C123_TLI/UH17_GEG05_TR.tif')\n",
|
||||
"outfile = Path('../Res/out.tiff')\n",
|
||||
"\n",
|
||||
"area_conf = Path('../Res/area.txt')\n",
|
||||
"deviation_conf = Path('../Res/deviation.txt')\n",
|
||||
"inertia_conf = Path('../Res/inertia.txt')\n",
|
||||
"\n",
|
||||
"# Attributes definition\n",
|
||||
"area = np.arange(100)#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",
|
||||
"np.savetxt(deviation_conf, deviation, fmt='%d')\n",
|
||||
"np.savetxt(inertia_conf, inertia, fmt='%d')\n",
|
||||
"\n",
|
||||
"process = [triskele_bin.absolute(),\n",
|
||||
" '-i', infile.absolute(),\n",
|
||||
" '--tos-tree',\n",
|
||||
" '--area', area_conf.absolute(),\n",
|
||||
" '--standard-deviation', deviation_conf.absolute(),\n",
|
||||
" '--moment-of-inertia', inertia_conf.absolute(),\n",
|
||||
" '-o', outfile.absolute()]\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())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"np.expand_dims(out[:,:,0] < 50, axis=2).shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"out = plt.imread(outfile.absolute())\n",
|
||||
"display(out.shape)\n",
|
||||
"\n",
|
||||
"dwidth = 32\n",
|
||||
"plt.figure(figsize=(dwidth, dwidth * out.shape[0] / out.shape[1] * .80))\n",
|
||||
"#plt.figure(figsize=(16,9))\n",
|
||||
"\n",
|
||||
"display_channel = 2\n",
|
||||
"plt.imshow(out[:,:,display_channel] * (out[:,:,display_channel] < 50))\n",
|
||||
"plt.colorbar()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"out_df = pd.DataFrame(out.reshape(-1, out.shape[2]))\n",
|
||||
"out_df.describe()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"np.unique(out_df, return_counts=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.hist(out_df[0] * out_df[0] , 256, log=True)\n",
|
||||
"plt.show()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
Loading…
Reference in New Issue
Block a user