Skip to content

Instantly share code, notes, and snippets.

@jpolchlo
Created August 9, 2021 13:59
Show Gist options
  • Select an option

  • Save jpolchlo/07e58f5c6e05e3469c00d28750cd7108 to your computer and use it in GitHub Desktop.

Select an option

Save jpolchlo/07e58f5c6e05e3469c00d28750cd7108 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "MIF denoise.ipynb",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU",
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"eddd97f1c09941b5beef4183161e9191": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HBoxModel",
"state": {
"_view_name": "HBoxView",
"_dom_classes": [],
"_model_name": "HBoxModel",
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.5.0",
"box_style": "",
"layout": "IPY_MODEL_0979227cd443470cbbd8cc6a9affde6c",
"_model_module": "@jupyter-widgets/controls",
"children": [
"IPY_MODEL_b8c5927134234049b647c8178489bfab",
"IPY_MODEL_d3dced01a2fa4c1f96dce93a1c50d46b"
]
}
},
"0979227cd443470cbbd8cc6a9affde6c": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
},
"b8c5927134234049b647c8178489bfab": {
"model_module": "@jupyter-widgets/controls",
"model_name": "FloatProgressModel",
"state": {
"_view_name": "ProgressView",
"style": "IPY_MODEL_27513c2a296e4b5a9875bc9faa681c1a",
"_dom_classes": [],
"description": "",
"_model_name": "FloatProgressModel",
"bar_style": "danger",
"max": 1000,
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"value": 1000,
"_view_count": null,
"_view_module_version": "1.5.0",
"orientation": "horizontal",
"min": 0,
"description_tooltip": null,
"_model_module": "@jupyter-widgets/controls",
"layout": "IPY_MODEL_ff002b2f7d9c48d3a178496b24ad63aa"
}
},
"d3dced01a2fa4c1f96dce93a1c50d46b": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"state": {
"_view_name": "HTMLView",
"style": "IPY_MODEL_248ebceb24cc4f65b921e8077d8464a8",
"_dom_classes": [],
"description": "",
"_model_name": "HTMLModel",
"placeholder": "​",
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"value": " 1207/? [2:53:57<00:00, 35.22s/it]",
"_view_count": null,
"_view_module_version": "1.5.0",
"description_tooltip": null,
"_model_module": "@jupyter-widgets/controls",
"layout": "IPY_MODEL_7d1c8453ad4c42c2b80167ed6dbc6772"
}
},
"27513c2a296e4b5a9875bc9faa681c1a": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ProgressStyleModel",
"state": {
"_view_name": "StyleView",
"_model_name": "ProgressStyleModel",
"description_width": "initial",
"_view_module": "@jupyter-widgets/base",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.2.0",
"bar_color": null,
"_model_module": "@jupyter-widgets/controls"
}
},
"ff002b2f7d9c48d3a178496b24ad63aa": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
},
"248ebceb24cc4f65b921e8077d8464a8": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"state": {
"_view_name": "StyleView",
"_model_name": "DescriptionStyleModel",
"description_width": "",
"_view_module": "@jupyter-widgets/base",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.2.0",
"_model_module": "@jupyter-widgets/controls"
}
},
"7d1c8453ad4c42c2b80167ed6dbc6772": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
}
}
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"collapsed": true,
"id": "Iynul0Jj03Rg",
"outputId": "ea60c21f-5f08-49d9-b346-7545c72e4db6"
},
"source": [
"!pip install rasterio h5py\n",
"!pip install --upgrade 'git+https://github.com/azavea/nasa-hyperspectral.git#egg=hyperspectral&subdirectory=src/hyperspectral'"
],
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": [
"Collecting rasterio\n",
" Downloading rasterio-1.2.6-cp37-cp37m-manylinux1_x86_64.whl (19.3 MB)\n",
"\u001b[K |████████████████████████████████| 19.3 MB 5.9 MB/s \n",
"\u001b[?25hRequirement already satisfied: h5py in /usr/local/lib/python3.7/dist-packages (3.1.0)\n",
"Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from rasterio) (57.2.0)\n",
"Collecting affine\n",
" Downloading affine-2.3.0-py2.py3-none-any.whl (15 kB)\n",
"Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from rasterio) (1.19.5)\n",
"Requirement already satisfied: attrs in /usr/local/lib/python3.7/dist-packages (from rasterio) (21.2.0)\n",
"Requirement already satisfied: certifi in /usr/local/lib/python3.7/dist-packages (from rasterio) (2021.5.30)\n",
"Collecting snuggs>=1.4.1\n",
" Downloading snuggs-1.4.7-py3-none-any.whl (5.4 kB)\n",
"Collecting click-plugins\n",
" Downloading click_plugins-1.1.1-py2.py3-none-any.whl (7.5 kB)\n",
"Collecting cligj>=0.5\n",
" Downloading cligj-0.7.2-py3-none-any.whl (7.1 kB)\n",
"Requirement already satisfied: click>=4.0 in /usr/local/lib/python3.7/dist-packages (from rasterio) (7.1.2)\n",
"Requirement already satisfied: pyparsing>=2.1.6 in /usr/local/lib/python3.7/dist-packages (from snuggs>=1.4.1->rasterio) (2.4.7)\n",
"Requirement already satisfied: cached-property in /usr/local/lib/python3.7/dist-packages (from h5py) (1.5.2)\n",
"Installing collected packages: snuggs, cligj, click-plugins, affine, rasterio\n",
"Successfully installed affine-2.3.0 click-plugins-1.1.1 cligj-0.7.2 rasterio-1.2.6 snuggs-1.4.7\n",
"Collecting hyperspectral\n",
" Cloning https://github.com/azavea/nasa-hyperspectral.git to /tmp/pip-install-o7qzopm_/hyperspectral_c5688b65ebb34e0190f1c147654e40ca\n",
" Running command git clone -q https://github.com/azavea/nasa-hyperspectral.git /tmp/pip-install-o7qzopm_/hyperspectral_c5688b65ebb34e0190f1c147654e40ca\n",
"Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from hyperspectral) (1.19.5)\n",
"Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from hyperspectral) (1.4.1)\n",
"Collecting parsec\n",
" Downloading parsec-3.9-py2.py3-none-any.whl (11 kB)\n",
"Building wheels for collected packages: hyperspectral\n",
" Building wheel for hyperspectral (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for hyperspectral: filename=hyperspectral-0.0.1-py3-none-any.whl size=205942 sha256=f27320e86508bc93d27a009589d544140b3f9d59a57d6d720ca29986ba7caf5e\n",
" Stored in directory: /tmp/pip-ephem-wheel-cache-yfny9opn/wheels/90/f0/8d/e77432075e6316f306a38819bc2b19abfa15886ca5e11c1aee\n",
"Successfully built hyperspectral\n",
"Installing collected packages: parsec, hyperspectral\n",
"Successfully installed hyperspectral-0.0.1 parsec-3.9\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "B0Bgto8s1DUr",
"outputId": "859ec73c-da1a-4a64-ffbe-07f016c2e85c"
},
"source": [
"from google.colab import drive\n",
"\n",
"drive.mount(\"~/data\")"
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"Mounted at /root/data\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "cg-gjqZZ1K3P"
},
"source": [
"import numpy as np\n",
"from hyperspectral.decorrelation.mif import get_mask_2d, spherical_radius_torch, imf_torch\n",
"import matplotlib.pyplot as plt\n",
"import torch"
],
"execution_count": 3,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "9x6hTO5f1b3Y"
},
"source": [
"nmf2 = np.load('/root/data/MyDrive/Hyperspectral/oil_nmf_2.npz')['nmf']"
],
"execution_count": 4,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"id": "0K9A8A8T1pw_",
"outputId": "110c86c0-92e7-4b96-b7cf-1fb826e7b6a5"
},
"source": [
"_, ax = plt.subplots(figsize=(6, 150))\n",
"ax.imshow(nmf2, vmin=-1, vmax=1)"
],
"execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f7b95cd6290>"
]
},
"metadata": {
"tags": []
},
"execution_count": 5
},
{
"output_type": "display_data",
"data": {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment