From 9c9e349467338b7b4568fb3339e4109dfa3e4aa9 Mon Sep 17 00:00:00 2001
From: tkerr1 <theodoremkerr@gmail.com>
Date: Wed, 1 Dec 2021 21:30:29 +0000
Subject: [PATCH] Finalized everything and changed the zlim for the CCI plots

---
 .../forest_biomass_summary_DRC_output.ipynb   | 211 ++++++------------
 1 file changed, 73 insertions(+), 138 deletions(-)

diff --git a/country_outputs/forest_biomass_summary_DRC_output.ipynb b/country_outputs/forest_biomass_summary_DRC_output.ipynb
index b13a8a7..ae71c3f 100644
--- a/country_outputs/forest_biomass_summary_DRC_output.ipynb
+++ b/country_outputs/forest_biomass_summary_DRC_output.ipynb
@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "markdown",
-   "id": "bronze-organization",
+   "id": "worse-devon",
    "metadata": {},
    "source": [
     "# ESA Biomass Climate Change Initiative global forest aboveground biomass dataset v2.0 2010, 2017, 2018\n",
@@ -18,7 +18,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "shaped-prison",
+   "id": "passing-cannon",
    "metadata": {},
    "source": [
     "#### Install these R packages first, and load them into the R session. Source R script with support functions."
@@ -27,7 +27,7 @@
   {
    "cell_type": "code",
    "execution_count": 1,
-   "id": "swiss-modem",
+   "id": "thick-farming",
    "metadata": {},
    "outputs": [
     {
@@ -114,7 +114,7 @@
       "\n",
       "Attaching package ff\n",
       "\n",
-      "- getOption(\"fftempdir\")==\"/tmp/RtmpKu4r1p/ff\"\n",
+      "- getOption(\"fftempdir\")==\"/tmp/RtmpV2y1W7/ff\"\n",
       "\n",
       "\n",
       "- getOption(\"ffextension\")==\"ff\"\n",
@@ -200,7 +200,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "historic-liberty",
+   "id": "conditional-mount",
    "metadata": {},
    "source": [
     "#### Set the path to the CCI, JPL, and NCEO Biomass data folders & read in world countries shapefile"
@@ -209,7 +209,7 @@
   {
    "cell_type": "code",
    "execution_count": 2,
-   "id": "built-thousand",
+   "id": "former-governor",
    "metadata": {},
    "outputs": [
     {
@@ -243,7 +243,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "lasting-entry",
+   "id": "premier-rental",
    "metadata": {},
    "source": [
     "#### Generate 10x10 degree WGS84 grid that the CCI Biomass and Hansen Forest Cover products are tiled on"
@@ -252,7 +252,7 @@
   {
    "cell_type": "code",
    "execution_count": 3,
-   "id": "laden-crest",
+   "id": "visible-newman",
    "metadata": {},
    "outputs": [
     {
@@ -274,7 +274,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "owned-narrow",
+   "id": "isolated-montgomery",
    "metadata": {},
    "source": [
     "#### Print out country names in Africa to select from"
@@ -283,7 +283,7 @@
   {
    "cell_type": "code",
    "execution_count": 4,
-   "id": "needed-software",
+   "id": "foster-institution",
    "metadata": {},
    "outputs": [
     {
@@ -591,7 +591,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "recognized-causing",
+   "id": "discrete-england",
    "metadata": {},
    "source": [
     "#### Select a country in Africa to plot with corresponding data tiles"
@@ -600,7 +600,7 @@
   {
    "cell_type": "code",
    "execution_count": 5,
-   "id": "visible-lightning",
+   "id": "imported-haven",
    "metadata": {},
    "outputs": [
     {
@@ -660,7 +660,7 @@
   {
    "cell_type": "code",
    "execution_count": 6,
-   "id": "special-lithuania",
+   "id": "oriented-planner",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -670,7 +670,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "republican-plastic",
+   "id": "soviet-merchandise",
    "metadata": {},
    "source": [
     "#### Read in the CCI Biomass data for this AOI from the downloaded CCI Biomass tiles, mosaicing multiple tiles as necessary"
@@ -678,28 +678,10 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 11,
-   "id": "driving-universe",
+   "execution_count": 7,
+   "id": "suited-computer",
    "metadata": {},
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "class      : RasterBrick \n",
-       "dimensions : 21188, 21454, 454567352, 2  (nrow, ncol, ncell, nlayers)\n",
-       "resolution : 0.0008888889, 0.0008888889  (x, y)\n",
-       "extent     : 12.21067, 31.28089, -13.45867, 5.375111  (xmin, xmax, ymin, ymax)\n",
-       "crs        : +proj=longlat +datum=WGS84 +no_defs \n",
-       "source     : r_tmp_2021-11-29_195041_783_44667.tif \n",
-       "names      : agbd_2020, agbd_sd_2020 \n",
-       "min values :         0,            0 \n",
-       "max values :       552,         1068 \n"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "cci <- readCCI(data_folder=cci_folder, year=\"2020\", version=3, aoi=aoi)\n",
     "cci"
@@ -707,7 +689,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "numeric-omaha",
+   "id": "ceramic-anchor",
    "metadata": {},
    "source": [
     "#### Plot the CCI AGBD for 2020"
@@ -716,16 +698,16 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "regular-ethics",
+   "id": "intense-palmer",
    "metadata": {},
    "outputs": [],
    "source": [
-    "plot(cci$agbd_2020, main=\"CCI AGBD 2020\", zlim=c(0,250)); plot(aoi, add=T)"
+    "plot(cci$agbd_2020, main=\"CCI AGBD 2020\", zlim=c(0,300)); plot(aoi, add=T)"
    ]
   },
   {
    "cell_type": "markdown",
-   "id": "robust-costa",
+   "id": "stylish-iceland",
    "metadata": {},
    "source": [
     "#### Read in the NCEO Biomass data for this AOI from the downloaded data. NCEO data is stored as a single file for the continent of Africa, rather than multiple tiles."
@@ -733,34 +715,10 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 12,
-   "id": "spanish-permission",
+   "execution_count": null,
+   "id": "approximate-swiss",
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "[1] \"/projects/shared-buckets/minord/data/nceo_africa_biomass/clipped/AGB_map_2017v0m.tif\"\n"
-     ]
-    },
-    {
-     "ename": "ERROR",
-     "evalue": "Error in rgdal::getRasterData(object@file@con, offset = offs, region.dim = reg, : Failure during raster IO\n\n",
-     "output_type": "error",
-     "traceback": [
-      "Error in rgdal::getRasterData(object@file@con, offset = offs, region.dim = reg, : Failure during raster IO\n\nTraceback:\n",
-      "1. crop(stack(filenames_nceo), aoi)",
-      "2. crop(stack(filenames_nceo), aoi)",
-      "3. .local(x, y, ...)",
-      "4. getValuesBlock(x, row = tr$row[i] + row1 - 1, nrows = tr$nrows[i], \n .     col1, nc)",
-      "5. getValuesBlock(x, row = tr$row[i] + row1 - 1, nrows = tr$nrows[i], \n .     col1, nc)",
-      "6. .local(x, ...)",
-      "7. .readRasterLayerValues(xx, row, nrows, col, ncols)",
-      "8. rgdal::getRasterData(object@file@con, offset = offs, region.dim = reg, \n .     band = object@data@band)"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "nceo_file <- 'AGB_map_2017v0m.tif'\n",
     "# nceo_sd_file <- 'SD_map_2017v0m.tif'\n",
@@ -786,7 +744,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "acute-complex",
+   "id": "excess-customer",
    "metadata": {},
    "source": [
     "#### Plot the NCEO AGBD for 2017"
@@ -795,7 +753,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "natural-tuner",
+   "id": "representative-detective",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -805,7 +763,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "major-definition",
+   "id": "delayed-functionality",
    "metadata": {},
    "source": [
     "#### Read in the JPL Biomass data for this AOI"
@@ -814,7 +772,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "stock-toolbox",
+   "id": "freelance-solid",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -848,7 +806,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "tender-juice",
+   "id": "satisfied-picnic",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -862,7 +820,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "sharp-blood",
+   "id": "cultural-columbia",
    "metadata": {},
    "source": [
     "#### Plot the JPL AGBD for 2020"
@@ -870,40 +828,17 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
-   "id": "fewer-issue",
+   "execution_count": null,
+   "id": "valuable-performer",
    "metadata": {},
-   "outputs": [
-    {
-     "ename": "ERROR",
-     "evalue": "Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'jpl_corr' not found\n",
-     "output_type": "error",
-     "traceback": [
-      "Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'jpl_corr' not found\nTraceback:\n",
-      "1. plot(jpl_corr$agbd_2020, main = \"JPL AGBD 2020\", zlim = c(0, \n .     500))",
-      "2. .handleSimpleError(function (cond) \n . .Internal(C_tryCatchHelper(addr, 1L, cond)), \"object 'jpl_corr' not found\", \n .     base::quote(plot(jpl_corr$agbd_2020, main = \"JPL AGBD 2020\", \n .         zlim = c(0, 500))))",
-      "3. h(simpleError(msg, call))"
-     ]
-    },
-    {
-     "ename": "ERROR",
-     "evalue": "Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'aoi' not found\n",
-     "output_type": "error",
-     "traceback": [
-      "Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'aoi' not found\nTraceback:\n",
-      "1. plot(aoi, add = T)",
-      "2. .handleSimpleError(function (cond) \n . .Internal(C_tryCatchHelper(addr, 1L, cond)), \"object 'aoi' not found\", \n .     base::quote(plot(aoi, add = T)))",
-      "3. h(simpleError(msg, call))"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "plot(jpl_corr$agbd_2020, main=\"JPL AGBD 2020\", zlim=c(0,500)); plot(aoi, add=T)"
    ]
   },
   {
    "cell_type": "markdown",
-   "id": "plastic-making",
+   "id": "elder-pickup",
    "metadata": {},
    "source": [
     "#### Read in forest cover raster. Currently using 30% forest cover from Hansen product. The cover rasters have been resampled to the resolutions of CCI Biomass, JPL Biomass, and NCEO Biomass for use as a forest cover mask."
@@ -912,7 +847,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "funny-tournament",
+   "id": "brave-funeral",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -923,7 +858,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "growing-center",
+   "id": "impressed-header",
    "metadata": {},
    "source": [
     "#### Create 30% cover forest threshold mask for CCI"
@@ -932,7 +867,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "chinese-travel",
+   "id": "smooth-repair",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -945,7 +880,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "permanent-recognition",
+   "id": "mathematical-performance",
    "metadata": {},
    "source": [
     "#### Create 30% cover forest threshold mask for JPL"
@@ -954,7 +889,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "joint-correction",
+   "id": "religious-mitchell",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -967,7 +902,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "impossible-estate",
+   "id": "moral-nigeria",
    "metadata": {},
    "source": [
     "#### Create 30% cover forest threshold mask for NCEO"
@@ -976,7 +911,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "demographic-mobile",
+   "id": "convinced-appeal",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -990,7 +925,7 @@
   {
    "cell_type": "code",
    "execution_count": 28,
-   "id": "center-toronto",
+   "id": "mobile-fashion",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -1001,7 +936,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "aging-mortality",
+   "id": "adult-begin",
    "metadata": {},
    "source": [
     "### Checkpoint: Write out and read in Forest cover threshold mask for CCI and JPL"
@@ -1010,7 +945,7 @@
   {
    "cell_type": "code",
    "execution_count": 29,
-   "id": "facial-bermuda",
+   "id": "therapeutic-shoot",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -1029,7 +964,7 @@
   {
    "cell_type": "code",
    "execution_count": 8,
-   "id": "according-richards",
+   "id": "sound-muslim",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -1051,7 +986,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "purple-error",
+   "id": "mediterranean-phone",
    "metadata": {},
    "source": [
     "#### Apply the forest cover threshold mask to CCI, JPL, and NCEO"
@@ -1060,7 +995,7 @@
   {
    "cell_type": "code",
    "execution_count": 9,
-   "id": "pharmaceutical-oxygen",
+   "id": "rental-chapel",
    "metadata": {},
    "outputs": [
     {
@@ -1088,7 +1023,7 @@
   {
    "cell_type": "code",
    "execution_count": 10,
-   "id": "killing-apache",
+   "id": "martial-private",
    "metadata": {},
    "outputs": [
     {
@@ -1138,15 +1073,15 @@
     }
    ],
    "source": [
-    "plot(cci$agbd_2020, zlim=c(0,500), main=\"CCI biomass\"); plot(aoi, add=T)\n",
+    "plot(cci$agbd_2020, zlim=c(0,300), main=\"CCI biomass\"); plot(aoi, add=T)\n",
     "plot(gfc_cci_thresholded$forest2020, main=\"forest mask\"); plot(aoi, add=T)\n",
-    "plot(cci_thresholded$agbd_2020, zlim=c(0,500), main=\"CCI masked\"); plot(aoi, add=T)"
+    "plot(cci_thresholded$agbd_2020, zlim=c(0,300), main=\"CCI masked\"); plot(aoi, add=T)"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": 15,
-   "id": "secure-dating",
+   "id": "distant-newman",
    "metadata": {},
    "outputs": [
     {
@@ -1174,7 +1109,7 @@
   {
    "cell_type": "code",
    "execution_count": 16,
-   "id": "placed-handbook",
+   "id": "written-harris",
    "metadata": {},
    "outputs": [
     {
@@ -1232,7 +1167,7 @@
   {
    "cell_type": "code",
    "execution_count": 17,
-   "id": "bibliographic-event",
+   "id": "regulation-entry",
    "metadata": {},
    "outputs": [
     {
@@ -1260,7 +1195,7 @@
   {
    "cell_type": "code",
    "execution_count": 18,
-   "id": "spread-assets",
+   "id": "systematic-violation",
    "metadata": {},
    "outputs": [
     {
@@ -1317,7 +1252,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "romance-shannon",
+   "id": "worldwide-edinburgh",
    "metadata": {},
    "source": [
     "### Checkpoint: Write out and read in Forest only biomass for CCI, JPL, and NCEO"
@@ -1326,7 +1261,7 @@
   {
    "cell_type": "code",
    "execution_count": 19,
-   "id": "authentic-raleigh",
+   "id": "chubby-black",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -1345,7 +1280,7 @@
   {
    "cell_type": "code",
    "execution_count": 7,
-   "id": "waiting-canyon",
+   "id": "thermal-brook",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -1367,7 +1302,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "surprising-resolution",
+   "id": "liberal-reynolds",
    "metadata": {},
    "source": [
     "#### Mask to country shape"
@@ -1376,7 +1311,7 @@
   {
    "cell_type": "code",
    "execution_count": 8,
-   "id": "blank-browse",
+   "id": "impaired-president",
    "metadata": {},
    "outputs": [],
    "source": [
@@ -1391,7 +1326,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "controlling-testimony",
+   "id": "african-floating",
    "metadata": {},
    "source": [
     "#### Plot forest biomass map and histogram of biomass density for CCI, JPL, and NCEO"
@@ -1400,7 +1335,7 @@
   {
    "cell_type": "code",
    "execution_count": 9,
-   "id": "experienced-essay",
+   "id": "expanded-module",
    "metadata": {},
    "outputs": [
     {
@@ -1438,7 +1373,7 @@
     "par(mfrow=c(2,2), mai=c(0.5,0.5,0.5,0.5))\n",
     "options(repr.plot.width=15, repr.plot.height=15)\n",
     "\n",
-    "plot(cci_masked$agbd_2020, main=\"CCI AGBD 2020 (cover>30%)\", zlim=c(0,500) ); plot(aoi, add=T)\n",
+    "plot(cci_masked$agbd_2020, main=\"CCI AGBD 2020 (cover>30%)\", zlim=c(0,300) ); plot(aoi, add=T)\n",
     "\n",
     "val.cci2020 <- ff(getValues(cci_masked$agbd_2020))\n",
     "hist(val.cci2020[,3][val.cci2020[,3]>0], freq=F,\n",
@@ -1463,7 +1398,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "irish-genome",
+   "id": "robust-cartoon",
    "metadata": {},
    "source": [
     "#### Calculate total aboveground biomass and average aboveground biomass density for 2020 CCI and JPL biomass for the selected country"
@@ -1472,7 +1407,7 @@
   {
    "cell_type": "code",
    "execution_count": 13,
-   "id": "urban-approval",
+   "id": "recognized-spice",
    "metadata": {},
    "outputs": [
     {
@@ -1508,7 +1443,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "presidential-zoning",
+   "id": "endless-withdrawal",
    "metadata": {},
    "source": [
     "#### Print out basic forest aboveground biomass statistics for the selected country\n"
@@ -1517,7 +1452,7 @@
   {
    "cell_type": "code",
    "execution_count": 14,
-   "id": "balanced-textbook",
+   "id": "political-narrative",
    "metadata": {},
    "outputs": [
     {
@@ -1556,7 +1491,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "selected-acoustic",
+   "id": "normal-bahrain",
    "metadata": {},
    "source": [
     "## The following is old code I'm keeping here for reference purposes"
@@ -1564,7 +1499,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "thrown-framework",
+   "id": "committed-coupon",
    "metadata": {},
    "source": [
     "#### Calculate total aboveground biomass and average aboveground biomass density for 2020 CCI and NCEO biomass for the selected country"
@@ -1573,7 +1508,7 @@
   {
    "cell_type": "code",
    "execution_count": 23,
-   "id": "imperial-endorsement",
+   "id": "unlikely-tuition",
    "metadata": {
     "collapsed": true,
     "jupyter": {
@@ -1785,7 +1720,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "exempt-sandwich",
+   "id": "wooden-welding",
    "metadata": {},
    "source": [
     "#### Print out basic forest aboveground biomass statistics for the selected country\n",
@@ -1795,7 +1730,7 @@
   {
    "cell_type": "code",
    "execution_count": 24,
-   "id": "fabulous-president",
+   "id": "historical-windsor",
    "metadata": {},
    "outputs": [
     {
@@ -1825,7 +1760,7 @@
   {
    "cell_type": "code",
    "execution_count": 26,
-   "id": "electoral-potato",
+   "id": "signed-easter",
    "metadata": {},
    "outputs": [
     {
@@ -1872,7 +1807,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "hundred-official",
+   "id": "demographic-mexican",
    "metadata": {},
    "outputs": [],
    "source": []
-- 
GitLab