mobisurvstd 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. {mobisurvstd-0.1.0/src/mobisurvstd.egg-info → mobisurvstd-0.2.0}/PKG-INFO +5 -4
  2. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/README.md +3 -3
  3. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/pyproject.toml +2 -1
  4. mobisurvstd-0.2.0/src/mobisurvstd/edgt/common.py +40 -0
  5. mobisurvstd-0.2.0/src/mobisurvstd/edgt/deplacements.py +167 -0
  6. mobisurvstd-0.2.0/src/mobisurvstd/edgt/menages.py +353 -0
  7. mobisurvstd-0.2.0/src/mobisurvstd/edgt/personnes.py +307 -0
  8. mobisurvstd-0.2.0/src/mobisurvstd/edgt/survey.py +330 -0
  9. mobisurvstd-0.2.0/src/mobisurvstd/edgt/trajets.py +278 -0
  10. mobisurvstd-0.2.0/src/mobisurvstd/edgt/zones.py +192 -0
  11. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2010/deplacements.py +17 -0
  12. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2010/survey.py +3 -1
  13. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2020/deplacements.py +17 -0
  14. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emc2/deplacements.py +14 -4
  15. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emc2/menages.py +1 -1
  16. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emc2/survey.py +3 -30
  17. mobisurvstd-0.2.0/src/mobisurvstd/emp/__init__.py +1 -0
  18. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emp/deplacements.py +9 -2
  19. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/main.py +5 -5
  20. mobisurvstd-0.2.0/src/mobisurvstd/resources/__init__.py +3 -0
  21. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/resources/admin_express.py +5 -3
  22. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/resources/insee_data.py +5 -3
  23. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/schema.py +19 -4
  24. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0/src/mobisurvstd.egg-info}/PKG-INFO +5 -4
  25. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd.egg-info/SOURCES.txt +8 -0
  26. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd.egg-info/requires.txt +1 -0
  27. mobisurvstd-0.1.0/src/mobisurvstd/resources/__init__.py +0 -0
  28. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/LICENSE.md +0 -0
  29. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/setup.cfg +0 -0
  30. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/__init__.py +0 -0
  31. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/__main__.py +0 -0
  32. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/classes.py +0 -0
  33. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/clean.py +0 -0
  34. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/cli.py +0 -0
  35. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/common/__init__.py +0 -0
  36. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/common/cars.py +0 -0
  37. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/common/clean.py +0 -0
  38. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/common/households.py +0 -0
  39. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/common/legs.py +0 -0
  40. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/common/modes.py +0 -0
  41. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/common/motorcycles.py +0 -0
  42. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/common/persons.py +0 -0
  43. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/common/trips.py +0 -0
  44. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/common/zones.py +0 -0
  45. {mobisurvstd-0.1.0/src/mobisurvstd/egt2010 → mobisurvstd-0.2.0/src/mobisurvstd/edgt}/__init__.py +0 -0
  46. {mobisurvstd-0.1.0/src/mobisurvstd/egt2020 → mobisurvstd-0.2.0/src/mobisurvstd/egt2010}/__init__.py +0 -0
  47. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2010/menages.py +0 -0
  48. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2010/personnes.py +0 -0
  49. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2010/trajets.py +0 -0
  50. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2010/zones.py +0 -0
  51. {mobisurvstd-0.1.0/src/mobisurvstd/emc2 → mobisurvstd-0.2.0/src/mobisurvstd/egt2020}/__init__.py +0 -0
  52. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2020/menages.py +0 -0
  53. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2020/motos.py +0 -0
  54. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2020/personnes.py +0 -0
  55. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2020/survey.py +0 -0
  56. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2020/trajets.py +0 -0
  57. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/egt2020/voitures.py +0 -0
  58. {mobisurvstd-0.1.0/src/mobisurvstd/emp → mobisurvstd-0.2.0/src/mobisurvstd/emc2}/__init__.py +0 -0
  59. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emc2/common.py +0 -0
  60. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emc2/personnes.py +0 -0
  61. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emc2/trajets.py +0 -0
  62. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emc2/zones.py +0 -0
  63. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emp/menages.py +0 -0
  64. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emp/motos.py +0 -0
  65. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emp/personnes.py +0 -0
  66. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emp/survey.py +0 -0
  67. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/emp/voitures.py +0 -0
  68. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/logger.py +0 -0
  69. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/resources/nuts.py +0 -0
  70. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd/utils.py +0 -0
  71. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd.egg-info/dependency_links.txt +0 -0
  72. {mobisurvstd-0.1.0 → mobisurvstd-0.2.0}/src/mobisurvstd.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mobisurvstd
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: A tool to standardize French mobility survey datasets (EMC2, EGT, EMP, etc.) into a unified format.
5
5
  Author-email: Lucas Javaudin <lucas@lucasjavaudin.com>
6
6
  License-Expression: MIT
@@ -22,6 +22,7 @@ Requires-Dist: loguru>=0.7.3
22
22
  Requires-Dist: matplotlib>=3.10.1
23
23
  Requires-Dist: numpy>=2.2.4
24
24
  Requires-Dist: pandas>=2.2.3
25
+ Requires-Dist: platformdirs>=4.3.8
25
26
  Requires-Dist: polars>=1.31.0
