pass fix ipynbs olv16

intro16
darkblueb 2023-06-01 16:16:12 -07:00
parent 216591840c
commit 66e9f4cfed
9 changed files with 55 additions and 305 deletions

View File

@ -28,30 +28,12 @@
"\n",
" ax.coastlines()\n",
" ax.gridlines()\n",
" ax.stock_img()\n",
"\n",
" im = ax.stock_img()\n",
"\n",
" def on_draw(event=None):\n",
" \"\"\"\n",
" Hook into matplotlib's event mechanism to define the clip path of the\n",
" background image.\n",
"\n",
" \"\"\"\n",
" # Clip the image to the current background boundary.\n",
" im.set_clip_path(ax.background_patch.get_path(),\n",
" transform=ax.background_patch.get_transform())\n",
"\n",
" # Register the on_draw method and call it once now.\n",
" fig.canvas.mpl_connect('draw_event', on_draw)\n",
" on_draw()\n",
"\n",
" # Generate a matplotlib path representing the character \"C\".\n",
" fp = FontProperties(family='Bitstream Vera Sans', weight='bold')\n",
" # Generate a matplotlib path representing the character "C".\n",
" fp = FontProperties(family='DejaVu Sans', weight='bold')\n",
" logo_path = matplotlib.textpath.TextPath((-4.5e7, -3.7e7),\n",
" 'C', size=1, prop=fp)\n",
"\n",
" # Scale the letter up to an appropriate X and Y scale.\n",
" logo_path._vertices *= np.array([103250000, 103250000])\n",
" 'C', size=103250000, prop=fp)\n",
"\n",
" # Add the path as a patch, drawing black outlines around the text.\n",
" patch = matplotlib.patches.PathPatch(logo_path, facecolor='white',\n",
@ -59,6 +41,7 @@
" transform=ccrs.SouthPolarStereo())\n",
" ax.add_patch(patch)\n",
" plt.show()\n",
"\n",
"\n"
]
},

View File

@ -61,9 +61,9 @@
"\n",
" # Add a text annotation for the license information to the\n",
" # the bottom right corner.\n",
" text = AnchoredText(r'$\\mathcircled{{c}}$ {}; license: {}'\n",
" text = AnchoredText(r'(c) {}; license: {}'\n",
" ''.format(SOURCE, LICENSE),\n",
" loc=4, prop={'size': 12}, frameon=True)\n",
" loc=4, prop={'size': 10}, frameon=True)\n",
" ax.add_artist(text)\n",
"\n",
" plt.show()"

View File

