diff --git a/.github/workflows/netlify-test.yaml b/.github/workflows/netlify-test.yaml index 602e10362..d3c9e888f 100644 --- a/.github/workflows/netlify-test.yaml +++ b/.github/workflows/netlify-test.yaml @@ -37,6 +37,8 @@ jobs: conda list - name: Build to md run: | + git diff --name-only origin/master origin/${GITHUB_HEAD_REF} >> diff.txt + cat diff.txt Rscript -e 'source("./build/build_light.R")' - name: Clean files with Python function run: | diff --git a/build/build_light.R b/build/build_light.R index 72af11a94..21ca40bd5 100644 --- a/build/build_light.R +++ b/build/build_light.R @@ -1,7 +1,8 @@ -content_rmd <- list.files("./content/course", recursive = TRUE, pattern = "*.Rmd", full.names = TRUE) +content_rmd <- readLines("diff.txt") +content_rmd <- content_rmd[startsWith(content_rmd, "content/course")] +content_rmd <- content_rmd[endsWith(content_rmd, ".Rmd")] content_rmd <- content_rmd[!grepl("/git/", content_rmd)] content_rmd <- content_rmd[!grepl("06a_exo_supp_webscraping.", content_rmd)] -content_rmd <- content_rmd[8:9] file.remove( gsub( diff --git a/content/course/manipulation/03_geopandas_TP.Rmd b/content/course/manipulation/03_geopandas_TP.Rmd index f16c0b252..519f02723 100644 --- a/content/course/manipulation/03_geopandas_TP.Rmd +++ b/content/course/manipulation/03_geopandas_TP.Rmd @@ -41,7 +41,7 @@ print_badges() Installations préalables : -```{python, eval=FALSE, echo=TRUE} +```{python, eval=FALSE, echo=TRUE, include=TRUE} !pip install pandas fiona shapely pyproj rtree # à faire obligatoirement en premier pour utiliser rtree ou pygeos pour les jointures spatiales !pip install contextily !pip install geopandas diff --git a/content/course/manipulation/03_geopandas_tutorial.Rmd b/content/course/manipulation/03_geopandas_tutorial.Rmd index 905996b26..51b8961b6 100644 --- a/content/course/manipulation/03_geopandas_tutorial.Rmd +++ b/content/course/manipulation/03_geopandas_tutorial.Rmd @@ -243,7 +243,8 @@ du shapefile utilisé : ```{python} paris = communes[communes.insee.str.startswith("75")] -ax = paris.plot(figsize=(10, 10), alpha=0.5, edgecolor='blue') +fig,ax = plt.subplots(figsize=(10, 10)) +paris.plot(ax = ax, alpha=0.5, edgecolor='blue') ctx.add_basemap(ax, crs = paris.crs.to_string()) ax.set_axis_off() ax @@ -262,7 +263,7 @@ knitr::include_graphics("map_paris1.png") On voit ainsi que les données pour Paris ne comportent pas d'arrondissement, ce qui est limitant pour une analyse focalisée sur Paris. On va donc les récupérer sur le site d'open data de la ville de Paris et les substituer -à Paris +à Paris : ```{python} arrondissements = gpd.read_file("https://opendata.paris.fr/explore/dataset/arrondissements/download/?format=geojson&timezone=Europe/Berlin&lang=fr") @@ -276,7 +277,10 @@ espéré ```{python} paris = communes[communes.insee.str.startswith("75")] -ax = paris.plot(figsize=(10, 10), alpha=0.5, edgecolor='k') + +fig,ax = plt.subplots(figsize=(10, 10)) + +paris.plot(ax = ax, alpha=0.5, edgecolor='k') ctx.add_basemap(ax, crs = paris.crs.to_string()) ax.set_axis_off() ax @@ -315,25 +319,59 @@ communes['dep'] = communes.insee.str[:2] On peut se rassurer en affichant les données sur la carte des communes d'Île-de-France. -Découvrez ci-dessous par étape les différentes lignes de commandes permettant d'afficher une carte complète, +```{python, include = FALSE} +fig,ax = plt.subplots(figsize=(10, 10)) +stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2) +communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none", + color = None) +ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor) +ax.set_axis_off() +ax +``` + +```{python, echo = FALSE, include = FALSE} +plt.tight_layout(pad=0, h_pad = 0) +plt.savefig('map1.png', bbox_inches='tight') +``` + +```{r, echo = FALSE} +knitr::include_graphics("map1.png") +``` + + +Découvrez ci-dessous par étape les différentes lignes de commandes permettant d'afficher cette carte complète, étape par étape: -1. Afficher le nuage de point de 200 stations vélibs prises au hasard +:one: +Afficher le nuage de points de 200 stations vélibs prises au hasard -```{python} -ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2) +```{python, include = FALSE} +fig,ax = plt.subplots(figsize=(10, 10)) +stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2) #communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none", # color = None) #ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor) # ax.set_axis_off() +ax +``` + +```{python, echo = FALSE, include = FALSE} +plt.tight_layout(pad=0, h_pad = 0) +plt.show() +plt.savefig('map2aa.png', bbox_inches='tight') +``` + +```{r, echo = FALSE, include = FALSE} +knitr::include_graphics("map2aa.png") ``` :two: Ajouter à cette couche, en dessous, les contours des communes -```{python} -ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2) +```{python, include = FALSE} +fig,ax = plt.subplots(figsize=(10, 10)) +stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2) communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none", color = None) #ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor) @@ -343,19 +381,22 @@ ax ```{python, echo = FALSE, include = FALSE} plt.tight_layout(pad=0, h_pad = 0) +plt.show() plt.savefig('map2a.png', bbox_inches='tight') ``` -```{r, echo = FALSE} +```{r, echo = FALSE, include = FALSE} knitr::include_graphics("map2a.png") ``` -3. Ajouter un fond de carte de type *open street map* grâce au package +:three: +Ajouter un fond de carte de type *open street map* grâce au package `contextily` -```{python} -ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2) +```{python, include = FALSE} +fig,ax = plt.subplots(figsize=(10, 10)) +stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2) communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none", color = None) ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor) @@ -372,11 +413,13 @@ plt.savefig('map3a.png', bbox_inches='tight') knitr::include_graphics("map3a.png") ``` +:four: Ne reste plus qu'à retirer l'axe des coordonnées, qui n'est pas très esthétique. Pour cela: -```{python} -ax = stations.sample(200).plot(figsize = (10,10), color = 'red', alpha = 0.4, zorder=2) +```{python, include = FALSE, eval = FALSE} +fig,ax = plt.subplots(figsize=(10, 10)) +stations.sample(200).plot(ax = ax, color = 'red', alpha = 0.4, zorder=2) communes[communes['dep'].isin(['75','92','93','94'])].plot(ax = ax, zorder=1, edgecolor = "black", facecolor="none", color = None) ctx.add_basemap(ax, crs = stations.crs.to_string(), source = ctx.providers.Stamen.Watercolor) @@ -384,16 +427,7 @@ ax.set_axis_off() ax ``` -*In fine*, on obtient la carte ci-dessous: - -```{python, echo = FALSE, include = FALSE} -plt.tight_layout(pad=0, h_pad = 0) -plt.savefig('map1.png', bbox_inches='tight') -``` - -```{r, echo = FALSE} -knitr::include_graphics("map1.png") -``` +*In fine*, on obtient la carte désirée. ## Opérations sur les attributs @@ -433,7 +467,8 @@ attribus avec la méthode `dissolve`: ```{python} -ax = communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').plot(column = "surf_ha") +fig,ax = plt.subplots(figsize=(10, 10)) +communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').plot(ax = ax, column = "surf_ha") ax.set_axis_off() ax ``` @@ -569,7 +604,8 @@ communes = communes.set_crs(2154) Alors que la reprojection (projection Albers: 5070) s'obtient de la manière suivante: ```{python} -ax = communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').to_crs(5070).plot() +fig,ax = plt.subplots(figsize=(10, 10)) +communes[communes.dep != "97"].dissolve(by='dep', aggfunc='sum').to_crs(5070).plot(ax = ax) ax ``` @@ -595,7 +631,9 @@ nord-américain (et encore, pas dans son ensemble !). ```{python, eval = TRUE} world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')) -ax = world[world.continent == "North America"].to_crs(5070).plot(alpha = 0.2, edgecolor = "k") + +fig,ax = plt.subplots(figsize=(10, 10)) +world[world.continent == "North America"].to_crs(5070).plot(alpha = 0.2, edgecolor = "k", ax = ax) ax ```