{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Outline: \n", " \n", "1. Package intro\n", "2. How to read food webs from file?\n", "3. How to work with food webs?\n", "4. How to visualize food webs?\n", "\n", "This tutorial is a Jupyter Notebook consisting of text ('Markdown') and code cells. A code cell (with grey background) can be evaluated by pressing Shift+Enter when the cell is selected (as indicated by a green rectangle). The output will appear below the code. You can insert a new cell selecting \"+\" in the menu above, to write and evaluate your own code." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# foodwebviz \n", "\n", "foodwebviz is a Python package for visualisation of foodwebs (trophic networks)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import foodwebviz as fw" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on function read_from_XLS in module foodwebviz.io:\n", "\n", "read_from_XLS(filename)\n", " Read foodweb from an XLS (spreadsheet) file, see examples/data/Richards_Bay_C_Summer.xls.\n", " \n", " Parameters\n", " ----------\n", " foodweb : foodwebs.FoodWeb\n", " Object to save.\n", " filename: string\n", " Destination path.\n", " \n", " Description\n", " ----------\n", " The XLS file consists of three sheets: \n", " 'Title':\n", " containing the name of the food web\n", " 'Node properties':\n", " with a table describing nodes through the following columns: \n", " 'Names', 'IsAlive', 'Biomass', 'Import', 'Export', 'Respiration', 'TrophicLevel'\n", " 'Internal flows':\n", " with a table describing flows between the nodes in the system; \n", " the first row and the first column contain node names;\n", " table elements contain flow values from the node in the row to the node in the column.\n", "\n" ] } ], "source": [ "help(fw.read_from_XLS)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# How to read food webs?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`fw.read_from_SCOR(scor_path)` allows to read food web from a file in the SCOR format. An example is provided: data/Richards_Bay_C_Summer.scor. To check the format specification please evaluate `help(fw.read_from_SCOR)`.\n", "\n", "`fw.read_from_CSV(csv_path)` allows to read a food web from a text file with semicolon-separated variables. An example is provided: data/Richards_Bay_C_Summer.CSV. To check the format specification please evaluate `help(fw.read_from_CSV)`.\n", "\n", "`fw.read_from_XLS(csv_path)` allows to read a food web from an XLS file. An example is provided: data/Richards_Bay_C_Summer.XLS. To check the format specification please evaluate `help(fw.read_from_XLS)`.\n", "\n", "Each path can be an absolute or a relative path (w.r.t. the folder foodwebviz/examples)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Reading file: data/Alaska_Prince_William_Sound.scor\n" ] } ], "source": [ "foodweb = fw.read_from_SCOR('data/Alaska_Prince_William_Sound.scor')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# How to work with food webs? " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's check some basic information about a food web:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Title: Test elasticities\n", "\n", "Number of nodes: 3\n", "Number of living nodes: 2\n" ] } ], "source": [ "print(f'Title: {foodweb.title}\\n')\n", "print(f'Number of nodes: {foodweb.n}')\n", "print(f'Number of living nodes: {foodweb.n_living}')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's see the first rows of the table with information on nodes (vertices) - pandas.DataFrame:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | IsAlive | \n", "Biomass | \n", "Export | \n", "Respiration | \n", "TrophicLevel | \n", "Import | \n", "
|---|---|---|---|---|---|---|
| Names | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| Diatoms | \n", "True | \n", "0.5011 | \n", "0.0 | \n", "74.649 | \n", "2.000000 | \n", "0.0 | \n", "
| Flagellates | \n", "True | \n", "0.3424 | \n", "0.0 | \n", "53.438 | \n", "2.000000 | \n", "0.0 | \n", "
| Bacteria | \n", "True | \n", "0.5200 | \n", "0.0 | \n", "27.560 | \n", "2.029999 | \n", "0.0 | \n", "
| HM plankton | \n", "True | \n", "0.0818 | \n", "0.0 | \n", "5.892 | \n", "2.029986 | \n", "0.0 | \n", "
| Small copepods | \n", "True | \n", "0.0375 | \n", "0.0 | \n", "3.450 | \n", "2.868366 | \n", "0.0 | \n", "
| \n", " | Diatoms | \n", "Flagellates | \n", "Bacteria | \n", "HM plankton | \n", "Small copepods | \n", "Medium copepods | \n", "Large copepods | \n", "Other lg zooplankton | \n", "Sm macrobenthos | \n", "Lg suspension feeder | \n", "... | \n", "Sm pelagic fish | \n", "Lg pelagic fish | \n", "Skates and rays | \n", "Sm benthic shark | \n", "Large sharks | \n", "Cetaceans | \n", "Susp POC | \n", "Sed POC | \n", "DOC | \n", "DIC | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Names | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| Diatoms | \n", "0.0 | \n", "0.0 | \n", "1.677 | \n", "0.264 | \n", "2.8900 | \n", "1.8000 | \n", "0.8940 | \n", "0.0307 | \n", "0.00 | \n", "0.0 | \n", "... | \n", "251.0000 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "41.10 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| Flagellates | \n", "0.0 | \n", "0.0 | \n", "1.677 | \n", "0.264 | \n", "2.0600 | \n", "1.2300 | \n", "0.6380 | \n", "0.0219 | \n", "0.00 | \n", "0.0 | \n", "... | \n", "188.0000 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "22.10 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| Bacteria | \n", "0.0 | \n", "0.0 | \n", "0.000 | \n", "0.000 | \n", "0.1860 | \n", "0.7910 | \n", "0.4100 | \n", "0.0205 | \n", "0.00 | \n", "58.8 | \n", "... | \n", "0.0000 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "24.00 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| HM plankton | \n", "0.0 | \n", "0.0 | \n", "0.000 | \n", "0.000 | \n", "0.0012 | \n", "0.0048 | \n", "0.0025 | \n", "0.0005 | \n", "7.76 | \n", "0.0 | \n", "... | \n", "0.0000 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "3.93 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
| Small copepods | \n", "0.0 | \n", "0.0 | \n", "0.000 | \n", "0.000 | \n", "0.1240 | \n", "0.8780 | \n", "0.2070 | \n", "0.0579 | \n", "0.00 | \n", "0.0 | \n", "... | \n", "0.0542 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "1.30 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "
5 rows × 33 columns
\n", "