Skip to content

Commit 676ab40

Browse files
committed
fix: fixed style for gutils and oz
1 parent c6027b2 commit 676ab40

File tree

2 files changed

+49
-54
lines changed

2 files changed

+49
-54
lines changed

src/hydrodiy/gis/gutils.py

+14-20
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import numpy as np
2-
import math
3-
import matplotlib.image as mpimg
4-
5-
import time
6-
7-
from hydrodiy.stat import sutils
8-
92
from hydrodiy import has_c_module
103

114
if has_c_module("gis", False):
125
import c_hydrodiy_gis
136

14-
def points_inside_polygon(points, polygon, inside=None, atol=1e-8, \
15-
nprint=0):
7+
8+
def points_inside_polygon(points, polygon, inside=None, atol=1e-8,
9+
nprint=0):
1610
"""
1711
1812
Determines if a set of points are inside a given polygon or not
@@ -52,24 +46,24 @@ def points_inside_polygon(points, polygon, inside=None, atol=1e-8, \
5246
inside = np.zeros(len(points), dtype=np.int32)
5347
else:
5448
if not inside.dtype == np.int32:
55-
raise ValueError("Expected inside of "+\
56-
f"dtype np.int32, got {inside.dtype}.")
49+
errmess = "Expected inside of dtype np.int32, "\
50+
+ f"got {inside.dtype}."
51+
raise ValueError(errmess)
5752

5853
if not len(inside) == len(points):
59-
raise ValueError("Expected inside of length "+\
60-
f"{len(points)}, got {len(inside)}.")
54+
errmess = f"Expected inside of length {len(points)},"\
55+
+ f"got {len(inside)}."
56+
raise ValueError(errmess)
6157

6258
# To make sure that the inside vector is properly initialised
6359
inside.fill(0)
6460

6561
# run C code
66-
ierr = c_hydrodiy_gis.points_inside_polygon(atol, nprint, points, \
67-
polygon, inside)
62+
ierr = c_hydrodiy_gis.points_inside_polygon(atol, nprint, points,
63+
polygon, inside)
6864

69-
if ierr>0:
70-
raise ValueError("c_hydrodiy_gis.points_inside_polygon "+\
71-
"returns "+str(ierr))
65+
if ierr > 0:
66+
errmess = f"c_hydrodiy_gis.points_inside_polygon returns {ierr}."
67+
raise ValueError(errmess)
7268

7369
return inside
74-
75-

src/hydrodiy/gis/oz.py

+35-34
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
""" Module to plot data on an Australia map """
22

3-
import re, os, json, tarfile
3+
import re
4+
import json
45
from pathlib import Path
56

67
import numpy as np
78
import pandas as pd
89

9-
import matplotlib as mpl
10-
mpl.use("Agg")
11-
1210
import matplotlib.pyplot as plt
13-
from matplotlib.patches import Polygon
14-
from matplotlib.collections import PatchCollection
1511
import matplotlib.patheffects as patheff
1612

13+
import matplotlib as mpl
14+
mpl.use("Agg")
15+
1716
HAS_PYSHP = False
1817
try:
1918
import shapefile
2019
HAS_PYSHP = True
21-
except (ImportError, FileNotFoundError) as err:
20+
except (ImportError, FileNotFoundError):
2221
pass
2322

2423
# Decompress australia shoreline shapefile
2524
FHERE = Path(__file__).resolve().parent
2625
FDATA = FHERE / "data"
2726
SHAPEFILES = {
28-
"ozcoast10m": FDATA / "ne_10m_admin_0_countries_australia.shp", \
29-
"ozcoast50m": FDATA / "ne_50m_admin_0_countries_australia.shp", \
30-
"ozstates50m": FDATA / "ne_50m_admin_1_states_australia.shp", \
31-
"ozdrainage": FDATA / "drainage_divisions_lines_simplified.shp", \
27+
"ozcoast10m": FDATA / "ne_10m_admin_0_countries_australia.shp",
28+
"ozcoast50m": FDATA / "ne_50m_admin_0_countries_australia.shp",
29+
"ozstates50m": FDATA / "ne_50m_admin_1_states_australia.shp",
30+
"ozdrainage": FDATA / "drainage_divisions_lines_simplified.shp",
3231
"ozbasins": FDATA / "rbasin_lines_simplified.shp"
33-
}
32+
}
3433

3534
# Lat long coordinate boxes for regions in Australia
3635
freg = FDATA / "regions.json"
@@ -39,18 +38,18 @@
3938

4039
# Capital cities
4140
CAPITAL_CITIES = {
42-
"Brisbane": [153.026, -27.471], \
43-
"Melbourne": [144.960, -37.821],\
44-
"Sydney": [151.206, -33.864], \
45-
"Canberra": [149.134, -35.299], \
46-
"Hobart": [147.3265, -42.8818], \
47-
"Adelaide": [138.60, -34.92833], \
41+
"Brisbane": [153.026, -27.471],
42+
"Melbourne": [144.960, -37.821],
43+
"Sydney": [151.206, -33.864],
44+
"Canberra": [149.134, -35.299],
45+
"Hobart": [147.3265, -42.8818],
46+
"Adelaide": [138.60, -34.92833],
4847
"Perth": [115.86134, -31.95182]
49-
}
48+
}
5049

5150

52-
def ozlayer(ax, name, filter_field=None, filter_regex=None, proj=None, \
53-
fixed_lim=True, *args, **kwargs):
51+
def ozlayer(ax, name, filter_field=None, filter_regex=None, proj=None,
52+
fixed_lim=True, *args, **kwargs):
5453
""" plot Australian geographic layer in axes using data
5554
from Natural Earth.
5655
(see https://www.naturalearthdata.com/)
@@ -81,7 +80,7 @@ def ozlayer(ax, name, filter_field=None, filter_regex=None, proj=None, \
8180
raise ValueError("pyshp package could not be imported")
8281

8382
# Select shapefile to draw
84-
if not name in SHAPEFILES:
83+
if name not in SHAPEFILES:
8584
names = "|".join(list(SHAPEFILES.keys()))
8685
raise ValueError(f"Expected name in {names}, got {name}.")
8786

@@ -94,7 +93,7 @@ def ozlayer(ax, name, filter_field=None, filter_regex=None, proj=None, \
9493
# Plotting function
9594
def plotit(x, y, recs):
9695
# Project
97-
if not proj is None:
96+
if proj is not None:
9897
x, y = np.array([proj(xx, yy) for xx, yy in zip(x, y)]).T
9998

10099
# Plot
@@ -112,11 +111,13 @@ def plotit(x, y, recs):
112111
# Get shapefile fields
113112
fields = np.array([f[0] for f in shp_object.fields])[1:]
114113

115-
if not filter_field is None:
114+
if filter_field is not None:
116115
# Filter field
117-
if not filter_field in fields:
118-
raise ValueError("Expected filter_field in "+\
119-
"/".join(list(fields)) + ", got "+filter_field)
116+
if filter_field not in fields:
117+
ftxt = "/".join(list(fields))
118+
errmess = f"Expected filter_field in {ftxt}, "\
119+
+ f"got {filter_field}."
120+
raise ValueError(errmess)
120121

121122
ifilter = np.where(fields == filter_field)[0][0]
122123
else:
@@ -126,7 +127,7 @@ def plotit(x, y, recs):
126127
lines = []
127128
for shp, rec in zip(shp_object.shapes(), shp_object.records()):
128129
# Apply filter if needed
129-
if not ifilter is None:
130+
if ifilter is not None:
130131
if not re.search(filter_regex, rec[ifilter]):
131132
continue
132133

@@ -159,10 +160,10 @@ def plotit(x, y, recs):
159160
return lines
160161

161162

162-
def ozcities(ax, cities=None, \
163-
filter_regex=None, \
164-
fixed_lim=True, plot_kwargs={}, \
165-
text_kwargs={}, proj=None):
163+
def ozcities(ax, cities=None,
164+
filter_regex=None,
165+
fixed_lim=True, plot_kwargs={},
166+
text_kwargs={}, proj=None):
166167
""" plot Australian capital cities.
167168
168169
Parameters
@@ -213,12 +214,12 @@ def ozcities(ax, cities=None, \
213214
elements = {}
214215
for icity, (city, xy) in enumerate(cities.items()):
215216
# Skip if filtered
216-
if not filter_regex is None:
217+
if filter_regex is not None:
217218
if not re.search(filter_regex, city):
218219
continue
219220

220221
xyproj = xy
221-
if not proj is None:
222+
if proj is not None:
222223
xyproj = proj(*xyproj)
223224

224225
lab = "Capital city" if icity == 0 else ""

0 commit comments

Comments
 (0)