SAUSy-Lab/retro-gtfs

Division by zero error

Closed this issue · 2 comments

I seem to get this division by zero error when processing trips on multiple threads. When I rerun the same trips without multiprocessing, there is no error.

starting trip: 412510
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/lib/python3.5/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/usr/lib/python3.5/multiprocessing/pool.py", line 44, in mapstar
    return list(map(*args))
  File "process.py", line 20, in process_trip
    t.process()
  File "/home/nate/retro-gtfs/trip.py", line 130, in process
    self.interpolate_stop_times()
  File "/home/nate/retro-gtfs/trip.py", line 187, in interpolate_stop_times
    timepoint.set_time( self.interpolate_time(timepoint.measure) )
  File "/home/nate/retro-gtfs/trip.py", line 291, in interpolate_time
    trip_speed = (vlast.time-vfirst.time)/(vlast.measure-vfirst.measure)
ZeroDivisionError: float division by zero
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "process.py", line 55, in <module>
    process_trips(trip_ids)
  File "process.py", line 29, in process_trips
    p.map(process_trip,trip_ids,chunksize=3)
  File "/usr/lib/python3.5/multiprocessing/pool.py", line 260, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "/usr/lib/python3.5/multiprocessing/pool.py", line 608, in get
    raise self._value
ZeroDivisionError: float division by zero

This has nothing to do with multiprocessing; I was looking at the wrong trips before somehow. The problem occurs when len(Trip.vehicles) == 1 during the interpolation of a default geometry.

Fixed. Just needed to be slightly more stringent in a check for vehicle len!