logo Netzschleuder network catalog, repository, and centrifuge

History of insee_commuting

The changes to the source code of this entry in the repository, newest first, each with the differences it made to the entry's files. They are also listed on GitLab.

[entries] Add the date when each entry was added, and remove icon_hash by Tiago de Paula Peixoto beff7c9
The dates are those of the commits that first added the entries' files
(2020-08-11 for the entries of the initial commit); renamed entries keep
the date of their first name.

Changed: none
diff --git a/entries/insee_commuting/__init__.py b/entries/insee_commuting/__init__.py
index 4a4d61c..42f1de1 100644
--- a/entries/insee_commuting/__init__.py
+++ b/entries/insee_commuting/__init__.py
@@ -35,7 +35,7 @@ url = ['https://www.insee.fr/fr/statistiques/8998300',
        'https://www.insee.fr/fr/information/2383337']
 citation = [('INSEE, "Mobilités professionnelles: déplacements domicile - lieu de travail." Recensement de la population, base flux de mobilité, editions 2006-2023 (2009-2026)',
              'https://www.insee.fr/fr/statistiques/8998300')]
-icon_hash = None
+date_added = '2026-10-31'
 upstream_license = ("Licence Ouverte / Open Licence (Etalab)", "https://www.etalab.gouv.fr/licence-ouverte-open-licence/")
 
 upstream_prefix = 'https://www.insee.fr/fr/statistiques/fichier'
