Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
dakk committed Jun 2, 2022
1 parent fc39c47 commit 16854c0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
8 changes: 4 additions & 4 deletions tests/linearbestisorouter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_step(self):

class checkRoute_mediumWind_mockIsland_8(unittest.TestCase):
def setUp(self):
grib = mock_grib(5,45,0.5)
grib = mock_grib(5,45,0.5)
self.track = [(5,38),(4.6,37.6)]
island_route = mock_point_validity(self.track, factor=8)
self.routing_obj = weatherrouting.Routing(
Expand All @@ -157,7 +157,7 @@ def test_step(self):

class checkRoute_highWind_mockIsland_3(unittest.TestCase):
def setUp(self):
grib = mock_grib(10,270,0.5)
grib = mock_grib(10,270,0.5)
self.track = [(5,38),(5.5,38.5)]
island_route = mock_point_validity(self.track, factor=3)
self.routing_obj = weatherrouting.Routing(
Expand All @@ -182,7 +182,7 @@ def test_step(self):

class checkRoute_out_of_scope(unittest.TestCase):
def setUp(self):
grib = mock_grib(10,270,0.5,out_of_scope=datetime.datetime.fromisoformat('2021-04-02T15:00:00'))
grib = mock_grib(10,270,0.5,out_of_scope=datetime.datetime.fromisoformat('2021-04-02T15:00:00'))
self.track = [(5,38),(5.5,38.5)]
island_route = mock_point_validity(self.track, factor=3)
self.routing_obj = weatherrouting.Routing(
Expand Down Expand Up @@ -210,7 +210,7 @@ class checkRoute_multipoint(unittest.TestCase):
def setUp(self):
grib = mock_grib(10,270,0.5)
self.track = [(5,38),(5.3,38.3),(5.6,38.6)]
island_route = mock_point_validity(self.track, factor=3)
# island_route = mock_point_validity(self.track, factor=3)
self.routing_obj = weatherrouting.Routing(
LinearBestIsoRouter,
polar_bavaria38,
Expand Down
2 changes: 1 addition & 1 deletion weatherrouting/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def toString(self) -> str:
sl = self.speedTable[l]

for x in sl:
s += '\t{:.1f}'.format(x)
s += f'\t{x:.1f}'
s += '\n'

l += 1
Expand Down
7 changes: 4 additions & 3 deletions weatherrouting/routers/linearbestisorouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def generate_path(p):
position = path[-1].pos

if self.grib.getWindAt (time + datetime.timedelta(hours=1), end[0],end[1]):
if lastlog is None and len (lastlog.isochrones) > 0:
if lastlog is not None and len (lastlog.isochrones) > 0:
isoc = isoF(time + datetime.timedelta(hours=1), lastlog.isochrones, end)
else:
nwdist = utils.pointDistance (end[0], end[1], start[0], start[1])
Expand All @@ -54,10 +54,11 @@ def generate_path(p):
for p in isoc[-1]:
distance_to_end_point = p.pointDistance (end)
if distance_to_end_point < self.getParamValue('minIncrease'):
(twd,tws) = self.grib.getWindAt (time + datetime.timedelta(hours=1), p.pos[0], p.pos[1])
# (twd,tws) = self.grib.getWindAt (time + datetime.timedelta(hours=1), p.pos[0], p.pos[1])
maxReachDistance = utils.maxReachDistance(p.pos, p.speed)
if distance_to_end_point < abs(maxReachDistance*1.1):
if (not self.pointValidity or self.pointValidity(end[0],end[1])) and (not self.lineValidity or self.lineValidity(end[0],end[1], p.pos[0], p.pos[1])):
if (not self.pointValidity or self.pointValidity(end[0],end[1])) and (
not self.lineValidity or self.lineValidity(end[0],end[1], p.pos[0], p.pos[1])):
if distance_to_end_point < nearest_dist:
nearest_dist = distance_to_end_point
nearest_solution = p
Expand Down
6 changes: 3 additions & 3 deletions weatherrouting/routers/shortestpathrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class ShortestPathRouter (LinearBestIsoRouter):
'Set the fixed speed', default=5.0, lower=1.0, upper=60.0, step=0.1, digits=1)
}

def route (self, lastlog, time, start, end) -> RoutingResult:
return self._route(lastlog, time, start, end, lambda time, isoc,
end: self.calculateShortestPathIsochrones (self.getParamValue('fixedSpeed'), time, isoc, end))
def route (self, lastlog, t, start, end) -> RoutingResult:
return self._route(lastlog, t, start, end, lambda t, isoc,
end: self.calculateShortestPathIsochrones (self.getParamValue('fixedSpeed'), t, isoc, end))
16 changes: 10 additions & 6 deletions weatherrouting/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Routing:
Routing class
"""

def __init__ (self, algorithm, polar, track, grib, startDatetime, startPosition = None, pointValidity = None, lineValidity = None, pointsValidity = None, linesValidity = None):
def __init__ (self, algorithm, polar, track, grib, startDatetime, startPosition = None,
pointValidity = None, lineValidity = None, pointsValidity = None, linesValidity = None):
"""
Parameters
----------
Expand All @@ -52,13 +53,16 @@ def __init__ (self, algorithm, polar, track, grib, startDatetime, startPosition
A functions that receives lat and lon and returns True if the point is valid (ie: in the sea)
lineValidity : function(lat1, lon1, lat2, lon2)
Optional, default to None
A functions that receives a vector defined by lat1, lon1, lat2, lon2 and returns True if the line is valid (ie: completely in the sea)
A functions that receives a vector defined by lat1, lon1, lat2, lon2 and returns True if the
line is valid (ie: completely in the sea)
pointsValidity : function (latlons)
Optional, default to None
A functions that receives a list of latlon and returns a list of boolean with True if the point at i is valid (ie: in the sea)
A functions that receives a list of latlon and returns a list of boolean with True if the point
at i is valid (ie: in the sea)
linesValidity : function(latlons)
Optional, default to None
A functions that receives a list of vectors defined by lat1, lon1, lat2, lon2 and returns a list of boolean with True if the line at i is valid (ie: completely in the sea)
A functions that receives a list of vectors defined by lat1, lon1, lat2, lon2 and returns a
list of boolean with True if the line at i is valid (ie: completely in the sea)
"""

Expand All @@ -69,7 +73,7 @@ def __init__ (self, algorithm, polar, track, grib, startDatetime, startPosition
self.path = []
self.time = startDatetime
self.grib = grib
self.log = []
self.log = []
self._startingNewPoint = True

if startPosition:
Expand Down Expand Up @@ -109,7 +113,7 @@ def step (self) -> RoutingResult:
self._startingNewPoint = True

np = []
ptime = None
ptime = None
for x in self.path:
nt = x.time

Expand Down

0 comments on commit 16854c0

Please sign in to comment.