{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Print metadata of a GPM file downloaded from NASA\n", "from osgeo import gdal\n", "import urllib.request\n", "import pandas as pd\n", "\n", "BASE_URL = 'https://swatshare.rcac.purdue.edu/temp/MOD16A2.A2014001.'\n", "GPM_FILES = ['h00v10.105.2015034090805.hdf', 'h00v09.105.2015034090749.hdf', 'h00v08.105.2015034090734.hdf']\n", "\n", "def download_and_show_meta(filename):\n", " # download data\n", " url = BASE_URL + filename\n", " print('URL: ', url)\n", " tmpfile = 'data.hdf'\n", " urllib.request.urlretrieve(url, tmpfile)\n", "\n", " # Read the downloaded hdf file\n", " hdf = gdal.Open(tmpfile, gdal.GA_ReadOnly)\n", " metadata = hdf.GetMetadata()\n", "\n", " # Print Metadata\n", " print(pd.DataFrame(list(metadata.items())))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "download_and_show_meta(GPM_FILES[0])" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import ipywidgets as widgets" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Label\n", "lb = widgets.Label(\n", " value=\"Printing Metadata of a GPM file\"\n", ")\n", "\n", "display(lb)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "txtbox = widgets.Text()\n", "\n", "display(txtbox)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "txtbox.value" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "download_and_show_meta(txtbox.value)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "selector = widgets.Select(\n", " options=GPM_FILES,\n", " value=GPM_FILES[0], \n", ")\n", "display(selector)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "selector.value" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "download_and_show_meta(selector.value)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# selector\n", "selector = widgets.Select(\n", " options=GPM_FILES,\n", " value=GPM_FILES[0], \n", ")\n", "\n", "# button\n", "btn = widgets.Button(\n", " description='Show Meta'\n", ")\n", "display(selector, btn)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def on_button_clicked(b):\n", " download_and_show_meta(selector.value)\n", " \n", "btn.on_click(on_button_clicked)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:qgis]", "language": "python", "name": "conda-env-qgis-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.3" } }, "nbformat": 4, "nbformat_minor": 4 }