From 9dbbbaeb999bf101a83e5f4ce9c4c3a05c6481ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Grelot?= <frederic.grelot@irstea.fr>
Date: Thu, 20 Jan 2022 18:14:15 +0100
Subject: [PATCH] catnat, population, clc
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- catnat dataset remplace gaspar dataset
	- passage en array pour garder les types d'aléa
- estimate_catnat_freq incluse dans la librairie
- population dataset pour la population
- clc_color dataset pour les couleurs et label de clc
- map_so_ii inclus population, gère les légendes pour les thèmes
- dossier script hors librairie por garder la trace des mises à jour des données (doit aller dand floodam.data)

0 errors ✔ | 0 warnings ✔ | 1 note ✖
Mais la note concerne le temps...
---
 geau/NAMESPACE                   |   1 +
 geau/R/data.r                    |  39 +++++++++--
 geau/R/estimate_catnat_freq.R    |  47 +++++++++++++
 geau/R/map_so_ii.r               | 116 +++++++++++++++++++++++++++++--
 geau/data-raw/so_ii_catnat.R     |  29 ++++++++
 geau/data-raw/so_ii_population.R |  32 +++++++++
 geau/data-raw/so_ii_scope.R      |  42 +++++++----
 geau/data/clc_color.rda          | Bin 0 -> 329 bytes
 geau/data/so_ii_catnat.rda       | Bin 0 -> 864 bytes
 geau/data/so_ii_gaspar.rda       | Bin 795 -> 0 bytes
 geau/data/so_ii_population.rda   | Bin 0 -> 5274 bytes
 geau/man/clc_color.Rd            |  16 +++++
 geau/man/estimate_catnat_freq.Rd |  36 ++++++++++
 geau/man/map_so_ii.Rd            |  17 +++--
 geau/man/so_ii_catnat.Rd         |  25 +++++++
 geau/man/so_ii_gaspar.Rd         |  17 -----
 geau/man/so_ii_population.Rd     |  23 ++++++
 map_so_ii.rmd                    |  18 +++--
 script/gaspar.R                  |  89 ++++++++++++++++++++++++
 19 files changed, 492 insertions(+), 55 deletions(-)
 create mode 100644 geau/R/estimate_catnat_freq.R
 create mode 100644 geau/data-raw/so_ii_catnat.R
 create mode 100644 geau/data-raw/so_ii_population.R
 create mode 100644 geau/data/clc_color.rda
 create mode 100644 geau/data/so_ii_catnat.rda
 delete mode 100644 geau/data/so_ii_gaspar.rda
 create mode 100644 geau/data/so_ii_population.rda
 create mode 100644 geau/man/clc_color.Rd
 create mode 100644 geau/man/estimate_catnat_freq.Rd
 create mode 100644 geau/man/so_ii_catnat.Rd
 delete mode 100644 geau/man/so_ii_gaspar.Rd
 create mode 100644 geau/man/so_ii_population.Rd
 create mode 100644 script/gaspar.R

diff --git a/geau/NAMESPACE b/geau/NAMESPACE
index 2862409..f4d57d0 100644
--- a/geau/NAMESPACE
+++ b/geau/NAMESPACE
@@ -2,5 +2,6 @@
 
 export(add.inset)
 export(current_version)
+export(estimate_catnat_freq)
 export(kable_units)
 export(map_so_ii)
diff --git a/geau/R/data.r b/geau/R/data.r
index 09a94a9..3395972 100644
--- a/geau/R/data.r
+++ b/geau/R/data.r
@@ -50,17 +50,44 @@
 #' }
 "so_ii_limit"
 
-#' Flood frequency for the municipalities of so-ii
+#' Population for so-ii
 #'
-#' A dataset containing the flood frequency by year and so-ii municipality 
-#' according to the GASPAR database.
+#' A dataset containing the population of commune in so-ii according to INSEE.
 #'
-#' @format matrix 78 rows, 41 variables
-"so_ii_gaspar"
+#' @format numeric matrix
+#' \describe{
+#'   \item{row}{commune as in so_ii_scope}
+#'   \item{column}{year}
+#' }
+#'
+#' @source \url{https://www.insee.fr/fr/statistiques/2522602}
+"so_ii_population"
+
+#' Number of Cat Nat events for the municipalities of so-ii
+#'
+#' A dataset containing the number of Cat Nat events (linked to flood) by year
+#' and so-ii municipality according to the GASPAR database.
+#'
+#' @format array with 3 dimensions
+#' \describe{
+#'   \item{first}{commune as in so_ii_scope}
+#'   \item{second}{year of Cat Nat events}
+#'   \item{third}{type of hazard}
+#' }
+#'
+#' @source \url{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar}
+"so_ii_catnat"
 
 #' CLC information for so-ii
 #'
 #' A dataset containing the 2018 version of CLC information for so-ii
 #'
 #' @format sf object
