{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "UCL\n", "\n", "\n", "\n", "[](005_Packages.ipynb)\n", "[](003_Help.ipynb)\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 004 Setup, Accounts and logins" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### NASA Earthdata login and password\n", "\n", "\n", "Before you can use the material in these notebooks, you will need to register as a user at the [`NASA EarthData`](https://urs.earthdata.nasa.gov/users/new).\n", "\n", "Once you have done that, make sure you know your `username` and `password` ready for below.\n", "\n", "Some web resources require you to use a login and password. In any publicly available files (like these notebooks) we do not want to expose sensitive information such information.\n", "\n", "To that in these notes we can make use of stored passwords and usernames using the local [cylog](geog0111/cylog.py) package. \n", "\n", "Information is encrypted in a user read-only file in your home directory (mode `400`) and accessed through the `Cylog` `login` function.\n", "\n", "You need to store your username and password in a database file (that only you can access) to be able to make convenient use oof the notes in later classes.\n", "\n", "You can do this by running through the following cell, and responding as appropriate." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from geog0111.cylog import Cylog\n", "\n", "sites = ['https://n5eil01u.ecs.nsidc.org',\\\n", " 'https://urs.earthdata.nasa.gov',\\\n", " 'https://e4ftl01.cr.usgs.gov']\n", "\n", "l = Cylog(sites)\n", "test = l.login()\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Test\n", "\n", "You can run a test on your login to NASA Earthdata using the information you have stored this using `cylog` for the site `https://e4ftl01.cr.usgs.gov`. We can test this with the following code if you set do_test to True (N.B. Don't run this test on Wednesday afternoon (UK time) when the server is down):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from osgeo import gdal\n", "from geog0111.modisUtils import modisFile\n", "# settings\n", "\n", "modinfo = { \n", " 'product' : 'MCD15A3H',\n", " 'year' : 2019,\n", " 'month' : 2,\n", " 'day' : 10,\n", " 'tile' : 'h08v06'\n", "}\n", "\n", "do_test = True\n", "\n", "# run the test\n", "if do_test:\n", " filename = modisFile(force=True,**modinfo,verbose=False)\n", "if filename != None:\n", " print('test passed: login to NASA server achieved and data pulled')\n", " print(f'{filename}')\n", "else:\n", " print('test FAILED: check that your login works on https://urs.earthdata.nasa.gov')\n", " l = Cylog(sites)\n", " test = l.login()\n", " print(test)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reset password\n", "\n", "If you are interested, you can see the help page for `Cylog`. It shows, for instance, how to over-ride the current entry (e.g. if you have changed your password), by using `force=True`)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from geog0111.cylog import Cylog\n", "help(Cylog.login)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You should be aware that the NASA servers this connects you to go down for maintenance on Wednesdays. You can ping the servers with the follwoing code:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If this fails, you may have entered your account information incorrectly for `https://e4ftl01.cr.usgs.gov` (or it could just be Wednesday, in which case, don't run this again)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to force the code to let you re-enter your credentials (e.g. you got it wrong before, or have changed them, or the test fails), then change the call to:\n", "\n", " cy = Cylog(sites,force=True)\n", " \n", "and re-run." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Summary\n", "\n", "This short notebook is intended to let you store your NASA Earthdata login to make later calls to collect NASA data more straightforward. We have used code from the local class `Cylog` from `geog0111.cylog`, and seen how to setl, reset and test our login.\n", "\n", "| command | purpose | \n", "|---|---|\n", "| `l = Cylog(sites); test = l.login()` | set / run login for list of URLs `sites` | \n", "| `cy = Cylog(sites,force=True); test = l.login()` | reset / run login for list of URLs `sites` |\n", "| `test_login(True)` | test the login by pulling a dataset from the NASA site| \n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "[](005_Packages.ipynb)\n", "[](003_Help.ipynb)\n", "\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:geog0111-geog0111]", "language": "python", "name": "conda-env-geog0111-geog0111-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.7.8" } }, "nbformat": 4, "nbformat_minor": 4 }