[entries] Prefix the properties in the descriptions with (Node), (Edge) or (Graph) by Tiago de Paula Peixoto bc3dbbd
The lists of properties at the end of the descriptions marked edge
properties with "Edge" but left node properties unmarked, or grouped
them in "Nodes: `a`, ...; `b`, ..." items, so the kind of a property
was often unclear. Every item now starts with (Node), (Edge) or (Graph),
followed by the property names, a colon and the explanation, one item
per property or group of properties; qualifications (kinds of nodes,
networks) follow the names in parentheses. Properties that were only
named got a short explanation, and a few items that named the wrong
kind of property were corrected.
diff --git a/entries/insee_commuting/__init__.py b/entries/insee_commuting/__init__.py
index da06f98..4a4d61c 100644
--- a/entries/insee_commuting/__init__.py
+++ b/entries/insee_commuting/__init__.py
@@ -26,10 +26,10 @@ There is one network for each edition, from 2006 to 2023, named after its year (
 
 The networks have the following properties:
 
-- `code`: the code of the commune (the 5-character official geographic code of INSEE, e.g. `75056` or `2A004`; `75101` to `75120` for the arrondissements of Paris, etc.), or the code of the place abroad as given by INSEE (e.g. `SUC1L`, `LU320`, `ZZZZZ`).
-- `name`: the name of the commune or place.
-- `abroad`: whether the place is outside France (a place of work abroad).
-- Edge `workers`: the estimated number of employed persons of 15 years or older that live in the source commune and work in the target place."""
+- (Node) `code`: the code of the commune (the 5-character official geographic code of INSEE, e.g. `75056` or `2A004`; `75101` to `75120` for the arrondissements of Paris, etc.), or the code of the place abroad as given by INSEE (e.g. `SUC1L`, `LU320`, `ZZZZZ`).
+- (Node) `name`: the name of the commune or place.
+- (Node) `abroad`: whether the place is outside France (a place of work abroad).
+- (Edge) `workers`: the estimated number of employed persons of 15 years or older that live in the source commune and work in the target place."""
 tags = ['Transportation', 'Employment', 'Weighted', 'Metadata']
 url = ['https://www.insee.fr/fr/statistiques/8998300',
        'https://www.insee.fr/fr/information/2383337']
[entries] New entry: insee_commuting by Tiago de Paula Peixoto ff4b5ce
diff --git a/entries/insee_commuting/__init__.py b/entries/insee_commuting/__init__.py
new file mode 100644
index 0000000..da06f98
--- /dev/null
+++ b/entries/insee_commuting/__init__.py
@@ -0,0 +1,137 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2026 Tiago de Paula Peixoto <tiago@skewed.de>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Affero General Public License along
+# with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from .. import *
+import csv
+
+title = "French commuting flows between communes (INSEE, 2006-2023)"
+description = r"""Networks of the commutes of workers between their communes of residence and of work in France, from the population census of the French national statistics institute (INSEE), as published in its "base flux de mobilité: mobilités professionnelles (déplacements domicile - lieu de travail)". The census of each year combines the surveys of five consecutive years (around that year), so that consecutive editions overlap; the flows are estimates (with decimals), based on samples of the households in the communes of 10,000 inhabitants or more, and INSEE warns that flows below 200 workers should be taken as orders of magnitude only. Because the data of a commune are collected over several years, the flows into and out of a commune may not refer to the same year.
+
+There is one network for each edition, from 2006 to 2023, named after its year (e.g. `2023`); each uses the communes of the geography of its time (communes are frequently merged), so the nodes of different networks do not necessarily correspond. Nodes are the communes of metropolitan France and the overseas departments (with the municipal arrondissements instead of the communes of Paris, Lyon and Marseille), and the places of work abroad, which are given as foreign communes (or regions, mostly near the borders, e.g. `GENEVE` or `LUXEMBOURG`), or as a single node `ZZZZZ` for the workers whose place of work abroad was not given. A directed edge goes from the commune of residence to the place of work, weighted by the number of employed persons of 15 years or older that commute between them; workers who work in their commune of residence are counted by self-loops. Only the pairs of places with a nonzero flow are included, and only the places that take part in some flow. The edition of 2023 attributes to the commune of Maxey-sur-Vaise (55328), in the Meuse, many jobs that are actually in the quarter of Vaise in Lyon (an error noted by INSEE), and has 12 flows without a commune of residence, which start at a node with an empty code and name. Names that are encoded twice in UTF-8 in some editions (e.g. a few names of places abroad in the edition of 2017) were repaired. The coordinates of the communes are not given by the data, and are not included.
+
+The networks have the following properties:
+
+- `code`: the code of the commune (the 5-character official geographic code of INSEE, e.g. `75056` or `2A004`; `75101` to `75120` for the arrondissements of Paris, etc.), or the code of the place abroad as given by INSEE (e.g. `SUC1L`, `LU320`, `ZZZZZ`).
+- `name`: the name of the commune or place.
+- `abroad`: whether the place is outside France (a place of work abroad).
+- Edge `workers`: the estimated number of employed persons of 15 years or older that live in the source commune and work in the target place."""
+tags = ['Transportation', 'Employment', 'Weighted', 'Metadata']
+url = ['https://www.insee.fr/fr/statistiques/8998300',
+       'https://www.insee.fr/fr/information/2383337']
+citation = [('INSEE, "Mobilités professionnelles: déplacements domicile - lieu de travail." Recensement de la population, base flux de mobilité, editions 2006-2023 (2009-2026)',
+             'https://www.insee.fr/fr/statistiques/8998300')]
+icon_hash = None
+upstream_license = ("Licence Ouverte / Open Licence (Etalab)", "https://www.etalab.gouv.fr/licence-ouverte-open-licence/")
+
+upstream_prefix = 'https://www.insee.fr/fr/statistiques/fichier'
+
+# The files with all the flows (CSV or text with ";" separators) of each
+# edition, with the id of its page on insee.fr (the XLSX files have only the
+# flows of 100 or more). INSEE revised the edition of 2021 in place
+# (2025-12-16); the files are those of the time of download.
+editions = {
+    2006: "2022123/BTT_FM_DTR_2006.zip",
+    2007: "2022121/BTT_FM_DTR_2007.zip",
+    2008: "2022119/BTT_FM_DTR_2008.zip",
+    2009: "2022117/BTT_FM_DTR_2009.zip",
+    2010: "2022115/base-texte-flux-mobilite-domicile-lieu-travail-2010.zip",
+    2011: "2022113/base-texte-flux-mobilite-domicile-lieu-travail-2011.zip",
+    2012: "2022463/base-texte-flux-mobilite-domicile-lieu-travail-2012.zip",
+    2013: "2022109/base-texte-flux-mobilite-domicile-lieu-travail-2013.zip",
+    2014: "2862065/base-texte-flux-mobilite-domicile-lieu-travail-2014.zip",
+    2015: "3566477/base-texte-flux-mobilite-domicile-lieu-travail-2015.zip",
+    2016: "4171554/base-texte-flux-mobilite-domicile-lieu-travail-2016.zip",
+    2017: "4509353/base-csv-flux-mobilite-domicile-lieu-travail-2017.zip",
+    2018: "5393835/base-csv-flux-mobilite-domicile-lieu-travail-2018.zip",
+    2019: "6454112/base-csv-flux-mobilite-domicile-lieu-travail-2019.zip",
+    2020: "7630376/base-flux-mobilite-domicile-lieu-travail-2020-csv.zip",
+    2021: "8201899/base-flux-mobilite-domicile-lieu-travail-2021-csv.zip",
+    2022: "8582949/base-flux-mobilite-domicile-lieu-travail-2022_csv.zip",
+    2023: "8998300/base-flux-mobilite-domicile-lieu-travail-2023_csv.zip",
+}
+
+files = [((f,), str(y), None) for y, f in editions.items()]
+
+def fetch_upstream(force=False):
+    return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
+                                force)
+
+def _fix_name(s):
+    "Names encoded twice in UTF-8 (in a few rows of some editions), repaired."
+    if "Ã" in s or "Â" in s:
+        try:
+            return s.encode("latin1").decode("utf8")
+        except (UnicodeEncodeError, UnicodeDecodeError):
+            pass
+    return s
+
+def _is_french(code):
+    # French communes: 5 digits, or "2A"/"2B" (Corsica) followed by 3 digits
+    return len(code) == 5 and (code.isdigit() or
+                               (code[:2] in ("2A", "2B") and code[2:].isdigit()))
+
+@cache_network()
+@coerce_props()
+@annotate()
+def parse(alts=None):
+    import zipfile
+    name = __name__.split(".")[-1]
+    for fnames, alt, fmt in files:
+        if alts is not None and alt not in alts:
+            continue
+        with open_upstream_file(name, fnames[0], "rb", seekable=True) as f:
+            with zipfile.ZipFile(f) as zf:
+                members = [m for m in zf.namelist()
+                           if m.lower().endswith((".csv", ".txt"))]
+                if len(members) != 1:
+                    raise ValueError(f"unexpected members: {zf.namelist()}")
+                data = zf.read(members[0])
+        try:
+            text = data.decode("utf8")
+        except UnicodeDecodeError:
+            text = data.decode("latin1")
+        del data
+        rows = csv.reader(io.StringIO(text), delimiter=";")
+        header = next(rows)
+        if len(header) != 5 or header[2] != "DCLT" or not header[4].startswith("NBFLUX"):
+            raise ValueError(f"unexpected header: {header}")
+        idx = {}
+        names = []
+        edges = []
+        w = []
+        for r in rows:
+            if not r:
+                continue
+            ids = []
+            for c, l in ((r[0], r[1]), (r[2], r[3])):
+                c = c.strip()
+                if c not in idx:
+                    idx[c] = len(idx)
+                    names.append(_fix_name(l.strip()))
+                ids.append(idx[c])
+            edges.append(ids)
+            w.append(float(r[4].replace(",", ".")))
+        del text
+        g = Graph(directed=True)
+        g.add_vertex(len(idx))
+        g.add_edge_list(edges)
+        g.vp.code = g.new_vp("string", vals=list(idx))
+        g.vp.name = g.new_vp("string", vals=names)
+        g.vp.abroad = g.new_vp("bool", vals=[c != "" and not _is_french(c) for c in idx])
+        g.ep.workers = g.new_ep("double", vals=w)
+        yield alt, g