-"so_ii_clc"
\ No newline at end of file
+"so_ii_clc"
+
+#' Color and label for CLC
+#'
+#' A dataset proposing default colors and labels for plotting CLC
+#'
+#' @format data.frame 5 rows, 3 variables
+"clc_color"
\ No newline at end of file
diff --git a/geau/R/estimate_catnat_freq.R b/geau/R/estimate_catnat_freq.R
new file mode 100644
index 0000000..4a1c457
--- /dev/null
+++ b/geau/R/estimate_catnat_freq.R
@@ -0,0 +1,47 @@
+#' @title Estimate frequency of Cat Nat events
+#' 
+#' @param commune factor, commune
+#' @param period POSIXct, a date for the event
+#' @param hazard factor, type of hazard
+#' @param period_format character, format to extract information from period
+#'
+#' @return array fivving frequency of Cat Nat events with 3 dimensions
+#'      (commune, period, hazard)
+#'
+#' @export
+#'
+#' @encoding UTF-8
+#' @author Frédéric Grelot
+#' @author David Nortes Martinez
+#' 
+#' @examples
+#' 
+#' \dontrun{
+#' # To be added (soon)
+#' }
+ 
+estimate_catnat_freq = function(
+    commune,
+    period,
+    hazard,
+    period_format = "%Y"
+) {
+    period = format(as.Date(period), period_format)
+    period_levels = switch(
+        EXPR = period_format,
+        "%Y" = formatC(
+            1982:as.integer(format(Sys.Date(),"%Y")),
+            width = 4, format = "d", flag = "0"
+        ),
+        "%m" = formatC(1:12, width = 2, format = "d", flag = "0"),
+        sort(unique(as.character(period)))
+    )
+    result = data.frame(
+        commune = commune,
+        period = factor(period, levels = period_levels),
+        hazard = hazard
+    )
+    result = table(result)
+    class(result) = "array"
+    return(result)
+}
diff --git a/geau/R/map_so_ii.r b/geau/R/map_so_ii.r
index 21aec3d..23713be 100644
--- a/geau/R/map_so_ii.r
+++ b/geau/R/map_so_ii.r
@@ -1,11 +1,16 @@
 #' @title Plot a thematic map of so-ii
 #' 
+#' @details 
+#' hazard must be chosen in c("inondation", "submersion", "nappe").
+#' 
 #' @param dataset sf objectf, data to be plotted
 #' @param dataset_legend list of parameters to be passed to legend
 #' @param theme character, choice for the theme (if any)
-#' @param bar logical, should a bar be plotted
+#' @param bar logical, should a bar be plotted for the dataset
 #' @param path character, the name of the file to save the plot
-#' @param gaspar_year character, the year chosen for gaspar theme
+#' @param legend_theme logical, should a legend be plotted for the theme
+#' @param year character, the year chosen for some themes (catnat, population)
+#' @param hazard character, type of hazard chosen (if any). See details.
 #' @param ...  some parameters that will be used by plot (from sf)
 #'
 #' @return Nothing useful.
@@ -24,10 +29,12 @@
 map_so_ii = function(
     dataset,
     dataset_legend = NULL,
-    theme = c("clc", "gaspar"),
+    theme = "clc",
     bar = TRUE,
     path = NULL,
-    gaspar_year,
+    legend_theme = FALSE,
+    year,
+    hazard,
     ...
 ) {
 
@@ -52,18 +59,101 @@ map_so_ii = function(
             col = geau::so_ii_clc[["color"]],
             add = TRUE
         )
+
+        theme_legend = list(
+            title = "CLC (2018)",
+            legend = geau::clc_color[["label_fr"]],
+            x = "topright",
+            cex = .8,
+            bg = "white",
+            inset = 0.01,
+            fill = geau::clc_color[["color"]]
+        )
     }
 
