@@ -245,6 +245,8 @@ def shape(self):
245245
246246 def valid_index (self , xi , yi ):
247247 """Return True if point is a valid index of grid."""
248+ # Note that xi/yi can be floats; so, for example, we can't simply check
249+ # `xi < self.nx` since `xi` can be `self.nx - 1 < xi < self.nx`
248250 return xi >= 0 and xi <= self .nx - 1 and yi >= 0 and yi <= self .ny - 1
249251
250252
@@ -258,7 +260,7 @@ class StreamMask(object):
258260 """
259261
260262 def __init__ (self , density ):
261- if type (density ) == float or type ( density ) == int :
263+ if isinstance (density , ( float , int )) :
262264 assert density > 0
263265 self .nx = self .ny = int (30 * density )
264266 else :
@@ -320,7 +322,7 @@ def get_integrator(u, v, dmap, minlength):
320322 def forward_time (xi , yi ):
321323 ds_dt = interpgrid (speed , xi , yi )
322324 if ds_dt == 0 :
323- raise TerminateTrajectory
325+ raise TerminateTrajectory ()
324326 dt_ds = 1. / ds_dt
325327 ui = interpgrid (u , xi , yi )
326328 vi = interpgrid (v , xi , yi )
0 commit comments