Skip to content

Commit 7d87291

Browse files
authored
Merge pull request #230 from jGaboardi/lint_and_format_tobler
[maint] `ruff` review for `tobler`
2 parents 4a43e01 + 07d757c commit 7d87291

24 files changed

+366
-295
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,7 @@ ENV/
9797
nlcd_2011.tif
9898

9999
docs/generated/
100-
docs/apidocs/
100+
docs/apidocs/
101+
102+
# macOS
103+
*.DS_Store

notebooks/01_interpolation_methods_overview.ipynb

Lines changed: 75 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
"metadata": {},
4949
"outputs": [],
5050
"source": [
51-
"c1 = load_example('Charleston1')\n",
52-
"c2 = load_example('Charleston2')"
51+
"c1 = load_example(\"Charleston1\")\n",
52+
"c2 = load_example(\"Charleston2\")"
5353
]
5454
},
5555
{
@@ -74,7 +74,7 @@
7474
"metadata": {},
7575
"outputs": [],
7676
"source": [
77-
"tracts = gpd.read_file(c1.get_path('sc_final_census2.shp')).to_crs(crs)"
77+
"tracts = gpd.read_file(c1.get_path(\"sc_final_census2.shp\")).to_crs(crs)"
7878
]
7979
},
8080
{
@@ -83,7 +83,7 @@
8383
"metadata": {},
8484
"outputs": [],
8585
"source": [
86-
"zip_codes = gpd.read_file(c2.get_path('CharlestonMSA2.shp')).to_crs(crs)"
86+
"zip_codes = gpd.read_file(c2.get_path(\"CharlestonMSA2.shp\")).to_crs(crs)"
8787
]
8888
},
8989
{
@@ -105,13 +105,13 @@
105105
}
106106
],
107107
"source": [
108-
"fig, ax = plt.subplots(1,2, figsize=(14,7))\n",
108+
"fig, ax = plt.subplots(1, 2, figsize=(14, 7))\n",
109109
"\n",
110110
"tracts.plot(ax=ax[0])\n",
111111
"zip_codes.plot(ax=ax[1])\n",
112112
"\n",
113113
"for ax in ax:\n",
114-
" ax.axis('off')"
114+
" ax.axis(\"off\")"
115115
]
116116
},
117117
{
@@ -145,7 +145,7 @@
145145
"metadata": {},
146146
"outputs": [],
147147
"source": [
148-
"tracts['pct_poverty'] = tracts.POV_POP/tracts.POV_TOT"
148+
"tracts[\"pct_poverty\"] = tracts.POV_POP / tracts.POV_TOT"
149149
]
150150
},
151151
{
@@ -168,7 +168,12 @@
168168
"metadata": {},
169169
"outputs": [],
170170
"source": [
171-
"results = area_interpolate(source_df=tracts, target_df=zip_codes, intensive_variables=['pct_poverty'], extensive_variables=['EMP_MALE'])"
171+
"results = area_interpolate(\n",
172+
" source_df=tracts,\n",
173+
" target_df=zip_codes,\n",
174+
" intensive_variables=[\"pct_poverty\"],\n",
175+
" extensive_variables=[\"EMP_MALE\"],\n",
176+
")"
172177
]
173178
},
174179
{
@@ -200,16 +205,16 @@
200205
}
201206
],
202207
"source": [
203-
"fig, ax = plt.subplots(1,2, figsize=(14,7))\n",
208+
"fig, ax = plt.subplots(1, 2, figsize=(14, 7))\n",
204209
"\n",
205-
"results.plot('EMP_MALE', scheme='quantiles', ax=ax[0])\n",
206-
"tracts.plot('EMP_MALE', scheme='quantiles', ax=ax[1])\n",
210+
"results.plot(\"EMP_MALE\", scheme=\"quantiles\", ax=ax[0])\n",
211+
"tracts.plot(\"EMP_MALE\", scheme=\"quantiles\", ax=ax[1])\n",
207212
"\n",
208-
"ax[0].set_title('interpolated')\n",
209-
"ax[1].set_title('original')\n",
213+
"ax[0].set_title(\"interpolated\")\n",
214+
"ax[1].set_title(\"original\")\n",
210215
"for ax in ax:\n",
211-
" ax.axis('off')\n",
212-
"fig.suptitle('Male Employment (extensive)')"
216+
" ax.axis(\"off\")\n",
217+
"fig.suptitle(\"Male Employment (extensive)\")"
213218
]
214219
},
215220
{
@@ -241,16 +246,16 @@
241246
}
242247
],
243248
"source": [
244-
"fig, ax = plt.subplots(1,2, figsize=(14,7))\n",
249+
"fig, ax = plt.subplots(1, 2, figsize=(14, 7))\n",
245250
"\n",
246-
"results.plot('pct_poverty', scheme='quantiles', cmap='magma', ax=ax[0])\n",
247-
"tracts.plot('pct_poverty', scheme='quantiles', cmap='magma', ax=ax[1])\n",
251+
"results.plot(\"pct_poverty\", scheme=\"quantiles\", cmap=\"magma\", ax=ax[0])\n",
252+
"tracts.plot(\"pct_poverty\", scheme=\"quantiles\", cmap=\"magma\", ax=ax[1])\n",
248253
"\n",
249-
"ax[0].set_title('interpolated')\n",
250-
"ax[1].set_title('original')\n",
254+
"ax[0].set_title(\"interpolated\")\n",
255+
"ax[1].set_title(\"original\")\n",
251256
"for ax in ax:\n",
252-
" ax.axis('off')\n",
253-
"fig.suptitle('Poverty Rate (intensive)')"
257+
" ax.axis(\"off\")\n",
258+
"fig.suptitle(\"Poverty Rate (intensive)\")"
254259
]
255260
},
256261
{
@@ -308,6 +313,7 @@
308313
],
309314
"source": [
310315
"from quilt3 import Package\n",
316+
"\n",
311317
"p = Package.browse(\"rasters/nlcd\", \"s3://spatial-ucr\")\n",
312318
"p[\"nlcd_2011.tif\"].fetch()"
313319
]
@@ -329,11 +335,13 @@
329335
}
330336
],
331337
"source": [
332-
"results = masked_area_interpolate(raster=\"nlcd_2011.tif\", \n",
333-
" source_df=tracts, \n",
334-
" target_df=zip_codes, \n",
335-
" intensive_variables=['pct_poverty'], \n",
336-
" extensive_variables=['EMP_MALE'])"
338+
"results = masked_area_interpolate(\n",
339+
" raster=\"nlcd_2011.tif\",\n",
340+
" source_df=tracts,\n",
341+
" target_df=zip_codes,\n",
342+
" intensive_variables=[\"pct_poverty\"],\n",
343+
" extensive_variables=[\"EMP_MALE\"],\n",
344+
")"
337345
]
338346
},
339347
{
@@ -365,16 +373,16 @@
365373
}
366374
],
367375
"source": [
368-
"fig, ax = plt.subplots(1,2, figsize=(14,7))\n",
376+
"fig, ax = plt.subplots(1, 2, figsize=(14, 7))\n",
369377
"\n",
370-
"results.plot('EMP_MALE', scheme='quantiles', ax=ax[0])\n",
371-
"tracts.plot('EMP_MALE', scheme='quantiles', ax=ax[1])\n",
378+
"results.plot(\"EMP_MALE\", scheme=\"quantiles\", ax=ax[0])\n",
379+
"tracts.plot(\"EMP_MALE\", scheme=\"quantiles\", ax=ax[1])\n",
372380
"\n",
373-
"ax[0].set_title('interpolated')\n",
374-
"ax[1].set_title('original')\n",
381+
"ax[0].set_title(\"interpolated\")\n",
382+
"ax[1].set_title(\"original\")\n",
375383
"for ax in ax:\n",
376-
" ax.axis('off')\n",
377-
"fig.suptitle('Male Employment (extensive)')"
384+
" ax.axis(\"off\")\n",
385+
"fig.suptitle(\"Male Employment (extensive)\")"
378386
]
379387
},
380388
{
@@ -406,16 +414,16 @@
406414
}
407415
],
408416
"source": [
409-
"fig, ax = plt.subplots(1,2, figsize=(14,7))\n",
417+
"fig, ax = plt.subplots(1, 2, figsize=(14, 7))\n",
410418
"\n",
411-
"results.plot('pct_poverty', scheme='quantiles', cmap='magma', ax=ax[0])\n",
412-
"tracts.plot('pct_poverty', scheme='quantiles', cmap='magma', ax=ax[1])\n",
419+
"results.plot(\"pct_poverty\", scheme=\"quantiles\", cmap=\"magma\", ax=ax[0])\n",
420+
"tracts.plot(\"pct_poverty\", scheme=\"quantiles\", cmap=\"magma\", ax=ax[1])\n",
413421
"\n",
414-
"ax[0].set_title('interpolated')\n",
415-
"ax[1].set_title('original')\n",
422+
"ax[0].set_title(\"interpolated\")\n",
423+
"ax[1].set_title(\"original\")\n",
416424
"for ax in ax:\n",
417-
" ax.axis('off')\n",
418-
"fig.suptitle('Poverty Rate (intensive)')"
425+
" ax.axis(\"off\")\n",
426+
"fig.suptitle(\"Poverty Rate (intensive)\")"
419427
]
420428
},
421429
{
@@ -469,7 +477,12 @@
469477
}
470478
],
471479
"source": [
472-
"emp_results = glm(raster=\"nlcd_2011.tif\",source_df=tracts, target_df=zip_codes, variable='EMP_MALE', )"
480+
"emp_results = glm(\n",
481+
" raster=\"nlcd_2011.tif\",\n",
482+
" source_df=tracts,\n",
483+
" target_df=zip_codes,\n",
484+
" variable=\"EMP_MALE\",\n",
485+
")"
473486
]
474487
},
475488
{
@@ -501,16 +514,16 @@
501514
}
502515
],
503516
"source": [
504-
"fig, ax = plt.subplots(1,2, figsize=(14,7))\n",
517+
"fig, ax = plt.subplots(1, 2, figsize=(14, 7))\n",
505518
"\n",
506-
"emp_results.plot('EMP_MALE', scheme='quantiles', ax=ax[0])\n",
507-
"tracts.plot('EMP_MALE', scheme='quantiles', ax=ax[1])\n",
519+
"emp_results.plot(\"EMP_MALE\", scheme=\"quantiles\", ax=ax[0])\n",
520+
"tracts.plot(\"EMP_MALE\", scheme=\"quantiles\", ax=ax[1])\n",
508521
"\n",
509-
"ax[0].set_title('interpolated')\n",
510-
"ax[1].set_title('original')\n",
522+
"ax[0].set_title(\"interpolated\")\n",
523+
"ax[1].set_title(\"original\")\n",
511524
"for ax in ax:\n",
512-
" ax.axis('off')\n",
513-
"fig.suptitle('Male Employment (extensive)')"
525+
" ax.axis(\"off\")\n",
526+
"fig.suptitle(\"Male Employment (extensive)\")"
514527
]
515528
},
516529
{
@@ -536,7 +549,12 @@
536549
}
537550
],
538551
"source": [
539-
"pov_results = glm(raster=\"nlcd_2011.tif\",source_df=tracts, target_df=zip_codes, variable='pct_poverty', )"
552+
"pov_results = glm(\n",
553+
" raster=\"nlcd_2011.tif\",\n",
554+
" source_df=tracts,\n",
555+
" target_df=zip_codes,\n",
556+
" variable=\"pct_poverty\",\n",
557+
")"
540558
]
541559
},
542560
{
@@ -568,16 +586,16 @@
568586
}
569587
],
570588
"source": [
571-
"fig, ax = plt.subplots(1,2, figsize=(14,7))\n",
589+
"fig, ax = plt.subplots(1, 2, figsize=(14, 7))\n",
572590
"\n",
573-
"pov_results.plot('pct_poverty', scheme='quantiles', cmap='magma', ax=ax[0])\n",
574-
"tracts.plot('pct_poverty', scheme='quantiles', cmap='magma', ax=ax[1])\n",
591+
"pov_results.plot(\"pct_poverty\", scheme=\"quantiles\", cmap=\"magma\", ax=ax[0])\n",
592+
"tracts.plot(\"pct_poverty\", scheme=\"quantiles\", cmap=\"magma\", ax=ax[1])\n",
575593
"\n",
576-
"ax[0].set_title('interpolated')\n",
577-
"ax[1].set_title('original')\n",
594+
"ax[0].set_title(\"interpolated\")\n",
595+
"ax[1].set_title(\"original\")\n",
578596
"for ax in ax:\n",
579-
" ax.axis('off')\n",
580-
"fig.suptitle('Poverty Rate (intensive)')"
597+
" ax.axis(\"off\")\n",
598+
"fig.suptitle(\"Poverty Rate (intensive)\")"
581599
]
582600
},
583601
{

notebooks/02_areal_interpolation_example.ipynb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"source": [
1818
"import tobler\n",
1919
"import matplotlib.pyplot as plt\n",
20+
"\n",
2021
"%matplotlib inline"
2122
]
2223
},
@@ -35,7 +36,7 @@
3536
"metadata": {},
3637
"outputs": [],
3738
"source": [
38-
"tracts = geopandas.read_file(\"https://ndownloader.figshare.com/files/20460645\") "
39+
"tracts = geopandas.read_file(\"https://ndownloader.figshare.com/files/20460645\")"
3940
]
4041
},
4142
{
@@ -222,7 +223,7 @@
222223
}
223224
],
224225
"source": [
225-
"tracts.plot(facecolor='none', edgecolor='g')"
226+
"tracts.plot(facecolor=\"none\", edgecolor=\"g\")"
226227
]
227228
},
228229
{
@@ -238,7 +239,7 @@
238239
"metadata": {},
239240
"outputs": [],
240241
"source": [
241-
"precincts = geopandas.read_file(\"https://ndownloader.figshare.com/files/20460549\") \n"
242+
"precincts = geopandas.read_file(\"https://ndownloader.figshare.com/files/20460549\")"
242243
]
243244
},
244245
{
@@ -297,7 +298,7 @@
297298
}
298299
],
299300
"source": [
300-
"precincts.plot(facecolor='none', edgecolor='r')"
301+
"precincts.plot(facecolor=\"none\", edgecolor=\"r\")"
301302
]
302303
},
303304
{
@@ -321,7 +322,9 @@
321322
}
322323
],
323324
"source": [
324-
"estimates = tobler.area_weighted.area_interpolate(tracts, precincts, intensive_variables=['pct Youth'])"
325+
"estimates = tobler.area_weighted.area_interpolate(\n",
326+
" tracts, precincts, intensive_variables=[\"pct Youth\"]\n",
327+
")"
325328
]
326329
},
327330
{
@@ -353,7 +356,7 @@
353356
"metadata": {},
354357
"outputs": [],
355358
"source": [
356-
"tracts = tracts.to_crs(precincts.crs) "
359+
"tracts = tracts.to_crs(precincts.crs)"
357360
]
358361
},
359362
{
@@ -371,7 +374,9 @@
371374
}
372375
],
373376
"source": [
374-
"estimates = tobler.area_weighted.area_interpolate(tracts, precincts, intensive_variables=['pct Youth'])"
377+
"estimates = tobler.area_weighted.area_interpolate(\n",
378+
" tracts, precincts, intensive_variables=[\"pct Youth\"]\n",
379+
")"
375380
]
376381
},
377382
{
@@ -511,7 +516,9 @@
511516
],
512517
"source": [
513518
"f, ax = plt.subplots(1, figsize=(8, 8))\n",
514-
"ax = tracts.plot(column='pct Youth', ax=ax, legend=True, alpha=0.5, scheme='Quantiles', k=10)\n",
519+
"ax = tracts.plot(\n",
520+
" column=\"pct Youth\", ax=ax, legend=True, alpha=0.5, scheme=\"Quantiles\", k=10\n",
521+
")\n",
515522
"plt.show()"
516523
]
517524
},
@@ -534,9 +541,11 @@
534541
}
535542
],
536543
"source": [
537-
"precincts['pct Youth'] = estimates['pct Youth']\n",
544+
"precincts[\"pct Youth\"] = estimates[\"pct Youth\"]\n",
538545
"f, ax = plt.subplots(1, figsize=(8, 8))\n",
539-
"ax = precincts.plot(column='pct Youth', ax=ax, legend=True, alpha=0.5, scheme='Quantiles', k=10)\n",
546+
"ax = precincts.plot(\n",
547+
" column=\"pct Youth\", ax=ax, legend=True, alpha=0.5, scheme=\"Quantiles\", k=10\n",
548+
")\n",
540549
"plt.show()"
541550
]
542551
},

0 commit comments

Comments
 (0)