Last active
October 16, 2021 21:23
-
-
Save isaaccorley/7f972f70f5c8d1fbe36864328d7d2166 to your computer and use it in GitHub Desktop.
resample-benchmarkipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Untitled0.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyPzIP20YBUayfoiWWYiIAOe", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/isaaccorley/7f972f70f5c8d1fbe36864328d7d2166/untitled0.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "JTyhzLze2FZm" | |
}, | |
"source": [ | |
"!pip install rasterio opencv-python imageio" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "sVU8GKC64JG0" | |
}, | |
"source": [ | |
"import rasterio\n", | |
"import cv2\n", | |
"import skimage.transform\n", | |
"from rasterio.enums import Resampling" | |
], | |
"execution_count": 62, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ryHP5_oI4chz" | |
}, | |
"source": [ | |
"path = \"S2A_MSIL2A_20170613T101031_0_45_B01.tif\"\n", | |
"shape = (120, 120)\n", | |
"dataset = rasterio.open(path)" | |
], | |
"execution_count": 89, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "m4yuzHFk7e8M" | |
}, | |
"source": [ | |
"dataset.close()" | |
], | |
"execution_count": 88, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "MHOnpVDT4lAS", | |
"outputId": "ef8f51e0-b750-4fe8-9d37-b5567fac7284" | |
}, | |
"source": [ | |
"%timeit -n 100 -r 100 dataset.read(indexes=1, out_shape=shape, resampling=Resampling.bilinear)" | |
], | |
"execution_count": 81, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"100 loops, best of 100: 79.7 µs per loop\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "qzXJm_Xv5sjn", | |
"outputId": "4d723551-77b1-417c-a6f2-e2dbcac7025e" | |
}, | |
"source": [ | |
"%timeit -n 100 -r 10 cv2.resize(dataset.read(indexes=1), dsize=shape, interpolation=cv2.INTER_LINEAR)" | |
], | |
"execution_count": 84, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"100 loops, best of 10: 59.5 µs per loop\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "vxw_wohN558-", | |
"outputId": "7fcd4ec8-da1e-4a00-ab7b-aa5988ec2546" | |
}, | |
"source": [ | |
"%timeit -n 100 -r 10 skimage.transform.resize(dataset.read(indexes=1), output_shape=shape, order=1) # bilinear=1" | |
], | |
"execution_count": 87, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"100 loops, best of 10: 1.94 ms per loop\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "vqRh6JW39JKt", | |
"outputId": "5f400fcb-0116-4923-ef70-e6e5c0b953da" | |
}, | |
"source": [ | |
"%timeit -n 100 -r 10 dataset.read(indexes=1)" | |
], | |
"execution_count": 90, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"100 loops, best of 10: 30 µs per loop\n" | |
] | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment