Skip to content

Commit ff7a2f6

Browse files
author
mz
committed
pep8 style + file headers
1 parent fba022c commit ff7a2f6

7 files changed

+71
-71
lines changed

SpatialPositionModel.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
A QGIS plugin
66
Compute spatial interaction models
77
-------------------
8-
begin : 2015-12-10
8+
begin : 2017-05-15
99
git sha : $Format:%H$
10-
copyright : (C) 2015 by #H
11-
email : mth@#!.org
10+
copyright : (C) 2015 by mthh
11+
1212
***************************************************************************/
1313
1414
/***************************************************************************
@@ -30,6 +30,7 @@
3030
from .SpatialPositionModel_utils import *
3131
import os.path
3232

33+
3334
class SpatialPositionModel:
3435
"""QGIS Plugin Implementation."""
3536

@@ -84,7 +85,6 @@ def tr(self, message):
8485
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
8586
return QCoreApplication.translate('SpatialPositionModel', message)
8687

87-
8888
def add_action(
8989
self,
9090
icon_path,
@@ -168,7 +168,6 @@ def initGui(self):
168168
callback=self.run,
169169
parent=self.iface.mainWindow())
170170

171-
172171
def unload(self):
173172
"""Removes the plugin menu item and icon from QGIS GUI."""
174173
for action in self.actions:

SpatialPositionModel_dialog.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
SpatialPositionModelDialog
55
A QGIS plugin
66
Compute spatial interaction models
7-
-------------------
8-
begin : 2015-12-10
7+
-------------------
8+
begin : 2017-05-15
99
git sha : $Format:%H$
10-
copyright : (C) 2015 by #H
11-
email : mth@#!.org
10+
copyright : (C) 2015 by mthh
11+
1212
***************************************************************************/
1313
1414
/***************************************************************************
@@ -200,24 +200,25 @@ def run_stewart(self):
200200
self.iface.setActiveLayer(pot_layer)
201201
self.iface.zoomToActiveLayer()
202202

203-
## Todo : display better information/error message + show progression
203+
# Todo : display better information/error message + show progression
204204
def display_log_error(self, error, msg_nb):
205205
error_msg = {
206-
# 1: "Error when loading the choosen matrix. See QGis log for error traceback.",
207-
2: "The computation have been aborted, please choose a larger resolution value.",
206+
2: ("The computation have been aborted, "
207+
"please choose a larger resolution value."),
208208
3: "Error when generating the grid of unknownpts.",
209209
4: "Span, resolution and beta should not be set to 0.",
210210
5: "Crs mismatch between point and mask layers. Mask not used.",
211211
6: "Mask contains invalid geometries. Mask not used.",
212-
7: "Unable to parse class breaks (levels must be increasing and sepated by a dash). Using default value of 7 class."
212+
7: ("Unable to parse class breaks (levels must be increasing and "
213+
"separated by a dash). Using default value of 7 class.")
213214
}
214215
QtGui.QMessageBox.information(
215216
self.iface.mainWindow(), 'Error', error_msg[msg_nb])
216217

217-
218218
def load_dataset(self):
219-
home_path = \
220-
os.getenv('HOMEPATH') or os.getenv('HOME') or os.getenv('USERPROFILE')
219+
home_path = os.getenv('HOMEPATH') \
220+
or os.getenv('HOME') \
221+
or os.getenv('USERPROFILE')
221222
self.iface.addVectorLayer(os.sep.join(
222223
[home_path, '.qgis2', 'python', 'plugins', 'SpatialPositionModel',
223224
'test_data', 'paris_mask.geojson']),

SpatialPositionModel_utils.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def parse_expression(expr):
2424
if nexpr[-2] != ' ':
2525
_ix = len(nexpr) - 1
2626
nexpr.insert(_ix, ' ')
27-
if expr[i+1] != ' ':
27+
if expr[i + 1] != ' ':
2828
nexpr.append(' ')
2929
except IndexError:
3030
pass
@@ -108,31 +108,18 @@ def gen_unknownpts(pts_layer, mask_layer, resolution, longlat):
108108

109109
return make_regular_points(bounds, resolution, longlat)
110110

111+
111112
def parse_class_breaks(class_breaks):
112113
try:
113-
values = [float(i.strip().replace(',', '.')) for i in class_breaks.split('-')]
114+
values = [float(i.strip().replace(',', '.'))
115+
for i in class_breaks.split('-')]
114116
last = -float('inf')
115117
for i in values:
116118
assert i > last
117119
last = i
118120
return values
119121
except:
120122
return None
121-
#def get_matdist_user(matdist, dim1, dim2):
122-
# try:
123-
# mat_dist = np.array([
124-
# map(int, feat.attributes()[1:])
125-
# for feat in matdist.getFeatures()
126-
# ])
127-
# except ValueError:
128-
# mat_dist = np.array([
129-
# map(float, feat.attributes()[1:])
130-
# for feat in matdist.getFeatures()
131-
# ])
132-
# assert dim1 in mat_dist.shape \
133-
# and dim2 in mat_dist.shape
134-
# return mat_dist
135-
#
136123

137124

138125
def compute_opportunity(pts_values, matdens):
@@ -158,11 +145,11 @@ def get_height_width(bounds, longlat):
158145
)
159146
else:
160147
height = np.linalg.norm(
161-
np.array([(maxlon + minlon) / 2, minlat])
162-
- np.array([(maxlon + minlon) / 2, maxlat])) / 1000
148+
np.array([(maxlon + minlon) / 2, minlat]) -
149+
np.array([(maxlon + minlon) / 2, maxlat])) / 1000
163150
width = np.linalg.norm(
164-
np.array([minlon, (maxlat + minlat) / 2])
165-
- np.array([maxlon, (maxlat + minlat) / 2])) / 1000
151+
np.array([minlon, (maxlat + minlat) / 2]) -
152+
np.array([maxlon, (maxlat + minlat) / 2])) / 1000
166153

167154
return height, width
168155

@@ -221,14 +208,16 @@ class ProbableMemoryError(Exception):
221208
def render_stewart(polygons, pot_layer, levels, nb_class, mask_layer):
222209
if mask_layer:
223210
try:
224-
renderer = \
225-
_render_stewart_mask(polygons, pot_layer, levels, nb_class, mask_layer)
211+
renderer = _render_stewart_mask(
212+
polygons, pot_layer, levels, nb_class, mask_layer)
226213
return (False, renderer)
227214
except:
228-
renderer = _render_stewart(polygons, pot_layer, levels, nb_class)
215+
renderer = _render_stewart(
216+
polygons, pot_layer, levels, nb_class)
229217
return (True, renderer)
230218
else:
231-
renderer = _render_stewart(polygons, pot_layer, levels, nb_class)
219+
renderer = _render_stewart(
220+
polygons, pot_layer, levels, nb_class)
232221
return (False, renderer)
233222

234223

@@ -244,7 +233,7 @@ def _render_stewart(polygons, pot_layer, levels, nb_class):
244233
if i == 0:
245234
last_level = 0
246235
else:
247-
last_level = float(levels[i-1])
236+
last_level = float(levels[i - 1])
248237
current_level = float(levels[i])
249238
ft = QgsFeature()
250239
ft.setGeometry(poly)
@@ -276,7 +265,7 @@ def _render_stewart_mask(polygons, pot_layer, levels, nb_class, mask_layer):
276265
if i == 0:
277266
last_level = 0
278267
else:
279-
last_level = float(levels[i-1])
268+
last_level = float(levels[i - 1])
280269
current_level = float(levels[i])
281270
if geom.area() > 0:
282271
ft = QgsFeature()
@@ -317,3 +306,19 @@ def qgsgeom_from_mpl_collec(collections):
317306
elif len(mpoly) == 1:
318307
polygons.append(QgsGeometry.fromPolygon(mpoly[0]))
319308
return polygons
309+
310+
#def get_matdist_user(matdist, dim1, dim2):
311+
# try:
312+
# mat_dist = np.array([
313+
# map(int, feat.attributes()[1:])
314+
# for feat in matdist.getFeatures()
315+
# ])
316+
# except ValueError:
317+
# mat_dist = np.array([
318+
# map(float, feat.attributes()[1:])
319+
# for feat in matdist.getFeatures()
320+
# ])
321+
# assert dim1 in mat_dist.shape \
322+
# and dim2 in mat_dist.shape
323+
# return mat_dist
324+
#

metadata.txt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# This file contains metadata for your plugin. Since
2-
# version 2.0 of QGIS this is the proper way to supply
3-
# information about a plugin. The old method of
4-
# embedding metadata in __init__.py will
1+
# This file contains metadata for your plugin. Since
2+
# version 2.0 of QGIS this is the proper way to supply
3+
# information about a plugin. The old method of
4+
# embedding metadata in __init__.py will
55
# is no longer supported since version 2.0.
66

77
# This file should be included when you package your plugin.# Mandatory items:
@@ -11,13 +11,13 @@ name=SpatialPositionModel
1111
qgisMinimumVersion=2.8
1212
description=Compute spatial interaction models
1313
version=0.1
14-
author=#H
15-
email=mth@#!.org
14+
author=mthh
15+
1616

17-
about=There are two main ways of modeling spatial interactions: the first one focuses on links between places (flows), the second one focuses on places and their influence at a distance. Following the physics metaphor, the flow may be seen as the gravitational force between two masses, the place influence as the gravitational potential. The SpatialPosition package, as its name suggests, proposes an implementation of place-based models: Stewart, Reilly and Huff models.
17+
about=There are two main ways of modeling spatial interactions: the first one focuses on links between places (flows), the second one focuses on places and their influence at a distance. Following the physics metaphor, the flow may be seen as the gravitational force between two masses, the place influence as the gravitational potential. This plugin proposes an implementation of a place-based model: Stewart potentials model.
1818

19-
tracker=
20-
repository=
19+
tracker=
20+
repository=
2121
# End of mandatory metadata
2222

2323
# Recommended items:
@@ -26,7 +26,7 @@ repository=
2626
# changelog=
2727

2828
# Tags are comma separated with spaces allowed
29-
tags=
29+
tags=Potentials,Accessibility,Spatial analysis
3030

3131
homepage=
3232
category=Plugins
@@ -36,4 +36,3 @@ experimental=True
3636

3737
# deprecated flag (applies to the whole plugin, not just a single version)
3838
deprecated=False
39-

pb_tool.cfg

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616
# * (at your option) any later version. *
1717
# * *
1818
# ***************************************************************************/
19-
#
20-
#
19+
#
20+
#
2121
# You can install pb_tool using:
2222
# pip install http://geoapt.net/files/pb_tool.zip
23-
#
23+
#
2424
# Consider doing your development (and install of pb_tool) in a virtualenv.
25-
#
25+
#
2626
# For details on setting up and using pb_tool, see:
2727
# http://spatialgalaxy.net/qgis-plugin-development-with-pb_tool
2828
#
2929
# Issues and pull requests here:
3030
# https://github.com/g-sherman/plugin_build_tool:
31-
#
31+
#
3232
# Sane defaults for your plugin generated by the Plugin Builder are
3333
# already set below.
34-
#
34+
#
3535
# As you add Python source files and UI files to your plugin, add
3636
# them to the appropriate [files] section below.
3737

