Skip to content

Commit

Permalink
Documentation update (#200)
Browse files Browse the repository at this point in the history
* switch to sirene v3.11 + all var become historic var

* sirene v3 still applies + no var switched to hist var according to insee until v4

* remove warning concat list df

* check historicisation variable in sirene + bug fix

* and condition becomes an option/argument, conversion to upper case or decoding are options too

* streamline testing to avoir data gaps from v3.11 api version

* ident fix

* fix sirene tests

* remove codecov comment via yml file

* search_sirene doc update

* sirene v3.11

* doc update - silent arg

* example fix

* example census update

* get_last_release try catch
  • Loading branch information
hadrilec authored Jul 10, 2024
1 parent c3222a0 commit 4b3c208
Show file tree
Hide file tree
Showing 15 changed files with 515 additions and 253 deletions.
81 changes: 46 additions & 35 deletions docs/examples/example_cadre_iris_idf.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"import geopandas as gpd\n",
"from pathlib import Path\n",
"from contextlib import closing\n",
"import urllib.request as request\n",
"# import urllib.request as request\n",
"from urllib.request import Request, urlopen\n",
"import os\n",
"import py7zr\n",
"import re\n",
Expand Down Expand Up @@ -180,29 +181,12 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 13,
"id": "b7fd9209-d2ce-486d-9cf7-939f52f90925",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Downloading: 100%|██████████| 58.0M/58.0M [00:06<00:00, 9.09MiB/s]\n",
"Extracting: 100%|██████████| 58.0M/58.0M [00:00<00:00, 303MB/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data saved:\n",
"/home/onyxia/.cache/pynsee/pynsee/f68f175baadf284aadfd854e462a0cce.parquet\n"
]
}
],
"outputs": [],
"source": [
"dfraw = download_file(\"RP_ACTRES_IRIS\", update=True)"
"dfraw = download_file(\"RP_ACTRES_IRIS\")"
]
},
{
Expand Down Expand Up @@ -445,14 +429,15 @@
},
{
"cell_type": "code",
"execution_count": 8,
"id": "f6264626-69c6-40dc-ae1e-7e7908506011",
"execution_count": 7,
"id": "0a555783-1bdc-4a17-9c74-5ebbf76dbb4c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found credentials in environment variables.\n",
"Found credentials in environment variables.\n",
"Found credentials in environment variables.\n"
]
Expand All @@ -471,30 +456,39 @@
"Found credentials in environment variables.\n",
"Found credentials in environment variables.\n",
"Found credentials in environment variables.\n",
"Found credentials in environment variables.\n",
"Found credentials in environment variables.\n"
]
}
],
"source": [
"import os\n",
"import shutil\n",
"from pathlib import Path\n",
"from urllib.request import Request, urlopen\n",
"from contextlib import closing\n",
"\n",
"ign_iris_2022 = \"https://data.geopf.fr/telechargement/download/CONTOURS-IRIS/CONTOURS-IRIS_2-1__SHP__FRA_2022-01-01/CONTOURS-IRIS_2-1__SHP__FRA_2022-01-01.7z\"\n",
"\n",
"def get_iris_data(url=ign_iris_2022, update=False):\n",
" \n",
" list_string_split = url.split(\"/\")\n",
" filename = list_string_split[len(list_string_split)-1]\n",
" filename = list_string_split[-1]\n",
" list_string_split_filename = filename.split(\".\")\n",
" filename_clean = list_string_split_filename[0]\n",
" \n",
" home = Path.home()\n",
" dataDir = str(home) + \"/\" + filename_clean\n",
" dataDir = os.path.join(home, filename_clean)\n",
" if not os.path.exists(dataDir):\n",
" os.mkdir(dataDir)\n",
"\n",
" file_iris = dataDir + \"/\" + \"file_\" + filename_clean\n",
" file_iris = os.path.join(dataDir, \"file_\" + filename_clean)\n",
"\n",
" req = Request(\n",
" url=url, \n",
" headers={'User-Agent': 'Mozilla/5.0'},\n",
" )\n",
" \n",
" if (not os.path.exists(file_iris)) or (update):\n",
" with closing(request.urlopen(url, timeout=None)) as r:\n",
" if not os.path.exists(file_iris) or update:\n",
" with closing(urlopen(req)) as r:\n",
" with open(file_iris, 'wb') as f:\n",
" shutil.copyfileobj(r, f)\n",
"\n",
Expand All @@ -520,11 +514,20 @@
" list_shp_df += [shp]\n",
" \n",
" shpFinal = pd.concat(list_shp_df)\n",
" \n",
" return shpFinal\n",
"\n",
"shapefile = get_iris_data(update=True)\n",
" return shpFinal\n",
"\n",
"# Example call to the function\n",
"shapefile = get_iris_data()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "dd433aa9-be5e-4867-84b6-137314fc49d1",
"metadata": {},
"outputs": [],
"source": [
"shp = shapefile.sort_values(by = [\"INSEE_COM\"]).reset_index(drop=True)"
]
},
Expand Down Expand Up @@ -556,7 +559,7 @@
}
],
"source": [
"mapplot = gpd.GeoDataFrame(DF)\n",
"mapplot = gpd.GeoDataFrame(DF).set_crs(\"EPSG:3857\")\n",
"\n",
"fig, ax = plt.subplots(1,1,figsize=[15,15])\n",
"mapplot.plot(column='pct', cmap=cm.jet,\n",
Expand All @@ -565,6 +568,14 @@
"ax.set(title='Proportion of upper and middle middle class workers among working population in 2017')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "95f0c9af-2ad6-479b-b0a8-aa3de0539e75",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -583,7 +594,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 4b3c208

Please sign in to comment.