@ -21,35 +21,35 @@
"outputs": [],
"source": [
"\n",
"def main():\n",
" fig = plt.figure(figsize=[12, 6])\n",
" ax = fig.add_subplot(1, 1, 1, projection=ccrs.Robinson())\n",
"\n",
" ax.coastlines()\n",
" ax = fig.add_subplot(1, 1, 1, projection=ccrs.Robinson())\n",
" \n",
" ax.coastlines()\n",
" ax.gridlines()\n",
"\n",
" # generate a matplotlib path representing the word \"cartopy\"\n",
" fp = FontProperties(family='Bitstream Vera Sans', weight='bold')\n",
" logo_path = matplotlib.textpath.TextPath((-175, -35), 'cartopy',\n",
" size=1, prop=fp)\n",
" # scale the letters up to sensible longitude and latitude sizes\n",
" logo_path._vertices *= np.array([80, 160])\n",
"\n",
" # add a background image\n",
" im = ax.stock_img()\n",
" # clip the image according to the logo_path. mpl v1.2.0 does not support\n",
" # the transform API that cartopy makes use of, so we have to convert the\n",
" # projection into a transform manually\n",
" plate_carree_transform = ccrs.PlateCarree()._as_mpl_transform(ax)\n",
" im.set_clip_path(logo_path, transform=plate_carree_transform)\n",
"\n",
" # add the path as a patch, drawing black outlines around the text\n",
" patch = matplotlib.patches.PathPatch(logo_path,\n",
" facecolor='none', edgecolor='black',\n",
" transform=ccrs.PlateCarree())\n",
" ax.add_patch(patch)\n",
"\n",
" plt.show()\n"
" \n",
" # generate a matplotlib path representing the word "cartopy"\n",
" fp = FontProperties(family='DejaVu Sans', weight='bold')\n",
" logo_path = matplotlib.textpath.TextPath((-175, -35), 'cartopy',\n",
" size=80, prop=fp)\n",
" # scale the letters up to sensible longitude and latitude sizes\n",
" transform = matplotlib.transforms.Affine2D().scale(1, 2).translate(0, 35)\n",
" \n",
" # add a background image\n",
" im = ax.stock_img()\n",
" # Apply the scale transform and then the map coordinate transform\n",
" plate_carree_transform = (transform +\n",
" ccrs.PlateCarree()._as_mpl_transform(ax))\n",
" \n",
" # add the path as a patch, drawing black outlines around the text\n",
" patch = matplotlib.patches.PathPatch(logo_path,\n",
" facecolor='none', edgecolor='black',\n",
" transform=plate_carree_transform)\n",
" im.set_clip_path(patch)\n",
" ax.add_patch(patch)\n",
" \n",
" plt.show()\n",
" \n",
"\n"
]
},
{

View File

@ -16,13 +16,6 @@
"import cartopy.crs as ccrs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### http://scitools.org.uk/iris/docs/v1.9.0/html/gallery.html"
]
},
{
"cell_type": "code",
"execution_count": 2,

View File

@ -56,7 +56,7 @@
"\n",
" ax.set_extent([-125, -66.5, 20, 50], ccrs.Geodetic())\n",
"\n",
" shapename = 'admin_1_states_provinces_lakes_shp'\n",
" shapename = 'admin_1_states_provinces_lakes'\n",
" states_shp = shpreader.natural_earth(resolution='110m',\n",
" category='cultural', name=shapename)\n",
"\n",

View File

@ -1,72 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"import cartopy.crs as ccrs\n",
"from cartopy.examples.arrows import sample_data\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def main():\n",
" fig = plt.figure(figsize=(10, 5))\n",
" ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())\n",
" ax.set_extent([-90, 75, 10, 85], crs=ccrs.PlateCarree())\n",
" ax.coastlines()\n",
"\n",
" x, y, u, v, vector_crs = sample_data(shape=(80, 100))\n",
" magnitude = (u ** 2 + v ** 2) ** 0.5\n",
" ax.streamplot(x, y, u, v, transform=vector_crs,\n",
" linewidth=2, density=2, color=magnitude)\n",
" plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"main()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -123,8 +123,10 @@
" ax = fig.add_axes([0.25, 0.24, 0.5, 0.54], projection=az_eq)\n",
"\n",
" # The background patch and outline patch are not needed in this example.\n",
" ax.background_patch.set_facecolor('none')\n",
" ax.outline_patch.set_edgecolor('none')\n",
" ax.patch.set_facecolor('none')\n",
" # The Axes frame produces the outer meridian line.\n",
" for spine in ax.spines.values():\n",
" spine.update({'edgecolor': 'white', 'linewidth': 2})\n",
"\n",
" # We want the map to go down to -60 degrees latitude.\n",
" ax.set_extent([-180, 180, -60, 90], ccrs.PlateCarree())\n",

View File

@ -1,8 +1,8 @@
### OSGeoLive Notebook Gallery ###
[logo]: http://live.osgeo.org/_images/banner.png "OSGeoLive"
[logo]: https://live.osgeo.org/_images/banner.png "OSGeoLive"
This directory hosts a set of **[Jupyter Notebooks](https://jupyter.org/)** that demonstrate the *Open Source Geospatial Tools* capabilities on **[OSGeoLive](http://live.osgeo.org/en/index.html)**.
This directory hosts a set of **[Jupyter Notebooks](https://jupyter.org/)** that demonstrate the *Open Source Geospatial Tools* capabilities on **[OSGeoLive](https://live.osgeo.org/en/index.html)**.
To start the *Jupyter* server on *OSGeoLive*, use the menu item *Geospatial -> Spatial Tools -> Jupyter Notebook*.

View File

@ -11,14 +11,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The IPython notebook server is a custom web server that runs the notebook web application. Most of the time, users run the notebook server on their local computer using IPython's command line interface."
"The Jupyter notebook server runs Notebooks on the web."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Starting the notebook server using the command line"
"## Starting a notebook server using the command line"
]
},
{
@ -27,7 +27,7 @@
"source": [
"You can start the notebook server from the command line (Terminal on Mac/Linux, CMD prompt on Windows) by running the following command: \n",
"\n",
" ipython notebook\n",
" jupyter notebook\n",
"\n",
"This will print some information about the notebook server in your terminal, including the URL of the web application (by default, `http://127.0.0.1:8888`). It will then open your default web browser to this URL.\n",
"\n",
@ -37,18 +37,18 @@
"\n",
"You can also specify the port manually:\n",
"\n",
" ipython notebook --port 9999\n",
" jupyter notebook --port 8883\n",
"\n",
"Or start notebook server without opening a web browser.\n",
"\n",
" ipython notebook --no-browser\n",
" jupyter notebook --no-browser\n",
"\n",
"The notebook server has a number of other command line arguments that can be displayed with the `--help` flag: \n",
"\n",
" ipython notebook --help\n",
" jupyter notebook --help\n",
"\n",
"<div class=\"alert alert-failure\">\n",
"It used to be possible to specify kernel options, such as <code>--pylab inline</code> from the command line. This is deprecated in IPython 2.0 and will be removed in IPython 3.0. To enable matplotlib based plotting for the Python kernel use the <code>%matplotlib</code> magic command.\n",
" \n",
"</div>\n",
"\n"
]
@ -83,60 +83,7 @@
}
],
"source": [
"!ipython profile locate default"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The default version of `ipython_notebook_config.py` lists all of the options available along with documentation for each. Changes made to that file will affect all notebook servers run under that profile. Command line options always override those set in configuration files.\n",
"\n",
"You can create a new profile:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ProfileCreate] Generating default config file: u'/Users/bgranger/.ipython/profile_my_profile/ipython_config.py'\r\n",
"[ProfileCreate] Generating default config file: u'/Users/bgranger/.ipython/profile_my_profile/ipython_qtconsole_config.py'\r\n",
"[ProfileCreate] Generating default config file: u'/Users/bgranger/.ipython/profile_my_profile/ipython_notebook_config.py'\r\n",
"[ProfileCreate] Generating default config file: u'/Users/bgranger/.ipython/profile_my_profile/ipython_nbconvert_config.py'\r\n"
]
}
],
"source": [
"!ipython profile create my_profile"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And then view its location:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/bgranger/.ipython/profile_my_profile\r\n"
]
}
],
"source": [
"!ipython profile locate my_profile"
"!jupyter --paths"
]
},
{
@ -145,117 +92,14 @@
"source": [
"To start the notebook server using a given profile, run the following:\n",
"\n",
" ipython notebook --profile=my_profile"
" jupyter notebook --profile=my_profile"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"More details about IPython configuration files and profiles can be found [here](http://ipython.org/ipython-doc/dev/config/intro.html)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Securing the notebook server"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The IPython Notebook allows arbitrary code execution on the computer running it. Thus, the notebook web server should never be run on the open internet without first securing it. By default, the notebook server only listens on local network interface (`127.0.0.1`) There are two steps required to secure the notebook server:\n",
"\n",
"1. Setting a password\n",
"2. Encrypt network traffic using SSL"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Setting a password"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can protect your notebook server with a simple single password by setting the `NotebookApp.password` configurable. You can prepare a hashed password using the function `IPython.lib.passwd`:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'sha1:6c2164fc2b22:ed55ecf07fc0f985ab46561483c0e888e8964ae6'"
]
},
"execution_count": 1,
"output_type": "execute_result",
"metadata": {}
}
],
"source": [
"from IPython.lib import passwd\n",
"password = passwd(\"secret\")\n",
"password"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can then add this to your `ipython_notebook_config.py`:\n",
"\n",
"```python\n",
"# Password to use for web authentication\n",
"c = get_config()\n",
"c.NotebookApp.password = \n",
"u'sha1:6c2164fc2b22:ed55ecf07fc0f985ab46561483c0e888e8964ae6'\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using SSL/HTTPS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When using a password, it is a good idea to also use SSL, so that your \n",
"password is not sent unencrypted by your browser to the web server. When running the notebook on the public internet this is absolutely required.\n",
"\n",
"The first step is to generate an SSL certificate. A self-signed certificate can be generated with ``openssl``. For example, the following command will create a certificate valid for 365 days with both the key and certificate data written to the same file:\n",
"\n",
" openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem\n",
"\n",
"In most cases, you should run this command in your profile directory, which will make it easy to use the generated key and certificate.\n",
"\n",
"When you connect to a notebook server over HTTPS using a self-signed certificate, your browser will warn you of a dangerous certificate because it is self-signed. If you want to have a fully compliant certificate that will not raise warnings, it is possible (but rather involved) to obtain one,\n",
"as explained in detail in [this tutorial](http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-secure-sertificate-for-free.ars)\n",
"\t\n",
"When you enable SSL support, you will need to access the notebook server over ``https://``, rather than plain ``http://``. The startup message from the notebook server prints the correct URL, but it is easy to overlook and think the server is for some reason non-responsive.\n",
"\n",
"Once you have generated the key and certificate, you can configure the notebook server to use them, by adding the following to `ipython_notebook_config.py`:\n",
"\n",
"```python\n",
"# The full path to an SSL/TLS certificate file.\n",
"c.NotebookApp.certfile = u'/Users/bgranger/.ipython/profile_my_profile/mycert.crt'\n",
"\n",
"# The full path to a private key file for usage with SSL/TLS.\n",
"c.NotebookApp.keyfile = u'/Users/bgranger/.ipython/profile_my_profile/mycert.key'\n",
"```"
"More details about Jupyter configuration files and profiles can be found [here](https://jupyter-notebook.readthedocs.io/en/stable/config.html)."
]
},
{
@ -270,14 +114,14 @@
"metadata": {},
"source": [
"<div class=\"alert alert-error\">\n",
"Don't run a public notebook server unless you first secure it with a password and SSL/HTTPS as described above\n",
"Don't run a public notebook server unless you know what you are doing.\n",
"</div>\n",
"\n",
"By default the notebook server only listens on the `localhost/127.0.0.1` network interface. If you want to connect to the notebook from another computers, or over the internet, you need to configure the notebook server to listen on all network interfaces and not open the browser. You will often also want to disable the automatic launching of the web browser.\n",
"\n",
"This can be accomplished by passing a command line options.\n",
"\n",
" ipython notebook --ip=* --no-browser\n",
" jupyter notebook --ip=* --no-browser\n",
"\n",
"You can also add the following to your`ipython_notebook_config.py` file:\n",
"\n",
@ -364,7 +208,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"JupyterHub is a multi-user server that manages and proxies multiple instances of the single-user IPython/Jupyter Notebook server.\n",
"JupyterHub is a multi-user server that manages and proxies multiple instances of the single-user IPython/Jupyter Notebook server. (see also Bindr project)\n",
"\n",
"<img src=\"https://c2a32ff18d23c8f567f0-e44b0df73868b5d567b1e58e01681d15.ssl.cf5.rackcdn.com/2015-03-24-deploying-jupyterhub-for-education/jupyterhub-9efc59baf33d2640641cb4a1fd9145ff.gif\" width=\"800px\" />\n",
"\n",
@ -469,4 +313,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}