Commit efefa1bf authored by Charpentier Maxime's avatar Charpentier Maxime

initial commit

parents
./RAW_DATA/
This source diff could not be displayed because it is too large. You can view the blob instead.
Fichier de démographie du département d'Ille et Vilaine SANS Rennes concaténé par cantons
Issu du recensement de la population de 2017 (https://www.insee.fr/fr/statistiques/4799268)
This source diff could not be displayed because it is too large. You can view the blob instead.
Fichier de géométrie des cantons du département d'Ille et Vilaine
Issu de :
- Découpage communal de l'INSEE au 1er janvier 2021 (https://www.insee.fr/fr/information/2028028)
- Découpage administratif communal français issu d'OpenStreetMap (https://www.data.gouv.fr/fr/datasets/decoupage-administratif-communal-francais-issu-d-openstreetmap/#_)
This source diff could not be displayed because it is too large. You can view the blob instead.
Fichier de démographie de Rennes découpé par IRIS (unité statistique INSEE)
Issu du recensement de la population de 2017 (https://www.insee.fr/fr/statistiques/4799268)
This source diff could not be displayed because it is too large. You can view the blob instead.
Fichier de géométrie des IRIS de Rennes uniquement
Issu du produit CONTOUR_IRIS 2020 de l'IGN (https://geoservices.ign.fr/documentation/diffusion/index.html)
{
"cells": [
{
"cell_type": "markdown",
"id": "27bb0903",
"metadata": {},
"source": [
"# Données démographiques de Rennes"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ae4f0da1",
"metadata": {},
"outputs": [],
"source": [
"import ipyleaflet as ipyl\n",
"import ipywidgets as ipyw\n",
"import matplotlib.pyplot as plt\n",
"import geopandas as gpd\n",
"import pandas as pd\n",
"from IPython.display import display,clear_output\n",
"from branca.colormap import linear\n",
"import json\n",
"#import plotly.express as px\n",
"#import plotly.graph_objects as go\n",
"%matplotlib inline\n",
"\n",
"# To prevent automatic figure display when execution of the cell ends\n",
"%config InlineBackend.close_figures=False "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e62e8f22",
"metadata": {},
"outputs": [],
"source": [
"gdep_demo_cantons = gpd.read_file(\"PROCESSED_DATA/gdep_demo_cantons.geojson\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c7ad1fe8",
"metadata": {},
"outputs": [],
"source": [
"grennes_demo = gpd.read_file(\"PROCESSED_DATA/grennes_demo.geojson\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "775d3853",
"metadata": {},
"outputs": [],
"source": [
"def get_mean(cantville=None, iris=None):\n",
" assert cantville or iris\n",
" assert not (cantville and iris)\n",
" if cantville:\n",
" part = gdep_demo_cantons[gdep_demo_cantons[\"CV\"]==cantville].iloc[0]\n",
" else:\n",
" part = grennes_demo[grennes_demo[\"IRIS\"]==iris].iloc[0]\n",
" mean = (((24+15)*part[\"P17_POP1524\"] + (54+25)*part[\"P17_POP2554\"] + (79+55)*part[\"P17_POP5579\"])/2 + 80*part[\"P17_POP80P\"])/part[\"P17_POP15P\"]\n",
" return mean"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "93249907",
"metadata": {},
"outputs": [],
"source": [
"def name_age(col_age):\n",
" if col_age[-1] == \"P\":\n",
" return col_age[7:9] + \"-\"\n",
" else:\n",
" return col_age[7:9] + \"-\" + col_age[9:11]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97b9938d",
"metadata": {},
"outputs": [],
"source": [
"csp_cat = {\n",
" 1: \"Agriculteurs \\n exploitants\",\n",
" 2: \"Artisans\",\n",
" 3: \"Cadres\",\n",
" 4: \"Professions \\n Intermédiaires\",\n",
" 5: \"Employés\",\n",
" 6: \"Ouvriers\",\n",
" 7: \"Retraités\",\n",
" 8: \"Autres\"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "06718613",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"mymap = ipyl.Map(center=(48.117266,-1.6777926), zoom=10, scroll_wheel_zoom=True)\n",
"\n",
"\n",
"geo_dep_demo_cantons = ipyl.GeoData(\n",
" geo_dataframe=gdep_demo_cantons,\n",
" border_color='black',\n",
" style={'fillOpacity': 0.4, 'dashArray': '5, 5'},\n",
" hover_style={'fillOpacity': 0.8, 'dashArray': '5, 5'},\n",
" name=\"Département 35\")\n",
"\n",
"\n",
"geo_dep_demo_rennes = ipyl.GeoData(\n",
" geo_dataframe=grennes_demo,\n",
" border_color='black',\n",
" style={'fillOpacity': 0.4, 'dashArray': '5, 5'},\n",
" hover_style={'fillOpacity': 0.8, 'dashArray': '5, 5'},\n",
" name=\"IRIS Rennes\")\n",
"\n",
"\n",
"\n",
"tranches = [\"P17_POP1524\", \"P17_POP2554\", \"P17_POP5579\", \"P17_POP80P\"]\n",
"csp_cols = [\"C17_PMEN_CS\"+str(k)for k in csp_cat]\n",
"visu_output = ipyw.Output()\n",
"\n",
"plt.ioff()\n",
"fig, ax = plt.subplots(figsize=(7,10), dpi=150)\n",
"\n",
"def age(ax, value):\n",
" ax.clear()\n",
" if len(value)==4:\n",
" part = gdep_demo_cantons[gdep_demo_cantons[\"CV\"]==value].iloc[0][tranches]\n",
" values = [part[col]/1000 for col in tranches]\n",
" else:\n",
" part = grennes_demo[grennes_demo[\"IRIS\"]==value].iloc[0][tranches]\n",
" values = [part[col] for col in tranches]\n",
" labels = [name_age(col) for col in tranches]\n",
" ax.barh(labels, values, height=.5, color=\"orange\")\n",
" ax.set_title(\"Répartition des âges du canton/iris {}\".format(value))\n",
" ax.set_xlabel(\"x 1000 hab\")\n",
" ax.set_ylabel(\"Tranche d'âge\")\n",
" ax.grid()\n",
" with visu_output:\n",
" clear_output(wait=True)\n",
" display(ax.figure) \n",
" \n",
" \n",
"def csp(ax, value):\n",
" ax.clear()\n",
" if len(value)==4:\n",
" part = gdep_demo_cantons[gdep_demo_cantons[\"CV\"]==value].iloc[0][csp_cols]\n",
" values = [part[csp_col]/1000 for csp_col in csp_cols]\n",
" else:\n",
" part = grennes_demo[grennes_demo[\"IRIS\"]==value].iloc[0][csp_cols]\n",
" values = [part[csp_col] for csp_col in csp_cols]\n",
" labels = [csp_cat[csp_index] for csp_index in csp_cat]\n",
" ax.pie(labels=labels, x=values)\n",
" ax.set_title(\"Répartition des csp du canton/iris {}\".format(value))\n",
" with visu_output:\n",
" clear_output(wait=True)\n",
" display(ax.figure) \n",
"\n",
"\n",
"save_value = None\n",
" \n",
"dropdown = ipyw.Dropdown(\n",
" options=[(\"Tranches d'âge\", 1), (\"CSP\", 2)],\n",
" value=1,\n",
" description='Visualisation:',\n",
")\n",
" \n",
" \n",
"def on_click(event, feature, properties, id):\n",
" global save_value\n",
" try:\n",
" value = properties['CV']\n",
" except:\n",
" value = properties['IRIS']\n",
" save_value = value\n",
" if dropdown.value == 1:\n",
" age(ax, value)\n",
" elif dropdown.value == 2:\n",
" csp(ax, value)\n",
" \n",
"\n",
"def handler_dropdown(event):\n",
" plt.ioff()\n",
" fig, ax = plt.subplots(figsize=(7,10), dpi=150)\n",
" if save_value:\n",
" value = save_value\n",
" if event['new'] == 1:\n",
" age(ax, value)\n",
" if event['new'] == 2:\n",
" csp(ax, value) \n",
"\n",
" \n",
"dropdown.observe(handler_dropdown, names=\"value\")\n",
" \n",
"controler = ipyl.LayersControl()\n",
"geo_dep_demo_cantons.on_click(on_click)\n",
"geo_dep_demo_rennes.on_click(on_click)\n",
"mymap.add_layer(geo_dep_demo_cantons)\n",
"mymap.add_layer(geo_dep_demo_rennes)\n",
"mymap.add_control(controler)\n",
"mymap.layout.width = '50%'\n",
"mymap.layout.height = '600px'\n",
"#visu_output.layout.width = '30%'\n",
"#visu_output.layout.height = '600px'"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8c3906af",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"right = ipyw.VBox([dropdown, visu_output])\n",
"\n",
"right.layout.width = '30%'\n",
"right.layout.height = '600px'\n",
"\n",
"\n",
"ipyw.HBox([mymap,\n",
" right])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
"autoclose": false,
"autocomplete": true,
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 1,
"hotkeys": {
"equation": "Ctrl-E",
"itemize": "Ctrl-I"
},
"labels_anchors": false,
"latex_user_defs": false,
"report_style_numbering": false,
"user_envs_cfg": false
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}
This source diff could not be displayed because it is too large. You can view the blob instead.
#! /bin/bash
pyenv virtualenv 3.8.6 amasco_action3
pyenv local amasco_action3
pip install -r ./requirements.txt
echo Done!
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment