crimepy-cdc 0.1.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.
- crimepy_cdc-0.1.0/LICENSE +21 -0
- crimepy_cdc-0.1.0/MANIFEST.in +27 -0
- crimepy_cdc-0.1.0/PKG-INFO +179 -0
- crimepy_cdc-0.1.0/README.md +112 -0
- crimepy_cdc-0.1.0/crimepy/CDCWLineRec.PNG +0 -0
- crimepy_cdc-0.1.0/crimepy/CarrolltonGrid.csv.zip +0 -0
- crimepy_cdc-0.1.0/crimepy/Dallas_MainArea_Proj.zip +0 -0
- crimepy_cdc-0.1.0/crimepy/Edges_Gang1.csv +49 -0
- crimepy_cdc-0.1.0/crimepy/Nodes_Gang1.csv +23 -0
- crimepy_cdc-0.1.0/crimepy/__init__.py +0 -0
- crimepy_cdc-0.1.0/crimepy/_optional.py +34 -0
- crimepy_cdc-0.1.0/crimepy/aoristic.py +412 -0
- crimepy_cdc-0.1.0/crimepy/cdcplot.py +274 -0
- crimepy_cdc-0.1.0/crimepy/chain.py +139 -0
- crimepy_cdc-0.1.0/crimepy/dallasdata.csv.zip +0 -0
- crimepy_cdc-0.1.0/crimepy/data.py +101 -0
- crimepy_cdc-0.1.0/crimepy/domset.py +322 -0
- crimepy_cdc-0.1.0/crimepy/exact.py +268 -0
- crimepy_cdc-0.1.0/crimepy/gbtm_scale.py +602 -0
- crimepy_cdc-0.1.0/crimepy/geo.py +1671 -0
- crimepy_cdc-0.1.0/crimepy/pmed.py +935 -0
- crimepy_cdc-0.1.0/crimepy/query.py +514 -0
- crimepy_cdc-0.1.0/crimepy/sppt.py +99 -0
- crimepy_cdc-0.1.0/crimepy/sppt_scale.py +510 -0
- crimepy_cdc-0.1.0/crimepy/time.py +493 -0
- crimepy_cdc-0.1.0/crimepy/wdd.py +432 -0
- crimepy_cdc-0.1.0/crimepy_cdc.egg-info/PKG-INFO +179 -0
- crimepy_cdc-0.1.0/crimepy_cdc.egg-info/SOURCES.txt +37 -0
- crimepy_cdc-0.1.0/crimepy_cdc.egg-info/dependency_links.txt +1 -0
- crimepy_cdc-0.1.0/crimepy_cdc.egg-info/requires.txt +48 -0
- crimepy_cdc-0.1.0/crimepy_cdc.egg-info/top_level.txt +1 -0
- crimepy_cdc-0.1.0/pyproject.toml +116 -0
- crimepy_cdc-0.1.0/setup.cfg +4 -0
- crimepy_cdc-0.1.0/tests/test_aor.py +578 -0
- crimepy_cdc-0.1.0/tests/test_bundled_data.py +44 -0
- crimepy_cdc-0.1.0/tests/test_cdcplot.py +18 -0
- crimepy_cdc-0.1.0/tests/test_chain.py +55 -0
- crimepy_cdc-0.1.0/tests/test_domset.py +10 -0
- crimepy_cdc-0.1.0/tests/test_exact.py +534 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Andrew Wheeler, Crime De-Coder LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# setuptools starts from the package, tests, and project metadata, then this
|
|
2
|
+
# file drops example notebooks, figures, and analysis outputs from the sdist.
|
|
3
|
+
prune notebooks
|
|
4
|
+
prune images
|
|
5
|
+
prune .claude
|
|
6
|
+
|
|
7
|
+
exclude chapel_hill_analysis.py
|
|
8
|
+
exclude chapel_hill_crimes.csv
|
|
9
|
+
exclude cluster_summary.csv
|
|
10
|
+
exclude breakins_map.html
|
|
11
|
+
exclude gem_chapel_hill.md
|
|
12
|
+
exclude weekly_breakins_cdc.png
|
|
13
|
+
exclude monthly_breakins_cdc.png
|
|
14
|
+
exclude Claude.md
|
|
15
|
+
|
|
16
|
+
# Example datasets the library does not load. Notebooks in a git checkout
|
|
17
|
+
# still read these paths; they are not part of the installed package.
|
|
18
|
+
exclude crimepy/bronx_data.csv
|
|
19
|
+
exclude crimepy/bronx_precinct.gpkg
|
|
20
|
+
exclude crimepy/bronx_uberhex.gpkg
|
|
21
|
+
exclude crimepy/CDC_Logo.svg
|
|
22
|
+
|
|
23
|
+
recursive-exclude crimepy/.ipynb_checkpoints *
|
|
24
|
+
recursive-exclude crimepy/__pycache__ *
|
|
25
|
+
global-exclude __pycache__
|
|
26
|
+
global-exclude *.py[cod]
|
|
27
|
+
global-exclude *~
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: crimepy-cdc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Crime analysis in Python
|
|
5
|
+
Author-email: Andrew Wheeler <andrew.wheeler@crimede-coder.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/apwheele/crimepy
|
|
8
|
+
Project-URL: Repository, https://github.com/apwheele/crimepy
|
|
9
|
+
Project-URL: Issues, https://github.com/apwheele/crimepy/issues
|
|
10
|
+
Project-URL: Crime De-Coder, https://crimede-coder.com/
|
|
11
|
+
Keywords: crime,crime-analysis,criminology,gis,hotspots
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: beautifulsoup4
|
|
26
|
+
Requires-Dist: cycler
|
|
27
|
+
Requires-Dist: folium
|
|
28
|
+
Requires-Dist: geopandas
|
|
29
|
+
Requires-Dist: lxml
|
|
30
|
+
Requires-Dist: matplotlib
|
|
31
|
+
Requires-Dist: networkx
|
|
32
|
+
Requires-Dist: numpy
|
|
33
|
+
Requires-Dist: openpyxl
|
|
34
|
+
Requires-Dist: pandas
|
|
35
|
+
Requires-Dist: pyproj
|
|
36
|
+
Requires-Dist: requests
|
|
37
|
+
Requires-Dist: scikit-learn
|
|
38
|
+
Requires-Dist: scipy>=1.11
|
|
39
|
+
Requires-Dist: shapely
|
|
40
|
+
Provides-Extra: network
|
|
41
|
+
Requires-Dist: osmnx; extra == "network"
|
|
42
|
+
Provides-Extra: opt
|
|
43
|
+
Requires-Dist: pulp; extra == "opt"
|
|
44
|
+
Requires-Dist: highspy; extra == "opt"
|
|
45
|
+
Requires-Dist: libpysal; extra == "opt"
|
|
46
|
+
Provides-Extra: notebooks
|
|
47
|
+
Requires-Dist: jupyter; extra == "notebooks"
|
|
48
|
+
Requires-Dist: ipycytoscape; extra == "notebooks"
|
|
49
|
+
Requires-Dist: contextily; extra == "notebooks"
|
|
50
|
+
Provides-Extra: gbtm
|
|
51
|
+
Requires-Dist: statsmodels; extra == "gbtm"
|
|
52
|
+
Provides-Extra: tableau
|
|
53
|
+
Requires-Dist: TableauScraper; extra == "tableau"
|
|
54
|
+
Provides-Extra: all
|
|
55
|
+
Requires-Dist: osmnx; extra == "all"
|
|
56
|
+
Requires-Dist: pulp; extra == "all"
|
|
57
|
+
Requires-Dist: highspy; extra == "all"
|
|
58
|
+
Requires-Dist: libpysal; extra == "all"
|
|
59
|
+
Requires-Dist: jupyter; extra == "all"
|
|
60
|
+
Requires-Dist: ipycytoscape; extra == "all"
|
|
61
|
+
Requires-Dist: contextily; extra == "all"
|
|
62
|
+
Requires-Dist: statsmodels; extra == "all"
|
|
63
|
+
Requires-Dist: TableauScraper; extra == "all"
|
|
64
|
+
Provides-Extra: test
|
|
65
|
+
Requires-Dist: pytest; extra == "test"
|
|
66
|
+
Dynamic: license-file
|
|
67
|
+
|
|
68
|
+
# crimepy -- a python package for crime analysis
|
|
69
|
+
|
|
70
|
+
A python package to help conduct different various types of crime analysis. Mostly a collection of various functions I have used over the years.
|
|
71
|
+
|
|
72
|
+
Andrew Wheeler
|
|
73
|
+
|
|
74
|
+
[Crime De-Coder LLC](https://crimede-coder.com/)
|
|
75
|
+
|
|
76
|
+

|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
Requires Python 3.11 or newer.
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install crimepy-cdc
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The PyPI project name is `crimepy-cdc`. The import name is `crimepy`:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import crimepy
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Some heavier pieces are optional extras:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
pip install "crimepy-cdc[network]" # OpenStreetMap street networks (osmnx)
|
|
96
|
+
pip install "crimepy-cdc[opt]" # patrol districting and site selection (PuLP, HiGHS, libpysal)
|
|
97
|
+
pip install "crimepy-cdc[notebooks]" # Jupyter, ipycytoscape, and contextily basemaps
|
|
98
|
+
pip install "crimepy-cdc[gbtm]" # statsmodels for Poisson-mixture GBTM
|
|
99
|
+
pip install "crimepy-cdc[tableau]" # Tableau dashboard scraping
|
|
100
|
+
pip install "crimepy-cdc[all]" # every extra above
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Patrol-district notebooks use both `[network]` (street distances) and `[opt]` (the solver). To work from a checkout:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
git clone https://github.com/apwheele/crimepy.git
|
|
107
|
+
cd crimepy
|
|
108
|
+
pip install -e ".[all,test]"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Examples
|
|
112
|
+
|
|
113
|
+
See the notebooks folder for example analyses:
|
|
114
|
+
|
|
115
|
+
- [Aoristic analysis](https://github.com/apwheele/crimepy/blob/main/notebooks/AoristicAnalysis.ipynb)
|
|
116
|
+
- [DBScan hotspots](https://github.com/apwheele/crimepy/blob/main/notebooks/DBScanHotspots.ipynb)
|
|
117
|
+
- [Prioritizing Call Ins via Dominant Sets](https://github.com/apwheele/crimepy/blob/main/notebooks/DominantSetNetwork.ipynb)
|
|
118
|
+
- [Time Series Charts](https://github.com/apwheele/crimepy/blob/main/notebooks/TimeSeriesCharts.ipynb)
|
|
119
|
+
- [Patrol Districting with Workload Equality](https://github.com/apwheele/crimepy/blob/main/notebooks/PatrolDistricts.ipynb)
|
|
120
|
+
- [Drone Base Site Selection](https://github.com/apwheele/crimepy/blob/main/notebooks/DroneSites.ipynb)
|
|
121
|
+
- [SPPT Compare Pre to Post Crime](https://github.com/apwheele/crimepy/blob/main/notebooks/SPPT_Compare_PrePost.ipynb)
|
|
122
|
+
- [Scalable SPPT by Crime Theme, Pre/Post](https://github.com/apwheele/crimepy/blob/main/notebooks/SPPT_ScaledByTheme_PrePost.ipynb)
|
|
123
|
+
- [Group-Based Trajectory Modelling (GBTM)](https://github.com/apwheele/crimepy/blob/main/notebooks/GBTMExample.ipynb)
|
|
124
|
+
- [Querying public Socrata or ESRI data](https://github.com/apwheele/crimepy/blob/main/notebooks/QueryData.ipynb)
|
|
125
|
+
- [Example Interactive Maps with Folium](https://github.com/apwheele/crimepy/blob/main/notebooks/FoliumExample.ipynb)
|
|
126
|
+
- [Weighted Displacement Difference to See Changes over Time](https://github.com/apwheele/crimepy/blob/main/notebooks/WDD_Examples.ipynb)
|
|
127
|
+
- [Analysis of Vandalism in Dallas (generated using Claude Code + Skills)](https://github.com/apwheele/crimepy/blob/main/notebooks/VandalismAnalysis.ipynb)
|
|
128
|
+
|
|
129
|
+
## Contributors
|
|
130
|
+
|
|
131
|
+
- [Andrew Wheeler (@apwheele)](https://github.com/apwheele) — creator and maintainer
|
|
132
|
+
- [agari (@routineactivity)](https://github.com/routineactivity) — scalable SPPT and GBTM functions and examples
|
|
133
|
+
|
|
134
|
+
## ToDo
|
|
135
|
+
|
|
136
|
+
Additional examples in Notebooks and documentation (contributors welcome!)
|
|
137
|
+
|
|
138
|
+
- Funnel charts
|
|
139
|
+
- nearby chains
|
|
140
|
+
- SPPT crime to police activity example
|
|
141
|
+
- small sample Benford/Day of week functions & example
|
|
142
|
+
- HDBSCAN functions
|
|
143
|
+
- github actions for linting
|
|
144
|
+
- try patrol districting with googles ORtools, see how fast it runs
|
|
145
|
+
- simpler tests for districting
|
|
146
|
+
- Folium example for lines and graduated circles
|
|
147
|
+
|
|
148
|
+
Other additional methods *I may* add (if you want these, let me know):
|
|
149
|
+
|
|
150
|
+
- synthetic control using Lasso ([blog post](https://andrewpwheeler.com/2023/10/04/synthetic-control-in-python-opioid-death-increases-in-oregon-and-washington/))
|
|
151
|
+
- network spillovers optimal assignment ([blog post](https://andrewpwheeler.com/2019/09/27/optimal-treatment-assignment-with-network-spillovers/))
|
|
152
|
+
- network experiment design ([Notebook](https://github.com/apwheele/Blog_Code/blob/master/Python/NetworkExperiment/NetworkExperimentDesign.ipynb))
|
|
153
|
+
- ?survey duplicates? ([Notebook](https://github.com/apwheele/Blog_Code/blob/master/Python/SurveyMatch/DupsSurvey.ipynb))
|
|
154
|
+
|
|
155
|
+
Suggestions are always welcome -- direct contributions are a better way to get the items you want in the codebase.
|
|
156
|
+
|
|
157
|
+
## Getting Started with Python
|
|
158
|
+
|
|
159
|
+
Don't know where to get started? Check out my introductory book on python for crime analysts, [Data Science for Crime Analysis with Python](https://crimede-coder.com/blogposts/2024/PythonDataScience)
|
|
160
|
+
|
|
161
|
+

|
|
162
|
+
|
|
163
|
+
## References
|
|
164
|
+
|
|
165
|
+
- Wheeler, A. P. (2016). Tables and graphs for monitoring temporal crime trends: Translating theory into practical crime analysis advice. [*International Journal of Police Science & Management*, 18(3), 159-172](https://journals.sagepub.com/doi/abs/10.1177/1461355716642781). [Preprint](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2551472)
|
|
166
|
+
|
|
167
|
+
- Wheeler, A. P. (2019). Creating optimal patrol areas using the p-median model. [*Policing: An International Journal*, 42(3), 318-333](https://www.emerald.com/insight/content/doi/10.1108/pijpsm-02-2018-0027/full/html). [Preprint](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3109791)
|
|
168
|
+
|
|
169
|
+
- Wheeler, A. P., & Kovandzic, T. V. (2018). Monitoring volatile homicide trends across US cities. [*Homicide Studies*, 22(2), 119-144](https://journals.sagepub.com/doi/abs/10.1177/1088767917740171). [Preprint](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2977556)
|
|
170
|
+
|
|
171
|
+
- Wheeler, A. P., McLean, S. J., Becker, K. J., & Worden, R. E. (2019). Choosing representatives to deliver the message in a group violence intervention. [*Justice Evaluation Journal*, 2(2), 93-117](https://www.tandfonline.com/doi/abs/10.1080/24751979.2019.1630661). [Preprint](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2934325)
|
|
172
|
+
|
|
173
|
+
- Wheeler, A. P., & Ratcliffe, J. H. (2018). A simple weighted displacement difference test to evaluate place based crime interventions. [*Crime Science*, 7(1), 11](https://link.springer.com/article/10.1186/s40163-018-0085-5). (Crime Science is an open journal)
|
|
174
|
+
|
|
175
|
+
- Wheeler, A. P., & Reuter, S. (2021). Redrawing hot spots of crime in Dallas, Texas. [*Police Quarterly*, 24(2), 159-184](https://journals.sagepub.com/doi/abs/10.1177/1098611120957948). [Preprint](https://www.crimrxiv.com/pub/wmelrli9)
|
|
176
|
+
|
|
177
|
+
- Wheeler, A. P., Riddell, J. R., & Haberman, C. P. (2021). Breaking the chain: How arrests reduce the probability of near repeat crimes. [*Criminal Justice Review*, 46(2), 236-258](https://journals.sagepub.com/doi/abs/10.1177/0734016821999707). [Preprint](https://osf.io/7tazd/download)
|
|
178
|
+
|
|
179
|
+
- Wheeler, A. P., Steenbeek, W., & Andresen, M. A. (2018). Testing for similarity in area‐based spatial patterns: Alternative methods to Andresen's spatial point pattern test. [*Transactions in GIS*, 22(3), 760-774](https://onlinelibrary.wiley.com/doi/abs/10.1111/tgis.12341). [Preprint](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3111822)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# crimepy -- a python package for crime analysis
|
|
2
|
+
|
|
3
|
+
A python package to help conduct different various types of crime analysis. Mostly a collection of various functions I have used over the years.
|
|
4
|
+
|
|
5
|
+
Andrew Wheeler
|
|
6
|
+
|
|
7
|
+
[Crime De-Coder LLC](https://crimede-coder.com/)
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Requires Python 3.11 or newer.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install crimepy-cdc
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The PyPI project name is `crimepy-cdc`. The import name is `crimepy`:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import crimepy
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Some heavier pieces are optional extras:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install "crimepy-cdc[network]" # OpenStreetMap street networks (osmnx)
|
|
29
|
+
pip install "crimepy-cdc[opt]" # patrol districting and site selection (PuLP, HiGHS, libpysal)
|
|
30
|
+
pip install "crimepy-cdc[notebooks]" # Jupyter, ipycytoscape, and contextily basemaps
|
|
31
|
+
pip install "crimepy-cdc[gbtm]" # statsmodels for Poisson-mixture GBTM
|
|
32
|
+
pip install "crimepy-cdc[tableau]" # Tableau dashboard scraping
|
|
33
|
+
pip install "crimepy-cdc[all]" # every extra above
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Patrol-district notebooks use both `[network]` (street distances) and `[opt]` (the solver). To work from a checkout:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
git clone https://github.com/apwheele/crimepy.git
|
|
40
|
+
cd crimepy
|
|
41
|
+
pip install -e ".[all,test]"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Examples
|
|
45
|
+
|
|
46
|
+
See the notebooks folder for example analyses:
|
|
47
|
+
|
|
48
|
+
- [Aoristic analysis](https://github.com/apwheele/crimepy/blob/main/notebooks/AoristicAnalysis.ipynb)
|
|
49
|
+
- [DBScan hotspots](https://github.com/apwheele/crimepy/blob/main/notebooks/DBScanHotspots.ipynb)
|
|
50
|
+
- [Prioritizing Call Ins via Dominant Sets](https://github.com/apwheele/crimepy/blob/main/notebooks/DominantSetNetwork.ipynb)
|
|
51
|
+
- [Time Series Charts](https://github.com/apwheele/crimepy/blob/main/notebooks/TimeSeriesCharts.ipynb)
|
|
52
|
+
- [Patrol Districting with Workload Equality](https://github.com/apwheele/crimepy/blob/main/notebooks/PatrolDistricts.ipynb)
|
|
53
|
+
- [Drone Base Site Selection](https://github.com/apwheele/crimepy/blob/main/notebooks/DroneSites.ipynb)
|
|
54
|
+
- [SPPT Compare Pre to Post Crime](https://github.com/apwheele/crimepy/blob/main/notebooks/SPPT_Compare_PrePost.ipynb)
|
|
55
|
+
- [Scalable SPPT by Crime Theme, Pre/Post](https://github.com/apwheele/crimepy/blob/main/notebooks/SPPT_ScaledByTheme_PrePost.ipynb)
|
|
56
|
+
- [Group-Based Trajectory Modelling (GBTM)](https://github.com/apwheele/crimepy/blob/main/notebooks/GBTMExample.ipynb)
|
|
57
|
+
- [Querying public Socrata or ESRI data](https://github.com/apwheele/crimepy/blob/main/notebooks/QueryData.ipynb)
|
|
58
|
+
- [Example Interactive Maps with Folium](https://github.com/apwheele/crimepy/blob/main/notebooks/FoliumExample.ipynb)
|
|
59
|
+
- [Weighted Displacement Difference to See Changes over Time](https://github.com/apwheele/crimepy/blob/main/notebooks/WDD_Examples.ipynb)
|
|
60
|
+
- [Analysis of Vandalism in Dallas (generated using Claude Code + Skills)](https://github.com/apwheele/crimepy/blob/main/notebooks/VandalismAnalysis.ipynb)
|
|
61
|
+
|
|
62
|
+
## Contributors
|
|
63
|
+
|
|
64
|
+
- [Andrew Wheeler (@apwheele)](https://github.com/apwheele) — creator and maintainer
|
|
65
|
+
- [agari (@routineactivity)](https://github.com/routineactivity) — scalable SPPT and GBTM functions and examples
|
|
66
|
+
|
|
67
|
+
## ToDo
|
|
68
|
+
|
|
69
|
+
Additional examples in Notebooks and documentation (contributors welcome!)
|
|
70
|
+
|
|
71
|
+
- Funnel charts
|
|
72
|
+
- nearby chains
|
|
73
|
+
- SPPT crime to police activity example
|
|
74
|
+
- small sample Benford/Day of week functions & example
|
|
75
|
+
- HDBSCAN functions
|
|
76
|
+
- github actions for linting
|
|
77
|
+
- try patrol districting with googles ORtools, see how fast it runs
|
|
78
|
+
- simpler tests for districting
|
|
79
|
+
- Folium example for lines and graduated circles
|
|
80
|
+
|
|
81
|
+
Other additional methods *I may* add (if you want these, let me know):
|
|
82
|
+
|
|
83
|
+
- synthetic control using Lasso ([blog post](https://andrewpwheeler.com/2023/10/04/synthetic-control-in-python-opioid-death-increases-in-oregon-and-washington/))
|
|
84
|
+
- network spillovers optimal assignment ([blog post](https://andrewpwheeler.com/2019/09/27/optimal-treatment-assignment-with-network-spillovers/))
|
|
85
|
+
- network experiment design ([Notebook](https://github.com/apwheele/Blog_Code/blob/master/Python/NetworkExperiment/NetworkExperimentDesign.ipynb))
|
|
86
|
+
- ?survey duplicates? ([Notebook](https://github.com/apwheele/Blog_Code/blob/master/Python/SurveyMatch/DupsSurvey.ipynb))
|
|
87
|
+
|
|
88
|
+
Suggestions are always welcome -- direct contributions are a better way to get the items you want in the codebase.
|
|
89
|
+
|
|
90
|
+
## Getting Started with Python
|
|
91
|
+
|
|
92
|
+
Don't know where to get started? Check out my introductory book on python for crime analysts, [Data Science for Crime Analysis with Python](https://crimede-coder.com/blogposts/2024/PythonDataScience)
|
|
93
|
+
|
|
94
|
+

|
|
95
|
+
|
|
96
|
+
## References
|
|
97
|
+
|
|
98
|
+
- Wheeler, A. P. (2016). Tables and graphs for monitoring temporal crime trends: Translating theory into practical crime analysis advice. [*International Journal of Police Science & Management*, 18(3), 159-172](https://journals.sagepub.com/doi/abs/10.1177/1461355716642781). [Preprint](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2551472)
|
|
99
|
+
|
|
100
|
+
- Wheeler, A. P. (2019). Creating optimal patrol areas using the p-median model. [*Policing: An International Journal*, 42(3), 318-333](https://www.emerald.com/insight/content/doi/10.1108/pijpsm-02-2018-0027/full/html). [Preprint](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3109791)
|
|
101
|
+
|
|
102
|
+
- Wheeler, A. P., & Kovandzic, T. V. (2018). Monitoring volatile homicide trends across US cities. [*Homicide Studies*, 22(2), 119-144](https://journals.sagepub.com/doi/abs/10.1177/1088767917740171). [Preprint](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2977556)
|
|
103
|
+
|
|
104
|
+
- Wheeler, A. P., McLean, S. J., Becker, K. J., & Worden, R. E. (2019). Choosing representatives to deliver the message in a group violence intervention. [*Justice Evaluation Journal*, 2(2), 93-117](https://www.tandfonline.com/doi/abs/10.1080/24751979.2019.1630661). [Preprint](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2934325)
|
|
105
|
+
|
|
106
|
+
- Wheeler, A. P., & Ratcliffe, J. H. (2018). A simple weighted displacement difference test to evaluate place based crime interventions. [*Crime Science*, 7(1), 11](https://link.springer.com/article/10.1186/s40163-018-0085-5). (Crime Science is an open journal)
|
|
107
|
+
|
|
108
|
+
- Wheeler, A. P., & Reuter, S. (2021). Redrawing hot spots of crime in Dallas, Texas. [*Police Quarterly*, 24(2), 159-184](https://journals.sagepub.com/doi/abs/10.1177/1098611120957948). [Preprint](https://www.crimrxiv.com/pub/wmelrli9)
|
|
109
|
+
|
|
110
|
+
- Wheeler, A. P., Riddell, J. R., & Haberman, C. P. (2021). Breaking the chain: How arrests reduce the probability of near repeat crimes. [*Criminal Justice Review*, 46(2), 236-258](https://journals.sagepub.com/doi/abs/10.1177/0734016821999707). [Preprint](https://osf.io/7tazd/download)
|
|
111
|
+
|
|
112
|
+
- Wheeler, A. P., Steenbeek, W., & Andresen, M. A. (2018). Testing for similarity in area‐based spatial patterns: Alternative methods to Andresen's spatial point pattern test. [*Transactions in GIS*, 22(3), 760-774](https://onlinelibrary.wiley.com/doi/abs/10.1111/tgis.12341). [Preprint](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3111822)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Source,Target
|
|
2
|
+
20,1
|
|
3
|
+
3,2
|
|
4
|
+
2,3
|
|
5
|
+
18,4
|
|
6
|
+
6,5
|
|
7
|
+
5,6
|
|
8
|
+
7,6
|
|
9
|
+
21,6
|
|
10
|
+
6,7
|
|
11
|
+
21,7
|
|
12
|
+
10,8
|
|
13
|
+
14,8
|
|
14
|
+
15,8
|
|
15
|
+
21,8
|
|
16
|
+
17,9
|
|
17
|
+
8,10
|
|
18
|
+
18,10
|
|
19
|
+
20,10
|
|
20
|
+
21,10
|
|
21
|
+
22,11
|
|
22
|
+
16,12
|
|
23
|
+
17,13
|
|
24
|
+
8,14
|
|
25
|
+
16,14
|
|
26
|
+
8,15
|
|
27
|
+
20,15
|
|
28
|
+
21,15
|
|
29
|
+
12,16
|
|
30
|
+
14,16
|
|
31
|
+
9,17
|
|
32
|
+
13,17
|
|
33
|
+
4,18
|
|
34
|
+
10,18
|
|
35
|
+
20,18
|
|
36
|
+
21,19
|
|
37
|
+
1,20
|
|
38
|
+
10,20
|
|
39
|
+
15,20
|
|
40
|
+
18,20
|
|
41
|
+
21,20
|
|
42
|
+
6,21
|
|
43
|
+
7,21
|
|
44
|
+
8,21
|
|
45
|
+
10,21
|
|
46
|
+
15,21
|
|
47
|
+
19,21
|
|
48
|
+
20,21
|
|
49
|
+
11,22
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Id,TotalInc,Attended,impact,Prob_or_Par
|
|
2
|
+
1,2,0,0,0
|
|
3
|
+
2,2,0,1,1
|
|
4
|
+
3,5,0,1,0
|
|
5
|
+
4,5,1,1,0
|
|
6
|
+
5,4,1,1,1
|
|
7
|
+
6,4,0,1,0
|
|
8
|
+
7,4,0,1,1
|
|
9
|
+
8,11,0,1,0
|
|
10
|
+
9,7,0,1,0
|
|
11
|
+
10,7,0,1,0
|
|
12
|
+
11,4,1,1,0
|
|
13
|
+
12,12,0,0,1
|
|
14
|
+
13,4,0,1,0
|
|
15
|
+
14,13,0,0,0
|
|
16
|
+
15,9,0,0,0
|
|
17
|
+
16,3,0,0,0
|
|
18
|
+
17,8,0,1,0
|
|
19
|
+
18,4,0,1,0
|
|
20
|
+
19,2,0,1,0
|
|
21
|
+
20,19,0,1,1
|
|
22
|
+
21,16,0,1,0
|
|
23
|
+
22,7,1,1,0
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Import optional dependencies the first time they are used."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import importlib
|
|
6
|
+
from types import ModuleType
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class optional_dependency:
|
|
10
|
+
"""Attribute access imports *module_name* and caches the module.
|
|
11
|
+
|
|
12
|
+
A missing install raises ``ImportError`` naming the extra that provides it.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, module_name: str, extra: str, feature: str) -> None:
|
|
16
|
+
self._module_name = module_name
|
|
17
|
+
self._extra = extra
|
|
18
|
+
self._feature = feature
|
|
19
|
+
self._module: ModuleType | None = None
|
|
20
|
+
|
|
21
|
+
def _load(self) -> ModuleType:
|
|
22
|
+
if self._module is None:
|
|
23
|
+
try:
|
|
24
|
+
self._module = importlib.import_module(self._module_name)
|
|
25
|
+
except ImportError as exc:
|
|
26
|
+
raise ImportError(
|
|
27
|
+
f"{self._feature} requires the optional package "
|
|
28
|
+
f"{self._module_name!r}. Install it with: "
|
|
29
|
+
f"pip install 'crimepy-cdc[{self._extra}]'"
|
|
30
|
+
) from exc
|
|
31
|
+
return self._module
|
|
32
|
+
|
|
33
|
+
def __getattr__(self, name: str):
|
|
34
|
+
return getattr(self._load(), name)
|