def test_NotFileInput(self): """loadTracksFromFiles raises TypeError if list contents not files""" with self.assertRaises(TypeError): list(track.loadTracksFromFiles([0, 1, 2, 3, 4])) with self.assertRaises(IOError): list(track.loadTracksFromFiles(['string01', 'string02']))
def processTrack(trackfile, locations): """ Process individual track to determine distance to locations, etc. Any empty tracks are filtered at an earlier stage. If an empty track is passed, then a None result is returned. :param track: :class:`Track` instance. :param locations: list of locations in the simulation domain. """ tracks = [t for t in loadTracksFromFiles([trackfile])] points = [Point(loc[2], loc[3]) for loc in locations] records = [] for track in tracks: length = len(track.data) if length == 0: log.info("Got an empty track: returning None") continue #return None distances = track.minimumDistance(points) for (loc, dist) in zip(locations, distances): locRecs = (loc[0], "%03d-%05d" % (track.trackId), dist, None, None, "", datetime.now()) records.append(locRecs) log.info("Track {0}-{1} has {2} records".format( track.trackId[0], track.trackId[1], len(records))) return records
def test_NotListInput(self): """loadTracksFromFiles raises TypeError if passed non-list""" with self.assertRaises(TypeError): list(track.loadTracksFromFiles(self.dummy_track_file))
def processTracks(self): """ Populate tblTracks with the details of tracks and their proximity to the locations in the domain. """ log.info("Inserting records into tblTracks") locations = self.getLocations() files = os.listdir(self.trackPath) trackfiles = [pjoin(self.trackPath, f) for f in files \ if f.startswith('tracks')] tracks = [t for t in loadTracksFromFiles(sorted(trackfiles))] work_tag = 0 result_tag = 1 if (pp.rank() == 0) and (pp.size() > 1): w = 0 p = pp.size() - 1 for d in range(1, pp.size()): if w < len(tracks): pp.send((tracks[w], locations), destination=d, tag=work_tag) log.debug("Processing track {0:d} of {1:d}".\ format(w, len(tracks))) w += 1 else: pp.send(None, destination=d, tag=work_tag) p = w terminated = 0 while terminated < p: result, status = pp.receive(pp.any_source, tag=result_tag, return_status=True) if result is not None: self.insertTracks(result) d = status.source if w < len(tracks): pp.send((tracks[w], locations), destination=d, tag=work_tag) log.debug("Processing track {0:d} of {1:d}".\ format(w, len(tracks))) w += 1 else: pp.send(None, destination=d, tag=work_tag) terminated += 1 elif (pp.size() > 1) and (pp.rank() != 0): while True: W = pp.receive(source=0, tag=work_tag) if W is None: break results = self.processTrack(*W) pp.send(results, destination=0, tag=work_tag) elif pp.size() == 1 and pp.rank() == 0: # No Pypar for w, track in enumerate(tracks): log.debug("Processing track {0:d} of {1:d}".\ format(w, len(tracks))) if len(track.data) == 0: continue result = self.processTrack(track, locations) if result is not None: self.insertTracks(result)