{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Geospatial networks\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import os\n\nimport cartopy.crs as ccrs\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nimport nngt\nimport nngt.geospatial as ng\n\n\nplt.rcParams.update({\n    'axes.edgecolor': 'grey', 'xtick.color': 'grey', 'ytick.color': 'grey',\n    \"figure.facecolor\": (0, 0, 0, 0), \"axes.facecolor\": (0, 0, 0, 0),\n    \"axes.labelcolor\": \"grey\", \"axes.titlecolor\": \"grey\", \"text.color\": \"grey\"\n})\n\n\nnngt.seed(2)\n\n\n# take random countries\nnum_nodes = 20\n\nworld = ng.maps[\"adaptive\"]\nunits = nngt._rng.choice(50, num_nodes, replace=False)\ncodes = list(world.iloc[units].SU_A3)\n\n# make random network\ng = nngt.generation.erdos_renyi(nodes=num_nodes, avg_deg=3)\n\n# add the A3 code for each country (that's the crucial part that will link\n# the graph to the geospatial data)\ng.new_node_attribute(\"code\", \"string\", codes)\n\ng.set_weights(nngt._rng.exponential(2, g.edge_nb()))\n\n# plot using draw_map and the A3 codes stored in \"code\"\nng.draw_map(g, \"code\", ncolor=\"in-degree\", esize=\"weight\", threshold=0,\n            ecolor=\"grey\", proj=ccrs.EqualEarth(), show=False)\n\nplt.tight_layout()\nplt.show()"
      ]
    }
  ],
  "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.10"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}