@@ -48,7 +48,7 @@ python_files: __init__.py SpatialPositionModel.py SpatialPositionModel_dialog.py
4848
main_dialog: SpatialPositionModel_dialog_base.ui
4949

5050
# Other ui files for dialogs you create (these will be compiled)
51-
compiled_ui_files:
51+
compiled_ui_files:
5252

5353
# Resource file(s) that will be compiled
5454
resource_files: resources.qrc
@@ -58,7 +58,7 @@ extras: metadata.txt icon.png
5858

5959
# Other directories to be deployed with the plugin.
6060
# These must be subdirectories under the plugin directory
61-
extra_dirs:
61+
extra_dirs: test_data/
6262

6363
# ISO code(s) for any locales (translations), separated by spaces.
6464
# Corresponding .ts files must exist in the i18n directory
@@ -67,8 +67,5 @@ locales:
6767
[help]
6868
# the built help directory that should be deployed with the plugin
6969
dir: help/build/html
70-
# the name of the directory to target in the deployed plugin
70+
# the name of the directory to target in the deployed plugin
7171
target: help
72-
73-
74-

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
SpatialPositionModel
22
--------------------
33

4-
Python port of "Stewart Potentials" method from [R SpatialPosition package](https://github.com/Groupe-ElementR/SpatialPosition).
4+
Python port of "Stewart Potentials" method from [R SpatialPosition package](https://github.com/Groupe-ElementR/SpatialPosition) for [QGIS](http://qgis.org).
55
Original package (documentation and R source code) are available on [GitHub](https://github.com/Groupe-ElementR/SpatialPosition) or on the [CRAN](https://cran.r-project.org/web/packages/SpatialPosition/).
6-
6+
If you are only interested in computing potentials and drawing contour but not in QGIS, take a llo to the [smoomapy](https://pypi.python.org/pypi/smoomapy/) python package.
77

88
**Stewart Potentials**
99
<img src="misc/stewart_screenshot.png" width="408.5" height="248.5">

test/test_SpatialPositionModel_dialog.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
99
"""
1010

11-
__author__ = 'mth@#!.org'
11+
__author__ = '[email protected]'
1212
__date__ = '2015-12-10'
13-
__copyright__ = 'Copyright 2015, #H'
13+
__copyright__ = 'Copyright 2015, mthh'
1414

1515
import unittest
1616

@@ -52,4 +52,3 @@ def test_dialog_cancel(self):
5252
suite = unittest.makeSuite(SpatialPositionModelDialogTest)
5353
runner = unittest.TextTestRunner(verbosity=2)
5454
runner.run(suite)
55-

0 commit comments

Comments
 (0)