{ "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", "import ipywidgets as widgets\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())))\n", "\n", "# Label\n", "lb=widgets.Label(value=\"Select a filename, then click [Show Meta] button\")\n", "display(lb)\n", "\n", "# 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)\n", "\n", "# Event Handler for the button\n", "def on_button_clicked(b):\n", " download_and_show_meta(selector.value)\n", " \n", "btn.on_click(on_button_clicked)" ] } ], "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 }