Skip to content

Commit

Permalink
Merge branch 'lsoa_bornames' of https://github.com/palpatel0/project-…
Browse files Browse the repository at this point in the history
  • Loading branch information
TomWFox committed Dec 19, 2023
2 parents c8bc7ee + 93b388a commit b791073
Show file tree
Hide file tree
Showing 15 changed files with 346 additions and 222 deletions.
14 changes: 10 additions & 4 deletions _toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

format: jb-book
root: pages/intro
chapters:
- file: pages/markdown
- file: pages/markdown-notebooks
- file: pages/notebooks
parts:
- caption: Exploration
chapters:
- file: pages/aviation-security
- caption: Analysis
chapters:
- file: pages/seasonal-changes
- caption: Usage
chapters:
- file: pages/multi_index.Rmd
Binary file added assets/New_Ward_Map_2022.pdf
Binary file not shown.
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 126 additions & 0 deletions pages/aviation-security.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Aviation Security (SO18) Borough

The most standout borough in the Met crime stats dataset is the one named "Aviation Security (SO18)". Perhaps unsurprisingly, you won't find this borough in [lists of London Boroughs](https://en.wikipedia.org/wiki/List_of_London_boroughs).

```{python}
import math
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from projtools.data import Data
plt.style.use('../styles/rose-pine-dawn.mplstyle')
data = Data()
```

```{python}
(data.ward
.loc[:, :, :, :, "Aviation Security (SO18)"]
.index
.get_level_values("ward_code")
.unique())
```

There is only one ward associated with the Aviation Security (SO18) borough. Searching the rest of the data for the `ward_code` reveals that this ward is present in both Avaition Security (SO18) and Hillingdon (which is actually a London Borough)...

```{python}
(data.ward
.loc[:, "E05013570", :]
.index
.get_level_values("borough")
.unique())
```

A quick DuckDuckGo search will inform you that this borough represents a [specialist operations unit](https://en.wikipedia.org/wiki/Aviation_Security_Operational_Command_Unit) within the Met. The unit is responsible for the policing of Heathrow Airport and London City Airport which raised the question; why is there no ward associated with SO18 in the area of London City Airport?

London City Airport is located in the borough of Newham...

```{python}
(data.ward
.loc[:, :, :, :, "Newham"]
.index
.get_level_values("ward_name")
.unique())
```

Looking on Newham's website we can see the the airport sits in the Royal Albert ward:

![New_Ward_Map_2022](../assets/New_Ward_Map_2022.pdf)

Source: [Newham Borough](https://www.newham.gov.uk/council/review-polling-districts-polling-places-new-ward-arrangements/2)

Presumably the SO18 borough in the Heathrow Villages ward has been made to separate the data for reporting purposes. For whatever reason the same principle has not been applied in the case of London City Airport.

Digging into the crime stats for the Heathrow Villages ward can give us an idea of when this change seems to have been made...

```{python}
(data.ward
.loc["Heathrow Villages", :, :, "Other Theft", "Hillingdon"]
.T
.groupby(level="year")
.sum()
.plot(ylabel="number of crimes", title="other theft in Hillingdon"))
```

There is a sharp decline in 2020 before a rise in 2022. A sharp decline in theft in 2020 can probably be explained by COVID-19 lockdowns, with the return to 'normal' activity causing a rise to near pre-pandemic levels. At first glance the sharp decline in 2023 is puzzling, the dataset runs until the end of October so the number of crimes shouldn't be this low. By plotting the SO18 numbers we get an idea of what might have happened...

```{python}
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12,4), sharey=True)
fig.tight_layout()
(data.ward
.loc["Heathrow Villages", :, :, "Other Theft"]
.T
.groupby(level="year")
.sum()
.plot(ax=axes[0], ylabel="number of crimes", title="other theft offences"))
plot = (data.ward
.loc["Heathrow Villages", :, :, "Other Theft"]
.T
.groupby(level="year")
.sum()
.sum(axis=1)
.plot(ax=axes[1], title="other theft offences"))
plot.legend(["E05013570 - Hillingdon & SO18"])
```

As you can see, the first other theft recorded in SO18 was in 2020, followed by a sharp rise in 2023. Adding the two sets of crimes together removes a large amount of the 2023 fall. It seems safe to assume that in 2023 the way the Met recorded data about crimes in this ward was changed leading to a shift in crimes from the Hillingdon row to the SO18 row.


## Other Crimes

Plotting all the crimes in which there is data recorded for both Hillingdon and SO18 we can see that the same 'shift' of recorded crimes from Hillingdon to SO18 in 2023 can be seen clearly across most offences.

```{python}
offences_both = (data.ward
.loc["Heathrow Villages", :, :, :]
.groupby(level="offence")
.size()) == 2
offences_both = offences_both.keys()[offences_both]
offences = (data.ward
.loc["Heathrow Villages", :, :, :]
.index
.get_level_values("offence")
.unique())
offences = offences[offences.isin(offences_both)]
rows = math.ceil(len(offences) / 3)
fig, axes = plt.subplots(nrows=rows, ncols=3, figsize=(20,40))
fig.tight_layout()
fig.subplots_adjust(top=1.8)
for index, value in enumerate(offences):
y = index % 3
x = index // 3
plot_data = data.ward.xs(("Heathrow Villages", slice(None), slice(None), value), drop_level=False)
plot = (plot_data.T
.groupby(level="year")
.sum()
.plot(ax=axes[x,y], title=value, ylabel="number of crimes"))
plot.legend(plot_data.index.get_level_values("borough"))
```
2 changes: 1 addition & 1 deletion pages/intro.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Project Daylight Robbery
# Introduction

This is a data science project investigating a geographical dataset of crimes recorded by the Metropolitan Police in London. See the table of contents below for the different sections of the project.

Expand Down
54 changes: 0 additions & 54 deletions pages/markdown-notebooks.md

This file was deleted.

55 changes: 0 additions & 55 deletions pages/markdown.md

This file was deleted.

2 changes: 1 addition & 1 deletion multi_index.Rmd → pages/multi_index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import numpy as np
import pandas as pd
from projtools.data import Data
import matplotlib.pyplot as plt
plt.style.use('projtools/styles/rose-pine.mplstyle')
plt.style.use('../styles/rose-pine.mplstyle')
```

```{python jupyter={'outputs_hidden': True}}
Expand Down
107 changes: 0 additions & 107 deletions pages/notebooks.Rmd

This file was deleted.

Loading

0 comments on commit b791073

Please sign in to comment.