ld2daps/Notebooks/Differential.ipynb

154 lines
2.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Detect overflow with two rasters"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"im1 = np.arange(16*9*1).astype(np.uint8).reshape(16,9,1)\n",
"\n",
"im2 = im1.copy()\n",
"f = np.random.random(im2.shape) < .2\n",
"im2[f] += 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Detection"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(im2 > im1).any()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"old_settings = np.seterr(all='ignore')\n",
"np.seterr(all='print')\n",
"np.unique(im1 - im2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Detect overflow in a Stack"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stack = np.arange(16*9*4).astype(np.uint8).reshape(16,9,4)\n",
"stack.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(stack[:,:,1:] > stack[:,:,:-1]).any()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"np.subtract(stack[:,:,:-1], stack[:,:,1:], dtype=stack.dtype)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stack.dtype.str\n",
"np.dtype('|i1')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t = str(stack.dtype)\n",
"np.dtype('int8')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t.replace('u', '')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t.lstrip('u')"
]
}
],
"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
}