diff --git a/Landuse_classification.ipynb b/Landuse_classification.ipynb
deleted file mode 100644
index 07c61e1..0000000
--- a/Landuse_classification.ipynb
+++ /dev/null
@@ -1,4765 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# TODO list\n",
- "\n",
- "- Add the following metrics:\n",
- " 1. Density of built floor area (sum of built pixels' height / area of block)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "
\n",
- "
Table of contents \n",
- "
"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- ""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 109,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "application/javascript": [
- "$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')"
- ],
- "text/plain": [
- ""
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- }
- ],
- "source": [
- "%%javascript\n",
- "$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- " Define working environment
\n",
- "\n",
- "The following cells are used to :\n",
- "- Set the environment variables for Python and GRASS GIS and R statistical computing \n",
- "- Define the [\"GRASSDATA\" folder](https://grass.osgeo.org/grass73/manuals/helptext.html), the name of \"location\" and \"mapset\" where you will to work."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**Import libraries**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "## Import libraries needed for setting parameters of operating system \n",
- "import os\n",
- "import sys"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**Set 'Python' and 'GRASS GIS' environment variables**"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Here, we set [the environment variables allowing to use of GRASS GIS](https://grass.osgeo.org/grass64/manuals/variables.html) inside this Jupyter notebook. Please change the directory path according to your own system configuration. Here after are the environment variables defined on a Linux Mint system."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "### Define GRASS GIS environment variables for LINUX UBUNTU Mint 18.1 (Serena)\n",
- "# Check is environmental variables exists and create them (empty) if not exists.\n",
- "if not 'PYTHONPATH' in os.environ:\n",
- " os.environ['PYTHONPATH']=''\n",
- "if not 'LD_LIBRARY_PATH' in os.environ:\n",
- " os.environ['LD_LIBRARY_PATH']=''\n",
- "# Set environmental variables\n",
- "os.environ['GISBASE'] = '/home/tais/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-gnu'\n",
- "os.environ['PATH'] += os.pathsep + os.path.join(os.environ['GISBASE'],'bin')\n",
- "os.environ['PATH'] += os.pathsep + os.path.join(os.environ['GISBASE'],'script')\n",
- "os.environ['PATH'] += os.pathsep + os.path.join(os.environ['GISBASE'],'lib')\n",
- "#os.environ['PATH'] += os.pathsep + os.path.join(os.environ['GISBASE'],'etc','python')\n",
- "os.environ['PYTHONPATH'] += os.pathsep + os.path.join(os.environ['GISBASE'],'etc','python')\n",
- "os.environ['PYTHONPATH'] += os.pathsep + os.path.join(os.environ['GISBASE'],'etc','python','grass')\n",
- "os.environ['PYTHONPATH'] += os.pathsep + os.path.join(os.environ['GISBASE'],'etc','python','grass','script')\n",
- "os.environ['PYTHONLIB'] = '/usr/lib/python2.7'\n",
- "os.environ['LD_LIBRARY_PATH'] += os.pathsep + os.path.join(os.environ['GISBASE'],'lib')\n",
- "os.environ['GIS_LOCK'] = '$$'\n",
- "os.environ['GISRC'] = os.path.join(os.environ['HOME'],'.grass7','rc')\n",
- "os.environ['PATH'] += os.pathsep + os.path.join(os.environ['HOME'],'.grass7','addons')\n",
- "os.environ['PATH'] += os.pathsep + os.path.join(os.environ['HOME'],'.grass7','addons','bin')\n",
- "os.environ['PATH'] += os.pathsep + os.path.join(os.environ['HOME'],'.grass7','addons')\n",
- "os.environ['PATH'] += os.pathsep + os.path.join(os.environ['HOME'],'.grass7','addons','scripts')\n",
- "\n",
- "## Define GRASS-Python environment\n",
- "sys.path.append(os.path.join(os.environ['GISBASE'],'etc','python'))"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "**Import GRASS Python packages**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "## Import libraries needed to launch GRASS GIS in the jupyter notebook\n",
- "import grass.script.setup as gsetup\n",
- "\n",
- "## Import libraries needed to call GRASS using Python\n",
- "import grass.script as gscript\n",
- "from grass.script import core as grass"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-**"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "**Display current environment variables of your computer**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "MDMSESSION = mate \t\n",
- "MANDATORY_PATH = /usr/share/gconf/mate.mandatory.path \t\n",
- "MATE_DESKTOP_SESSION_ID = this-is-deprecated \t\n",
- "LESSOPEN = | /usr/bin/lesspipe %s \t\n",
- "MDM_LANG = fr_BE.UTF-8 \t\n",
- "LOGNAME = tais \t\n",
- "USER = tais \t\n",
- "HOME = /home/tais \t\n",
- "XDG_VTNR = 9 \t\n",
- "PATH = /usr/local/bin:/home/tais/BIN:/home/tais/bin:/home/tais/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/tais/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-gnu/bin:/home/tais/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-gnu/script:/home/tais/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-gnu/lib:/home/tais/.grass7/addons:/home/tais/.grass7/addons/bin:/home/tais/.grass7/addons:/home/tais/.grass7/addons/scripts \t\n",
- "CLICOLOR = 1 \t\n",
- "DISPLAY = :0.0 \t\n",
- "SSH_AGENT_PID = 5974 \t\n",
- "LANG = fr_BE.UTF-8 \t\n",
- "TERM = xterm-color \t\n",
- "SHELL = /bin/bash \t\n",
- "GIS_LOCK = $$ \t\n",
- "XAUTHORITY = /home/tais/.Xauthority \t\n",
- "SESSION_MANAGER = local/tais-HP-Z620-Workstation:@/tmp/.ICE-unix/5837,unix/tais-HP-Z620-Workstation:/tmp/.ICE-unix/5837 \t\n",
- "SHLVL = 1 \t\n",
- "QT_LINUX_ACCESSIBILITY_ALWAYS_ON = 1 \t\n",
- "INSIDE_CAJA_PYTHON = \t\n",
- "QT_ACCESSIBILITY = 1 \t\n",
- "LD_LIBRARY_PATH = :/home/tais/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-gnu/lib \t\n",
- "COMPIZ_CONFIG_PROFILE = mate \t\n",
- "WINDOWPATH = 9 \t\n",
- "GTK_OVERLAY_SCROLLING = 0 \t\n",
- "PYTHONPATH = :/home/tais/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-gnu/etc/python:/home/tais/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-gnu/etc/python/grass:/home/tais/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-gnu/etc/python/grass/script \t\n",
- "GISBASE = /home/tais/SRC/GRASS/grass_trunk/dist.x86_64-pc-linux-gnu \t\n",
- "CLUTTER_BACKEND = x11 \t\n",
- "USERNAME = tais \t\n",
- "XDG_SESSION_DESKTOP = mate \t\n",
- "GDM_XSERVER_LOCATION = local \t\n",
- "XDG_RUNTIME_DIR = /run/user/1000 \t\n",
- "JPY_PARENT_PID = 7955 \t\n",
- "QT_STYLE_OVERRIDE = gtk \t\n",
- "SSH_AUTH_SOCK = /run/user/1000/keyring/ssh \t\n",
- "VTE_VERSION = 4205 \t\n",
- "GDMSESSION = mate \t\n",
- "GISRC = /home/tais/.grass7/rc \t\n",
- "GIT_PAGER = cat \t\n",
- "XDG_CONFIG_DIRS = /etc/xdg/xdg-mate:/etc/xdg \t\n",
- "XDG_CURRENT_DESKTOP = MATE \t\n",
- "XDG_SESSION_ID = c21 \t\n",
- "DBUS_SESSION_BUS_ADDRESS = unix:abstract=/tmp/dbus-oiw1S789SI,guid=e626cdc47bce079de737e4fe5a3fcda7 \t\n",
- "_ = /usr/local/bin/jupyter \t\n",
- "XDG_SESSION_COOKIE = 8441891e86e24d76b9616edf516d5734-1514130855.90561-444848216 \t\n",
- "DESKTOP_SESSION = mate \t\n",
- "WINDOWID = 56623110 \t\n",
- "LESSCLOSE = /usr/bin/lesspipe %s %s \t\n",
- "DEFAULTS_PATH = /usr/share/gconf/mate.default.path \t\n",
- "MPLBACKEND = module://ipykernel.pylab.backend_inline \t\n",
- "MDM_XSERVER_LOCATION = local \t\n",
- "GTK_MODULES = gail:atk-bridge \t\n",
- "XDG_DATA_DIRS = /usr/share/mate:/usr/local/share/:/usr/share/:/usr/share/mdm/ \t\n",
- "PWD = /media/tais/data/Dropbox/ULB/MAUPP/Traitements/Landscape_metrics/r.li/Landuse_mapping \t\n",
- "COLORTERM = mate-terminal \t\n",
- "PYTHONLIB = /usr/lib/python2.7 \t\n",
- "LS_COLORS = rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36: \t\n",
- "PAGER = cat \t\n",
- "XDG_SEAT = seat0 \t\n"
- ]
- }
- ],
- "source": [
- "## Display the current defined environment variables\n",
- "for key in os.environ.keys():\n",
- " print \"%s = %s \\t\" % (key,os.environ[key])"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-**"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- " Define functions
"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "This section of the notebook is dedicated to defining functions which will then be called later in the script. If you want to create your own functions, define them here."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Function for computing processing time"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "The \"print_processing_time\" is used to calculate and display the processing time for various stages of the processing chain. At the beginning of each major step, the current time is stored in a new variable, using [time.time() function](https://docs.python.org/2/library/time.html). At the end of the stage in question, the \"print_processing_time\" function is called and takes as argument the name of this new variable containing the recorded time at the beginning of the stage, and an output message."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "## Import library for managing time in python\n",
- "import time \n",
- "\n",
- "## Function \"print_processing_time()\" compute processing time and printing it.\n",
- "# The argument \"begintime\" wait for a variable containing the begintime (result of time.time()) of the process for which to compute processing time.\n",
- "# The argument \"printmessage\" wait for a string format with information about the process. \n",
- "def print_processing_time(begintime, printmessage): \n",
- " endtime=time.time() \n",
- " processtime=endtime-begintime\n",
- " remainingtime=processtime\n",
- "\n",
- " days=int((remainingtime)/86400)\n",
- " remainingtime-=(days*86400)\n",
- " hours=int((remainingtime)/3600)\n",
- " remainingtime-=(hours*3600)\n",
- " minutes=int((remainingtime)/60)\n",
- " remainingtime-=(minutes*60)\n",
- " seconds=round((remainingtime)%60,1)\n",
- "\n",
- " if processtime<60:\n",
- " finalprintmessage=str(printmessage)+str(seconds)+\" seconds\"\n",
- " elif processtime<3600:\n",
- " finalprintmessage=str(printmessage)+str(minutes)+\" minutes and \"+str(seconds)+\" seconds\"\n",
- " elif processtime<86400:\n",
- " finalprintmessage=str(printmessage)+str(hours)+\" hours and \"+str(minutes)+\" minutes and \"+str(seconds)+\" seconds\"\n",
- " elif processtime>=86400:\n",
- " finalprintmessage=str(printmessage)+str(days)+\" days, \"+str(hours)+\" hours and \"+str(minutes)+\" minutes and \"+str(seconds)+\" seconds\"\n",
- " \n",
- " return finalprintmessage"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Function for creation of configuration file for r.li (landscape units provided as polygons) (multiprocessed)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "##### Function that create the r.li configuration file for a list of landcover raster.\n",
- "### It enable to create in one function as many configuration file as the number of raster provided in 'listoflandcoverraster'.\n",
- "### It could be use only in case study with a several landcover raster and only one landscape unit layer.\n",
- "### So, the landscape unit layer if fixed and there are the landcover raster which change. \n",
- "# 'listoflandcoverraster' wait for a list with the name (string) of landcover rasters.\n",
- "# 'landscape_polygons' wait for the name (string) of the vector layer containing the polygons to be used as landscape units.\n",
- "# 'masklayerhardcopy' wait for a boolean value (True/False) depending if the user want to create hard copy of the landscape units mask layers or not.\n",
- "# 'returnlistpath' wait for a boolean value (True/False) according to the fact that a list containing the path to the configuration files is desired.\n",
- "# 'ncores' wait for a integer corresponding to the number of desired cores to be used for parallelization.\n",
- "\n",
- "# Import libraries for multiprocessing \n",
- "import multiprocessing\n",
- "from multiprocessing import Pool\n",
- "from functools import partial \n",
- "\n",
- "# Function that copy the landscape unit raster masks on a new layer with name corresponding to the current 'landcover_raster'\n",
- "def copy_landscapeunitmasks(current_landcover_raster,base_landcover_raster,landscape_polygons,landscapeunit_bbox,cat):\n",
- " ### Copy the landscape units mask for the current 'cat'\n",
- " # Define the name of the current \"current_landscapeunit_rast\" layer\n",
- " current_landscapeunit_rast=current_landcover_raster.split(\"@\")[0]+\"_\"+landscape_polygons.split(\"@\")[0]+\"_\"+str(cat) \n",
- " base_landscapeunit_rast=base_landcover_raster.split(\"@\")[0]+\"_\"+landscape_polygons.split(\"@\")[0]+\"_\"+str(cat) \n",
- " # Copy the the landscape unit created for the first landcover map in order to match the name of the current landcover map\n",
- " gscript.run_command('g.copy', overwrite=True, quiet=True, raster=(base_landscapeunit_rast,current_landscapeunit_rast))\n",
- " # Add the line to the text variable\n",
- " text=\"MASKEDOVERLAYAREA \"+current_landscapeunit_rast+\"|\"+landscapeunit_bbox[cat]\n",
- " return text\n",
- "\n",
- "# Function that create the r.li configuration file for the base landcover raster and then for all the binary rasters\n",
- "def create_rli_configfile(listoflandcoverraster,landscape_polygons,\n",
- " masklayerhardcopy=False,returnlistpath=True,ncores=2):\n",
- " # Check if 'listoflandcoverraster' is not empty\n",
- " if len(listoflandcoverraster)==0:\n",
- " sys.exit(\"The list of landcover raster is empty and should contain at least one raster name\")\n",
- " # Check if rasters provided in 'listoflandcoverraster' exists to avoid error in mutliprocessing \n",
- " for cur_rast in listoflandcoverraster:\n",
- " try:\n",
- " mpset=cur_rast.split(\"@\")[1]\n",
- " except:\n",
- " mpset=\"\"\n",
- " if cur_rast.split(\"@\")[0] not in [x[0] for x in gscript.list_pairs(type='raster',mapset=mpset)]:\n",
- " sys.exit('Raster <%s> not found' %cur_rast)\n",
- " # Check if rasters provided in 'listoflandcoverraster' have the same extend and spatial resolution \n",
- " raster={}\n",
- " for x, rast in enumerate(raster_list):\n",
- " raster[x]=gscript.raster_info(rast)\n",
- " key_list=raster.keys()\n",
- " for x in key_list[1:]:\n",
- " for info in ('north','south','east','west','ewres','nsres'):\n",
- " if not raster[0][info]==raster[x][info]:\n",
- " sys.exit(\"Some raster provided in the list have different spatial resolution or extend, please check\") \n",
- " # Get the version of GRASS GIS \n",
- " version=grass.version()['version'].split('.')[0]\n",
- " # Define the folder to save the r.li configuration files\n",
- " if sys.platform==\"win32\":\n",
- " rli_dir=os.path.join(os.environ['APPDATA'],\"GRASS\"+version,\"r.li\")\n",
- " else: \n",
- " rli_dir=os.path.join(os.environ['HOME'],\".grass\"+version,\"r.li\")\n",
- " if not os.path.exists(rli_dir):\n",
- " os.makedirs(rli_dir)\n",
- " ## Create an ordered list with the 'cat' value of landscape units to be processed.\n",
- " list_cat=[int(x) for x in gscript.parse_command('v.db.select', quiet=True, \n",
- " map=landscape_polygons, column='cat', flags='c')]\n",
- " list_cat.sort()\n",
- " # Declare a empty dictionnary which will contains the north, south, east, west values for each landscape unit\n",
- " landscapeunit_bbox={}\n",
- " # Declare a empty list which will contain the path of the configation files created\n",
- " listpath=[]\n",
- " # Declare a empty string variable which will contains the core part of the r.li configuration file\n",
- " maskedoverlayarea_1=\"\"\n",
- " # Duplicate 'listoflandcoverraster' in a new variable called 'tmp_list'\n",
- " tmp_list=list(listoflandcoverraster)\n",
- " # Set the current landcover raster as the first of the list\n",
- " base_landcover_raster=tmp_list.pop(0) #The pop function return the first item of the list and delete it from the list at the same time\n",
- " # Loop trough the landscape units\n",
- " for cat in list_cat:\n",
- " # Extract the current landscape unit polygon as temporary vector\n",
- " tmp_vect=\"tmp_\"+base_landcover_raster.split(\"@\")[0]+\"_\"+landscape_polygons.split(\"@\")[0]+\"_\"+str(cat)\n",
- " gscript.run_command('v.extract', overwrite=True, quiet=True, \n",
- " input=landscape_polygons, cats=cat, output=tmp_vect)\n",
- " # Set region to match the extent of the current landscape polygon, with resolution and alignement matching the landcover raster\n",
- " gscript.run_command('g.region', vector=tmp_vect, align=base_landcover_raster)\n",
- " # Rasterize the landscape unit polygon\n",
- " landscapeunit_rast=tmp_vect[4:]\n",
- " gscript.run_command('v.to.rast', overwrite=True, quiet=True, input=tmp_vect, output=landscapeunit_rast, use='cat', memory='3000')\n",
- " # Remove temporary vector\n",
- " gscript.run_command('g.remove', quiet=True, flags=\"f\", type='vector', name=tmp_vect)\n",
- " # Set the region to match the raster landscape unit extent and save the region info in a dictionary\n",
- " region_info=gscript.parse_command('g.region', raster=landscapeunit_rast, flags='g')\n",
- " n=str(round(float(region_info['n']),5)) #the config file need 5 decimal for north and south\n",
- " s=str(round(float(region_info['s']),5))\n",
- " e=str(round(float(region_info['e']),6)) #the config file need 6 decimal for east and west\n",
- " w=str(round(float(region_info['w']),6))\n",
- " # Save the coordinates of the bbox in the dictionary (n,s,e,w)\n",
- " landscapeunit_bbox[cat]=n+\"|\"+s+\"|\"+e+\"|\"+w\n",
- " # Add the line to the maskedoverlayarea_1 variable\n",
- " maskedoverlayarea_1+=\"MASKEDOVERLAYAREA \"+landscapeunit_rast+\"|\"+landscapeunit_bbox[cat]+\"\\n\"\n",
- "\n",
- " # Compile the content of the r.li configuration file\n",
- " config_file_content=\"SAMPLINGFRAME 0|0|1|1\\n\"\n",
- " config_file_content+=maskedoverlayarea_1\n",
- " config_file_content+=\"RASTERMAP \"+base_landcover_raster+\"\\n\"\n",
- " config_file_content+=\"VECTORMAP \"+landscape_polygons+\"\\n\"\n",
- "\n",
- " # Create a new file and save the content\n",
- " configfilename=base_landcover_raster.split(\"@\")[0]+\"_\"+landscape_polygons.split(\"@\")[0]\n",
- " path=os.path.join(rli_dir,configfilename)\n",
- " listpath.append(path)\n",
- " f=open(path, 'w')\n",
- " f.write(config_file_content)\n",
- " f.close()\n",
- " \n",
- " # Continue creation of r.li configuration file and landscape unit raster the rest of the landcover raster provided\n",
- " while len(tmp_list)>0:\n",
- " # Initialize 'maskedoverlayarea_2' variable as an empty string\n",
- " maskedoverlayarea_2=\"\"\n",
- " # Set the current landcover raster as the first of the list\n",
- " current_landcover_raster=tmp_list.pop(0) #The pop function return the first item of the list and delete it from the list at the same time\n",
- " if masklayerhardcopy: # If the user asked for hard copy of the landscape units mask layers\n",
- " # Copy all the landscape units masks for the current landcover raster\n",
- " p=Pool(ncores) #Create a pool of processes and launch them using 'map' function\n",
- " func=partial(copy_landscapeunitmasks,current_landcover_raster,base_landcover_raster,landscape_polygons,landscapeunit_bbox) # Set fixed argument of the function\n",
- " maskedoverlayarea_2=p.map(func,list_cat) # Launch the processes for as many items in the list and get the ordered results using map function\n",
- " p.close()\n",
- " p.join()\n",
- " # Compile the content of the r.li configuration file\n",
- " config_file_content=\"SAMPLINGFRAME 0|0|1|1\\n\"\n",
- " config_file_content+=\"\\n\".join(maskedoverlayarea_2)+\"\\n\"\n",
- " config_file_content+=\"RASTERMAP \"+current_landcover_raster+\"\\n\"\n",
- " config_file_content+=\"VECTORMAP \"+landscape_polygons+\"\\n\"\n",
- " else: # If the user not asked for hard copy\n",
- " # Compile the content of the r.li configuration file\n",
- " config_file_content=\"SAMPLINGFRAME 0|0|1|1\\n\"\n",
- " config_file_content+=maskedoverlayarea_1 # If user do not asked for hard copy, the mask layers are the same than for the first configuration file\n",
- " config_file_content+=\"RASTERMAP \"+current_landcover_raster+\"\\n\" # But the name of the RASTERMAP should be the one of the current landcover raster\n",
- " config_file_content+=\"VECTORMAP \"+landscape_polygons+\"\\n\"\n",
- " # Create a new file and save the content\n",
- " configfilename=current_landcover_raster.split(\"@\")[0]+\"_\"+landscape_polygons.split(\"@\")[0]\n",
- " path=os.path.join(rli_dir,configfilename)\n",
- " listpath.append(path)\n",
- " f=open(path, 'w')\n",
- " f.write(config_file_content)\n",
- " f.close()\n",
- " \n",
- " # Return a list of path of configuration files creates if option actived\n",
- " if returnlistpath:\n",
- " return list_cat,listpath\n",
- " else:\n",
- " return list_cat"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Function for creation of binary raster from a categorical raster (multiprocessed)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "###### Function creating a binary raster for each category of a base raster. \n",
- "### The function run within the current region. If a category do not exists in the current region, no binary map will be produce\n",
- "# 'categorical_raster' wait for the name of the base raster to be used. It is the one from which one binary raster will be produced for each category value\n",
- "# 'prefix' wait for a string corresponding to the prefix of the name of the binary raster which will be produced\n",
- "# 'setnull' wait for a boolean value (True, False) according to the fact that the output binary should be 1/0 or 1/null\n",
- "# 'returnlistraster' wait for a boolean value (True, False) regarding to the fact that a list containing the name of binary raster is desired as return of the function\n",
- "# 'category_list' wait for a list of interger corresponding to specific category of the base raster to be used \n",
- "# 'ncores' wait for a integer corresponding to the number of desired cores to be used for parallelization\n",
- "\n",
- "# Import libraries for multiprocessing \n",
- "import multiprocessing\n",
- "from multiprocessing import Pool\n",
- "from functools import partial \n",
- "\n",
- "def create_binary_raster(categorical_raster,prefix=\"binary\",setnull=False,returnlistraster=True,category_list=None,ncores=2):\n",
- " # Check if raster exists to avoid error in mutliprocessing \n",
- " try:\n",
- " mpset=categorical_raster.split(\"@\")[1]\n",
- " except:\n",
- " mpset=\"\"\n",
- " if categorical_raster not in gscript.list_strings(type='raster',mapset=mpset):\n",
- " sys.exit('Raster <%s> not found' %categorical_raster)\n",
- " # Check for number of cores doesnt exceed available\n",
- " nbcpu=multiprocessing.cpu_count()\n",
- " if ncores>=nbcpu:\n",
- " ncores=nbcpu-1\n",
- " returnlist=[] #Declare empty list for return\n",
- " #gscript.run_command('g.region', raster=categorical_raster, quiet=True) #Set the region\n",
- " null='null()' if setnull else '0' #Set the value for r.mapcalc\n",
- " minclass=1 if setnull else 2 #Set the value to check if the binary raster is empty\n",
- " if category_list == None: #If no category_list provided\n",
- " category_list=[cl for cl in gscript.parse_command('r.category',map=categorical_raster,quiet=True)]\n",
- " for i,x in enumerate(category_list): #Make sure the format is UTF8 and not Unicode\n",
- " category_list[i]=x.encode('UTF8')\n",
- " category_list.sort(key=float) #Sort the raster categories in ascending.\n",
- " p=Pool(ncores) #Create a pool of processes and launch them using 'map' function\n",
- " func=partial(get_binary,categorical_raster,prefix,null,minclass) # Set the two fixed argument of the function\n",
- " returnlist=p.map(func,category_list) # Launch the processes for as many items in the 'functions_name' list and get the ordered results using map function\n",
- " p.close()\n",
- " p.join()\n",
- " if returnlistraster:\n",
- " return returnlist\n",
- "\n",
- "#### Function that extract binary raster for a specified class (called in 'create_binary_raster' function)\n",
- "def get_binary(categorical_raster,prefix,null,minclass,cl):\n",
- " binary_class=prefix+\"_\"+cl\n",
- " gscript.run_command('r.mapcalc', expression=binary_class+'=if('+categorical_raster+'=='+str(cl)+',1,'+null+')',overwrite=True, quiet=True)\n",
- " if len(gscript.parse_command('r.category',map=binary_class,quiet=True))>=minclass: #Check if created binary is not empty\n",
- " return binary_class\n",
- " else:\n",
- " gscript.run_command('g.remove', quiet=True, flags=\"f\", type='raster', name=binary_class)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Function for computation of spatial metrics at landscape level (multiprocessed)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "##### Function that compute different landscape metrics (spatial metrics) at landscape level. \n",
- "### The metric computed are \"dominance\",\"pielou\",\"renyi\",\"richness\",\"shannon\",\"simpson\".\n",
- "### It is important to set the computation region before runing this script so that it match the extent of the 'raster' layer.\n",
- "# 'configfile' wait for the path (string) to the configuration file corresponding to the 'raster' layer.\n",
- "# 'raster' wait for the name (string) of the landcover map on which landscape metrics will be computed.\n",
- "# 'returnlistresult' wait for a boolean value (True/False) according to the fact that a list containing the path to the result files is desired.\n",
- "# 'ncores' wait for a integer corresponding to the number of desired cores to be used for parallelization.\n",
- "\n",
- "# Import libraries for multiprocessing \n",
- "import multiprocessing\n",
- "from multiprocessing import Pool\n",
- "from functools import partial \n",
- "\n",
- "def compute_landscapelevel_metrics(configfile, raster, spatial_metric):\n",
- " filename=raster.split(\"@\")[0]+\"_%s\" %spatial_metric\n",
- " outputfile=os.path.join(os.path.split(configfile)[0],\"output\",filename)\n",
- " if spatial_metric=='renyi': # The alpha parameter was set to 2 as in https://en.wikipedia.org/wiki/R%C3%A9nyi_entropy\n",
- " gscript.run_command('r.li.%s' %spatial_metric, overwrite=True,\n",
- " input=raster,config=configfile,alpha='2', output=filename)\n",
- " else:\n",
- " gscript.run_command('r.li.%s' %spatial_metric, overwrite=True,\n",
- " input=raster,config=configfile, output=filename)\n",
- " return outputfile\n",
- " \n",
- "def get_landscapelevel_metrics(configfile, raster, returnlistresult=True, ncores=2):\n",
- " # Check if raster exists to avoid error in mutliprocessing \n",
- " try:\n",
- " mpset=raster.split(\"@\")[1]\n",
- " except:\n",
- " mpset=\"\"\n",
- " if raster not in gscript.list_strings(type='raster',mapset=mpset):\n",
- " sys.exit('Raster <%s> not found' %raster)\n",
- " # Check if configfile exists to avoid error in mutliprocessing \n",
- " if not os.path.exists(configfile):\n",
- " sys.exit('Configuration file <%s> not found' %configfile)\n",
- " # List of metrics to be computed\n",
- " spatial_metric_list=[\"dominance\",\"pielou\",\"renyi\",\"richness\",\"shannon\",\"simpson\"]\n",
- " # Check for number of cores doesnt exceed available\n",
- " nbcpu=multiprocessing.cpu_count()\n",
- " if ncores>=nbcpu:\n",
- " ncores=nbcpu-1\n",
- " if ncores>len(spatial_metric_list):\n",
- " ncores=len(spatial_metric_list) #Adapt number of cores to number of metrics to compute\n",
- " #Declare empty list for return\n",
- " returnlist=[] \n",
- " # Create a new pool\n",
- " p=Pool(ncores)\n",
- " # Set the two fixed argument of the 'compute_landscapelevel_metrics' function\n",
- " func=partial(compute_landscapelevel_metrics,configfile, raster)\n",
- " # Launch the processes for as many items in the 'functions_name' list and get the ordered results using map function\n",
- " returnlist=p.map(func,spatial_metric_list)\n",
- " p.close()\n",
- " p.join()\n",
- " # Return list of paths to result files\n",
- " if returnlistresult:\n",
- " return returnlist"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Function for computation of spatial metrics at class level (multiprocessed)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "##### Function that compute different landscape metrics (spatial metrics) at class level. \n",
- "### The metric computed are \"patch number (patchnum)\",\"patch density (patchdensity)\",\"mean patch size(mps)\",\n",
- "### \"coefficient of variation of patch area (padcv)\",\"range of patch area size (padrange)\",\n",
- "### \"standard deviation of patch area (padsd)\", \"shape index (shape)\", \"edge density (edgedensity)\".\n",
- "### It is important to set the computation region before runing this script so that it match the extent of the 'raster' layer.\n",
- "# 'configfile' wait for the path (string) to the configuration file corresponding to the 'raster' layer.\n",
- "# 'raster' wait for the name (string) of the landcover map on which landscape metrics will be computed.\n",
- "# 'returnlistresult' wait for a boolean value (True/False) according to the fact that a list containing the path to the result files is desired.\n",
- "# 'ncores' wait for a integer corresponding to the number of desired cores to be used for parallelization.\n",
- "\n",
- "# Import libraries for multiprocessing \n",
- "import multiprocessing\n",
- "from multiprocessing import Pool\n",
- "from functools import partial \n",
- "\n",
- "def compute_classlevel_metrics(configfile, raster, spatial_metric):\n",
- " filename=raster.split(\"@\")[0]+\"_%s\" %spatial_metric\n",
- " gscript.run_command('r.li.%s' %spatial_metric, overwrite=True,\n",
- " input=raster,config=configfile,output=filename)\n",
- " outputfile=os.path.join(os.path.split(configfile)[0],\"output\",filename)\n",
- " return outputfile\n",
- " \n",
- "def get_classlevel_metrics(configfile, raster, returnlistresult=True, ncores=2):\n",
- " # Check if raster exists to avoid error in mutliprocessing \n",
- " try:\n",
- " mpset=raster.split(\"@\")[1]\n",
- " except:\n",
- " mpset=\"\"\n",
- " if raster not in [x.split(\"@\")[0] for x in gscript.list_strings(type='raster',mapset=mpset)]:\n",
- " sys.exit('Raster <%s> not found' %raster)\n",
- " # Check if configfile exists to avoid error in mutliprocessing \n",
- " if not os.path.exists(configfile):\n",
- " sys.exit('Configuration file <%s> not found' %configfile)\n",
- " # List of metrics to be computed\n",
- " spatial_metric_list=[\"patchnum\",\"patchdensity\",\"mps\",\"padcv\",\"padrange\",\"padsd\",\"shape\",\"edgedensity\"]\n",
- " # Check for number of cores doesnt exceed available\n",
- " nbcpu=multiprocessing.cpu_count()\n",
- " if ncores>=nbcpu:\n",
- " ncores=nbcpu-1\n",
- " if ncores>len(spatial_metric_list):\n",
- " ncores=len(spatial_metric_list) #Adapt number of cores to number of metrics to compute\n",
- " # Declare empty list for return\n",
- " returnlist=[] \n",
- " # Create a new pool\n",
- " p=Pool(ncores)\n",
- " # Set the two fixed argument of the 'compute_classlevel_metrics' function\n",
- " func=partial(compute_classlevel_metrics,configfile, raster)\n",
- " # Launch the processes for as many items in the 'functions_name' list and get the ordered results using map function\n",
- " returnlist=p.map(func,spatial_metric_list)\n",
- " p.close()\n",
- " p.join()\n",
- " # Return list of paths to result files\n",
- " if returnlistresult:\n",
- " return returnlist"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Function for computation of each land cover class proportion in landscape units"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 47,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "### Function that compute the proportion of each class of landcover\n",
- "import itertools\n",
- "import multiprocessing\n",
- "from functools import partial\n",
- "import sys, csv\n",
- "import grass.script as gscript\n",
- "\n",
- "def random_string(N):\n",
- " import random, string\n",
- " prefix=random.choice(string.ascii_uppercase + string.ascii_lowercase)\n",
- " suffix=''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(N))\n",
- " return prefix+suffix\n",
- "\n",
- "def compute_prop_landcover(outputfolder,landscape_units_raster,binary_class_raster):\n",
- " # Save the current class in a new variable \n",
- " current_class=binary_class_raster.split(\"@\")[0].split(\"_\")[-1]\n",
- " # Initialize a temp files\n",
- " temp_file=os.path.join(outputfolder,random_string(10))\n",
- " tmp_copy='%s_%s'%(random_string(4),current_class)\n",
- " # Make copy of the raster and fill the null values with zero\n",
- " gscript.run_command('g.copy', overwrite=True, raster='%s,%s'%(binary_class_raster,tmp_copy))\n",
- " gscript.run_command('r.null', map=tmp_copy, null='0')\n",
- " # Compute area of landscape unit and total pixels of the current binary class raster\n",
- " gscript.run_command('i.segment.stats', flags=\"r\", quiet=True, overwrite=True, \n",
- " map=landscape_units_raster, area_measures='area', \n",
- " rasters=tmp_copy, raster_statistics='sum', \n",
- " csvfile=temp_file, separator='pipe')\n",
- " gscript.run_command('g.remove', flags='f', type='raster', name=tmp_copy)\n",
- " # Create outputfile and compute proportion of class\n",
- " outfile=os.path.join(outputfolder, \"prop_%s\"%current_class)\n",
- " writer=csv.writer(open(outfile,'w'), delimiter=\"|\")\n",
- " reader=csv.reader(open(temp_file,'r'), delimiter=\"|\")\n",
- " header=reader.next()\n",
- " crash_report=[]\n",
- " content=[]\n",
- " content.append([header[0],\"prop_%s\"%current_class]) #Create new header with first original column and current class related name for proportion\n",
- " for row in reader:\n",
- " try:\n",
- " prop=100*float(row[2])/float(row[1])\n",
- " content.append([row[0],\"{0:.5f}\".format(prop)])\n",
- " except ZeroDivisionError:\n",
- " crash_report.append(row[0])\n",
- " continue\n",
- " writer.writerows(content)\n",
- " os.remove(temp_file)\n",
- " # Print notification of ZeroDivisionError if it happened\n",
- " if len(crash_report)>0:\n",
- " print \"An 'ZeroDivisionError' has been registered for the following <%s>\"%header[0]+\"\\n\".join(crash_report)\n",
- " # Return the result file\n",
- " return outfile\n",
- " \n",
- "def get_classproportions(outputfolder,landscape_units_raster,binary_class_raster_list,\n",
- " returnlistresult=True,ncores=2):\n",
- " # Check if raster exists to avoid error in mutliprocessing \n",
- " try:\n",
- " mpset=landscape_units_raster.split(\"@\")[1]\n",
- " except:\n",
- " mpset=\"\"\n",
- " if landscape_units_raster not in [x.split(\"@\")[0] for x in gscript.list_strings(type='raster',mapset=mpset)]:\n",
- " sys.exit('Raster <%s> not found' %landscape_units_raster)\n",
- " # Check for number of cores doesnt exceed available\n",
- " nbcpu=multiprocessing.cpu_count()\n",
- " if ncores>=nbcpu:\n",
- " ncores=nbcpu-1\n",
- " if ncores>len(binary_class_raster_list):\n",
- " ncores=len(binary_class_raster_list) #Adapt number of cores to number of metrics to compute\n",
- " # Declare empty list for return\n",
- " returnlist=[] \n",
- " # Create a new pool\n",
- " p=Pool(ncores)\n",
- " # Set the two fixed argument of the 'compute_prop_landcover' function\n",
- " func=partial(compute_prop_landcover,outputfolder,landscape_units_raster)\n",
- " # Launch the processes for as many items in the 'functions_name' list and get the ordered results using map function\n",
- " returnlist=p.map(func,binary_class_raster_list)\n",
- " p.close()\n",
- " p.join()\n",
- " # Return list of paths to result files\n",
- " if returnlistresult:\n",
- " return returnlist"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Function that enable for join of multiple different .csv files"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 66,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "def atoi(text):\n",
- " '''\n",
- " Function that return integer if text is digit - Used in 'natural_keys' function\n",
- " '''\n",
- " return int(text) if text.isdigit() else text\n",
- "\n",
- "def natural_keys(text): # Trick was found here: https://stackoverflow.com/questions/5967500/how-to-correctly-sort-a-string-with-a-number-inside\n",
- " '''\n",
- " Return key to be used for sorting string containing numerical values - Used in 'leftjoin_2csv' function\n",
- " '''\n",
- " import re #Import needed library\n",
- " return [ atoi(c) for c in re.split('(\\d+)', text) ] #Split the string\n",
- "\n",
- "def join_2csv(file1,file2,separator=\";\",join='inner',fillempty='NULL'):\n",
- " '''\n",
- " Function that join two csv files according to the first column (primary key).\n",
- " 'file1' and 'file2' wait for complete path (strings) to the corresponding files. Please not that 'file1' is assume to be the left-one in the join\n",
- "\t'separator' wait for the character to be considered as .csv delimiter (string)\n",
- "\t'join' parameter wait either for 'left' or 'inner' according to type of join\n",
- "\t'fillempty' wait for the string to be use to fill the blank when no occurance is found for the join operation\n",
- " '''\n",
- " import tempfile,csv,os\n",
- " header_list=[]\n",
- " file1_values_dict={}\n",
- " file2_values_dict={}\n",
- " reader1=csv.reader(open(file1), delimiter=separator) #Csv reader for file 1\n",
- " reader2=csv.reader(open(file2), delimiter=separator) #Csv reader for file 2\n",
- " # Make a list of headers\n",
- " header_list1=[ x for x in reader1.next()]\n",
- " header_list2=[ x for x in reader2.next()[1:]]\n",
- " # Make a list of unique IDs from the first and second table according to type of join\n",
- " if join=='inner':\n",
- " id_list=[ row[0] for row in reader1]\n",
- " [id_list.append(row[0]) for row in reader2]\n",
- " id_list=list(set(id_list))\n",
- " id_list.sort(key=natural_keys)\n",
- " if join=='left':\n",
- " id_list=[ row[0] for row in reader1]\n",
- " id_list=list(set(id_list))\n",
- " id_list.sort(key=natural_keys)\n",
- " # Build dictionnary for values of file 1\n",
- " reader1=csv.reader(open(file1), delimiter=separator)\n",
- " reader1.next()\n",
- " values_dict1={rows[0]:rows[1:] for rows in reader1}\n",
- " # Build dictionnary for values of file 2\n",
- " reader2=csv.reader(open(file2), delimiter=separator)\n",
- " reader2.next()\n",
- " values_dict2={rows[0]:rows[1:] for rows in reader2}\n",
- " # Built new content\n",
- " new_content=[]\n",
- " new_header=header_list1+header_list2\n",
- " new_content.append(new_header)\n",
- " for key in id_list:\n",
- " new_row=[key]\n",
- " try:\n",
- " [new_row.append(value) for value in values_dict1[key]]\n",
- " except:\n",
- " [new_row.append('%s'%fillempty) for x in header_list1[1:]]\n",
- " try:\n",
- " [new_row.append(value) for value in values_dict2[key]]\n",
- " except:\n",
- " [new_row.append('%s'%fillempty) for x in header_list2]\n",
- " new_content.append(new_row)\n",
- " #Return the result\n",
- " outfile=os.path.join(tempfile.gettempdir(),\"temp\")\n",
- " writer=csv.writer(open(outfile,\"w\"), delimiter=separator)\n",
- " writer.writerows(new_content) #Write multiples rows in the file\n",
- " return outfile\n",
- "\n",
- "def join_multiplecsv(fileList,outfile,separator=\";\",join='inner', fillempty='NULL', overwrite=False):\n",
- " '''\n",
- " Function that apply join on multiple csv files\n",
- " '''\n",
- " import os, sys, shutil\n",
- " # Stop execution if outputfile exitst and can not be overwriten\n",
- " if os.path.isfile(outfile) and overwrite==False:\n",
- " print \"File '%s' aleady exists and overwrite option is not enabled.\"%outfile\n",
- " else:\n",
- " if os.path.isfile(outfile) and overwrite==True: # If outputfile exitst and can be overwriten\n",
- " #os.remove(outfile)\n",
- " print \"File '%s' will be overwrited.\"%outfile\n",
- " nbfile=len(fileList)\n",
- " if nbfile<=1: #Check if there are at least 2 files in the list\n",
- " sys.exit(\"This function require at least two .csv files to be jointed together.\")\n",
- " # Copy the list of file in a queue list\n",
- " queue_list=list(fileList)\n",
- " # Left join on the two first files\n",
- " file1=queue_list.pop(0)\n",
- " file2=queue_list.pop(0)\n",
- " tmp_file=join_2csv(file1,file2,separator=separator,join=join, fillempty=fillempty)\n",
- " # Left join on the rest of the files in the list\n",
- " while len(queue_list)>0:\n",
- " file2=queue_list.pop(0)\n",
- " tmp_file=join_2csv(tmp_file,file2,separator=separator,join=join, fillempty=fillempty)\n",
- " #Copy the temporary file to the desired output path\n",
- " shutil.copy2(tmp_file,outfile)\n",
- " # Print what happend\n",
- " print \"%s individual .csv files were joint together.\"%nbfile\n",
- "\n",
- "def create_csvt(csv_file,separator=\";\",first_col_type=\"Integer\",rest_type=\"Real\"):\n",
- " '''\n",
- " Function that create a .csvt file with the same type of all columns except first one\n",
- " '''\n",
- " import csv\n",
- " writer=csv.writer(open(csv_file+\"t\",\"w\"),delimiter=separator)\n",
- " reader=csv.reader(open(csv_file,\"r\"),delimiter=separator)\n",
- " header=reader.next()\n",
- " typecolumn=[]\n",
- " typecolumn.append(first_col_type)\n",
- " for columns in header[1:]:\n",
- " typecolumn.append(rest_type)\n",
- " writer.writerow(typecolumn)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-**"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- " User inputs
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "## Define a empty dictionnary for saving user inputs\n",
- "user={}"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "## Enter the path to GRASSDATA folder\n",
- "user[\"gisdb\"] = \"/home/tais/Documents/GRASSDATA_Spie2017subset_Ouaga\"\n",
- "\n",
- "## Enter the name of the location (existing or for a new one)\n",
- "user[\"location\"] = \"SPIE_subset\"\n",
- "\n",
- "## Enter the EPSG code for this location \n",
- "user[\"locationepsg\"] = \"32630\"\n",
- "\n",
- "## Enter the name of the mapset to use for segmentation\n",
- "user[\"mapsetname\"] = \"test_rli\""
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-**"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "# Compute landscape metrics (spatial metrics) from the land cover map, using r.li"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "**Launch GRASS GIS working session**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {
- "scrolled": false
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "You are now working in mapset 'test_rli'\n"
- ]
- }
- ],
- "source": [
- "## Set the name of the mapset in which to work\n",
- "mapsetname=user[\"mapsetname\"]\n",
- "\n",
- "## Launch GRASS GIS working session in the mapset\n",
- "if os.path.exists(os.path.join(user[\"gisdb\"],user[\"location\"],mapsetname)):\n",
- " gsetup.init(os.environ['GISBASE'], user[\"gisdb\"], user[\"location\"], mapsetname)\n",
- " print \"You are now working in mapset '\"+mapsetname+\"'\" \n",
- "else: \n",
- " print \"'\"+mapsetname+\"' mapset doesn't exists in \"+user[\"gisdb\"]"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "**Set the path to the r.li folder for configuration file and for results**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "GRASS GIS add-on's r.li configuration files will be saved under .\n",
- "GRASS GIS add-on's r.li outputs will be saved under .\n"
- ]
- }
- ],
- "source": [
- "# Define path of the outputfile (in r.li folder)\n",
- "version=grass.version()['version'].split('.')[0] # Get the version of GRASS GIS \n",
- "if sys.platform==\"win32\":\n",
- " rli_config_dir=os.path.join(os.environ['APPDATA'],\"GRASS\"+version,\"r.li\")\n",
- " rli_output_dir=os.path.join(os.environ['APPDATA'],\"GRASS\"+version,\"r.li\",\"output\")\n",
- "else: \n",
- " rli_config_dir=os.path.join(os.environ['HOME'],\".grass\"+version,\"r.li\")\n",
- " rli_output_dir=os.path.join(os.environ['HOME'],\".grass\"+version,\"r.li\",\"output\")\n",
- "if not os.path.exists(rli_config_dir):\n",
- " os.makedirs(rli_config_dir)\n",
- "if not os.path.exists(rli_output_dir):\n",
- " os.makedirs(rli_output_dir)\n",
- "# Print\n",
- "print \"GRASS GIS add-on's r.li configuration files will be saved under <%s>.\"%(rli_config_dir,)\n",
- "print \"GRASS GIS add-on's r.li outputs will be saved under <%s>.\"%(rli_output_dir,)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-**"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Define the name of the base landcover map and landscape units polygons"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Set the name of the 'base' landcover map\n",
- "baselandcoverraster=\"classif@test_rli\"\n",
- "# Set the name of the vector polygon layer containing the landscape units\n",
- "landscape_polygons=\"streetblocks\""
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Import shapefile containing street blocks polygons"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Set the path to the shapefile containing streetblocks polygons\n",
- "pathtoshp=\"/media/tais/data/Dropbox/ULB/MAUPP/Landuse_mapping/Test_spatial_metrics_computation/Data/streetblocks_subset.shp\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 17,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0"
- ]
- },
- "execution_count": 17,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Import shapefile\n",
- "gscript.run_command('v.in.ogr', quiet=True, overwrite=True, input=pathtoshp, output=landscape_polygons)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Create binary rasters from the base landcover map"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'Extraction of binary rasters achieved in 4.4 seconds'"
- ]
- },
- "execution_count": 18,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Save time for computing processin time\n",
- "begintime=time.time()\n",
- "\n",
- "# Create as many binary raster layer as categorical values existing in the base landcover map\n",
- "gscript.run_command('g.region', raster=baselandcoverraster, quiet=True) #Set the region\n",
- "pref=baselandcoverraster.split(\"@\")[0]+\"_cl\" #Set the prefix\n",
- "\n",
- "raster_list=[] # Initialize a empty list for results\n",
- "raster_list=create_binary_raster(baselandcoverraster,\n",
- " prefix=pref,setnull=True,returnlistraster=True,\n",
- " category_list=None,ncores=15) #Extract binary raster \n",
- "\n",
- "# Compute and print processing time\n",
- "print_processing_time(begintime,\"Extraction of binary rasters achieved in \")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 19,
- "metadata": {
- "scrolled": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "['classif@test_rli',\n",
- " 'classif_cl_11',\n",
- " 'classif_cl_13',\n",
- " 'classif_cl_14',\n",
- " 'classif_cl_20',\n",
- " 'classif_cl_30',\n",
- " 'classif_cl_31',\n",
- " 'classif_cl_41',\n",
- " 'classif_cl_51']"
- ]
- },
- "execution_count": 19,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Insert the name of the base landcover map at first position in the list\n",
- "raster_list.insert(0,baselandcoverraster)\n",
- "# Display the raster to be used for landscape analysis\n",
- "raster_list"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Create r.li configuration file for a list of landcover rasters"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 20,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'Creation of r.li configuration files achieved in 3 minutes and 33.1 seconds'"
- ]
- },
- "execution_count": 20,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Save time for computing processin time\n",
- "begintime=time.time()\n",
- "# Run creation of r.li configuration file and associated raster layers\n",
- "list_cats,list_configfile=create_rli_configfile(raster_list,landscape_polygons,masklayerhardcopy=False,returnlistpath=True,ncores=20)\n",
- "# Compute and print processing time\n",
- "print_processing_time(begintime,\"Creation of r.li configuration files achieved in \")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 21,
- "metadata": {
- "scrolled": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "[u'/home/tais/.grass7/r.li/classif_streetblocks',\n",
- " u'/home/tais/.grass7/r.li/classif_cl_11_streetblocks',\n",
- " u'/home/tais/.grass7/r.li/classif_cl_13_streetblocks',\n",
- " u'/home/tais/.grass7/r.li/classif_cl_14_streetblocks',\n",
- " u'/home/tais/.grass7/r.li/classif_cl_20_streetblocks',\n",
- " u'/home/tais/.grass7/r.li/classif_cl_30_streetblocks',\n",
- " u'/home/tais/.grass7/r.li/classif_cl_31_streetblocks',\n",
- " u'/home/tais/.grass7/r.li/classif_cl_41_streetblocks',\n",
- " u'/home/tais/.grass7/r.li/classif_cl_51_streetblocks']"
- ]
- },
- "execution_count": 21,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Display the path to the configuration files created\n",
- "list_configfile"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-**"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Compute spatial metrics at landscape level"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 22,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Initialize an empty list which will contains the resultfiles \n",
- "resultfiles=[]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 23,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'Computation of spatial metric achieved in 41.3 seconds'"
- ]
- },
- "execution_count": 23,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Save time for computing processin time\n",
- "begintime=time.time()\n",
- "# Get the path to the configuration file for the base landcover raster\n",
- "currentconfigfile=list_configfile[0]\n",
- "# Get the name of the base landcover raster\n",
- "currentraster=raster_list[0]\n",
- "# Set the region to match the extent of the base raster\n",
- "gscript.run_command('g.region', raster=currentraster, quiet=True)\n",
- "# Launch the processes for as many items in the 'functions_name' list and get the ordered results using map function\n",
- "resultfiles.append(get_landscapelevel_metrics(currentconfigfile, currentraster, returnlistresult=True, ncores=15))\n",
- "# Compute and print processing time\n",
- "print_processing_time(begintime,\"Computation of spatial metric achieved in \")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 24,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "[[u'/home/tais/.grass7/r.li/output/classif_dominance',\n",
- " u'/home/tais/.grass7/r.li/output/classif_pielou',\n",
- " u'/home/tais/.grass7/r.li/output/classif_renyi',\n",
- " u'/home/tais/.grass7/r.li/output/classif_richness',\n",
- " u'/home/tais/.grass7/r.li/output/classif_shannon',\n",
- " u'/home/tais/.grass7/r.li/output/classif_simpson']]"
- ]
- },
- "execution_count": 24,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "resultfiles"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Compute spatial metrics at class level"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 25,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'Computation of spatial metric achieved in 6 minutes and 1.1 seconds'"
- ]
- },
- "execution_count": 25,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Save time for computing processin time\n",
- "begintime=time.time()\n",
- "# Get a list with paths to the configuration file for class level metrics\n",
- "classlevelconfigfiles=list_configfile[1:]\n",
- "# Get a list with name of binary landcover raster for class level metrics\n",
- "classlevelrasters=raster_list[1:]\n",
- "\n",
- "for x,currentraster in enumerate(classlevelrasters[:]):\n",
- " # Get the path to the configuration file for the base landcover raster\n",
- " currentconfigfile=classlevelconfigfiles[x]\n",
- " # Set the region to match the extent of the base raster\n",
- " gscript.run_command('g.region', raster=currentraster, quiet=True)\n",
- " # Launch the processes for as many items in the 'functions_name' list and get the ordered results using map function\n",
- " resultfiles.append(get_classlevel_metrics(currentconfigfile, currentraster, returnlistresult=True, ncores=10))\n",
- "\n",
- "# Compute and print processing time\n",
- "print_processing_time(begintime,\"Computation of spatial metric achieved in \")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 26,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "[[u'/home/tais/.grass7/r.li/output/classif_dominance',\n",
- " u'/home/tais/.grass7/r.li/output/classif_pielou',\n",
- " u'/home/tais/.grass7/r.li/output/classif_renyi',\n",
- " u'/home/tais/.grass7/r.li/output/classif_richness',\n",
- " u'/home/tais/.grass7/r.li/output/classif_shannon',\n",
- " u'/home/tais/.grass7/r.li/output/classif_simpson'],\n",
- " [u'/home/tais/.grass7/r.li/output/classif_cl_11_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_edgedensity'],\n",
- " [u'/home/tais/.grass7/r.li/output/classif_cl_13_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_edgedensity'],\n",
- " [u'/home/tais/.grass7/r.li/output/classif_cl_14_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_edgedensity'],\n",
- " [u'/home/tais/.grass7/r.li/output/classif_cl_20_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_edgedensity'],\n",
- " [u'/home/tais/.grass7/r.li/output/classif_cl_30_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_edgedensity'],\n",
- " [u'/home/tais/.grass7/r.li/output/classif_cl_31_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_edgedensity'],\n",
- " [u'/home/tais/.grass7/r.li/output/classif_cl_41_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_edgedensity'],\n",
- " [u'/home/tais/.grass7/r.li/output/classif_cl_51_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_edgedensity']]"
- ]
- },
- "execution_count": 26,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "resultfiles"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Change the results files from r.li to get the correct 'cat' value for each landscape unit"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 28,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Flat the 'resultfiles' list which contains several lists\n",
- "resultfiles=[item for sublist in resultfiles for item in sublist]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 29,
- "metadata": {},
- "outputs": [],
- "source": [
- "import csv, shutil\n",
- "from itertools import izip\n",
- "\n",
- "for f in resultfiles:\n",
- " f_in=open(f)\n",
- " f_tmp=open(f+'_tmp',\"w\")\n",
- " f_in_reader=csv.reader(f_in,delimiter='|')\n",
- " f_tmp_writer=csv.writer(f_tmp,delimiter='|')\n",
- " f_tmp_writer.writerow(['cat',\"_\".join(os.path.split(f)[-1].split(\"_\")[1:])])\n",
- " for i,row in enumerate(f_in_reader):\n",
- " newrow=[]\n",
- " try:\n",
- " newrow.append(list_cats[i])\n",
- " newrow.append(row[1])\n",
- " f_tmp_writer.writerow(newrow)\n",
- " except:\n",
- " continue\n",
- " f_in.close()\n",
- " f_tmp.close()\n",
- " os.remove(f)\n",
- " shutil.copy2(f+'_tmp',f)\n",
- " os.remove(f+'_tmp')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "# Compute some special metrics"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "### Creating a raster layer of landscape units"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Creating a raster layer of landscape units with resolution corresponding to the one of land cover raster"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 30,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0"
- ]
- },
- "execution_count": 30,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Create a raster corresponding to the landscape units (for computing statistics using i.segment.stats)\n",
- "gscript.run_command('g.region', raster=baselandcoverraster, quiet=True) #Set the region\n",
- "raster_landscapeunits=\"temp_%s\"%landscape_polygons.split(\"@\")[0]\n",
- "gscript.run_command('v.to.rast', overwrite=True, input=landscape_polygons, output=raster_landscapeunits, use='cat') "
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "### Shape statistics for the landscape units"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 31,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Set the path to the file for i.segment.stats results for landscape units shape metrics\n",
- "landscape_units_shape_metrics=os.path.join(rli_output_dir,\"landscape_units_shape_metrics\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 32,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'Metrics computed in 1.0 seconds'"
- ]
- },
- "execution_count": 32,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Save time for computing processin time\n",
- "begintime=time.time()\n",
- "# Run i.segment.stats\n",
- "gscript.run_command('i.segment.stats', overwrite=True, map=raster_landscapeunits,\n",
- " area_measures='area,perimeter,compact_circle,compact_square,fd',\n",
- " csvfile=landscape_units_shape_metrics,\n",
- " processes='1')\n",
- "\n",
- "# Compute and print processing time\n",
- "print_processing_time(begintime,\"Metrics computed in \")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 33,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "resultfiles.append(landscape_units_shape_metrics)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "### Mean and standard deviation of SAR textures, NDVI, NDWI"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 34,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Set the name of the nDSM layer\n",
- "ndsm=\"ndsm\"\n",
- "# Set the name of the NDVI layer\n",
- "ndvi=\"ndvi\"\n",
- "# Set the name of the NDWI layer\n",
- "ndwi=\"ndwi\"\n",
- "# Set the prefix of SAR textures layer\n",
- "SAR_prefix=\"SAR_w\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 35,
- "metadata": {
- "scrolled": false
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Layer to be used :\n",
- "\n",
- "ndvi\n",
- "ndwi\n",
- "SAR_w11.1@PERMANENT\n",
- "SAR_w11.2@PERMANENT\n",
- "SAR_w11.3@PERMANENT\n",
- "SAR_w11.4@PERMANENT\n",
- "SAR_w11.5@PERMANENT\n",
- "SAR_w11.6@PERMANENT\n",
- "SAR_w11.7@PERMANENT\n",
- "SAR_w7.1@PERMANENT\n",
- "SAR_w7.2@PERMANENT\n",
- "SAR_w7.3@PERMANENT\n",
- "SAR_w7.4@PERMANENT\n",
- "SAR_w7.5@PERMANENT\n",
- "SAR_w7.6@PERMANENT\n",
- "SAR_w7.7@PERMANENT\n"
- ]
- }
- ],
- "source": [
- "# Set up a list with name of raster layer to be used\n",
- "ancillarylayers=[]\n",
- "ancillarylayers.append(ndvi)\n",
- "ancillarylayers.append(ndwi)\n",
- "[ancillarylayers.append(x) for x in gscript.list_strings(\"rast\", pattern=SAR_prefix, flag='r')] #Append SAR textures\n",
- "print \"Layer to be used :\\n\\n\"+'\\n'.join(ancillarylayers)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 36,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Set the path to the file for i.segment.stats results for metrics_ndvi_ndwi_sar\n",
- "metrics_ndvi_ndwi_sar=os.path.join(rli_output_dir,\"metrics_ndvi_ndwi_sar\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 37,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'Metrics computed in 11.2 seconds'"
- ]
- },
- "execution_count": 37,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Save time for computing processin time\n",
- "begintime=time.time()\n",
- "###### Compute shape metrics as well as mean and stddev of ancillary layers for each landscape unit\n",
- "## Set number of cores to be used\n",
- "ncores=len(ancillarylayers) \n",
- "nbcpu=multiprocessing.cpu_count()\n",
- "if ncores>=nbcpu:\n",
- " ncores=nbcpu-1\n",
- " if ncores>len(ancillarylayers):\n",
- " ncores=len(ancillarylayers) #Adapt number of cores to number of metrics to compute\n",
- "# Run i.segment.stats\n",
- "gscript.run_command('i.segment.stats', overwrite=True, map=raster_landscapeunits,\n",
- " raster_statistics='stddev,median',\n",
- " rasters=','.join(ancillarylayers),\n",
- " csvfile=metrics_ndvi_ndwi_sar,\n",
- " processes=ncores,\n",
- " flags='s')\n",
- "\n",
- "# Compute and print processing time\n",
- "print_processing_time(begintime,\"Metrics computed in \")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 38,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "resultfiles.append(metrics_ndvi_ndwi_sar)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 39,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "[u'/home/tais/.grass7/r.li/output/classif_dominance',\n",
- " u'/home/tais/.grass7/r.li/output/classif_pielou',\n",
- " u'/home/tais/.grass7/r.li/output/classif_renyi',\n",
- " u'/home/tais/.grass7/r.li/output/classif_richness',\n",
- " u'/home/tais/.grass7/r.li/output/classif_shannon',\n",
- " u'/home/tais/.grass7/r.li/output/classif_simpson',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/landscape_units_shape_metrics',\n",
- " u'/home/tais/.grass7/r.li/output/metrics_ndvi_ndwi_sar']"
- ]
- },
- "execution_count": 39,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "resultfiles"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "### Mean and standard deviation of building's height"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "**Create raster with nDSM value of 'buildings' pixels**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 40,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Set pixel value of 'buildings' on the 'baselandcoverraster'\n",
- "buildpixel=11\n",
- "# Set the name of the new layer containing height of buildings\n",
- "buildings_height='buildings_height'\n",
- "# Set the path to the file for i.segment.stats results for metrics_ndvi_ndwi_sar\n",
- "metrics_buildings_height=os.path.join(rli_output_dir,\"metrics_buildings_height\")\n",
- "# Create temp fil which will contain intermediate results\n",
- "TMP_sumheights=grass.tempfile()+'_sumheights.csv'\n",
- "TMP_nbrbuildpixels=grass.tempfile()+'_nbrbuildpixels.csv'"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 41,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'Creation of layer in 5.9 seconds'"
- ]
- },
- "execution_count": 41,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Save time for computing processin time\n",
- "begintime=time.time()\n",
- "# Create a raster layer with height of pixels classified as 'buildings'\n",
- "gscript.run_command('g.region', raster=baselandcoverraster, quiet=True) #Set the region\n",
- "formula=\"%s=if(%s==%s, %s, 0)\"%(buildings_height,baselandcoverraster,buildpixel,ndsm)\n",
- "gscript.mapcalc(formula, overwrite=True)\n",
- "# Compute and print processing time\n",
- "print_processing_time(begintime,\"Creation of layer in \")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "**Compute the metric**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 42,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'i.segment.stats run in 10.4 seconds'"
- ]
- },
- "execution_count": 42,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Save time for computing processin time\n",
- "begintime=time.time()\n",
- "# Compute sum of build pixels's height using i.segment.stats \n",
- "gscript.run_command('i.segment.stats', overwrite=True, map=raster_landscapeunits,\n",
- " raster_statistics='sum', flags='s', rasters='buildings_height',\n",
- " csvfile=TMP_sumheights,processes=ncores)\n",
- "# Compute number of built pixels using i.segment.stats\n",
- "binary_builtup_raster=\"%s_cl_%s\"%(baselandcoverraster.split(\"@\")[0],buildpixel)\n",
- "gscript.run_command('g.copy', overwrite=True, raster='%s,tmp'%binary_builtup_raster)\n",
- "gscript.run_command('r.null', map='tmp', null=0)\n",
- "gscript.run_command('i.segment.stats', overwrite=True, map=raster_landscapeunits,\n",
- " raster_statistics='sum', flags='s', rasters='tmp',\n",
- " csvfile=TMP_nbrbuildpixels,processes=ncores)\n",
- "# Compute and print processing time\n",
- "print_processing_time(begintime,\"i.segment.stats run in \")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 43,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "\"Mean build pixels's height computed in 0.0 seconds\""
- ]
- },
- "execution_count": 43,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Save time for computing processin time\n",
- "begintime=time.time()\n",
- "# Improt library to be able to iterate on two files in the same loop\n",
- "from itertools import izip\n",
- "# Declare empty dictionnary\n",
- "tmp_dic={}\n",
- "for i, (line_from_file_1, line_from_file_2) in enumerate(izip(open(TMP_sumheights), open(TMP_nbrbuildpixels))):\n",
- " if i==0:\n",
- " continue\n",
- " f1_items=line_from_file_1.split(\"\\n\")[0].split(\"|\")\n",
- " f2_items=line_from_file_2.split(\"\\n\")[0].split(\"|\")\n",
- " key=f1_items[0]\n",
- " sumheight=f1_items[1]\n",
- " nbpixel=f2_items[1]\n",
- " try:\n",
- " mean_height=float(sumheight)/float(nbpixel)\n",
- " except ZeroDivisionError:\n",
- " mean_height=0\n",
- " tmp_dic[key]=mean_height\n",
- "# Get the name of the first colum\n",
- "with open(TMP_sumheights) as f:\n",
- " column_a=f.next().split(\"\\n\")[0].split(\"|\")[0]\n",
- "# Built the content of the file\n",
- "content=[]\n",
- "content.append((column_a,'mean_build_height'))\n",
- "for key in tmp_dic.keys():\n",
- " content.append((key,tmp_dic[key]))\n",
- "# Create a new file\n",
- "fout=open(metrics_buildings_height,\"w\")\n",
- "writer=csv.writer(fout, delimiter='|')\n",
- "writer.writerows(content)\n",
- "fout.close()\n",
- "# Compute and print processing time\n",
- "print_processing_time(begintime,\"Mean build pixels's height computed in \")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 44,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Remove temporary layers\n",
- "gscript.run_command('g.remove', flags='ef', type='raster', name='tmp')\n",
- "# Remove temporary files\n",
- "os.remove(TMP_sumheights)\n",
- "os.remove(TMP_nbrbuildpixels)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 45,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "resultfiles.append(metrics_buildings_height)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 63,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "[u'/home/tais/.grass7/r.li/output/classif_dominance',\n",
- " u'/home/tais/.grass7/r.li/output/classif_pielou',\n",
- " u'/home/tais/.grass7/r.li/output/classif_renyi',\n",
- " u'/home/tais/.grass7/r.li/output/classif_richness',\n",
- " u'/home/tais/.grass7/r.li/output/classif_shannon',\n",
- " u'/home/tais/.grass7/r.li/output/classif_simpson',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/landscape_units_shape_metrics',\n",
- " u'/home/tais/.grass7/r.li/output/metrics_ndvi_ndwi_sar',\n",
- " u'/home/tais/.grass7/r.li/output/metrics_buildings_height']"
- ]
- },
- "execution_count": 63,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "resultfiles"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "### Proportion of each of individual classes in the landcover map"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 48,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Set a tuple with name of land cover class binary raster to be processed \n",
- "listofbinary=tuple(raster_list[1:])\n",
- "# Compute proportion of each land cover class in landscape units\n",
- "proportion_results=get_classproportions(rli_output_dir,raster_landscapeunits,listofbinary,returnlistresult=True,ncores=10)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 64,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "[None, None, None, None, None, None, None, None]"
- ]
- },
- "execution_count": 64,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "[resultfiles.append(x) for x in proportion_results]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 65,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "[u'/home/tais/.grass7/r.li/output/classif_dominance',\n",
- " u'/home/tais/.grass7/r.li/output/classif_pielou',\n",
- " u'/home/tais/.grass7/r.li/output/classif_renyi',\n",
- " u'/home/tais/.grass7/r.li/output/classif_richness',\n",
- " u'/home/tais/.grass7/r.li/output/classif_shannon',\n",
- " u'/home/tais/.grass7/r.li/output/classif_simpson',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_11_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_13_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_14_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_20_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_30_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_31_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_41_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_patchnum',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_patchdensity',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_mps',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padcv',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padrange',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_padsd',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_shape',\n",
- " u'/home/tais/.grass7/r.li/output/classif_cl_51_edgedensity',\n",
- " u'/home/tais/.grass7/r.li/output/landscape_units_shape_metrics',\n",
- " u'/home/tais/.grass7/r.li/output/metrics_ndvi_ndwi_sar',\n",
- " u'/home/tais/.grass7/r.li/output/metrics_buildings_height',\n",
- " u'/home/tais/.grass7/r.li/output/prop_11',\n",
- " u'/home/tais/.grass7/r.li/output/prop_13',\n",
- " u'/home/tais/.grass7/r.li/output/prop_14',\n",
- " u'/home/tais/.grass7/r.li/output/prop_20',\n",
- " u'/home/tais/.grass7/r.li/output/prop_30',\n",
- " u'/home/tais/.grass7/r.li/output/prop_31',\n",
- " u'/home/tais/.grass7/r.li/output/prop_41',\n",
- " u'/home/tais/.grass7/r.li/output/prop_51']"
- ]
- },
- "execution_count": 65,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "resultfiles"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "# File management (join, cleaning, etc)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Combine all .csv files together"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 67,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Define the path for the .csv with final results\n",
- "outfile=os.path.join(rli_output_dir,\"land_use_metrics.csv\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 68,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "81 individual .csv files were joint together.\n"
- ]
- }
- ],
- "source": [
- "# Join (inner join) all result files together in a new .csv file\n",
- "join_multiplecsv(resultfiles,outfile,separator=\"|\",join='inner',fillempty='NULL',overwrite=True)\n",
- "# Create .csvt file\n",
- "create_csvt(outfile,separator=\"|\",first_col_type=\"Integer\",rest_type=\"Real\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Make a copy of the .csv file with results, where 'null' values are empty cells "
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**For .csvt**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 69,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Define path to the .csv files\n",
- "afile=outfile+'t'\n",
- "pathtofile,extension=os.path.splitext(afile)\n",
- "bfile=pathtofile+\"_blanknull\"+extension\n",
- "# Make copy of the file\n",
- "shutil.copy2(afile,bfile)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**For .csv**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 70,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Define path to the .csv files\n",
- "afile=outfile\n",
- "pathtofile,extension=os.path.splitext(afile)\n",
- "outfile_withoutnull=pathtofile+\"_blanknull\"+extension"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 71,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "import csv\n",
- "# Create a copy by removing the 'NULL' values\n",
- "reader=csv.reader(open(afile,'r'),delimiter=\"|\")\n",
- "writer=csv.writer(open(outfile_withoutnull,'w'),delimiter=\"|\")\n",
- "for row in reader:\n",
- " newline=[]\n",
- " [newline.append(x) if x != \"NULL\" else newline.append(\"\") for x in row]\n",
- " writer.writerow(newline)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Check if all the lines have the same number of items"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 72,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "#### Function that check if rows of a .csv file have the same number of items than number of column in the first line (header)\n",
- "### If rows's lenght are identical, the function return 0. If not, it return a list containing the index number of row(s) that failed\n",
- "### The index is starting with value 1 for the first line of data (the header row is indexed 0)\n",
- "# 'csvfile' wait for the complete path (string) to the csvfile to be checked\n",
- "# 'separator' wait for the character used as separator in the .csv file (string)\n",
- "# 'allowemptycell' wait for a boolean value (True, False) depending if a empty cell should not be considered as a problem in the file\n",
- "\n",
- "def check_lenght_row(csvfile,separator,allowemptycell=True):\n",
- " listofunequalrow=[]\n",
- " afile=open(csvfile,'r')\n",
- " header=afile.next() # Save header row and go to the next one\n",
- " nb_item_control=len(header.split(separator))\n",
- " for x,row in enumerate(afile,1): # Start counting at \"1\" because header is already skipped\n",
- " row_items=row.split(separator)\n",
- " if len(row_items) != nb_item_control: # Check it number of items is identical than the number of items in the header\n",
- " listofunequalrow.append(x)\n",
- " if not allowemptycell:\n",
- " if \"\" in row_items:\n",
- " listofunequalrow.append(x)\n",
- " listofunequalrow=list(set(listofunequalrow)) # Recreate a list with uniques values from the original list\n",
- " if len(listofunequalrow)>0:\n",
- " return listofunequalrow # Return a list of indexes for line whose length is not equal to the header\n",
- " else:\n",
- " return 0"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 73,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "The csv looks good.\n"
- ]
- }
- ],
- "source": [
- "# Check number of row in the .csv file\n",
- "fout=check_lenght_row(outfile_withoutnull,\";\",allowemptycell=True)\n",
- "if fout>0:\n",
- " print \"Rows in csv do not have the same lenght. Please check the following row(s) index(es).\"\n",
- " print \"/n\".join(fout)\n",
- "else:\n",
- " print \"The csv looks good.\""
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Replace current delimiter by ';'"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 74,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "import csv\n",
- "reader=csv.reader(open(outfile,'r'),delimiter=\"|\")\n",
- "newfile=[]\n",
- "for row in reader:\n",
- " newline=[]\n",
- " [newline.append(x) for x in row]\n",
- " newfile.append(newline)\n",
- "writer=csv.writer(open(outfile,'w'),delimiter=\";\")\n",
- "writer.writerows(newfile)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 75,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "import csv\n",
- "reader=csv.reader(open(outfile+'t','r'),delimiter=\"|\")\n",
- "newfile=[]\n",
- "for row in reader:\n",
- " newline=[]\n",
- " [newline.append(x) for x in row]\n",
- " newfile.append(newline)\n",
- "writer=csv.writer(open(outfile+'t','w'),delimiter=\";\")\n",
- "writer.writerows(newfile)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 76,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "import csv\n",
- "reader=csv.reader(open(outfile_withoutnull,'r'),delimiter=\"|\")\n",
- "newfile=[]\n",
- "for row in reader:\n",
- " newline=[]\n",
- " [newline.append(x) for x in row]\n",
- " newfile.append(newline)\n",
- "writer=csv.writer(open(outfile_withoutnull,'w'),delimiter=\";\")\n",
- "writer.writerows(newfile)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 77,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "import csv\n",
- "reader=csv.reader(open(outfile_withoutnull+'t','r'),delimiter=\"|\")\n",
- "newfile=[]\n",
- "for row in reader:\n",
- " newline=[]\n",
- " [newline.append(x) for x in row]\n",
- " newfile.append(newline)\n",
- "writer=csv.writer(open(outfile_withoutnull+'t','w'),delimiter=\";\")\n",
- "writer.writerows(newfile)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Visual check of the table (display the .csv using pandas)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 78,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " cat | \n",
- " dominance | \n",
- " pielou | \n",
- " renyi | \n",
- " richness | \n",
- " shannon | \n",
- " simpson | \n",
- " cl_11_patchnum | \n",
- " cl_11_patchdensity | \n",
- " cl_11_mps | \n",
- " ... | \n",
- " SAR_w7_7_median | \n",
- " mean_build_height | \n",
- " prop_11 | \n",
- " prop_13 | \n",
- " prop_14 | \n",
- " prop_20 | \n",
- " prop_30 | \n",
- " prop_31 | \n",
- " prop_41 | \n",
- " prop_51 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 1 | \n",
- " 0.213708 | \n",
- " 0.867216 | \n",
- " 1.252613 | \n",
- " 5 | \n",
- " 1.395730 | \n",
- " 0.714243 | \n",
- " 18 | \n",
- " 9086.320040 | \n",
- " 0.011006 | \n",
- " ... | \n",
- " 1.042240 | \n",
- " 2.682045 | \n",
- " 39.17536 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 32.03639 | \n",
- " 6.38256 | \n",
- " 9.65541 | \n",
- " 0.00000 | \n",
- " 12.75028 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 2 | \n",
- " 0.875010 | \n",
- " 0.511647 | \n",
- " 0.656834 | \n",
- " 6 | \n",
- " 0.916749 | \n",
- " 0.481510 | \n",
- " 22 | \n",
- " 78501.338091 | \n",
- " 0.001274 | \n",
- " ... | \n",
- " 1.643660 | \n",
- " 0.596033 | \n",
- " 1.07294 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 24.19338 | \n",
- " 67.67580 | \n",
- " 3.21404 | \n",
- " 2.51438 | \n",
- " 1.32945 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 3 | \n",
- " 0.237762 | \n",
- " 0.867302 | \n",
- " 1.475816 | \n",
- " 6 | \n",
- " 1.553997 | \n",
- " 0.771408 | \n",
- " 25 | \n",
- " 14138.272303 | \n",
- " 0.007073 | \n",
- " ... | \n",
- " 1.225260 | \n",
- " 2.800861 | \n",
- " 28.72284 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 29.11269 | \n",
- " 18.63147 | \n",
- " 11.31777 | \n",
- " 0.47107 | \n",
- " 11.74416 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 4 | \n",
- " 0.373615 | \n",
- " 0.659921 | \n",
- " 0.629171 | \n",
- " 3 | \n",
- " 0.724997 | \n",
- " 0.466967 | \n",
- " 2 | \n",
- " 18433.179724 | \n",
- " 0.005425 | \n",
- " ... | \n",
- " 0.797337 | \n",
- " 1.280882 | \n",
- " 32.60706 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 65.28926 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 2.10368 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 5 | \n",
- " 0.685988 | \n",
- " 0.375587 | \n",
- " 0.217895 | \n",
- " 3 | \n",
- " 0.412625 | \n",
- " 0.195790 | \n",
- " 0 | \n",
- " NaN | \n",
- " 0.000000 | \n",
- " ... | \n",
- " 0.894313 | \n",
- " 0.000000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 5.31915 | \n",
- " 5.31915 | \n",
- " 89.36170 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " 6 | \n",
- " 0.440634 | \n",
- " 0.682150 | \n",
- " 0.843472 | \n",
- " 4 | \n",
- " 0.945660 | \n",
- " 0.569786 | \n",
- " 0 | \n",
- " NaN | \n",
- " 0.000000 | \n",
- " ... | \n",
- " 1.309910 | \n",
- " 0.000000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 42.46947 | \n",
- " 49.47987 | \n",
- " 7.01040 | \n",
- " 0.00000 | \n",
- " 1.04025 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " 7 | \n",
- " 1.327286 | \n",
- " 0.259228 | \n",
- " 0.246013 | \n",
- " 6 | \n",
- " 0.464474 | \n",
- " 0.218088 | \n",
- " 32 | \n",
- " 60491.493384 | \n",
- " 0.001653 | \n",
- " ... | \n",
- " 1.770790 | \n",
- " 0.313403 | \n",
- " 0.11101 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 7.34661 | \n",
- " 88.02124 | \n",
- " 4.15473 | \n",
- " 0.00131 | \n",
- " 0.36509 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " 8 | \n",
- " 0.890449 | \n",
- " 0.189479 | \n",
- " 0.092429 | \n",
- " 3 | \n",
- " 0.208163 | \n",
- " 0.088286 | \n",
- " 0 | \n",
- " NaN | \n",
- " 0.000000 | \n",
- " ... | \n",
- " 2.252300 | \n",
- " 0.000000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 95.40603 | \n",
- " 3.75870 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.83527 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " 9 | \n",
- " 0.173536 | \n",
- " 0.874820 | \n",
- " 1.095909 | \n",
- " 4 | \n",
- " 1.212758 | \n",
- " 0.665764 | \n",
- " 0 | \n",
- " NaN | \n",
- " 0.000000 | \n",
- " ... | \n",
- " 0.791420 | \n",
- " 0.000000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 44.48898 | \n",
- " 33.46693 | \n",
- " 11.22244 | \n",
- " 0.00000 | \n",
- " 10.82164 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " 10 | \n",
- " 0.416684 | \n",
- " 0.767444 | \n",
- " 1.201512 | \n",
- " 6 | \n",
- " 1.375075 | \n",
- " 0.699261 | \n",
- " 14 | \n",
- " 10588.012857 | \n",
- " 0.009445 | \n",
- " ... | \n",
- " 1.319530 | \n",
- " 2.309613 | \n",
- " 33.56177 | \n",
- " 0.31093 | \n",
- " 0.00000 | \n",
- " 40.81477 | \n",
- " 8.93458 | \n",
- " 7.44337 | \n",
- " 0.00000 | \n",
- " 8.93458 | \n",
- "
\n",
- " \n",
- " 10 | \n",
- " 11 | \n",
- " 0.486061 | \n",
- " 0.298762 | \n",
- " 0.105668 | \n",
- " 2 | \n",
- " 0.207086 | \n",
- " 0.100277 | \n",
- " 0 | \n",
- " NaN | \n",
- " 0.000000 | \n",
- " ... | \n",
- " 3.151870 | \n",
- " 0.000000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 94.70588 | \n",
- " 5.29412 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- "
\n",
- " \n",
- " 11 | \n",
- " 12 | \n",
- " 1.302626 | \n",
- " 0.330583 | \n",
- " 0.363104 | \n",
- " 7 | \n",
- " 0.643284 | \n",
- " 0.304486 | \n",
- " 69 | \n",
- " 70951.156812 | \n",
- " 0.001409 | \n",
- " ... | \n",
- " 1.353300 | \n",
- " 0.786419 | \n",
- " 0.99459 | \n",
- " 0.00000 | \n",
- " 0.06545 | \n",
- " 11.62142 | \n",
- " 82.50050 | \n",
- " 3.40284 | \n",
- " 0.40832 | \n",
- " 1.00687 | \n",
- "
\n",
- " \n",
- " 12 | \n",
- " 13 | \n",
- " 0.447633 | \n",
- " 0.769962 | \n",
- " 1.325055 | \n",
- " 7 | \n",
- " 1.498277 | \n",
- " 0.734212 | \n",
- " 40 | \n",
- " 13314.471166 | \n",
- " 0.007511 | \n",
- " ... | \n",
- " 1.216550 | \n",
- " 2.703586 | \n",
- " 35.52803 | \n",
- " 0.00000 | \n",
- " 2.19075 | \n",
- " 32.91450 | \n",
- " 5.73853 | \n",
- " 10.69359 | \n",
- " 0.28087 | \n",
- " 12.65374 | \n",
- "
\n",
- " \n",
- " 13 | \n",
- " 14 | \n",
- " 0.505261 | \n",
- " 0.686064 | \n",
- " 0.920011 | \n",
- " 5 | \n",
- " 1.104177 | \n",
- " 0.601485 | \n",
- " 14 | \n",
- " 18685.352019 | \n",
- " 0.005352 | \n",
- " ... | \n",
- " 0.314760 | \n",
- " 1.393364 | \n",
- " 33.87206 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 52.54295 | \n",
- " 6.02396 | \n",
- " 1.31103 | \n",
- " 0.00000 | \n",
- " 6.25000 | \n",
- "
\n",
- " \n",
- " 14 | \n",
- " 15 | \n",
- " 0.679698 | \n",
- " 0.620653 | \n",
- " 0.941395 | \n",
- " 6 | \n",
- " 1.112061 | \n",
- " 0.609917 | \n",
- " 18 | \n",
- " 8412.197687 | \n",
- " 0.011888 | \n",
- " ... | \n",
- " 0.448882 | \n",
- " 1.736907 | \n",
- " 43.87656 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 43.77916 | \n",
- " 5.98759 | \n",
- " 1.54304 | \n",
- " 0.25632 | \n",
- " 4.55734 | \n",
- "
\n",
- " \n",
- " 15 | \n",
- " 16 | \n",
- " 0.595400 | \n",
- " 0.630057 | \n",
- " 0.836454 | \n",
- " 5 | \n",
- " 1.014038 | \n",
- " 0.566756 | \n",
- " 17 | \n",
- " 38288.288288 | \n",
- " 0.002612 | \n",
- " ... | \n",
- " 1.254110 | \n",
- " 0.231378 | \n",
- " 27.09382 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 58.71854 | \n",
- " 12.17391 | \n",
- " 0.00000 | \n",
- " 0.64073 | \n",
- " 1.37300 | \n",
- "
\n",
- " \n",
- " 16 | \n",
- " 17 | \n",
- " 0.614400 | \n",
- " 0.657097 | \n",
- " 1.004676 | \n",
- " 6 | \n",
- " 1.177359 | \n",
- " 0.633837 | \n",
- " 10 | \n",
- " 8338.544924 | \n",
- " 0.011992 | \n",
- " ... | \n",
- " 0.847633 | \n",
- " 1.367177 | \n",
- " 43.54180 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 40.85504 | \n",
- " 6.86212 | \n",
- " 1.69738 | \n",
- " 0.21785 | \n",
- " 6.82581 | \n",
- "
\n",
- " \n",
- " 17 | \n",
- " 18 | \n",
- " 0.337715 | \n",
- " 0.811517 | \n",
- " 1.309070 | \n",
- " 6 | \n",
- " 1.454044 | \n",
- " 0.729929 | \n",
- " 29 | \n",
- " 7805.140627 | \n",
- " 0.012812 | \n",
- " ... | \n",
- " 1.164690 | \n",
- " 2.915765 | \n",
- " 38.95369 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 28.86798 | \n",
- " 12.10128 | \n",
- " 7.72416 | \n",
- " 0.36432 | \n",
- " 11.98857 | \n",
- "
\n",
- " \n",
- " 18 | \n",
- " 19 | \n",
- " 0.402212 | \n",
- " 0.775521 | \n",
- " 1.214702 | \n",
- " 6 | \n",
- " 1.389548 | \n",
- " 0.703202 | \n",
- " 97 | \n",
- " 30003.093102 | \n",
- " 0.003333 | \n",
- " ... | \n",
- " 0.361686 | \n",
- " 1.359388 | \n",
- " 23.31939 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 45.18718 | \n",
- " 16.43826 | \n",
- " 7.74127 | \n",
- " 0.09196 | \n",
- " 7.22194 | \n",
- "
\n",
- " \n",
- " 19 | \n",
- " 20 | \n",
- " 0.861303 | \n",
- " 0.585801 | \n",
- " 0.995894 | \n",
- " 8 | \n",
- " 1.218139 | \n",
- " 0.630607 | \n",
- " 32 | \n",
- " 8199.346615 | \n",
- " 0.012196 | \n",
- " ... | \n",
- " 0.646450 | \n",
- " 1.681310 | \n",
- " 45.47202 | \n",
- " 0.00291 | \n",
- " 2.31278 | \n",
- " 39.48327 | \n",
- " 1.67196 | \n",
- " 3.48082 | \n",
- " 0.76025 | \n",
- " 6.81600 | \n",
- "
\n",
- " \n",
- " 20 | \n",
- " 21 | \n",
- " 0.845977 | \n",
- " 0.527851 | \n",
- " 0.797247 | \n",
- " 6 | \n",
- " 0.945783 | \n",
- " 0.549432 | \n",
- " 11 | \n",
- " 15907.447578 | \n",
- " 0.006286 | \n",
- " ... | \n",
- " 0.839661 | \n",
- " 1.378350 | \n",
- " 39.35686 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 54.24018 | \n",
- " 1.06716 | \n",
- " 2.61810 | \n",
- " 0.12806 | \n",
- " 2.58964 | \n",
- "
\n",
- " \n",
- " 21 | \n",
- " 22 | \n",
- " 0.116904 | \n",
- " 0.927364 | \n",
- " 1.396801 | \n",
- " 5 | \n",
- " 1.492534 | \n",
- " 0.752613 | \n",
- " 48 | \n",
- " 10865.259465 | \n",
- " 0.009204 | \n",
- " ... | \n",
- " 1.369080 | \n",
- " 2.872126 | \n",
- " 34.17327 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 28.87836 | \n",
- " 15.39934 | \n",
- " 9.59582 | \n",
- " 0.00000 | \n",
- " 11.95320 | \n",
- "
\n",
- " \n",
- " 22 | \n",
- " 23 | \n",
- " 0.646570 | \n",
- " 0.598264 | \n",
- " 0.830907 | \n",
- " 5 | \n",
- " 0.962868 | \n",
- " 0.564346 | \n",
- " 9 | \n",
- " 71005.917160 | \n",
- " 0.001408 | \n",
- " ... | \n",
- " 2.381000 | \n",
- " 0.380468 | \n",
- " 1.06609 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 47.41678 | \n",
- " 45.69885 | \n",
- " 3.84171 | \n",
- " 0.00000 | \n",
- " 1.97658 | \n",
- "
\n",
- " \n",
- " 23 | \n",
- " 24 | \n",
- " 0.835973 | \n",
- " 0.570395 | \n",
- " 0.856043 | \n",
- " 7 | \n",
- " 1.109937 | \n",
- " 0.575160 | \n",
- " 58 | \n",
- " 20043.196544 | \n",
- " 0.004989 | \n",
- " ... | \n",
- " 1.056460 | \n",
- " 1.289893 | \n",
- " 24.31978 | \n",
- " 0.07144 | \n",
- " 0.00000 | \n",
- " 59.51045 | \n",
- " 9.58294 | \n",
- " 1.50226 | \n",
- " 0.40971 | \n",
- " 4.60342 | \n",
- "
\n",
- " \n",
- " 24 | \n",
- " 25 | \n",
- " 0.640894 | \n",
- " 0.642310 | \n",
- " 0.970165 | \n",
- " 6 | \n",
- " 1.150866 | \n",
- " 0.620979 | \n",
- " 26 | \n",
- " 15271.659325 | \n",
- " 0.006548 | \n",
- " ... | \n",
- " 0.836210 | \n",
- " 1.577875 | \n",
- " 33.28608 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 50.65252 | \n",
- " 9.15978 | \n",
- " 1.24640 | \n",
- " 0.07821 | \n",
- " 5.57701 | \n",
- "
\n",
- " \n",
- " 25 | \n",
- " 26 | \n",
- " 0.510542 | \n",
- " 0.715061 | \n",
- " 1.045408 | \n",
- " 6 | \n",
- " 1.281218 | \n",
- " 0.648452 | \n",
- " 60 | \n",
- " 24115.755627 | \n",
- " 0.004147 | \n",
- " ... | \n",
- " 0.855276 | \n",
- " 1.076095 | \n",
- " 24.68315 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 52.10447 | \n",
- " 10.88569 | \n",
- " 6.37169 | \n",
- " 0.28275 | \n",
- " 5.67226 | \n",
- "
\n",
- " \n",
- " 26 | \n",
- " 27 | \n",
- " 0.662028 | \n",
- " 0.681632 | \n",
- " 1.243738 | \n",
- " 8 | \n",
- " 1.417414 | \n",
- " 0.711695 | \n",
- " 23 | \n",
- " 9993.482511 | \n",
- " 0.010007 | \n",
- " ... | \n",
- " 1.394810 | \n",
- " 2.747778 | \n",
- " 38.97379 | \n",
- " 0.05927 | \n",
- " 0.65196 | \n",
- " 32.91986 | \n",
- " 4.52987 | \n",
- " 9.84717 | \n",
- " 0.27518 | \n",
- " 12.74290 | \n",
- "
\n",
- " \n",
- " 27 | \n",
- " 28 | \n",
- " 1.014343 | \n",
- " 0.433884 | \n",
- " 0.517119 | \n",
- " 6 | \n",
- " 0.777416 | \n",
- " 0.403764 | \n",
- " 13 | \n",
- " 53388.090349 | \n",
- " 0.001873 | \n",
- " ... | \n",
- " 2.201840 | \n",
- " 1.350748 | \n",
- " 4.62444 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 74.91216 | \n",
- " 18.06096 | \n",
- " 0.24689 | \n",
- " 0.55075 | \n",
- " 1.60479 | \n",
- "
\n",
- " \n",
- " 28 | \n",
- " 29 | \n",
- " 0.320349 | \n",
- " 0.821210 | \n",
- " 1.322629 | \n",
- " 6 | \n",
- " 1.471410 | \n",
- " 0.733566 | \n",
- " 28 | \n",
- " 5845.511482 | \n",
- " 0.017107 | \n",
- " ... | \n",
- " 1.220170 | \n",
- " 3.030122 | \n",
- " 40.92618 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 23.87859 | \n",
- " 12.79904 | \n",
- " 8.51418 | \n",
- " 0.36312 | \n",
- " 13.51888 | \n",
- "
\n",
- " \n",
- " 29 | \n",
- " 30 | \n",
- " 0.437495 | \n",
- " 0.728169 | \n",
- " 0.906174 | \n",
- " 5 | \n",
- " 1.171943 | \n",
- " 0.595933 | \n",
- " 65 | \n",
- " 39956.969418 | \n",
- " 0.002503 | \n",
- " ... | \n",
- " 0.869740 | \n",
- " 0.467453 | \n",
- " 12.75182 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 58.88728 | \n",
- " 19.07972 | \n",
- " 3.36678 | \n",
- " 0.00000 | \n",
- " 5.91440 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 556 | \n",
- " 557 | \n",
- " 0.578356 | \n",
- " 0.677213 | \n",
- " 1.061289 | \n",
- " 6 | \n",
- " 1.213403 | \n",
- " 0.653991 | \n",
- " 105 | \n",
- " 28315.243039 | \n",
- " 0.003532 | \n",
- " ... | \n",
- " 0.575197 | \n",
- " 1.116782 | \n",
- " 33.53834 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 45.75486 | \n",
- " 2.73815 | \n",
- " 2.89642 | \n",
- " 0.04296 | \n",
- " 15.02928 | \n",
- "
\n",
- " \n",
- " 557 | \n",
- " 558 | \n",
- " 0.094661 | \n",
- " 0.941184 | \n",
- " 1.432042 | \n",
- " 5 | \n",
- " 1.514777 | \n",
- " 0.761179 | \n",
- " 69 | \n",
- " 39473.684211 | \n",
- " 0.002533 | \n",
- " ... | \n",
- " 1.013640 | \n",
- " 0.833812 | \n",
- " 14.02495 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 31.77077 | \n",
- " 29.67866 | \n",
- " 12.78734 | \n",
- " 0.00000 | \n",
- " 11.73828 | \n",
- "
\n",
- " \n",
- " 558 | \n",
- " 559 | \n",
- " 0.500244 | \n",
- " 0.689181 | \n",
- " 0.932546 | \n",
- " 5 | \n",
- " 1.109194 | \n",
- " 0.606449 | \n",
- " 22 | \n",
- " 65233.506301 | \n",
- " 0.001533 | \n",
- " ... | \n",
- " 2.076590 | \n",
- " 0.370745 | \n",
- " 2.96542 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 38.27131 | \n",
- " 49.09982 | \n",
- " 6.33752 | \n",
- " 0.00000 | \n",
- " 3.32593 | \n",
- "
\n",
- " \n",
- " 559 | \n",
- " 560 | \n",
- " 0.608741 | \n",
- " 0.687169 | \n",
- " 1.171787 | \n",
- " 7 | \n",
- " 1.337170 | \n",
- " 0.690187 | \n",
- " 118 | \n",
- " 16236.111589 | \n",
- " 0.006159 | \n",
- " ... | \n",
- " 0.566650 | \n",
- " 1.147347 | \n",
- " 35.57609 | \n",
- " 0.05140 | \n",
- " 0.00000 | \n",
- " 40.02325 | \n",
- " 7.20920 | \n",
- " 4.24647 | \n",
- " 0.22273 | \n",
- " 12.67087 | \n",
- "
\n",
- " \n",
- " 560 | \n",
- " 561 | \n",
- " 0.476287 | \n",
- " 0.755237 | \n",
- " 1.353951 | \n",
- " 7 | \n",
- " 1.469623 | \n",
- " 0.741782 | \n",
- " 117 | \n",
- " 24198.552223 | \n",
- " 0.004132 | \n",
- " ... | \n",
- " 0.680145 | \n",
- " 1.599025 | \n",
- " 31.17042 | \n",
- " 0.04513 | \n",
- " 0.00000 | \n",
- " 34.27779 | \n",
- " 8.63714 | \n",
- " 9.03684 | \n",
- " 0.11927 | \n",
- " 16.71341 | \n",
- "
\n",
- " \n",
- " 561 | \n",
- " 562 | \n",
- " 0.433735 | \n",
- " 0.730505 | \n",
- " 0.941033 | \n",
- " 5 | \n",
- " 1.175703 | \n",
- " 0.609775 | \n",
- " 13 | \n",
- " 55201.698514 | \n",
- " 0.001812 | \n",
- " ... | \n",
- " 1.527530 | \n",
- " 0.000000 | \n",
- " 3.48051 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 25.94125 | \n",
- " 55.67707 | \n",
- " 9.21485 | \n",
- " 0.00000 | \n",
- " 5.68631 | \n",
- "
\n",
- " \n",
- " 562 | \n",
- " 563 | \n",
- " 0.445676 | \n",
- " 0.678513 | \n",
- " 0.862639 | \n",
- " 4 | \n",
- " 0.940619 | \n",
- " 0.577953 | \n",
- " 1 | \n",
- " 266666.666667 | \n",
- " 0.000375 | \n",
- " ... | \n",
- " 2.662720 | \n",
- " 0.559212 | \n",
- " 0.13783 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 46.97234 | \n",
- " 43.98603 | \n",
- " 0.00000 | \n",
- " 8.90379 | \n",
- "
\n",
- " \n",
- " 563 | \n",
- " 564 | \n",
- " 0.499046 | \n",
- " 0.721477 | \n",
- " 1.080124 | \n",
- " 6 | \n",
- " 1.292713 | \n",
- " 0.660447 | \n",
- " 93 | \n",
- " 38048.481129 | \n",
- " 0.002628 | \n",
- " ... | \n",
- " 1.225100 | \n",
- " 0.820916 | \n",
- " 13.45397 | \n",
- " 0.03440 | \n",
- " 0.00000 | \n",
- " 22.68336 | \n",
- " 51.02518 | \n",
- " 3.71267 | \n",
- " 0.00000 | \n",
- " 9.09041 | \n",
- "
\n",
- " \n",
- " 564 | \n",
- " 565 | \n",
- " 0.534174 | \n",
- " 0.725489 | \n",
- " 1.268577 | \n",
- " 7 | \n",
- " 1.411736 | \n",
- " 0.718768 | \n",
- " 285 | \n",
- " 18433.477783 | \n",
- " 0.005425 | \n",
- " ... | \n",
- " 0.719428 | \n",
- " 1.440415 | \n",
- " 34.22052 | \n",
- " 0.12229 | \n",
- " 0.00000 | \n",
- " 36.26288 | \n",
- " 7.99847 | \n",
- " 6.43641 | \n",
- " 0.09849 | \n",
- " 14.86095 | \n",
- "
\n",
- " \n",
- " 565 | \n",
- " 566 | \n",
- " 0.509342 | \n",
- " 0.738250 | \n",
- " 1.064468 | \n",
- " 7 | \n",
- " 1.436568 | \n",
- " 0.655089 | \n",
- " 24 | \n",
- " 56371.109806 | \n",
- " 0.001774 | \n",
- " ... | \n",
- " 0.991371 | \n",
- " 0.339261 | \n",
- " 3.33981 | \n",
- " 0.00000 | \n",
- " 9.92528 | \n",
- " 7.68371 | \n",
- " 54.93126 | \n",
- " 5.54215 | \n",
- " 3.82617 | \n",
- " 14.75162 | \n",
- "
\n",
- " \n",
- " 566 | \n",
- " 567 | \n",
- " 0.248211 | \n",
- " 0.845778 | \n",
- " 1.189244 | \n",
- " 5 | \n",
- " 1.361227 | \n",
- " 0.695549 | \n",
- " 63 | \n",
- " 48808.832074 | \n",
- " 0.002049 | \n",
- " ... | \n",
- " 1.818210 | \n",
- " 1.109659 | \n",
- " 6.25902 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 14.69287 | \n",
- " 45.20482 | \n",
- " 26.23016 | \n",
- " 0.00000 | \n",
- " 7.61314 | \n",
- "
\n",
- " \n",
- " 567 | \n",
- " 568 | \n",
- " 0.503226 | \n",
- " 0.741393 | \n",
- " 1.297476 | \n",
- " 7 | \n",
- " 1.442684 | \n",
- " 0.726779 | \n",
- " 31 | \n",
- " 11951.807229 | \n",
- " 0.008367 | \n",
- " ... | \n",
- " 0.427515 | \n",
- " 1.743390 | \n",
- " 40.56062 | \n",
- " 0.08992 | \n",
- " 0.00000 | \n",
- " 26.38102 | \n",
- " 7.37715 | \n",
- " 10.39134 | \n",
- " 0.07819 | \n",
- " 15.12178 | \n",
- "
\n",
- " \n",
- " 568 | \n",
- " 569 | \n",
- " 0.534372 | \n",
- " 0.667976 | \n",
- " 0.750988 | \n",
- " 5 | \n",
- " 1.075066 | \n",
- " 0.528100 | \n",
- " 32 | \n",
- " 79012.345679 | \n",
- " 0.001266 | \n",
- " ... | \n",
- " 1.518000 | \n",
- " 0.573302 | \n",
- " 4.88011 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 15.05302 | \n",
- " 66.07724 | \n",
- " 8.50102 | \n",
- " 0.00000 | \n",
- " 5.48861 | \n",
- "
\n",
- " \n",
- " 569 | \n",
- " 570 | \n",
- " 0.423897 | \n",
- " 0.736618 | \n",
- " 0.939398 | \n",
- " 5 | \n",
- " 1.185541 | \n",
- " 0.609137 | \n",
- " 7 | \n",
- " 24933.214604 | \n",
- " 0.004011 | \n",
- " ... | \n",
- " 2.080870 | \n",
- " 1.441198 | \n",
- " 3.12213 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 14.18444 | \n",
- " 20.23687 | \n",
- " 57.09083 | \n",
- " 0.00000 | \n",
- " 5.36573 | \n",
- "
\n",
- " \n",
- " 570 | \n",
- " 571 | \n",
- " 0.667553 | \n",
- " 0.627432 | \n",
- " 0.857727 | \n",
- " 6 | \n",
- " 1.124207 | \n",
- " 0.575875 | \n",
- " 44 | \n",
- " 60150.375940 | \n",
- " 0.001662 | \n",
- " ... | \n",
- " 2.292160 | \n",
- " 0.791101 | \n",
- " 1.94736 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 10.50481 | \n",
- " 60.65023 | \n",
- " 20.05524 | \n",
- " 0.02729 | \n",
- " 6.81508 | \n",
- "
\n",
- " \n",
- " 571 | \n",
- " 572 | \n",
- " 0.238162 | \n",
- " 0.852022 | \n",
- " 1.228001 | \n",
- " 5 | \n",
- " 1.371276 | \n",
- " 0.707123 | \n",
- " 28 | \n",
- " 46920.821114 | \n",
- " 0.002131 | \n",
- " ... | \n",
- " 1.547580 | \n",
- " 1.145190 | \n",
- " 5.49102 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 13.35603 | \n",
- " 35.76867 | \n",
- " 37.02698 | \n",
- " 0.00000 | \n",
- " 8.35730 | \n",
- "
\n",
- " \n",
- " 572 | \n",
- " 573 | \n",
- " 0.454485 | \n",
- " 0.746347 | \n",
- " 1.170207 | \n",
- " 6 | \n",
- " 1.337274 | \n",
- " 0.689697 | \n",
- " 36 | \n",
- " 12654.890588 | \n",
- " 0.007902 | \n",
- " ... | \n",
- " 0.643162 | \n",
- " 1.790001 | \n",
- " 44.38507 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 28.79432 | \n",
- " 6.75976 | \n",
- " 4.53251 | \n",
- " 0.11312 | \n",
- " 15.41522 | \n",
- "
\n",
- " \n",
- " 573 | \n",
- " 574 | \n",
- " 0.360131 | \n",
- " 0.776238 | \n",
- " 1.082831 | \n",
- " 5 | \n",
- " 1.249307 | \n",
- " 0.661365 | \n",
- " 17 | \n",
- " 45242.847638 | \n",
- " 0.002210 | \n",
- " ... | \n",
- " 1.737920 | \n",
- " 0.633819 | \n",
- " 2.88450 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 7.48090 | \n",
- " 42.71677 | \n",
- " 37.54270 | \n",
- " 0.00000 | \n",
- " 9.37512 | \n",
- "
\n",
- " \n",
- " 574 | \n",
- " 575 | \n",
- " 0.177358 | \n",
- " 0.889801 | \n",
- " 1.333546 | \n",
- " 5 | \n",
- " 1.432080 | \n",
- " 0.736459 | \n",
- " 21 | \n",
- " 59871.703493 | \n",
- " 0.001670 | \n",
- " ... | \n",
- " 1.194200 | \n",
- " 0.989345 | \n",
- " 7.00344 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 34.24350 | \n",
- " 28.59781 | \n",
- " 23.48126 | \n",
- " 0.00000 | \n",
- " 6.67399 | \n",
- "
\n",
- " \n",
- " 575 | \n",
- " 576 | \n",
- " 0.113373 | \n",
- " 0.929557 | \n",
- " 1.390506 | \n",
- " 5 | \n",
- " 1.496065 | \n",
- " 0.751051 | \n",
- " 23 | \n",
- " 31680.440771 | \n",
- " 0.003157 | \n",
- " ... | \n",
- " 1.534760 | \n",
- " 0.857678 | \n",
- " 15.30112 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 22.87265 | \n",
- " 37.86817 | \n",
- " 14.34744 | \n",
- " 0.00000 | \n",
- " 9.61062 | \n",
- "
\n",
- " \n",
- " 576 | \n",
- " 577 | \n",
- " 0.126811 | \n",
- " 0.921208 | \n",
- " 1.398320 | \n",
- " 5 | \n",
- " 1.482627 | \n",
- " 0.752988 | \n",
- " 188 | \n",
- " 46075.608112 | \n",
- " 0.002170 | \n",
- " ... | \n",
- " 1.240220 | \n",
- " 0.879164 | \n",
- " 8.50247 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 25.16202 | \n",
- " 33.06799 | \n",
- " 24.30974 | \n",
- " 0.00000 | \n",
- " 8.95778 | \n",
- "
\n",
- " \n",
- " 577 | \n",
- " 578 | \n",
- " 0.903592 | \n",
- " 0.348196 | \n",
- " 0.343443 | \n",
- " 4 | \n",
- " 0.482703 | \n",
- " 0.290676 | \n",
- " 0 | \n",
- " NaN | \n",
- " 0.000000 | \n",
- " ... | \n",
- " 2.736600 | \n",
- " 0.000000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.00572 | \n",
- " 17.18183 | \n",
- " 82.44932 | \n",
- " 0.36314 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- "
\n",
- " \n",
- " 578 | \n",
- " 579 | \n",
- " 0.677898 | \n",
- " 0.651629 | \n",
- " 0.948483 | \n",
- " 7 | \n",
- " 1.268012 | \n",
- " 0.612672 | \n",
- " 53 | \n",
- " 10976.493735 | \n",
- " 0.009110 | \n",
- " ... | \n",
- " 1.718200 | \n",
- " 3.795232 | \n",
- " 8.61905 | \n",
- " 0.00000 | \n",
- " 2.49548 | \n",
- " 20.50561 | \n",
- " 57.57146 | \n",
- " 6.09679 | \n",
- " 0.17136 | \n",
- " 4.54024 | \n",
- "
\n",
- " \n",
- " 579 | \n",
- " 580 | \n",
- " 0.722027 | \n",
- " 0.628952 | \n",
- " 0.989536 | \n",
- " 7 | \n",
- " 1.223883 | \n",
- " 0.628251 | \n",
- " 65 | \n",
- " 12824.939575 | \n",
- " 0.007797 | \n",
- " ... | \n",
- " 1.929240 | \n",
- " 3.403965 | \n",
- " 9.84155 | \n",
- " 0.00000 | \n",
- " 0.77138 | \n",
- " 29.27221 | \n",
- " 52.25686 | \n",
- " 2.47046 | \n",
- " 0.26651 | \n",
- " 5.12102 | \n",
- "
\n",
- " \n",
- " 580 | \n",
- " 581 | \n",
- " 0.571855 | \n",
- " 0.479475 | \n",
- " 0.355066 | \n",
- " 3 | \n",
- " 0.526757 | \n",
- " 0.298873 | \n",
- " 12 | \n",
- " 70484.581498 | \n",
- " 0.001419 | \n",
- " ... | \n",
- " 4.000000 | \n",
- " 0.021291 | \n",
- " 1.77353 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 16.06855 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 82.15792 | \n",
- " 0.00000 | \n",
- "
\n",
- " \n",
- " 581 | \n",
- " 582 | \n",
- " 0.815143 | \n",
- " 0.411999 | \n",
- " 0.357021 | \n",
- " 4 | \n",
- " 0.571151 | \n",
- " 0.300242 | \n",
- " 0 | \n",
- " NaN | \n",
- " 0.000000 | \n",
- " ... | \n",
- " 2.478960 | \n",
- " 0.000000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 0.09254 | \n",
- " 82.57249 | \n",
- " 12.48201 | \n",
- " 0.00000 | \n",
- " 4.85297 | \n",
- "
\n",
- " \n",
- " 582 | \n",
- " 583 | \n",
- " 1.076918 | \n",
- " 0.446574 | \n",
- " 0.520575 | \n",
- " 7 | \n",
- " 0.868993 | \n",
- " 0.405821 | \n",
- " 152 | \n",
- " 25531.200134 | \n",
- " 0.003917 | \n",
- " ... | \n",
- " 2.620970 | \n",
- " 3.241724 | \n",
- " 5.57681 | \n",
- " 0.00000 | \n",
- " 1.81632 | \n",
- " 75.78322 | \n",
- " 12.22595 | \n",
- " 0.40724 | \n",
- " 0.38148 | \n",
- " 3.80897 | \n",
- "
\n",
- " \n",
- " 583 | \n",
- " 584 | \n",
- " 0.987317 | \n",
- " 0.386546 | \n",
- " 0.352229 | \n",
- " 5 | \n",
- " 0.622121 | \n",
- " 0.296881 | \n",
- " 1 | \n",
- " 111111.111111 | \n",
- " 0.000900 | \n",
- " ... | \n",
- " 1.944440 | \n",
- " 0.394974 | \n",
- " 0.01974 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 6.86292 | \n",
- " 83.19327 | \n",
- " 7.58161 | \n",
- " 0.00000 | \n",
- " 2.34246 | \n",
- "
\n",
- " \n",
- " 584 | \n",
- " 585 | \n",
- " 1.089900 | \n",
- " 0.391715 | \n",
- " 0.403172 | \n",
- " 6 | \n",
- " 0.701859 | \n",
- " 0.331803 | \n",
- " 13 | \n",
- " 84552.845528 | \n",
- " 0.001183 | \n",
- " ... | \n",
- " 1.687950 | \n",
- " 0.219373 | \n",
- " 0.46314 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 4.19390 | \n",
- " 80.93277 | \n",
- " 9.48278 | \n",
- " 0.01506 | \n",
- " 4.91234 | \n",
- "
\n",
- " \n",
- " 585 | \n",
- " 586 | \n",
- " 1.121030 | \n",
- " 0.303465 | \n",
- " 0.270257 | \n",
- " 5 | \n",
- " 0.488408 | \n",
- " 0.236816 | \n",
- " 3 | \n",
- " 114285.714286 | \n",
- " 0.000875 | \n",
- " ... | \n",
- " 1.947070 | \n",
- " 0.568464 | \n",
- " 0.30128 | \n",
- " 0.00000 | \n",
- " 0.00000 | \n",
- " 10.41577 | \n",
- " 86.71774 | \n",
- " 1.27113 | \n",
- " 0.00000 | \n",
- " 1.29408 | \n",
- "
\n",
- " \n",
- "
\n",
- "
586 rows × 117 columns
\n",
- "
"
- ],
- "text/plain": [
- " cat dominance pielou renyi richness shannon simpson \\\n",
- "0 1 0.213708 0.867216 1.252613 5 1.395730 0.714243 \n",
- "1 2 0.875010 0.511647 0.656834 6 0.916749 0.481510 \n",
- "2 3 0.237762 0.867302 1.475816 6 1.553997 0.771408 \n",
- "3 4 0.373615 0.659921 0.629171 3 0.724997 0.466967 \n",
- "4 5 0.685988 0.375587 0.217895 3 0.412625 0.195790 \n",
- "5 6 0.440634 0.682150 0.843472 4 0.945660 0.569786 \n",
- "6 7 1.327286 0.259228 0.246013 6 0.464474 0.218088 \n",
- "7 8 0.890449 0.189479 0.092429 3 0.208163 0.088286 \n",
- "8 9 0.173536 0.874820 1.095909 4 1.212758 0.665764 \n",
- "9 10 0.416684 0.767444 1.201512 6 1.375075 0.699261 \n",
- "10 11 0.486061 0.298762 0.105668 2 0.207086 0.100277 \n",
- "11 12 1.302626 0.330583 0.363104 7 0.643284 0.304486 \n",
- "12 13 0.447633 0.769962 1.325055 7 1.498277 0.734212 \n",
- "13 14 0.505261 0.686064 0.920011 5 1.104177 0.601485 \n",
- "14 15 0.679698 0.620653 0.941395 6 1.112061 0.609917 \n",
- "15 16 0.595400 0.630057 0.836454 5 1.014038 0.566756 \n",
- "16 17 0.614400 0.657097 1.004676 6 1.177359 0.633837 \n",
- "17 18 0.337715 0.811517 1.309070 6 1.454044 0.729929 \n",
- "18 19 0.402212 0.775521 1.214702 6 1.389548 0.703202 \n",
- "19 20 0.861303 0.585801 0.995894 8 1.218139 0.630607 \n",
- "20 21 0.845977 0.527851 0.797247 6 0.945783 0.549432 \n",
- "21 22 0.116904 0.927364 1.396801 5 1.492534 0.752613 \n",
- "22 23 0.646570 0.598264 0.830907 5 0.962868 0.564346 \n",
- "23 24 0.835973 0.570395 0.856043 7 1.109937 0.575160 \n",
- "24 25 0.640894 0.642310 0.970165 6 1.150866 0.620979 \n",
- "25 26 0.510542 0.715061 1.045408 6 1.281218 0.648452 \n",
- "26 27 0.662028 0.681632 1.243738 8 1.417414 0.711695 \n",
- "27 28 1.014343 0.433884 0.517119 6 0.777416 0.403764 \n",
- "28 29 0.320349 0.821210 1.322629 6 1.471410 0.733566 \n",
- "29 30 0.437495 0.728169 0.906174 5 1.171943 0.595933 \n",
- ".. ... ... ... ... ... ... ... \n",
- "556 557 0.578356 0.677213 1.061289 6 1.213403 0.653991 \n",
- "557 558 0.094661 0.941184 1.432042 5 1.514777 0.761179 \n",
- "558 559 0.500244 0.689181 0.932546 5 1.109194 0.606449 \n",
- "559 560 0.608741 0.687169 1.171787 7 1.337170 0.690187 \n",
- "560 561 0.476287 0.755237 1.353951 7 1.469623 0.741782 \n",
- "561 562 0.433735 0.730505 0.941033 5 1.175703 0.609775 \n",
- "562 563 0.445676 0.678513 0.862639 4 0.940619 0.577953 \n",
- "563 564 0.499046 0.721477 1.080124 6 1.292713 0.660447 \n",
- "564 565 0.534174 0.725489 1.268577 7 1.411736 0.718768 \n",
- "565 566 0.509342 0.738250 1.064468 7 1.436568 0.655089 \n",
- "566 567 0.248211 0.845778 1.189244 5 1.361227 0.695549 \n",
- "567 568 0.503226 0.741393 1.297476 7 1.442684 0.726779 \n",
- "568 569 0.534372 0.667976 0.750988 5 1.075066 0.528100 \n",
- "569 570 0.423897 0.736618 0.939398 5 1.185541 0.609137 \n",
- "570 571 0.667553 0.627432 0.857727 6 1.124207 0.575875 \n",
- "571 572 0.238162 0.852022 1.228001 5 1.371276 0.707123 \n",
- "572 573 0.454485 0.746347 1.170207 6 1.337274 0.689697 \n",
- "573 574 0.360131 0.776238 1.082831 5 1.249307 0.661365 \n",
- "574 575 0.177358 0.889801 1.333546 5 1.432080 0.736459 \n",
- "575 576 0.113373 0.929557 1.390506 5 1.496065 0.751051 \n",
- "576 577 0.126811 0.921208 1.398320 5 1.482627 0.752988 \n",
- "577 578 0.903592 0.348196 0.343443 4 0.482703 0.290676 \n",
- "578 579 0.677898 0.651629 0.948483 7 1.268012 0.612672 \n",
- "579 580 0.722027 0.628952 0.989536 7 1.223883 0.628251 \n",
- "580 581 0.571855 0.479475 0.355066 3 0.526757 0.298873 \n",
- "581 582 0.815143 0.411999 0.357021 4 0.571151 0.300242 \n",
- "582 583 1.076918 0.446574 0.520575 7 0.868993 0.405821 \n",
- "583 584 0.987317 0.386546 0.352229 5 0.622121 0.296881 \n",
- "584 585 1.089900 0.391715 0.403172 6 0.701859 0.331803 \n",
- "585 586 1.121030 0.303465 0.270257 5 0.488408 0.236816 \n",
- "\n",
- " cl_11_patchnum cl_11_patchdensity cl_11_mps ... SAR_w7_7_median \\\n",
- "0 18 9086.320040 0.011006 ... 1.042240 \n",
- "1 22 78501.338091 0.001274 ... 1.643660 \n",
- "2 25 14138.272303 0.007073 ... 1.225260 \n",
- "3 2 18433.179724 0.005425 ... 0.797337 \n",
- "4 0 NaN 0.000000 ... 0.894313 \n",
- "5 0 NaN 0.000000 ... 1.309910 \n",
- "6 32 60491.493384 0.001653 ... 1.770790 \n",
- "7 0 NaN 0.000000 ... 2.252300 \n",
- "8 0 NaN 0.000000 ... 0.791420 \n",
- "9 14 10588.012857 0.009445 ... 1.319530 \n",
- "10 0 NaN 0.000000 ... 3.151870 \n",
- "11 69 70951.156812 0.001409 ... 1.353300 \n",
- "12 40 13314.471166 0.007511 ... 1.216550 \n",
- "13 14 18685.352019 0.005352 ... 0.314760 \n",
- "14 18 8412.197687 0.011888 ... 0.448882 \n",
- "15 17 38288.288288 0.002612 ... 1.254110 \n",
- "16 10 8338.544924 0.011992 ... 0.847633 \n",
- "17 29 7805.140627 0.012812 ... 1.164690 \n",
- "18 97 30003.093102 0.003333 ... 0.361686 \n",
- "19 32 8199.346615 0.012196 ... 0.646450 \n",
- "20 11 15907.447578 0.006286 ... 0.839661 \n",
- "21 48 10865.259465 0.009204 ... 1.369080 \n",
- "22 9 71005.917160 0.001408 ... 2.381000 \n",
- "23 58 20043.196544 0.004989 ... 1.056460 \n",
- "24 26 15271.659325 0.006548 ... 0.836210 \n",
- "25 60 24115.755627 0.004147 ... 0.855276 \n",
- "26 23 9993.482511 0.010007 ... 1.394810 \n",
- "27 13 53388.090349 0.001873 ... 2.201840 \n",
- "28 28 5845.511482 0.017107 ... 1.220170 \n",
- "29 65 39956.969418 0.002503 ... 0.869740 \n",
- ".. ... ... ... ... ... \n",
- "556 105 28315.243039 0.003532 ... 0.575197 \n",
- "557 69 39473.684211 0.002533 ... 1.013640 \n",
- "558 22 65233.506301 0.001533 ... 2.076590 \n",
- "559 118 16236.111589 0.006159 ... 0.566650 \n",
- "560 117 24198.552223 0.004132 ... 0.680145 \n",
- "561 13 55201.698514 0.001812 ... 1.527530 \n",
- "562 1 266666.666667 0.000375 ... 2.662720 \n",
- "563 93 38048.481129 0.002628 ... 1.225100 \n",
- "564 285 18433.477783 0.005425 ... 0.719428 \n",
- "565 24 56371.109806 0.001774 ... 0.991371 \n",
- "566 63 48808.832074 0.002049 ... 1.818210 \n",
- "567 31 11951.807229 0.008367 ... 0.427515 \n",
- "568 32 79012.345679 0.001266 ... 1.518000 \n",
- "569 7 24933.214604 0.004011 ... 2.080870 \n",
- "570 44 60150.375940 0.001662 ... 2.292160 \n",
- "571 28 46920.821114 0.002131 ... 1.547580 \n",
- "572 36 12654.890588 0.007902 ... 0.643162 \n",
- "573 17 45242.847638 0.002210 ... 1.737920 \n",
- "574 21 59871.703493 0.001670 ... 1.194200 \n",
- "575 23 31680.440771 0.003157 ... 1.534760 \n",
- "576 188 46075.608112 0.002170 ... 1.240220 \n",
- "577 0 NaN 0.000000 ... 2.736600 \n",
- "578 53 10976.493735 0.009110 ... 1.718200 \n",
- "579 65 12824.939575 0.007797 ... 1.929240 \n",
- "580 12 70484.581498 0.001419 ... 4.000000 \n",
- "581 0 NaN 0.000000 ... 2.478960 \n",
- "582 152 25531.200134 0.003917 ... 2.620970 \n",
- "583 1 111111.111111 0.000900 ... 1.944440 \n",
- "584 13 84552.845528 0.001183 ... 1.687950 \n",
- "585 3 114285.714286 0.000875 ... 1.947070 \n",
- "\n",
- " mean_build_height prop_11 prop_13 prop_14 prop_20 prop_30 \\\n",
- "0 2.682045 39.17536 0.00000 0.00000 32.03639 6.38256 \n",
- "1 0.596033 1.07294 0.00000 0.00000 24.19338 67.67580 \n",
- "2 2.800861 28.72284 0.00000 0.00000 29.11269 18.63147 \n",
- "3 1.280882 32.60706 0.00000 0.00000 65.28926 0.00000 \n",
- "4 0.000000 0.00000 0.00000 0.00000 5.31915 5.31915 \n",
- "5 0.000000 0.00000 0.00000 0.00000 42.46947 49.47987 \n",
- "6 0.313403 0.11101 0.00000 0.00000 7.34661 88.02124 \n",
- "7 0.000000 0.00000 0.00000 0.00000 95.40603 3.75870 \n",
- "8 0.000000 0.00000 0.00000 0.00000 44.48898 33.46693 \n",
- "9 2.309613 33.56177 0.31093 0.00000 40.81477 8.93458 \n",
- "10 0.000000 0.00000 0.00000 0.00000 94.70588 5.29412 \n",
- "11 0.786419 0.99459 0.00000 0.06545 11.62142 82.50050 \n",
- "12 2.703586 35.52803 0.00000 2.19075 32.91450 5.73853 \n",
- "13 1.393364 33.87206 0.00000 0.00000 52.54295 6.02396 \n",
- "14 1.736907 43.87656 0.00000 0.00000 43.77916 5.98759 \n",
- "15 0.231378 27.09382 0.00000 0.00000 58.71854 12.17391 \n",
- "16 1.367177 43.54180 0.00000 0.00000 40.85504 6.86212 \n",
- "17 2.915765 38.95369 0.00000 0.00000 28.86798 12.10128 \n",
- "18 1.359388 23.31939 0.00000 0.00000 45.18718 16.43826 \n",
- "19 1.681310 45.47202 0.00291 2.31278 39.48327 1.67196 \n",
- "20 1.378350 39.35686 0.00000 0.00000 54.24018 1.06716 \n",
- "21 2.872126 34.17327 0.00000 0.00000 28.87836 15.39934 \n",
- "22 0.380468 1.06609 0.00000 0.00000 47.41678 45.69885 \n",
- "23 1.289893 24.31978 0.07144 0.00000 59.51045 9.58294 \n",
- "24 1.577875 33.28608 0.00000 0.00000 50.65252 9.15978 \n",
- "25 1.076095 24.68315 0.00000 0.00000 52.10447 10.88569 \n",
- "26 2.747778 38.97379 0.05927 0.65196 32.91986 4.52987 \n",
- "27 1.350748 4.62444 0.00000 0.00000 74.91216 18.06096 \n",
- "28 3.030122 40.92618 0.00000 0.00000 23.87859 12.79904 \n",
- "29 0.467453 12.75182 0.00000 0.00000 58.88728 19.07972 \n",
- ".. ... ... ... ... ... ... \n",
- "556 1.116782 33.53834 0.00000 0.00000 45.75486 2.73815 \n",
- "557 0.833812 14.02495 0.00000 0.00000 31.77077 29.67866 \n",
- "558 0.370745 2.96542 0.00000 0.00000 38.27131 49.09982 \n",
- "559 1.147347 35.57609 0.05140 0.00000 40.02325 7.20920 \n",
- "560 1.599025 31.17042 0.04513 0.00000 34.27779 8.63714 \n",
- "561 0.000000 3.48051 0.00000 0.00000 25.94125 55.67707 \n",
- "562 0.559212 0.13783 0.00000 0.00000 0.00000 46.97234 \n",
- "563 0.820916 13.45397 0.03440 0.00000 22.68336 51.02518 \n",
- "564 1.440415 34.22052 0.12229 0.00000 36.26288 7.99847 \n",
- "565 0.339261 3.33981 0.00000 9.92528 7.68371 54.93126 \n",
- "566 1.109659 6.25902 0.00000 0.00000 14.69287 45.20482 \n",
- "567 1.743390 40.56062 0.08992 0.00000 26.38102 7.37715 \n",
- "568 0.573302 4.88011 0.00000 0.00000 15.05302 66.07724 \n",
- "569 1.441198 3.12213 0.00000 0.00000 14.18444 20.23687 \n",
- "570 0.791101 1.94736 0.00000 0.00000 10.50481 60.65023 \n",
- "571 1.145190 5.49102 0.00000 0.00000 13.35603 35.76867 \n",
- "572 1.790001 44.38507 0.00000 0.00000 28.79432 6.75976 \n",
- "573 0.633819 2.88450 0.00000 0.00000 7.48090 42.71677 \n",
- "574 0.989345 7.00344 0.00000 0.00000 34.24350 28.59781 \n",
- "575 0.857678 15.30112 0.00000 0.00000 22.87265 37.86817 \n",
- "576 0.879164 8.50247 0.00000 0.00000 25.16202 33.06799 \n",
- "577 0.000000 0.00000 0.00000 0.00572 17.18183 82.44932 \n",
- "578 3.795232 8.61905 0.00000 2.49548 20.50561 57.57146 \n",
- "579 3.403965 9.84155 0.00000 0.77138 29.27221 52.25686 \n",
- "580 0.021291 1.77353 0.00000 0.00000 16.06855 0.00000 \n",
- "581 0.000000 0.00000 0.00000 0.00000 0.09254 82.57249 \n",
- "582 3.241724 5.57681 0.00000 1.81632 75.78322 12.22595 \n",
- "583 0.394974 0.01974 0.00000 0.00000 6.86292 83.19327 \n",
- "584 0.219373 0.46314 0.00000 0.00000 4.19390 80.93277 \n",
- "585 0.568464 0.30128 0.00000 0.00000 10.41577 86.71774 \n",
- "\n",
- " prop_31 prop_41 prop_51 \n",
- "0 9.65541 0.00000 12.75028 \n",
- "1 3.21404 2.51438 1.32945 \n",
- "2 11.31777 0.47107 11.74416 \n",
- "3 0.00000 0.00000 2.10368 \n",
- "4 89.36170 0.00000 0.00000 \n",
- "5 7.01040 0.00000 1.04025 \n",
- "6 4.15473 0.00131 0.36509 \n",
- "7 0.00000 0.00000 0.83527 \n",
- "8 11.22244 0.00000 10.82164 \n",
- "9 7.44337 0.00000 8.93458 \n",
- "10 0.00000 0.00000 0.00000 \n",
- "11 3.40284 0.40832 1.00687 \n",
- "12 10.69359 0.28087 12.65374 \n",
- "13 1.31103 0.00000 6.25000 \n",
- "14 1.54304 0.25632 4.55734 \n",
- "15 0.00000 0.64073 1.37300 \n",
- "16 1.69738 0.21785 6.82581 \n",
- "17 7.72416 0.36432 11.98857 \n",
- "18 7.74127 0.09196 7.22194 \n",
- "19 3.48082 0.76025 6.81600 \n",
- "20 2.61810 0.12806 2.58964 \n",
- "21 9.59582 0.00000 11.95320 \n",
- "22 3.84171 0.00000 1.97658 \n",
- "23 1.50226 0.40971 4.60342 \n",
- "24 1.24640 0.07821 5.57701 \n",
- "25 6.37169 0.28275 5.67226 \n",
- "26 9.84717 0.27518 12.74290 \n",
- "27 0.24689 0.55075 1.60479 \n",
- "28 8.51418 0.36312 13.51888 \n",
- "29 3.36678 0.00000 5.91440 \n",
- ".. ... ... ... \n",
- "556 2.89642 0.04296 15.02928 \n",
- "557 12.78734 0.00000 11.73828 \n",
- "558 6.33752 0.00000 3.32593 \n",
- "559 4.24647 0.22273 12.67087 \n",
- "560 9.03684 0.11927 16.71341 \n",
- "561 9.21485 0.00000 5.68631 \n",
- "562 43.98603 0.00000 8.90379 \n",
- "563 3.71267 0.00000 9.09041 \n",
- "564 6.43641 0.09849 14.86095 \n",
- "565 5.54215 3.82617 14.75162 \n",
- "566 26.23016 0.00000 7.61314 \n",
- "567 10.39134 0.07819 15.12178 \n",
- "568 8.50102 0.00000 5.48861 \n",
- "569 57.09083 0.00000 5.36573 \n",
- "570 20.05524 0.02729 6.81508 \n",
- "571 37.02698 0.00000 8.35730 \n",
- "572 4.53251 0.11312 15.41522 \n",
- "573 37.54270 0.00000 9.37512 \n",
- "574 23.48126 0.00000 6.67399 \n",
- "575 14.34744 0.00000 9.61062 \n",
- "576 24.30974 0.00000 8.95778 \n",
- "577 0.36314 0.00000 0.00000 \n",
- "578 6.09679 0.17136 4.54024 \n",
- "579 2.47046 0.26651 5.12102 \n",
- "580 0.00000 82.15792 0.00000 \n",
- "581 12.48201 0.00000 4.85297 \n",
- "582 0.40724 0.38148 3.80897 \n",
- "583 7.58161 0.00000 2.34246 \n",
- "584 9.48278 0.01506 4.91234 \n",
- "585 1.27113 0.00000 1.29408 \n",
- "\n",
- "[586 rows x 117 columns]"
- ]
- },
- "execution_count": 78,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import pandas as pd\n",
- "# Load the .csv file in a pandas dataframe\n",
- "df=pd.read_csv(outfile_withoutnull, sep=';',header=0)\n",
- "# Display the dataframe\n",
- "df"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Move files to dedicated folder"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "**Configuration files**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 79,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Set the folder where to move the configuration files\n",
- "finalfolder='/home/tais/Documents/GRASSDATA_Spie2017subset_Ouaga/Results_spatial_metrics/rli_config'"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 80,
- "metadata": {
- "scrolled": true
- },
- "outputs": [],
- "source": [
- "## Create the folder if does not exists\n",
- "if not os.path.exists(finalfolder):\n",
- " os.makedirs(finalfolder)\n",
- " print \"Folder '\"+finalfolder+\"' created\"\n",
- "## Copy the files to the final folder and remove them from the original folder\n",
- "for configfile in list_configfile:\n",
- " shutil.copy2(configfile,finalfolder)\n",
- " os.remove(configfile)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "**Result files**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 81,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Set the folder where to move the configuration files\n",
- "finalfolder='/home/tais/Documents/GRASSDATA_Spie2017subset_Ouaga/Results_spatial_metrics/rli_results'"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 82,
- "metadata": {
- "scrolled": true
- },
- "outputs": [],
- "source": [
- "## Create the folder if does not exists\n",
- "if not os.path.exists(finalfolder):\n",
- " os.makedirs(finalfolder)\n",
- " print \"Folder '\"+finalfolder+\"' created\"\n",
- "## Copy the files to the final folder and remove them from the original folder\n",
- "for res_file in resultfiles:\n",
- " shutil.copy2(res_file,finalfolder)\n",
- " os.remove(res_file)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 83,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Copy the final csv file with all the results\n",
- "shutil.copy2(outfile,finalfolder)\n",
- "os.remove(outfile)\n",
- "shutil.copy2(outfile+'t',finalfolder)\n",
- "os.remove(outfile+'t')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 84,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Reasign the new path to the variable\n",
- "outfile=os.path.join(finalfolder,os.path.split(outfile)[-1])"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 85,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Copy the final csv file with all the results\n",
- "shutil.copy2(outfile_withoutnull,finalfolder)\n",
- "os.remove(outfile_withoutnull)\n",
- "shutil.copy2(outfile_withoutnull+'t',finalfolder)\n",
- "os.remove(outfile_withoutnull+'t')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 86,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Reasign the new path to the variable\n",
- "outfile_withoutnull=os.path.join(finalfolder,os.path.split(outfile_withoutnull)[-1])"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Export the landscape polygons (with 'cat' column) as shapefile"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 87,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Define the name of the shapefile with landscape units and the 'cat' column\n",
- "outputshp='/home/tais/Documents/GRASSDATA_Spie2017subset_Ouaga/Results_spatial_metrics/shapefile/Ouaga_subset_streetblocks.shp'"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 88,
- "metadata": {
- "scrolled": true
- },
- "outputs": [],
- "source": [
- "## Create the folder if does not exists\n",
- "dirname=os.path.dirname(outputshp)\n",
- "if not os.path.exists(dirname):\n",
- " os.makedirs(dirname)\n",
- " print \"Folder '\"+dirname+\"' created\""
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 89,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0"
- ]
- },
- "execution_count": 89,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Export vector layer as shapefile\n",
- "gscript.run_command('v.out.ogr', flags='cem', overwrite=True, \n",
- " input=landscape_polygons, output=outputshp, format='ESRI_Shapefile')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Join the .csv file to the landscape unit polygon layer"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 90,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0"
- ]
- },
- "execution_count": 90,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Import .csv as new table in GRASS\n",
- "csvfile=outfile\n",
- "gscript.run_command('db.in.ogr', overwrite=True, quiet=True, input=csvfile, output='spatial_metrics_table')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 91,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0"
- ]
- },
- "execution_count": 91,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Join the vector layer with the new table\n",
- "gscript.run_command('v.db.join', quiet=True, map=landscape_polygons, column='cat', \n",
- " other_table='spatial_metrics_table', other_column='cat_')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Remove temporary raster layer with landscape units"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 92,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0"
- ]
- },
- "execution_count": 92,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "gscript.run_command('g.remove',flags='f',type='raster', name=raster_landscapeunits)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "## Fill the NULL values in .csv files with 0"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "If you want to fill NULL values with 0 value, please run the following cell"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 94,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "path,filename=os.path.split(outfile_withoutnull)\n",
- "base,ext=os.path.splitext(filename)\n",
- "newfilename=\"_\".join(base.split(\"_\")[:-1])+\"_nomissing\"+ext\n",
- "outfile_nomissing=os.path.join(path,newfilename)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 95,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Copy the csvt file \n",
- "shutil.copy2(outfile_withoutnull+'t',outfile_nomissing+'t')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 96,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "# Create a copy of the result file with NULL filled by 0 value\n",
- "reader=csv.reader(open(outfile_withoutnull,'r'),delimiter=\";\")\n",
- "writer=csv.writer(open(outfile_nomissing,'w'),delimiter=\";\")\n",
- "content=[]\n",
- "content.append(reader.next())\n",
- "for row in reader:\n",
- " new_row=[]\n",
- " for value in row:\n",
- " if value in ('NULL',''):\n",
- " new_row.append('0')\n",
- " else:\n",
- " new_row.append(value)\n",
- " content.append(new_row)\n",
- "writer.writerows(content)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "**-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-**"
- ]
- }
- ],
- "metadata": {
- "anaconda-cloud": {},
- "kernelspec": {
- "display_name": "Python 2",
- "language": "python",
- "name": "python2"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 2
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython2",
- "version": "2.7.12"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 1
-}