-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.qmd
executable file
·142 lines (113 loc) · 12.9 KB
/
README.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
format: gfm
execute:
cache: false
fig.path: "man/figures/README-"
message: false
---
# jtstats: Getting Journey Time Statistics data with R and Python
This short article demonstrates how to get data from the UK's Department for Transport funded JTS project with R and Python.
It accompanies a more detailed paper on the subject.
The R and Python versions are hosted on github at datasciencecampus/jtstats-r and datasciencecampus/jtstats-py.
For further details see the official JTS home page at https://www.gov.uk/government/statistical-data-sets/journey-time-statistics-data-tables-jts
If the information provided is of use and interest, please cite the accompanying paper as follows (TBC):
## Retrieval of JTS data using the R package
Install the package as follows:
```{r}
#| eval: false
remotes::install_github("datasciencecampus/jtstats-r")
```
From the readme of the R package we can download a specific dataset as follows:
```{r}
library(jtstats)
jts_geo = get_jts(type = "jts04", purpose = "GPs", sheet = 2017, geo = TRUE)
# We'll print data for Hartlepool and Middlesbrough:
jts_hartlepool_middlesbrough = jts_geo[jts_geo$LA_Name %in% c("Hartlepool", "Middlesbrough"), ]
jts_hartlepool_middlesbrough[, c("LA_Name", "GP_pop")]
```
## Retrieval of JTS data using the Python package
Install the package as follows from the `jtstats-py` directory:
```{bash}
#| eval: false
cd ../jtstats-py # if already there
curl -sSL https://install.python-poetry.org | python3 -
# See https://python-poetry.org/docs/#installing-with-the-official-installer
poetry install
# To open a Python session with all the dependencies you can run the following:
poetry shell
python
# From the Python shell, load the package to test it's installed:
import jtspy as jts
# Access the equivalent dataset from the Python package:
jts_geo = jts.get_jts(type_code = "jts04", spec = "gp", sheet = "2017")
# Print the values for Hartlepool and Middlesbrough:
jts_hartlepool_middlesbrough = jts_geo[jts_geo["LA_Name"].isin(["Hartlepool", "Middlesbrough"])]
# Print the first 5 columns:
print(jts_hartlepool_middlesbrough[["LA_Name", "GP_pop"]].head(4))
```
```
0 LA_Name GP_pop
2 Hartlepool 41483.728979
3 Middlesbrough 58295.046099
```
### Details of the Python package
The Python package allows easy retrieval of the JTS data using the ````get_jts()```` function. The key parameters that can be specified in order to specify what data to retrieve are: ````type_code````, ````spec````, ````sheet```` and ````table_code```` (even though this last parameter is only rarely needed). The table here reports the values to be used for these parameters in order to retrieve each of the JTS data. In some cases, the ````spec```` parameter should be set to empty and the ````sheet```` parameter should be used instead. These occurrences are indicated with $^\S$ in the table below. For all other occurrences, the ````sheet```` parameter should be simply set to the year for which data is needed, e.g. ````sheet = '2019'````. The ````get_jts()```` function returns a ````pandas```` dataframe. The size of the returned dataframe is given in the last column (in the format #rows $\times$ #columns}) of the table, for the specific case of 2019 data. Notes: $^\star$ here, public transport also includes walking. Walking was introduced as a separate mode of travel only for 2019 data. $^\S$ this value should actually be used for the ````sheet```` parameter in the ````get_jts()```` function, and the ````spec```` parameter should be left empty. $^\dagger$ this value should be used in the ````table_code```` parameter in the ````get_jts()```` function, and the ````type_code```` parameter should be left unspecified.
| Table title | Description | Type code | Spec/Sheet | Size |
|-------------|--------------------------------------------------------------------------------------------|----------------|------------------|-------------------|
| JTS0101 | Travel time to reach nearest key services by mode of travel (England) | jts01 | JTS0101$^\S$ | $16 \times 12$ |
| JTS0102 | Travel time to reach nearest key services by mode of travel (by urban/rural) | jts01 | urban | $48 \times 14$ |
| JTS0103 | Travel time to reach nearest key services by mode of travel (by region) | jts01 | region | $36 \times 13$ |
| JTS0104 | Travel time to reach nearest key services by mode of travel (by local authority) | jts01 | local authority | $361\times 7$ |
| JTS0201 | Access to key services within journey times by mode of travel (England) | jts02 | | 32$\times$ 13 |
| JTS0202 | Access to key services within journey times by mode of travel (by urban/rural) | jts02 | urban | 64$\times$ 14 |
| JTS0203 | Access to key services within journey times by public transport$^\star$ (by region) | jts02 | public transport | 71$\times$ 13 |
| JTS0204 | Access to key services within journey times by cycle (by region) | jts02 | cycle | 71$\times$ 13 |
| JTS0205 | Access to key services within journey times by car (by region) | jts02 | car | 71$\times$ 13 |
| JTS0206 | Access to key services within journey times by walking (by region) | jts0206$^\dagger$ | | 71$\times$ 13 |
| JTS0301 | Number of sites within journey time by key services and mode of travel (England) | jts03 | | 19$\times$ 13 |
| JTS0302 | Number of sites within journey time by key services and mode of travel (urban/rural) | jts03 | urban | 32$\times$ 15 |
| JTS0303 | Number of sites within journey time by key services and public transport$^\star$ (regions) | jts03 | public transport | 36$\times$ 14 |
| JTS0304 | Number of sites within journey time by key services and cycle (regions) | jts03 | cycle | 36$\times$ 14 |
| JTS0305 | Number of sites within journey time by key services and car (regions) | jts03 | car | 36$\times$ 14 |
| JTS0306 | Number of sites within journey time by key services and walking (regions) | jts0306$^\dagger$ | | 36$\times$ 14 |
| JTS0401 | Journey times for employment centres by mode of travel (local authority) | jts04 | employment | 361$\times$ 112 |
| JTS0402 | Journey times for primary schools by mode of travel (local authority) | jts04 | primary | 361$\times$ 40 |
| JTS0403 | Journey times for secondary schools by mode of travel (local authority) | jts04 | secondary | 361$\times$ 40 |
| JTS0404 | Journey times for further education by mode of travel (local authority) | jts04 | further | 361$\times$ 40 |
| JTS0405 | Journey times for GPs by mode of travel (local authority) | jts04 | gp | 361$\times$ 40 |
| JTS0406 | Journey times for hospitals by mode of travel (local authority) | jts04 | hospital | 361$\times$ 40 |
| JTS0407 | Journey times for food stores by mode of travel (local authority) | jts04 | food | 361$\times$ 40 |
| JTS0408 | Journey times for town centres by mode of travel (local authority) | jts04 | town | 361$\times$ 40 |
| JTS0409 | Journey times to pharmacy by cycle and car (local authority) | jts04 | pharmacy | 361$\times$ 22 |
| JTS0501 | Journey times for employment centres by mode of travel (LSOA) | jts05 | employment | 32844$\times$ 113 |
| JTS0502 | Journey times for primary schools by mode of travel (LSOA) | jts05 | primary | 32844$\times$ 41 |
| JTS0503 | Journey times for secondary schools by mode of travel (LSOA) | jts05 | secondary | 32844$\times$ 41 |
| JTS0504 | Journey times for further education by mode of travel (LSOA) | jts05 | further | 32844$\times$ 41 |
| JTS0505 | Journey times for GPs by mode of travel (LSOA) | jts05 | gp | 32844$\times$ 41 |
| JTS0506 | Journey times for hospitals by mode of travel (LSOA) | jts05 | hospital | 32844$\times$ 41 |
| JTS0507 | Journey times for food stores by mode of travel (LSOA) | jts05 | food | 32844$\times$ 41 |
| JTS0508 | Journey times for town centres by mode of travel (LSOA) | jts05 | town | 32844$\times$ 41 |
| JTS0509 | Journey times to pharmacy by cycle and car (LSOA) | jts05 | pharmacy | 32844$\times$ 23 |
## Retrieval of JTS data using the Python module ( JTS09)
As in the table above, we report here how to retrieve the JTS data using the Python package. In particular, this table focuses on the journey times connectivity (JTS09) data, which have a slightly different format than the rest. For this reason, the table includes separately the ````spec```` and ````sheet```` parameters, since in most cases here they both need to be set in order to retrieve the correct data.
| Table title | Description | Type code | Spec | Sheet | Size |
|-------------|----------------------------------------------------------------------|-----------|----------|-------------------|------------------|
| JTS0901 | Journey times to nearest airports (local authority) | jts09 | airports | JTS0901_Nearest | 128$\times$ 6 |
| JTS0901 | Journey times to selected airports (local authority) | jts09 | airports | JTS0901_Selected | 128$\times$ 44 |
| JTS0902 | Catchment population measures for airports (local authority) | jts09 | airports | JTS0902 | 32$\times$ 14 |
| JTS0903 | Population within journey time of airports (local authority) | jts0903 | airports | JTS0903 | 130$\times$ 9 |
| JTS0904 | Number airports within journey time (local authority) | jts09 | airports | JTS0904 | 129$\times$ 9 |
| JTS0905 | Journey times to selected airports (LSOA) | jts09 | airports | JTS0905_Selected | 32844$\times$ 41 |
| JTS0905 | Journey times to airports, summary (LSOA) | jts09 | airports | JTS0905_Summary | 32844$\times$ 9 |
| JTS0921 | Journey times to nearest rail stations (local authority) | jts09 | rail | JTS0921_Nearest | 119$\times$ 7 |
| JTS0921 | Journey times to rail stations by car (local authority) | jts09 | rail | car | 120$\times$ 81 |
| JTS0921 | Journey times to rail stations by public transport (local authority) | jts09 | rail | PT | 120$\times$ 81 |
| JTS0922 | Catchment population measures for rail stations (England) | jts09 | rail | JTS0922 | 79$\times$ 15 |
| JTS0923 | Population within journey time of rail stations (local authority) | jts09 | rail | JTS0923 | 130$\times$ 10 |
| JTS0924 | Number of rail stations within journey time (local authority) | jts09 | rail | JTS0924 | 129$\times$ 9 |
| JTS0925 | Journey times by public transport for selected rail stations (LSOA) | jts09 | rail | JTS0925_Selected | 32844$\times$ 84 |
| JTS0925 | Journey times by public transport for rail stations, summary (LSOA) | jts09 | rail | JTS0926_Summary | 32844$\times$ 7 |
| JTS0926 | Journey times by car for selected rail stations (LSOA) | jts09 | rail | JTS0926_Selected | 32844$\times$ 84 |
| JTS0926 | Journey times by car for rail stations, summary (LSOA) | jts09 | rail | JTS0926_Summary | 32844$\times$ 7 |
| JTS0930 | Travel time to city centres (local authority) | jts09 | | JTS0930_LA | 361$\times$ 5 |
| JTS0930 | Travel time to city centres (LSOA) | jts09 | | JTS0930_LSOA | 32844$\times$ 6 |