diff --git a/book/mars_maps_extended.ipynb b/book/mars_maps_extended.ipynb index 4158287..c4246d1 100644 --- a/book/mars_maps_extended.ipynb +++ b/book/mars_maps_extended.ipynb @@ -2,7 +2,9 @@ "cells": [ { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "mS_pJzTgQHsu" + }, "source": [ "# Making some Mars maps with pygmt (extended)\n", "\n", @@ -10,65 +12,54 @@ "\n", "## first, some options\n", "\n", - "You can run this notebook using your local pygmt installation, or via Binder, or even Google Colaboratory. See comments for each option below. " + "You can run this notebook using your local pygmt installation, or via Binder, or even Google Colaboratory. See comments for each option below." ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "YQReiiejQHsw" + }, "source": [ "**A)** A short note if you are using COLAB\n", "\n", - "The version of python in COLAB is different from what the newer GMT needs to install along with pygmt. So, one way around this problem is to reinstall GMT from scratch, along with other important packages. This is done with this block of commands below.\n", - "\n", - "**comment out the first line of the block (%%script echo skipping) if you want to use colab**" + "The version of python in COLAB is different from what the newer GMT needs to install along with pygmt. So, one way around this problem is to reinstall GMT from scratch, along with other important packages. This is done with this block of commands below." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "nnMDokWZuQyN", - "outputId": "0be69909-5cb9-4d8c-acfb-1b0b6b303b8f" + "id": "nnMDokWZuQyN" }, "outputs": [], "source": [ - "%%script echo skipping\n", - "\n", - "# because I like to enjoy my coffee in silence, it takes time. \n", - "# (3 runs averaged 6 minutes to install everything ! keep drinking your coffee)\n", - "# comment the %%capture line if you want to see the colab VM working\n", + "# Installing conda. Note the kernel needs to be restarted for changes to be applied and this happens automatically.\n", + "# If you are wondering why you are seeing a message \"Your session crashed for an unknown reason\", this is why.\n", + "# You can safely ignore this message!\n", "%%capture\n", - "!sudo apt update \n", - "!sudo apt upgrade -y\n", - "!sudo apt install -y build-essential cmake libcurl4-gnutls-dev libnetcdf-dev gdal-bin libgdal-dev libfftw3-dev libpcre3-dev liblapack-dev libblas-dev libglib2.0-dev ghostscript ghostscript-x graphicsmagick ffmpeg xdg-utils\n", - "# clone gmt from source\n", - "!git clone --depth 50 https://github.com/GenericMappingTools/gmt\n", - "# cmake everything\n", - "!cmake /content/gmt\n", - "# build and install\n", - "!cmake --build . --target install\n", - "\n", - "# and last but not least\n", - "!pip install pygmt\n", - "\n", - "# and if you don't believe in it\n", - "!gmt --version\n", - "!python --version" + "!pip install -q condacolab\n", + "import condacolab\n", + "condacolab.install()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "5KpPppcCRjeg" + }, + "outputs": [], + "source": [ + "%%capture\n", + "!mamba install pygmt #<- note we are using mamba, but you can use conda" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, "id": "oIdVNbxrr1lw", - "outputId": "05379551-c66c-4d0b-917c-74cc25fb8942", "tags": [ "remove-stdout" ] @@ -85,7 +76,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "_1yy0EHSQHsx" + }, "source": [ "**B)** Now, if you are using Binder or in your local jupyter\n", "\n", @@ -95,7 +88,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "oneEDu95QHsx" + }, "outputs": [], "source": [ "%matplotlib inline" @@ -103,7 +98,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "VtMm4mOWQHsx" + }, "source": [ "## Mars dataset\n", "\n", @@ -119,7 +116,7 @@ }, "outputs": [], "source": [ - "import xarray as xr \n", + "import xarray as xr\n", "\n", "dset_mars = xr.open_dataset('mola32.nc')\n", "dset_mars" @@ -127,7 +124,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "zppv0puWQHsx" + }, "source": [ "Just like any other notebook with pygmt, we import the library and manipulate other data. To make a map of the entire Martian surface without a lot of time and memory, let's reduce the resolution using `grdsample`. We also take the opportunity to transform an `alt` variable into a `float` to be used in maps." ] @@ -136,15 +135,11 @@ "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "XFfzKq4-42S2", - "outputId": "e1697b32-8a4c-46c6-cccf-bed9c5f9d421" + "id": "XFfzKq4-42S2" }, "outputs": [], "source": [ - "import pygmt \n", + "import pygmt\n", "\n", "# convert from int16 to float\n", "dset_mars_topo = dset_mars.alt.astype(float)\n", @@ -158,7 +153,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "QXRHm_9pQHsy" + }, "source": [ "Here we can create a map of the entire Martian surface, in the same projections we use for our planet." ] @@ -167,12 +164,7 @@ "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 50 - }, - "id": "4jmXhEsk0kYi", - "outputId": "cfeef10d-e42f-4ce4-9d21-97c1c6828d72" + "id": "4jmXhEsk0kYi" }, "outputs": [], "source": [ @@ -189,7 +181,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "6XKdJhaYQHsy" + }, "source": [ "A very interesting feature is Mount Olympus (Olympus Mons - see more details at https://mars.nasa.gov/resources/22587/olympus-mons), centered at approximately 19°N and 133°W, with a height of 22 km (14 miles) and approximately 700 km (435 miles) in diameter. Let's use the original dataset at 32 pixels/degree resolution and plot a (not so interesting) map with `xarray`." ] @@ -198,12 +192,7 @@ "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 297 - }, - "id": "ypeLac-gtjVI", - "outputId": "f9013715-c01e-484c-b63a-8714852ea755" + "id": "ypeLac-gtjVI" }, "outputs": [], "source": [ @@ -215,7 +204,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "k5h6BkJRQHsy" + }, "source": [ "We use the same sequence as other pygmt tutorial notebooks to make a map." ] @@ -224,12 +215,7 @@ "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 301 - }, "id": "4xPXldUJsbha", - "outputId": "4e68b731-68ff-46d2-f5b2-3fcd39c46f7f", "scrolled": true }, "outputs": [], @@ -246,7 +232,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "npje8r2RQHsy" + }, "source": [ "And we're going to add some perspective, as well as a more interesting color scale. For ease of understanding, let's separate the region of interest with the same cutout that we created the base of the Olympus Mons topography dataset.\n", "\n", @@ -261,12 +249,7 @@ "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 283 - }, "id": "GwCV6HIJ_Aa6", - "outputId": "7ccb2823-bbb8-4921-8ebd-e07cf3ba9ddc", "scrolled": true }, "outputs": [], @@ -301,14 +284,16 @@ "\n", "with fig.inset(position=\"JTR+w3.5c+o0.2c\", margin=0, box=None):\n", " # Create a figure in the inset using the global projection centered at Olympus MOns\n", - " fig.grdimage(grid=dset_mars_topo,region='g',frame='g',projection='G225/19/3.5c\"')\n", + " fig.grdimage(grid=dset_mars_topo,region='g',frame='g',projection='G225/19/3.5c')\n", " fig.plot(bounds,pen=\"1p,red\")\n", "fig.show()" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "tRmKA0fqQHsz" + }, "source": [ "## Now, how about Hawaii?\n", "\n", @@ -319,15 +304,11 @@ "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "XkeCs3NaLSbY", - "outputId": "920cd17f-cbe1-43d6-b6b2-7cfce418bfb8" + "id": "XkeCs3NaLSbY" }, "outputs": [], "source": [ - "# get SRTM around Hawaii \n", + "# get SRTM around Hawaii\n", "topo_hawaii = pygmt.datasets.load_earth_relief(region=[-170,-140,13,25],resolution=\"05m\")\n", "\n", "# and get the whole Earth at the same resolution of our low resolution Mars dataset\n", @@ -336,7 +317,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "GoMJnMLAQHsz" + }, "source": [ "And we use the same sequence as above to make a map." ] @@ -345,12 +328,7 @@ "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 295 - }, - "id": "SUsRWFJ-MZ3Y", - "outputId": "1830e744-b7a8-4c51-b543-c403716d8785" + "id": "SUsRWFJ-MZ3Y" }, "outputs": [], "source": [ @@ -367,23 +345,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "duMT3GAVQHsz" + }, "source": [ "**Another few notes**\n", "\n", - "As we want to make a comparison, let's keep the same color scale as Mars, still using as a basis for the Z plane, -5000 meters (see the line `plane=\"-5000+ggrey\"` exactly like the map above. The inset in the upper right corner is the same and we adjust the bounding box coordinates used to cut out the topography, drawing in red on the map. " + "As we want to make a comparison, let's keep the same color scale as Mars, still using as a basis for the Z plane, -5000 meters (see the line `plane=\"-5000+ggrey\"` exactly like the map above. The inset in the upper right corner is the same and we adjust the bounding box coordinates used to cut out the topography, drawing in red on the map." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 283 - }, - "id": "Q4IiufkLG5cW", - "outputId": "57e43215-a8b5-45e2-c9ea-9544eaea1ef8" + "id": "Q4IiufkLG5cW" }, "outputs": [], "source": [ @@ -416,16 +391,18 @@ "\n", "with fig.inset(position=\"JTR+w3.5c+o0.2c\", margin=0, box=None):\n", " # Create a figure in the inset using the global projection centered at Olympus MOns\n", - " fig.grdimage(grid=topo_globe,region='g',frame='g',projection='G-160/19/3.5c\"')\n", + " fig.grdimage(grid=topo_globe,region='g',frame='g',projection='G-160/19/3.5c')\n", " fig.coast(region='g',shorelines=\"thin\", frame=\"g\")\n", " fig.plot(bounds,pen=\"1p,red\")\n", - " \n", + "\n", "fig.show()" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "fpbPK80aQHsz" + }, "source": [ "## Combining the two maps side by side\n", "\n", @@ -436,12 +413,7 @@ "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 166 - }, - "id": "UiBEecTSRp6T", - "outputId": "1bd76a70-5892-40c8-8209-5414e6e4a46f" + "id": "UiBEecTSRp6T" }, "outputs": [], "source": [ @@ -471,7 +443,7 @@ "\n", " # we don't need the colormap in both figures\n", " #fig.colorbar(perspective=True, frame=[\"a5000\", \"x+lElevation\", \"y+lm\"])\n", - " \n", + "\n", " with fig.set_panel(panel=1):\n", " frame = [\"xa5f1\",\"ya5f1\", \"z5000+lmeters\", \"wSEnZ\"]\n", "\n", @@ -490,14 +462,16 @@ " # Set the contour pen thickness to \"0.1p\"\n", " contourpen=\"0.1p\",)\n", "\n", - " fig.colorbar(perspective=True, frame=[\"a5000\", \"x+lElevation\", \"y+lm\"]) \n", + " fig.colorbar(perspective=True, frame=[\"a5000\", \"x+lElevation\", \"y+lm\"])\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "aHmeGgRsQHs0" + }, "source": [ "## Bonus map\n", "\n", @@ -509,19 +483,21 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "sd_4KdYTQHs0" + }, "outputs": [], "source": [ "fig = pygmt.Figure()\n", "\n", "# we are using a Orthographic view centered at the landing site\n", - "fig.grdimage(grid=dset_mars_topo,region='g',frame='g',projection='G109.926/25.066/12c\"',shading='+a100+nt1')\n", + "fig.grdimage(grid=dset_mars_topo,region='g',frame='g',projection='G109.926/25.066/12c',shading='+a100+nt1')\n", "\n", "zhurong = [109.926,25.066]\n", "Olympus = [360-210,19.0] #position for Olympus Mons - see the letf border of the area\n", "\n", "# and we drop a \"star\" in the landing site and write with a small displacement of text\n", - "fig.plot(x=zhurong[0],y=zhurong[1],style=\"a0.5c\", pen=\"1p,black\", color=\"darkorange\")\n", + "fig.plot(x=zhurong[0],y=zhurong[1],style=\"a0.5c\", pen=\"1p,black\", fill=\"darkorange\")\n", "fig.text(x=zhurong[0]+5,y=zhurong[1]+5, text=\"Zhurong\", font='10p,Helvetica-Bold')\n", "\n", "fig.text(x=Olympus[0],y=Olympus[1], text=\"Olympus Mons\", font='10p,Helvetica-Bold')\n", @@ -532,7 +508,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "cmwPveXmQHs0" + }, "source": [ "# additional maps\n", "\n",