-    if ("gaspar" %in% theme) {
+    if ("population" %in% theme) {
+        if (missing(year)) {
+            year = utils::tail(sort(colnames(geau::so_ii_population)), 1)
+        }
+        population_palette = scales::colour_ramp(c("white", "red"), alpha = .5)
+        color = matrix(
+            scales::cscale(
+                geau::so_ii_population,
+                population_palette,
+                trans = scales::log_trans()),
+            nrow = nrow(geau::so_ii_population),
+            dimnames = dimnames(geau::so_ii_population)
+        )
+        border = "grey80"
+        plot(
+            geau::so_ii_commune[["geometry"]],
+            border = border,
+            col = color[ , year],
+            add = TRUE
+        )
+
+        value_legend = c(100, 1000, 10000, 100000, 250000)
+        color_legend = scales::cscale(
+                c(range(geau::so_ii_population), value_legend),
+                population_palette,
+                trans = scales::log_trans()
+            )[-(1:2)]
+        text_legend = formatC(
+            as.integer(value_legend),
+            big.mark = " "
+        )
+
+        theme_legend = list(
+            title = sprintf("Population %s", year),
+            legend = rep("", length(text_legend)),
+            x = "topright",
+            cex = .8,
+            bg = "white",
+            inset = 0.01,
+            fill = color_legend,
+            border = border,
+            text.width = graphics::strwidth(utils::tail(text_legend, 1))
+        )
+    }
+
+    if ("catnat" %in% theme) {
         border = NA
         color = NA
-        if (!missing(gaspar_year)) {
+        if (!missing(year)) {
             border = "grey80"
+            if (missing(hazard)) {
+                hazard = dimnames(geau::so_ii_catnat)[["hazard"]]
+            } else {
+                hazard = intersect(
+                    hazard,
+                    dimnames(geau::so_ii_catnat)[["hazard"]]
+                )
+                if (length(hazard) == 0) {
+                    hazard = dimnames(geau::so_ii_catnat)[["hazard"]]
+                }
+            }
+
+            catnat = apply(
+                geau::so_ii_catnat[, as.character(year), hazard, drop = FALSE],
+                1:2,
+                sum
+            )
             color = ifelse(
-                geau::so_ii_gaspar[ , as.character(gaspar_year)] > 0,
+                catnat > 0,
                 scales::alpha("grey80", .5),
                 NA
             )
+
+            theme_legend = list(
+                title = sprintf("Cat-Nat %s", year),
+                legend = c("Sans d\u00e9claration", "Avec d\u00e9claration"),
+                x = "topright",
+                cex = .8,
+                bg = "white",
+                inset = 0.01,
+                fill = unique(color),
+                border = border
+            )
         }
 
         plot(
@@ -98,5 +188,17 @@ map_so_ii = function(
         do.call(graphics::legend, dataset_legend)
     }
 
+    if (legend_theme == TRUE && exists("theme_legend")) {
+        temp = do.call(graphics::legend, theme_legend)
+        if (exists("text_legend")) {
+            graphics::text(
+                x = temp[["rect"]][["left"]] + temp[["rect"]][["w"]],
+                y = temp[["text"]][["y"]],
+                labels = text_legend,
+                pos = 2
+            )
+        }
+    }
+
     return(invisible(NULL))
 }
diff --git a/geau/data-raw/so_ii_catnat.R b/geau/data-raw/so_ii_catnat.R
new file mode 100644
index 0000000..eaf53df
--- /dev/null
+++ b/geau/data-raw/so_ii_catnat.R
@@ -0,0 +1,29 @@
+# code to prepare `so_ii_catnat` dataset goes here
+
+so_ii_catnat = read.csv2(
+    geau::current_version("data-common/so-ii/gaspar", "catnat-")
+)
+
+alea_scope = c("inondation", "nappe", "submersion")
+so_ii_catnat = so_ii_catnat[ so_ii_catnat[["alea"]] %in% alea_scope, ]
+
+so_ii_catnat[["commune"]] = factor(
+    so_ii_catnat[["commune"]],
+    levels = so_ii_scope
+)
+so_ii_catnat[["alea"]] = factor(
+    so_ii_catnat[["alea"]],
+    levels = alea_scope
+)
+
+so_ii_catnat = estimate_catnat_freq(
+    so_ii_catnat[["commune"]],
+    so_ii_catnat[["date.start"]],
+    so_ii_catnat[["alea"]]
+)
+
+# updating datasets
+
+actual = setwd("geau")
+usethis::use_data(so_ii_catnat, internal = FALSE, overwrite = TRUE)
+setwd(actual)
\ No newline at end of file
diff --git a/geau/data-raw/so_ii_population.R b/geau/data-raw/so_ii_population.R
new file mode 100644
index 0000000..a771c06
--- /dev/null
+++ b/geau/data-raw/so_ii_population.R
@@ -0,0 +1,32 @@
+# code to prepare `so_ii_population` dataset goes here
+
+so_ii_population = readxl::read_xlsx(
+    geau::current_version(
+        "data-common/data/INSEE/Population/Historique",
+        "base-pop-historique"
+    ),
+    sheet = 1,
+    skip = 5,
+)
+class(so_ii_population) = "data.frame"
+rownames(so_ii_population) = so_ii_population[["CODGEO"]]
+selection = grep(
+    "PMUN|PSCDC|PTOT",
+    colnames(so_ii_population),
+    value = TRUE
+)
+so_ii_population = as.matrix(
+    so_ii_population[geau::so_ii_scope, selection]
+)
+year = gsub("PMUN", "20", selection)
+year = gsub("PTOT", "19", year)
+year = gsub("1919", "19", year)
+year = gsub("1918", "18", year)
+dimnames(so_ii_population)[[2]] = year
+
+# updating datasets
+
+# actual = setwd(file.path(system.file(package = "geau"), ".."))
+actual = setwd("geau")
+usethis::use_data(so_ii_population, internal = FALSE, overwrite = TRUE)
+setwd(actual)
diff --git a/geau/data-raw/so_ii_scope.R b/geau/data-raw/so_ii_scope.R
index 7fe7810..c69a390 100644
--- a/geau/data-raw/so_ii_scope.R
+++ b/geau/data-raw/so_ii_scope.R
@@ -24,26 +24,40 @@ so_ii_limit = sf::st_union(so_ii_commune)
 so_ii_clc = readRDS("data-common/data/so-ii/so-ii_clc.rds")
 so_ii_clc = so_ii_clc["code_18"]
 names(so_ii_clc) = c("clc_2018", "geometry")
-color = scales::alpha(c("red3", "darkolivegreen3", "darkgreen", "#4C90B4", "lightblue"), .2)
+clc_color = data.frame(
+    color = scales::alpha(
+        c(
+            "red3",
+            "darkolivegreen3",
+            "darkgreen",
+            "#4C90B4",
+            "lightblue"
+        ),
+        .2
+    ),
+    label_fr = c(
+        "Zone urbaine",
+        "Zone agricole",
+        "Forêt, zone naturelle",
+        "Zone humide",
+        "Surface d'eau"
+    ),
+    label_uk = c(
+        "Urban area",
+        "Agricultural area",
+        "Forest, natural area",
+        "Humid area",
+        "Water surface"
+    )
+) 
 so_ii_clc[["color"]] = as.character(
     cut(
         as.integer(substr(so_ii_clc[["clc_2018"]], 1, 1)), 
         breaks = 5,
-        labels = color
+        labels = clc_color[["color"]]
     )
 )
 
-# code to prepare `so_ii_gaspar` dataset goes here
-
-so_ii_gaspar = read.csv2(
-    current_version("data-common/so-ii/gaspar", "catnat_year_n"),
-    header = TRUE,
-    row.names = 1
-)
-so_ii_gaspar = as.matrix(so_ii_gaspar)
-colnames(so_ii_gaspar) = gsub("^X", "", colnames(so_ii_gaspar))
-so_ii_gaspar = so_ii_gaspar[so_ii_scope, ]
-
 # updating datasets
 
 # actual = setwd(file.path(system.file(package = "geau"), ".."))
@@ -52,5 +66,5 @@ usethis::use_data(so_ii_scope, internal = FALSE, overwrite = TRUE)
 usethis::use_data(so_ii_commune, internal = FALSE, overwrite = TRUE)
 usethis::use_data(so_ii_limit, internal = FALSE, overwrite = TRUE)
 usethis::use_data(so_ii_clc, internal = FALSE, overwrite = TRUE)
-usethis::use_data(so_ii_gaspar, internal = FALSE, overwrite = TRUE)
+usethis::use_data(clc_color, internal = FALSE, overwrite = TRUE)
 setwd(actual)
diff --git a/geau/data/clc_color.rda b/geau/data/clc_color.rda
new file mode 100644
index 0000000000000000000000000000000000000000..468f6fb9fd841f01298b3298699aa43ff82fe708
GIT binary patch
literal 329
zcmV-P0k-}^T4*^jL0KkKS;lGd)Bpgr|J43|Z2(AxUtm8#8qmM*o{&HQ01yZO012=G
z7@{Jl=`@+Ch+;HoWDNrhri}wbCX9zLm;}HHgu-cn00haVfrO@#Pf@AiG7vNX$)IR7
z449aj4in2gFtVCv13F|wP5B#d@8t{{v;4sz0VWENS2~F>U4iWHY19%eS_Zr`2nOd&
z4#k&g5HmFCn<6?>4MI0GW&3y-6>0Zaj<UU%8_%~C3~e3TK_L@uQlQr*P?DF3#F>)G
zY!qH@M?`yLAc~|qJn9V~9Ij|GXu{oNz${?;uuEjZMHumF(+4KJ^=p)-f<)7XT8Fu4
zcB3_1mh2HE_eIk&NwT>dj9Ch6(-&eAwxjV(X)VORO(U&#!R#Yp#S1!ARZ!a_P>uTb
bZN5s4`EvW~UK<ht0sb!Jig2MJjML?)Z!wMY

literal 0
HcmV?d00001

diff --git a/geau/data/so_ii_catnat.rda b/geau/data/so_ii_catnat.rda
new file mode 100644
index 0000000000000000000000000000000000000000..4083200d81d8518fd6c2633a328c1d012148d4de
GIT binary patch
literal 864
zcmV-m1E2gtT4*^jL0KkKS(agBA^-?wfB*mf$cT!d|Llwjn83d4-Wmdk0EmPPh=>RP
z2to=82nkRF*dAwToDI>;K?P55Qc2-8Js<!EnE(I)28N9q7-a^g$RQ;F0000ChJerj
z0001!N`xrUpa26v00ThNO#lD@8V)jGni&j?jG7t%&}3l%&}h>kh-d(jD5t6Dfv2PZ
zXwU!v13&-(00tF`5kf2$V3ieAO4@}%V#o>$76rCKRzRo<vPCvkg2J#UkyZ><MHs6W
z%*uePAr=5BB1wX{qb(qz1rewfsHIR<6%~RaRwyk5i4;Xv(xN3x6m1G1n`RSZ8+25^
zs#6jIr6!P)gaE;$4#WVs@hi<JglNwQ2_ggtHvfn~By!S#5;&kynUR^qghWJUQXv@`
zl(I#w9=&~w7HnAn0000000000001jIIZhBLHBCjaty<pKygADdHc6E8NnwzDDo+zm
zTB?##UTTx#qYO^1#`48kTtyTh1Xe%*(hvoecq1z!D>-(UO(XBmJ~}KSOhOE-TJBxV
ztjDm(beZUtr&T{ue3iSCr8pXkW%Pj25$%l{1PEF@c_J=(i!7RfKJ>1|DXM30E+^h>
zFhu3O81~GzvAnpExye@BB83v3zNbfmJXFQ4F<rQ)P^|gnuR6--g04~IABQ3-v9#{X
zhKt%&3iSD_M<zBEv56LHT}&>0&B5wn$acA9@Y&MMh1t!f=uHe&G^t>^$x>r%ixdr}
zicA=Gv)nOk3N>?P*~biMprEkGw9W}vgK=gEssfR9Su;2)ELGJ>AW!l@Abqv0ki`iW
zNew-He6}&W9X}>G=SVEc6j@NEQHt{|V`+{WGRsB8%pwXVG^`UU7aA7^BXTSQ-ti&c
z_?fziTB7;L77*5Sh$YwyD4JPPk*hjWOEo@8=d}h*(IX?l0wJJHf^*&$a}*;vt))&X
zz*sW?EEt9Z4~K<U!kGf#f^P2OTCszOc(mZ-4xXk_b9p$>!v<#}u$COX)Tt)Gvl5v@
z&U1A*xuPz>vL?#JNQ7j<BD#iFknQ(h!RUWUYkvhVJNgv7XWmsM`eOW$##L%t{c*uf
qB_ir5wA7F;W`vyzS!IO32%?UOT5!oq;36Xf{9VZu;X*=Lg^-AT)nnuU

literal 0
HcmV?d00001

diff --git a/geau/data/so_ii_gaspar.rda b/geau/data/so_ii_gaspar.rda
deleted file mode 100644
index b043d07338c1978285be83914c7af4282819f5b2..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 795
zcmV+$1LXWdT4*^jL0KkKS;+m?oB#)I|Ns8}$cTub|Llwjn82>9*a-rN0EmDL2#5#(
z06+=|2nkRFd<5+?&a0(y1kqF5)TywOH4P6?G}=G_0iXlaX{WVAjF~iI7@A-pU`;Sa
z35lkf05F72kc5Z;13&{n8UWA$00f#;6+J@`G8q~GF#uu#pc)u}B{G@>q+|fd000bX
zWY7RK1Jq$yvI-GkvjnJ$iCbA!1uIelg2f?i2q`NeDzZgCs=*jm1!PcFixgf469sWm
zQWb<0OGs9+N}#b6RtSk$ptdArR8?&%A~x8F+7v-L9PK<YiXyrp0Mq3%LQ4P?Ao}PN
zv6sUL5b<kL1~!C;XZ=DF90>vzx*3^~l;~t;W<??ykr_<cHtu2E#a=q`fB*mh00000
z0000Q5D#O-j1FUwTIVXk(13f?Nbm#}iIY_*)iW&dHVZk-lL4Z0Em^%(3u&pTAs}^#
zNfH4Lrp+&NwR-M8hG&DnpL;I?Wtev;ra@@T%_%6~QkyE%0NT1*=?QsW$S9VA)vR<^
zXI~ewU0obl&wbv2RYJl6=1kZJ4Sw`{>B31~utvexRn2!kbkBNS_-xtek?rh!|I^Bn
z(|EruW8%uGqYWxq63F>HM@w33*Y>i!zi7ayR9k(mLqs~6Qe0{=iCXmK<=5x0OHu2#
z%EB;#B#oO;qzP{!qAJ`%P>>m`B8WVfbd<;#n)crM=9OszK$IDlnj<RfV}!wqpeYu4
z(p>FSSfsrQ00{4>Ab>dcoJ10UfZElnyb}0495XjaEXfpEP^D3d_U&V7jv6w{Ma0ZP
z1cXZ(ffZoogQ90JfSh8sCUKiZ3&FPZvcyRvteB91GNMR`W|WG`b%u*NDNA6BC@6>Z
zfPtt8NFietrkYmebkh8r+c$uLARtUZnatLg#%XH?1~-YBEU%or)?QIjTCr)w5W<iv
zXgZ>+1f5B%2BCuhNdl(msadv~VwTPw*@QJl;*bdtOa~f+;G^l`n%iUJA>hkm<_T#j
Zt*Goov2<08LLwsn7ji{7P>{&|)|{sIR)YWl

diff --git a/geau/data/so_ii_population.rda b/geau/data/so_ii_population.rda
new file mode 100644
index 0000000000000000000000000000000000000000..bc3a1b17f4b91879f41c30609c3c58215fe403f4
GIT binary patch
literal 5274
zcmV;L6lLo|T4*^jL0KkKS(eMKrT`rL|NsC0|NnpA|NsC0|NsC0|NsC0|NsC0|NsC0
z|MmTSfB)bQ|9$V0D)fC0hLX6Y@#)78y!7kNc@!Z%R7D&k=-rfV+yGS2nE+J%4JN=7
zQRJSf?IuT&PgB!RO;hxz=}$@Ni9b}^RBfi3k@%77pQ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yw=)%P0m6
z;Q(PQUAwf}+ujjzGVr|=46SjO0@+b%l(<hB>caCkdD3>p?vJt3&myb_8i=Wg9p}0r
zA&afWY9T?l(Jyu);AZMKDL96E>u4xonajwIf>mRUjE8YlSjcAQoOr`rir%boo1`j%
zc(LcJCv^65sI{+DC~mC{SDAfgw|kHcZmvS)q2k1jR!*(bNXcWJl}}bqQoTjXvR1xX
zNi^jXk2z@T6I+=|f_8;#5|w>jP(~%nb<Grotrwd73D9h$MZ(6LuYgssZ)w|@@%u%x
ztA?E#U$?`jEkt4!tYt80va0f{lI$BwlY=y?JDbZl@a!O<C*4@2mp#2H2~gkK%sN7v
z^tJC+^|x6T3@GqjM6|6$LUL6h1(1Qnc#KF(v@9K54@gn!aAF~}q{*XEV}xXY?IP2Q
glZ$b*i_EQLLmOz4y5^zf0E6xqaz!{$ke17>reR^)Z2$lO

literal 0
HcmV?d00001

diff --git a/geau/man/clc_color.Rd b/geau/man/clc_color.Rd
new file mode 100644
index 0000000..35203a5
--- /dev/null
+++ b/geau/man/clc_color.Rd
@@ -0,0 +1,16 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/data.r
+\docType{data}
+\name{clc_color}
+\alias{clc_color}
+\title{Color and label for CLC}
+\format{
+data.frame 5 rows, 3 variables
+}
+\usage{
+clc_color
+}
+\description{
+A dataset proposing default colors and labels for plotting CLC
+}
+\keyword{datasets}
diff --git a/geau/man/estimate_catnat_freq.Rd b/geau/man/estimate_catnat_freq.Rd
new file mode 100644
index 0000000..79ac253
--- /dev/null
+++ b/geau/man/estimate_catnat_freq.Rd
@@ -0,0 +1,36 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/estimate_catnat_freq.R
+\encoding{UTF-8}
+\name{estimate_catnat_freq}
+\alias{estimate_catnat_freq}
+\title{Estimate frequency of Cat Nat events}
+\usage{
+estimate_catnat_freq(commune, period, hazard, period_format = "\%Y")
+}
+\arguments{
+\item{commune}{factor, commune}
+
+\item{period}{POSIXct, a date for the event}
+
+\item{hazard}{factor, type of hazard}
+
+\item{period_format}{character, format to extract information from period}
+}
+\value{
+array fivving frequency of Cat Nat events with 3 dimensions
+(commune, period, hazard)
+}
+\description{
+Estimate frequency of Cat Nat events
+}
+\examples{
+
+\dontrun{
+# To be added (soon)
+}
+}
+\author{
+Frédéric Grelot
+
+David Nortes Martinez
+}
diff --git a/geau/man/map_so_ii.Rd b/geau/man/map_so_ii.Rd
index 118e736..b063bfd 100644
--- a/geau/man/map_so_ii.Rd
+++ b/geau/man/map_so_ii.Rd
@@ -8,10 +8,12 @@
 map_so_ii(
   dataset,
   dataset_legend = NULL,
-  theme = c("clc", "gaspar"),
+  theme = "clc",
   bar = TRUE,
   path = NULL,
-  gaspar_year,
+  legend_theme = FALSE,
+  year,
+  hazard,
   ...
 )
 }
@@ -22,11 +24,15 @@ map_so_ii(
 
 \item{theme}{character, choice for the theme (if any)}
 
-\item{bar}{logical, should a bar be plotted}
+\item{bar}{logical, should a bar be plotted for the dataset}
 
 \item{path}{character, the name of the file to save the plot}
 
-\item{gaspar_year}{character, the year chosen for gaspar theme}
+\item{legend_theme}{logical, should a legend be plotted for the theme}
+
+\item{year}{character, the year chosen for some themes (catnat, population)}
+
+\item{hazard}{character, type of hazard chosen (if any). See details.}
 
 \item{...}{some parameters that will be used by plot (from sf)}
 }
@@ -36,6 +42,9 @@ Nothing useful.
 \description{
 Plot a thematic map of so-ii
 }
+\details{
+hazard must be chosen in c("inondation", "submersion", "nappe").
+}
 \examples{
 
 \dontrun{
diff --git a/geau/man/so_ii_catnat.Rd b/geau/man/so_ii_catnat.Rd
new file mode 100644
index 0000000..8fd9e90
--- /dev/null
+++ b/geau/man/so_ii_catnat.Rd
@@ -0,0 +1,25 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/data.r
+\docType{data}
+\name{so_ii_catnat}
+\alias{so_ii_catnat}
+\title{Number of Cat Nat events for the municipalities of so-ii}
+\format{
+array with 3 dimensions
+\describe{
+\item{first}{commune as in so_ii_scope}
+\item{second}{year of Cat Nat events}
+\item{third}{type of hazard}
+}
+}
+\source{
+\url{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar}
+}
+\usage{
+so_ii_catnat
+}
+\description{
+A dataset containing the number of Cat Nat events (linked to flood) by year
+and so-ii municipality according to the GASPAR database.
+}
+\keyword{datasets}
diff --git a/geau/man/so_ii_gaspar.Rd b/geau/man/so_ii_gaspar.Rd
deleted file mode 100644
index dcf936d..0000000
--- a/geau/man/so_ii_gaspar.Rd
+++ /dev/null
@@ -1,17 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/data.r
-\docType{data}
-\name{so_ii_gaspar}
-\alias{so_ii_gaspar}
-\title{Flood frequency for the municipalities of so-ii}
-\format{
-matrix 78 rows, 41 variables
-}
-\usage{
-so_ii_gaspar
-}
-\description{
-A dataset containing the flood frequency by year and so-ii municipality
-according to the GASPAR database.
-}
-\keyword{datasets}
diff --git a/geau/man/so_ii_population.Rd b/geau/man/so_ii_population.Rd
new file mode 100644
index 0000000..e2fd737
--- /dev/null
+++ b/geau/man/so_ii_population.Rd
@@ -0,0 +1,23 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/data.r
+\docType{data}
+\name{so_ii_population}
+\alias{so_ii_population}
+\title{Population for so-ii}
+\format{
+numeric matrix
+\describe{
+\item{row}{commune as in so_ii_scope}
+\item{column}{year}
+}
+}
+\source{
+\url{https://www.insee.fr/fr/statistiques/2522602}
+}
+\usage{
+so_ii_population
+}
+\description{
+A dataset containing the population of commune in so-ii according to INSEE.
+}
+\keyword{datasets}
diff --git a/map_so_ii.rmd b/map_so_ii.rmd
index 870f96a..d6d6a50 100644
--- a/map_so_ii.rmd
+++ b/map_so_ii.rmd
@@ -16,13 +16,17 @@ pch = 21
 # Legend definition
 dataset_legend = list(
     title = "Enquêtes du REX 19 septembre 2020",
-    legend = c("Agriculteurs", "Habitants membre ROI"),
-    pch = 21,
+    legend = c("Agriculteur", "Habitant"),
+    pch = pch,
     pt.bg = c("deeppink4", "cornflowerblue"),
-    pt.cex = 1.4
+    pt.cex = cex
 )
 
-map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, cex = cex, col = col, pch = pch)
-map_so_ii(dataset, dataset_legend, path = "toto.png", bg = bg, cex = cex, col = col, pch = pch)
-map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, pch = 22)
-map_so_ii(dataset, dataset_legend, path = "toto.pdf", bg = bg, pch = 22, theme = "gaspar")
\ No newline at end of file
+map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "clc", legend_theme = TRUE)
+map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "catnat", year = 2020, legend_theme = TRUE)
+map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "catnat", year = 2020, hazard = "nappe", legend_theme = TRUE)
+map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "population", legend_theme = TRUE)
+
+map_so_ii(dataset, dataset_legend, path = "rex-clc.pdf", bg = bg, pch = pch, theme = "clc", year = 2020, legend_theme = TRUE)
+map_so_ii(dataset, dataset_legend, path = "rex-catnat.pdf", bg = bg, pch = pch, theme = "catnat", year = 2020, legend_theme = TRUE)
+map_so_ii(dataset, dataset_legend, path = "rex-population.pdf", bg = bg, pch = pch, theme = "population", legend_theme = TRUE)
\ No newline at end of file
diff --git a/script/gaspar.R b/script/gaspar.R
new file mode 100644
index 0000000..07c31a5
--- /dev/null
+++ b/script/gaspar.R
@@ -0,0 +1,89 @@
+# Functions
+
+plot_chronicle = function(catnat, file_path = "catnat-chronicle.pdf") {
+    year.month = format(catnat[["date.start"]], "%Y-%m")
+    n.ym = table(year.month)
+    d.ym = as.Date(paste(names(n.ym), "01", sep = "-"))
+
+    pdf(file_path, width = 20, height = 10)
+    plot(d.ym, as.integer(n.ym), type = "h", xaxt = "n", xlab = "", ylab = "n", col = "royalblue3")
+    axis.Date(1, format = "%Y-%m", las = 2, at = d.ym)
+    axis.Date(1, format = "%Y-%m", las = 2, label = FALSE,
+        at = seq(range(d.ym)[1], range(d.ym)[2], by = "month"))
+    dev.off()
+}
+
+plot_month = function(catnat, file_path = "catnat-month.pdf") {
+    month = format(seq(as.Date("2020-01-01"), length.out = 12, by = "month"), "%m")
+    month = table(factor(format(catnat[["date.start"]], "%m"), levels = month))
+
+    pdf(file_path, width = 20, height = 10)
+    barplot(height = month, ylab = "n", xlab = "month", col = "royalblue3")
+    dev.off()
+}
+
+# Data
+
+## Preparing files & version (today)
+
+today = as.character(Sys.Date())
+dir.create("data-common/data/gaspar/archive", showWarnings = FALSE)
+archive = sprintf("data-common/data/gaspar/archive/gaspar-%s", today)
+
+## Download uptodate data
+
+utils::download.file(
+    url = "https://files.georisques.fr/GASPAR/gaspar.zip",
+    destfile = file.path(sprintf("%s.zip", archive)),
+    method = "wget")
+
+utils::unzip(sprintf("%s.zip", archive), exdir = archive)
+unlink(archive, recursive = TRUE)
+catnat = rio::import(file.path(archive, "catnat_gaspar.csv"))[-c(1, 10)]
+
+## Formating data + scope
+
+names(catnat) = c(
+    "commune",
+    "commune_name",
+    "alea_code",
+    "alea_jo",
+    "date.start",
+    "date.end",
+    "date.arrete",
+    "date.jo"
+)
+# write.csv2(unique(catnat[c("alea_code", "alea")]), "lib_risque_jo.csv", row.names = FALSE)
+# catnat = catnat[ grep("nondation", catnat[["alea"]]), ]
+
+so_ii_scope = geau::so_ii_scope
+catnat_so_ii = merge(
+    catnat[ catnat[["commune"]] %in% so_ii_scope, ],
+    read.csv2("data-common/so-ii/gaspar/catnat_alea_jo.csv")
+)
+write.csv2(
+    catnat_so_ii, 
+    sprintf("data-common/so-ii/gaspar/catnat-%s.csv", today),
+    row.names = FALSE
+)
+
+alea_scope = c("inondation", "nappe", "submersion")
+catnat_so_ii = catnat_so_ii[ catnat_so_ii[["alea"]] %in% alea_scope, ]
+catnat_so_ii[["commune"]] = factor(
+    catnat_so_ii[["commune"]],
+    levels = so_ii_scope
+)
+catnat_so_ii[["alea"]] = factor(
+    catnat_so_ii[["alea"]],
+    levels = alea_scope
+)
+# Treatments
+
+plot_chronicle(catnat, "figure/catnat-france-chronicle.pdf")
+plot_month(catnat, "figure/catnat-france-month.pdf")
+
+plot_chronicle(catnat_so_ii, "catnat-so-ii-chronicle.pdf")
+plot_month(catnat_so_ii, "catnat-so-ii-month.pdf")
+
+write.csv2(catnat_year, sprintf("data-common/so-ii/gaspar/catnat_year_n-%s.csv", today))
+write.csv2(catnat_month, sprintf("data-common/so-ii/gaspar/catnat_month_n-%s.csv", today))
\ No newline at end of file
-- 
GitLab