26
27
  Requires-Dist: py7zr>=0.22.0
27
28
  Requires-Dist: pyarrow>=19.0.1
@@ -152,8 +153,7 @@ For more, check the [User Guide](https://mobisurvstd.github.io/MobiSurvStd/howto
152
153
 
153
154
  ## Case Study: Bicycle Use
154
155
 
155
- The following graph represents the share of bicycle trips for all EMC² surveys and the EGT 2020
156
- survey.
156
+ The following graph represents the share of bicycle trips for EMC², EDGT, and EGT surveys.
157
157
  The circle colors represent the average number of bicycles in the surveyed households.
158
158
  The circle sizes represent the expected number of trips in the surveyed area.
159
159
 
@@ -180,10 +180,11 @@ Currently, MobiSurvStd supports the following survey types:
180
180
  - `emc2`
181
181
  - `egt2020`
182
182
  - `egt2010`
183
+ - `edgt`
183
184
 
184
185
  See [Survey Types](https://mobisurvstd.github.io/MobiSurvStd/surveys.html) for more.
185
186
 
186
- Other survey types that are planned to be integrated are: `edvm`, `edgt`, `entd`, `emg`.
187
+ Other survey types that are planned to be integrated are: `edvm`, `entd`, `emg`.
187
188
  If you know another survey format that could be integrated, feel free to open an issue on GitHub.
188
189
 
189
190
  MobiSurvStd covers only French mobility survey formats.
@@ -121,8 +121,7 @@ For more, check the [User Guide](https://mobisurvstd.github.io/MobiSurvStd/howto
121
121
 
122
122
  ## Case Study: Bicycle Use
123
123
 
124
- The following graph represents the share of bicycle trips for all EMC² surveys and the EGT 2020
125
- survey.
124
+ The following graph represents the share of bicycle trips for EMC², EDGT, and EGT surveys.
126
125
  The circle colors represent the average number of bicycles in the surveyed households.
127
126
  The circle sizes represent the expected number of trips in the surveyed area.
128
127
 
@@ -149,10 +148,11 @@ Currently, MobiSurvStd supports the following survey types:
149
148
  - `emc2`
150
149
  - `egt2020`
151
150
  - `egt2010`
151
+ - `edgt`
152
152
 
153
153
  See [Survey Types](https://mobisurvstd.github.io/MobiSurvStd/surveys.html) for more.
154
154
 
155
- Other survey types that are planned to be integrated are: `edvm`, `edgt`, `entd`, `emg`.
155
+ Other survey types that are planned to be integrated are: `edvm`, `entd`, `emg`.
156
156
  If you know another survey format that could be integrated, feel free to open an issue on GitHub.
157
157
 
158
158
  MobiSurvStd covers only French mobility survey formats.
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "mobisurvstd"
9
- version = "0.1.0"
9
+ version = "0.2.0"
10
10
  description = "A tool to standardize French mobility survey datasets (EMC2, EGT, EMP, etc.) into a unified format."
11
11
  readme = "README.md"
12
12
  authors = [{ name = "Lucas Javaudin", email = "lucas@lucasjavaudin.com" }]
@@ -26,6 +26,7 @@ dependencies = [
26
26
  "matplotlib >= 3.10.1",
27
27
  "numpy >= 2.2.4",
28
28
  "pandas >= 2.2.3",
29
+ "platformdirs >= 4.3.8",
29
30
  "polars >= 1.31.0",
30
31
  "py7zr >= 0.22.0",
31
32
  "pyarrow >= 19.0.1",
@@ -0,0 +1,40 @@
1
+ MODE_MAP = {
2
+ 1: "walking", # Marche à pied.
3
+ 10: "bicycle:driver:traditional:shared", # Conducteur VLS
4
+ 11: "bicycle:driver:traditional", # Conducteur de vélo.
5
+ 12: "bicycle:passenger", # Passager de vélo.
6
+ 13: "motorcycle:driver:moped", # Conducteur de deux ou trois roues motorisés < 50 cm3.
7
+ 14: "motorcycle:passenger:moped", # Passager de deux ou trois roues motorisés < 50 cm3.
8
+ 15: "motorcycle:driver:moto", # Conducteur de deux ou trois roues motorisés >= 50 cm3
9
+ 16: "motorcycle:passenger:moto", # Passager de deux ou trois roues motorisés >= 50 cm3.
10
+ 17: "motorcycle:driver", # Conducteur de deux ou trois roues motorisés (si pas de détail sur la cylindrée).
11
+ 18: "motorcycle:passenger", # Passager de deux ou trois roues motorisés (si pas de détail sur la cylindrée)..
12
+ 21: "car:driver", # Conducteur de véhicule particulier (VP).
13
+ 22: "car:passenger", # Passager de véhicule particulier (VP).
14
+ 31: "public_transit:urban:bus", # Passager bus urbain (réseau ville centre).
15
+ 32: "public_transit:urban:tram", # Passager tramway (réseau ville centre).
16
+ 33: "public_transit:urban:metro", # Passager métro (réseau ville centre).
17
+ 34: "public_transit:urban:funicular", # Note. Not documented. Used in Le Havre (and other surveys?).
18
+ 37: "public_transit:urban:demand_responsive", # Transport à la demande (U ou IU)
19
+ 38: "public_transit:urban", # Passager autres réseaux urbains ds aire enquête.
20
+ 39: "public_transit:urban", # Passager autre réseau urbain hors AE
21
+ 41: "public_transit:urban:coach", # Passager transports interurbains routiers et autres autocars (TER routiers, lignes régulières départementales, scolaires, périscolaires, occasionnel….).
22
+ 42: "public_transit:interurban:coach", # Cars longues distances (Eurolines/Isilines, Ouibus, Flixbus…)).
23
+ 43: "public_transit:interurban:coach", # Passagers autocars anciennes définitions
24
+ 51: "public_transit:interurban:TGV", # Passager TGV
25
+ 52: "public_transit:urban:TER", # Passager train TER
26
+ 53: "public_transit:interurban:intercités", # Passagers autres trains (Intercité, TET)
27
+ 54: "public_transit:interurban:other_train", # Passager train non précisé
28
+ 61: "taxi", # Passager taxi.
29
+ 62: "VTC", # Passager VTC
30
+ 71: "employer_transport", # Transport employeur (exclusivement)
31
+ 81: "truck:driver", # Conducteur de fourgon, camionnette, camion (pour tournées professionnelles ou déplacements privés).
32
+ 82: "truck:passenger", # Passager de fourgon, camionnette, camion (pour tournées professionnelles ou déplacements privés)..
33
+ 91: "water_transport", # Transport Fluvial ou maritime.
34
+ 92: "airplane", # Avion.
35
+ 93: "personal_transporter:non_motorized", # Roller, skate, trottinette non électrique
36
+ 94: "wheelchair", # Fauteuil roulant.
37
+ 95: "other", # Autres modes (tracteur, engin agricole, quad, etc.).
38
+ 96: "personal_transporter:motorized", # Petits engins électriques (trottinette, segway, solowheel, etc)
39
+ 97: "personal_transporter:unspecified", # Roller, skate, trottinette électrique ou non (ancien code)
40
+ }
@@ -0,0 +1,167 @@
1
+ import polars as pl
2
+
3
+ from mobisurvstd.common.trips import clean
4
+
5
+ from .common import MODE_MAP
6
+
7
+ SCHEMA = {
8
+ "DP1": pl.UInt8, # Code fichier = 3 (déplacement)
9
+ "IDD3": pl.UInt16, # Année de fin d'enquête
10
+ "IDD4": pl.String, # Code Insee ville centre
11
+ "ZFD": pl.UInt32, # Zone fine de résidence
12
+ "ECH": pl.UInt32, # Numéro d’échantillon
13
+ "PER": pl.UInt8, # Numéro de personne
14
+ "NDEP": pl.UInt8, # Numéro de déplacement
15
+ "GD1": pl.String, # Insee Zone fine du lieu de résidence de la personne concernée par le déplacement
16
+ "STD": pl.UInt32, # Secteur de tirage dans l’enquête d’origine (résidence)
17
+ "D2A": pl.UInt8, # Motif Origine du déplacement
18
+ "D2B": pl.UInt8, # Motif Origine de la personne accompagnée
19
+ "D3": pl.UInt32, # Zone fine Origine du déplacement
20
+ "GDO1": pl.String, # Insee Zone fine Origine du déplacement
21
+ "STDO": pl.UInt32, # Secteur de tirage dans l’enquête d’origine (origine du déplacement)
22
+ "D4": pl.UInt16, # Heure de départ du déplacement
23
+ "D5A": pl.UInt8, # Motif Destination du déplacement
24
+ "D5B": pl.UInt8, # Motif Destination de la personne accompagnée
25
+ "D6": pl.UInt8, # Nombre d’arrêts sur la tournée
26
+ "D7": pl.UInt32, # Zone fine Destination du déplacement
27
+ "GDD1": pl.String, # Insee Zone fine Destination du déplacement
28
+ "STDD": pl.UInt32, # Secteur de tirage dans l’enquête d’origine (destination du déplacement)
29
+ "D8": pl.UInt16, # Heure d'arrivée du déplacement
30
+ "D9": pl.UInt16, # Durée du déplacement
31
+ "D10": pl.UInt8, # Nombre de trajets (en modes mécanisés)
32
+ "D11": pl.Float64, # Longueur à vol d'oiseau
33
+ "D12": pl.Float64, # Distance parcourue
34
+ "MODP": pl.UInt8, # Mode principal
35
+ "TYPD": pl.UInt8, # Type de déplacement
36
+ }
37
+
38
+ PURPOSE_MAP = {
39
+ 1: "home:main", # Domicile (partir de, se rendre à).
40
+ 2: "home:secondary", # Résidence secondaire, logement occasionnel, hôtel, autre domicile (partir de, se rendre à).
41
+ 11: "work:declared", # Travailler sur le lieu d’emploi déclaré.
42
+ 12: "work:telework", # Travailler sur un autre lieu – télétravail.
43
+ 13: "work:secondary", # Travailler sur un autre lieu hors télétravail
44
+ 14: "work:other", # Travailler sur un autre lieu sans distinction
45
+ # NOTE. We discard the information on the exact study location type (middle-school, high-school,
46
+ # etc.) because the information can read from the person characteristics (`student_group`).
47
+ 21: "education:childcare", # Être gardé (Nourrice, crèche...).
48
+ 22: "education:declared", # Étudier sur le lieu d'études déclaré (école maternelle et primaire).
49
+ 23: "education:declared", # Étudier sur le lieu d'études déclaré (collège).
50
+ 24: "education:declared", # Étudier sur le lieu d'études déclaré (lycée).
51
+ 25: "education:declared", # Étudier sur le lieu d'études déclaré (universités et grandes écoles).
52
+ 26: "education:other", # Étudier sur un autre lieu (école maternelle et primaire).
53
+ 27: "education:other", # Étudier sur un autre lieu (collège).
54
+ 28: "education:other", # Étudier sur un autre lieu (lycée).
55
+ 29: "education:other", # Étudier sur un autre lieu (universités et grandes écoles).
56
+ 30: "shopping:no_purchase", # Visite d’un magasin, d’un centre commercial ou d’un marché de plein vent sans effectuer d’achat
57
+ 31: "shopping:unspecified", # Réaliser plusieurs motifs en centre commercial.
58
+ 32: "shopping:unspecified", # Faire des achats en grand magasin, supermarché, hypermarché et leurs galeries marchandes.
59
+ 33: "shopping:unspecified", # Faire des achats en petit et moyen commerce et drive in
60
+ 34: "shopping:unspecified", # Faire des achats en marché couvert et de plein vent.
61
+ 35: "shopping:pickup", # Récupérer des achats faits à distance (Drive, points relais)
62
+ 41: "task:healthcare", # Recevoir des soins (santé).
63
+ 42: "task:procedure", # Faire une démarche autre que rechercher un emploi.
64
+ 43: "task:job_search", # Rechercher un emploi.
65
+ 51: "leisure:sport_or_culture", # Participer à des loisirs, des activités sportives, culturelles ou associatives.
66
+ 52: "leisure:walk_or_driving_lesson", # Faire une promenade, du « lèche-vitrines », prendre une leçon de conduite.
67
+ 53: "leisure:restaurant", # Se restaurer hors du domicile.
68
+ 54: "leisure:visiting", # Visiter des parents ou des amis.
69
+ # NOTE. We discard the information on whether the escorted person is present during pick_up /
70
+ # drop_off activity as it can be deduced (when I go pick-up someone, he's not there; when I come
71
+ # back from picking-up someone, he's there). Also, there are some errors in the data (like
72
+ # having the escorted person both before and after picking him up).
73
+ 61: "escort:activity:drop_off", # Accompagner quelqu’un (personne présente).
74
+ 62: "escort:activity:pick_up", # Aller chercher quelqu’un (personne présente).
75
+ 63: "escort:activity:drop_off", # Accompagner quelqu’un (personne absente).
76
+ 64: "escort:activity:pick_up", # Aller chercher quelqu’un (personne absente).
77
+ 68: "escort:unspecified:drop_off", # Accompagner quelqu’un ou déposer quelqu’un à un mode de transport (sans info présence personne)
78
+ 69: "escort:unspecified:pick_up", # Aller chercher quelqu’un ou reprendre quelqu’un à un mode de transport (sans info présence personne)
79
+ 71: "escort:transport:drop_off", # Déposer une personne à un mode de transport (personne présente).
80
+ 72: "escort:transport:pick_up", # Reprendre une personne à un mode de transport (personne présente).
81
+ 73: "escort:transport:drop_off", # Déposer d’une personne à un mode de transport (personne absente).
82
+ 74: "escort:transport:pick_up", # Reprendre une personne à un mode de transport( personne absente).
83
+ 81: "work:professional_tour", # Réaliser une tournée professionnelle.
84
+ 82: "shopping:tour_no_purchase", # Tournée de magasin sans achat
85
+ 91: "other", # Autres motifs
86
+ # 96: "escort:middle_high_school", # Étudier sur le lieu d'études déclaré (collège ou lycée). Cas egt personne accompagnée
87
+ # 97: "escort:middle_high_school:other", # Étudier sur un autre lieu (collège ou lycée). Cas egt personne accompagnée
88
+ # 98: "escort:shopping", # Faire des achats sans précision (egt, motif personne accompagnée)
89
+ # TODO: Fix 96, 97, and 98 if I find these values in a dataset.
90
+ }
91
+
92
+ SHOP_TYPE_MAP = {
93
+ 31: "mall", # Réaliser plusieurs motifs en centre commercial.
94
+ 32: "supermarket_or_hypermarket", # Faire des achats en grand magasin, supermarché, hypermarché et leurs galeries marchandes.
95
+ 33: "small_shop", # Faire des achats en petit et moyen commerce et drive in
96
+ 34: "market", # Faire des achats en marché couvert et de plein vent.
97
+ 35: "drive_in", # Récupérer des achats faits à distance (Drive, points relais)
98
+ }
99
+
100
+ TRIP_PERIMETER_MAP = {
101
+ 1: "internal", # interne au périmètre d'enquête
102
+ 2: "crossing", # en échange
103
+ 3: "external", # externe au périmètre d'enquête
104
+ 9: None, # inconnu (cas où origine ou destination inconnue)
105
+ }
106
+
107
+
108
+ def scan_trips(source1: str | bytes, source2: str | bytes):
109
+ lf = pl.concat(
110
+ (
111
+ pl.scan_csv(source1, separator=";", schema_overrides=SCHEMA),
112
+ pl.scan_csv(source2, separator=";", schema_overrides=SCHEMA),
113
+ ),
114
+ how="vertical",
115
+ )
116
+ return lf
117
+
118
+
119
+ def standardize_trips(
120
+ source1: str | bytes,
121
+ source2: str | bytes,
122
+ persons: pl.LazyFrame,
123
+ special_locations_coords: pl.DataFrame | None,
124
+ detailed_zones_coords: pl.DataFrame | None,
125
+ ):
126
+ lf = scan_trips(source1, source2)
127
+ # Add household_id, person_id, and trip date.
128
+ lf = lf.with_columns(original_person_id=pl.struct(ECH="ECH", STP="STD", PER="PER")).join(
129
+ persons.select("original_person_id", "person_id", "household_id", "trip_date"),
130
+ on="original_person_id",
131
+ how="left",
132
+ coalesce=True,
133
+ )
134
+ lf = lf.rename(
135
+ {
136
+ "D3": "origin_detailed_zone",
137
+ "GDO1": "origin_insee",
138
+ "STDO": "origin_draw_zone",
139
+ "D6": "nb_tour_stops",
140
+ "D7": "destination_detailed_zone",
141
+ "GDD1": "destination_insee",
142
+ "STDD": "destination_draw_zone",
143
+ }
144
+ )
145
+ lf = lf.with_columns(
146
+ original_trip_id=pl.struct("ECH", "STD", "PER", "NDEP"),
147
+ origin_purpose=pl.col("D2A").replace_strict(PURPOSE_MAP),
148
+ origin_escort_purpose=pl.col("D2B").replace_strict(PURPOSE_MAP),
149
+ origin_shop_type=pl.col("D2A").replace(SHOP_TYPE_MAP, default=None),
150
+ departure_time=60 * (pl.col("D4") // 100) + pl.col("D4") % 100,
151
+ destination_purpose=pl.col("D5A").replace_strict(PURPOSE_MAP),
152
+ destination_escort_purpose=pl.col("D5B").replace_strict(PURPOSE_MAP),
153
+ destination_shop_type=pl.col("D5A").replace(SHOP_TYPE_MAP, default=None),
154
+ arrival_time=60 * (pl.col("D8") // 100) + pl.col("D8") % 100,
155
+ trip_euclidean_distance_km=pl.col("D11") / 1e3,
156
+ trip_travel_distance_km=pl.col("D12") / 1e3,
157
+ main_mode=pl.col("MODP").replace_strict(MODE_MAP),
158
+ trip_perimeter=pl.col("TYPD").replace_strict(TRIP_PERIMETER_MAP),
159
+ )
160
+ year = int(lf.select(pl.col("trip_date").dt.year().mean().round()).collect().item())
161
+ lf = clean(
162
+ lf,
163
+ year=year,
164
+ special_locations=special_locations_coords,
165
+ detailed_zones=detailed_zones_coords,
166
+ )
167
+ return lf
@@ -0,0 +1,353 @@
1
+ import polars as pl
2
+
3
+ from mobisurvstd.common.cars import clean as clean_cars
4
+ from mobisurvstd.common.households import clean as clean_households
5
+ from mobisurvstd.common.motorcycles import clean as clean_motorcycles
6
+
7
+ SCHEMA = {
8
+ "MP1": pl.UInt8, # Code fichier = 1
9
+ "IDM1": pl.UInt8, # Type Enquête
10
+ "IDM2": pl.UInt8, # Méthode recueil données
11
+ "IDM3": pl.UInt16, # Année fin enquête
12
+ "IDM4": pl.String, # Code Insee ville centre
13
+ "ZFM": pl.UInt32, # zone fine
14
+ "ECH": pl.UInt32, # Numéro d’échantillon
15
+ "GM1": pl.String, # Insee Zone fine
16
+ "STM": pl.UInt32, # Secteur de tirage dans l’enquête d’origine
17
+ "M1": pl.UInt8, # TYPE D'HABITAT
18
+ "M2": pl.UInt8, # TYPE D'OCCUPATION
19
+ "M3": pl.UInt8, # POSSESSION DU TELEPHONE
20
+ "M4": pl.UInt8, # Annuaire
21
+ "M5": pl.UInt8, # Disposition d’une connexion internet
22
+ "M6": pl.UInt8, # Nombre de VP du ménage
23
+ "M7A": pl.UInt8, # GENRE DU VEHICULE n°1
24
+ "M8A": pl.UInt8, # TYPE D'ENERGIE DU VEHICULE n°1
25
+ "M9A": pl.UInt16, # ANNEE DE PREMIERE MISE EN CIRCULATION DU VEHICULE n°1
26
+ "M10A": pl.UInt8, # PUISSANCE FISCALE DU VEHICULE n°1
27
+ "M11A": pl.UInt8, # POSSESSION VEHICULE n°1 PAR MENAGE
28
+ "MAA": pl.UInt8, # CAS DE NON-POSSESSION DU VEHICULE n°1
29
+ "M12A": pl.UInt8, # LIEU DE STATIONNEMENT LA NUIT DU VEHICULE n°1
30
+ "M13A": pl.UInt8, # TYPE DE STATIONNEMENT LA NUIT DU VEHICULE n°1
31
+ "M7B": pl.UInt8,
32
+ "M8B": pl.UInt8,
33
+ "M9B": pl.UInt16,
34
+ "M10B": pl.UInt8,
35
+ "M11B": pl.UInt8,
36
+ "MAB": pl.UInt8,
37
+ "M12B": pl.UInt8,
38
+ "M13B": pl.UInt8,
39
+ "M7C": pl.UInt8,
40
+ "M8C": pl.UInt8,
41
+ "M9C": pl.UInt16,
42
+ "M10C": pl.UInt8,
43
+ "M11C": pl.UInt8,
44
+ "MAC": pl.UInt8,
45
+ "M12C": pl.UInt8,
46
+ "M13C": pl.UInt8,
47
+ "M7D": pl.UInt8,
48
+ "M8D": pl.UInt8,
49
+ "M9D": pl.UInt16,
50
+ "M10D": pl.UInt8,
51
+ "M11D": pl.UInt8,
52
+ "MAD": pl.UInt8,
53
+ "M12D": pl.UInt8,
54
+ "M13D": pl.UInt8,
55
+ "M14": pl.UInt8, # Nombre de DRM du ménage
56
+ "M15A": pl.UInt8, # GENRE DU DEUX ROUES MOTORISES n°1
57
+ "M16A": pl.UInt8, # CYLINDREE DU DEUX ROUES MOTORISES n°1
58
+ "M17A": pl.UInt8, # TYPE DE MOTEUR THERMIQUE
59
+ "M18A": pl.UInt16, # ANNEE DE MISE EN CIRCULATION DU DRM n°1
60
+ "M19A": pl.UInt8, # LIEU DE STATIONNEMENT LA NUIT DU DRM n°1
61
+ "M20A": pl.UInt8, # TYPE DE STATIONNEMENT LA NUIT DU DRM n°1
62
+ "M15B": pl.UInt8,
63
+ "M16B": pl.UInt8,
64
+ "M17B": pl.UInt8,
65
+ "M18B": pl.UInt16,
66
+ "M19B": pl.UInt8,
67
+ "M20B": pl.UInt8,
68
+ "M15C": pl.UInt8,
69
+ "M16C": pl.UInt8,
70
+ "M17C": pl.UInt8,
71
+ "M18C": pl.UInt16,
72
+ "M19C": pl.UInt8,
73
+ "M20C": pl.UInt8,
74
+ "M15D": pl.UInt8,
75
+ "M16D": pl.UInt8,
76
+ "M17D": pl.UInt8,
77
+ "M18D": pl.UInt16,
78
+ "M19D": pl.UInt8,
79
+ "M20D": pl.UInt8,
80
+ "M21": pl.UInt8, # VELOS A DISPOSITION
81
+ "M22": pl.UInt8, # VELOS ELECTRIQUES
82
+ "M23": pl.UInt8, # DISPOSITION D'UN LIEU DE STATIONNEMENT VELO AU DOMICILE
83
+ "COE0": pl.Float64, # COEFFICIENT DE REDRESSEMENT MENAGE
84
+ }
85
+
86
+ SURVEY_METHOD_MAP = {
87
+ 1: "face_to_face",
88
+ 2: "phone",
89
+ }
90
+
91
+ HOUSING_TYPE_MAP = {
92
+ 1: "house", # Individuel isolé
93
+ 2: "house", # Individuel accolé
94
+ 3: "apartment", # Petit collectif (R+1 à R+3)
95
+ 4: "apartment", # Grand collectif (R+4 et plus)
96
+ 5: "other", # Autres
97
+ }
98
+
99
+ HOUSING_STATUS_MAP = {
100
+ 1: "owner:unspecified", # Propriétaire ou accédant à la propriété
101
+ 2: "tenant:public_housing", # Locataire HLM
102
+ 3: "tenant:private", # Autre locataire
103
+ 4: "rent_free", # Logé gratuitement
104
+ 5: "university_resident", # Locataire en résidence universitaire
105
+ 6: "other", # Autre Exclusif
106
+ 7: "other", # Autre Non précisé
107
+ 8: "tenant:unspecified", # Locataire sans précision
108
+ 9: None,
109
+ }
110
+
111
+ CAR_TYPE_MAP = {
112
+ 1: "passenger_car", # Véhicule de tourisme
113
+ 2: "recreational_vehicle", # Camping-car
114
+ 3: "utility_vehicle", # Véhicule utilitaire de 800kg à 1000kg
115
+ 4: "license_free_car", # Voiture sans permis
116
+ }
117
+
118
+ CAR_FUEL_TYPE_MAP = {
119
+ 1: "thermic:petrol", # Sans plomb
120
+ 2: "thermic:petrol", # Super
121
+ 3: "thermic:diesel", # Diesel
122
+ 4: "thermic:gas", # Gaz
123
+ 5: "electric", # Électrique
124
+ 6: "hybrid:unspecified", # Hybride
125
+ 7: "other", # Autre
126
+ 9: None, # NR-Refus
127
+ }
128
+
129
+ CAR_FUEL_TYPE_GROUP_MAP = {
130
+ 1: "thermic", # Sans plomb
131
+ 2: "thermic", # Super
132
+ 3: "thermic", # Diesel
133
+ 4: "thermic", # Gaz
134
+ 5: "electric", # Électrique
135
+ 6: "hybrid", # Hybride
136
+ 7: "other", # Autre
137
+ 9: None, # NR-Refus
138
+ }
139
+
140
+ # Map for variable M11A + MAA.
141
+ CAR_OWNERSHIP_MAP = {
142
+ 1: "personal", # Possession véhicule par ménage
143
+ 3: "employer:full_availability", # Possédé par l'employeur mais à disposition totale d'une personne
144
+ 4: "employer:limited_availability", # Possédé par l'employeur mais à disposition limitée d'une personne
145
+ 5: "other", # Autre
146
+ 9: None, # NR-Refus
147
+ }
148
+
149
+ PARKING_LOCATION_MAP = {
150
+ 1: "garage", # Dans un garage, box, autre emplacement réservé
151
+ 2: "street", # Dans la rue
152
+ 3: "parking_lot", # Dans un parc à ciel ouvert (ou place publique)
153
+ 4: "parking_lot", # Dans un parc couvert accessible au public
154
+ 5: "other", # Autre (egt)
155
+ }
156
+
157
+ PARKING_TYPE_MAP = {
158
+ 1: "forbidden", # Interdit
159
+ 2: "free", # Gratuit
160
+ 3: "paid", # Payant à votre charge
161
+ 4: "paid_by_other", # Payant à la charge de quelqu'un d'autre
162
+ 5: "other", # Autre (egt)
163
+ }
164
+
165
+ MOTORCYCLE_TYPE_MAP = {
166
+ 1: "moped", # Cyclomoteur
167
+ 2: "scooter", # Scooter
168
+ 3: "motorbike", # Moto
169
+ 4: "motorized_tricycle", # 3-roues motorisé
170
+ }
171
+
172
+ MOTORCYCLE_FUEL_TYPE_MAP = {
173
+ 1: "thermic",
174
+ 2: "thermic",
175
+ 3: "thermic",
176
+ 4: "thermic",
177
+ 5: "thermic",
178
+ 6: "electric",
179
+ 7: "electric",
180
+ 8: "electric",
181
+ 9: "thermic",
182
+ 90: "other",
183
+ }
184
+
185
+ MOTORCYCLE_SIZE_LOWERBOUND_MAP = {
186
+ 1: 0,
187
+ 2: 50,
188
+ 3: 125,
189
+ 4: 250,
190
+ 5: 750,
191
+ 9: 125,
192
+ }
193
+
194
+ MOTORCYCLE_SIZE_UPPERBOUND_MAP = {
195
+ 1: 50,
196
+ 2: 125,
197
+ 3: 250,
198
+ 4: 750,
199
+ }
200
+
201
+ MOTORCYCLE_KW_LOWERBOUND_MAP = {
202
+ 6: 0,
203
+ 7: 4,
204
+ 8: 11,
205
+ }
206
+
207
+ MOTORCYCLE_KW_UPPERBOUND_MAP = {
208
+ 6: 4,
209
+ 7: 11,
210
+ }
211
+
212
+ MOTORCYCLE_THERMIC_ENGINE_TYPE_MAP = {
213
+ 1: "two_stroke",
214
+ 2: "four_stroke",
215
+ }
216
+
217
+
218
+ def scan_households(source1: str | bytes, source2: str | bytes):
219
+ lf = pl.concat(
220
+ (
221
+ pl.scan_csv(source1, separator=";", schema_overrides=SCHEMA, null_values=["a"]),
222
+ pl.scan_csv(source2, separator=";", schema_overrides=SCHEMA, null_values=["a"]),
223
+ ),
224
+ how="vertical",
225
+ )
226
+ return lf
227
+
228
+
229
+ def standardize_households(
230
+ source1: str | bytes,
231
+ source2: str | bytes,
232
+ special_locations_coords: pl.DataFrame | None,
233
+ detailed_zones_coords: pl.DataFrame | None,
234
+ ):
235
+ lf = scan_households(source1, source2)
236
+ lf = lf.rename(
237
+ {
238
+ "ZFM": "home_detailed_zone",
239
+ "GM1": "home_insee",
240
+ "M6": "nb_cars",
241
+ "M14": "nb_motorcycles",
242
+ "M21": "nb_bicycles",
243
+ "M22": "nb_electric_bicycles",
244
+ "COE0": "sample_weight",
245
+ }
246
+ )
247
+ lf = lf.with_columns(
248
+ original_household_id=pl.struct("ECH", "STM"),
249
+ home_draw_zone="STM",
250
+ survey_method=pl.col("IDM2").replace_strict(SURVEY_METHOD_MAP),
251
+ housing_type=pl.col("M1").replace_strict(HOUSING_TYPE_MAP),
252
+ housing_status=pl.col("M2").replace_strict(HOUSING_STATUS_MAP),
253
+ has_internet=pl.col("M5") == 1,
254
+ has_bicycle_parking=pl.col("M23") == 1,
255
+ )
256
+ lf = clean_households(
257
+ lf, special_locations=special_locations_coords, detailed_zones=detailed_zones_coords
258
+ )
259
+ return lf
260
+
261
+
262
+ def standardize_cars(source1: str | bytes, source2: str | bytes, households: pl.LazyFrame):
263
+ lf = scan_households(source1, source2)
264
+ # Add household_id.
265
+ lf = lf.with_columns(original_household_id=pl.struct("ECH", "STM")).join(
266
+ households.select("original_household_id", "household_id"),
267
+ on="original_household_id",
268
+ how="left",
269
+ coalesce=True,
270
+ )
271
+ lf = pl.concat(
272
+ (
273
+ lf.select(
274
+ "household_id",
275
+ original_car_id=pl.struct("ECH", "STM", index=pl.lit(a, dtype=pl.String)),
276
+ car_index=pl.lit(i + 1, dtype=pl.UInt8),
277
+ type=pl.col(f"M7{a}").replace_strict(CAR_TYPE_MAP),
278
+ fuel_type=pl.col(f"M8{a}").replace_strict(CAR_FUEL_TYPE_MAP),
279
+ fuel_type_group=pl.col(f"M8{a}").replace_strict(CAR_FUEL_TYPE_GROUP_MAP),
280
+ # Value 9999 seems to be used when year is unknown.
281
+ year=pl.col(f"M9{a}").replace(9999, None),
282
+ tax_horsepower=f"M10{a}",
283
+ ownership=(pl.col(f"M11{a}") + pl.col(f"MA{a}")).replace_strict(CAR_OWNERSHIP_MAP),
284
+ parking_location=pl.col(f"M12{a}").replace_strict(PARKING_LOCATION_MAP),
285
+ parking_type=pl.col(f"M13{a}").replace_strict(PARKING_TYPE_MAP),
286
+ )
287
+ for i, a in enumerate(("A", "B", "C", "D"))
288
+ ),
289
+ how="vertical",
290
+ )
291
+ # Drop the lines with empty car characteristics (there are always 4 cars per
292
+ # households even when the household has less than 4 cars).
293
+ lf = lf.filter(
294
+ pl.any_horizontal(
295
+ pl.all().exclude("household_id", "original_car_id", "car_index").is_not_null()
296
+ )
297
+ )
298
+ lf = clean_cars(lf)
299
+ return lf
300
+
301
+
302
+ def standardize_motorcycles(source1: str | bytes, source2: str | bytes, households: pl.LazyFrame):
303
+ lf = scan_households(source1, source2)
304
+ # Add household_id.
305
+ lf = lf.with_columns(original_household_id=pl.struct("ECH", "STM")).join(
306
+ households.select("original_household_id", "household_id"),
307
+ on="original_household_id",
308
+ how="left",
309
+ coalesce=True,
310
+ )
311
+ lf = pl.concat(
312
+ (
313
+ lf.select(
314
+ "household_id",
315
+ original_motorcycle_id=pl.struct("ECH", "STM", index=pl.lit(a, dtype=pl.String)),
316
+ motorcycle_index=pl.lit(i + 1, dtype=pl.UInt8),
317
+ type=pl.col(f"M15{a}").replace_strict(MOTORCYCLE_TYPE_MAP),
318
+ fuel_type=pl.col(f"M16{a}").replace_strict(MOTORCYCLE_FUEL_TYPE_MAP),
319
+ # Value 9999 seems to be used when year is unknown.
320
+ year=pl.col(f"M18{a}").replace(9999, None),
321
+ cm3_lower_bound=pl.col(f"M16{a}").replace_strict(
322
+ MOTORCYCLE_SIZE_LOWERBOUND_MAP, default=None
323
+ ),
324
+ cm3_upper_bound=pl.col(f"M16{a}").replace_strict(
325
+ MOTORCYCLE_SIZE_UPPERBOUND_MAP, default=None
326
+ ),
327
+ kw_lower_bound=pl.col(f"M16{a}").replace_strict(
328
+ MOTORCYCLE_KW_LOWERBOUND_MAP, default=None
329
+ ),
330
+ kw_upper_bound=pl.col(f"M16{a}").replace_strict(
331
+ MOTORCYCLE_KW_UPPERBOUND_MAP, default=None
332
+ ),
333
+ thermic_engine_type=pl.col(f"M17{a}").replace_strict(
334
+ MOTORCYCLE_THERMIC_ENGINE_TYPE_MAP, default=None
335
+ ),
336
+ parking_location=pl.col(f"M19{a}").replace_strict(PARKING_LOCATION_MAP),
337
+ # `default=None` is required because in some surveys (Rennes 2018), other values are
338
+ # used without being documented
339
+ parking_type=pl.col(f"M20{a}").replace_strict(PARKING_TYPE_MAP, default=None),
340
+ )
341
+ for i, a in enumerate(("A", "B", "C", "D"))
342
+ ),
343
+ how="vertical",
344
+ )
345
+ lf = lf.filter(
346
+ pl.any_horizontal(
347
+ pl.all()
348
+ .exclude("household_id", "original_motorcycle_id", "motorcycle_index")
349
+ .is_not_null()
350
+ )
351
+ )
352
+ lf = clean_motorcycles(lf)
353
+ return lf