示例#1
0
 def _prepare_frames(self):
     if self._frames_prepared:
         return
     tl = TrackLibrary()
     # TODO: We might want to do some cleverer sorting
     print("Sorting tracks by time...")
     tracks = [t for t in tl.sort_tracks_by_time() if t in self.tracks]
     print("Sorted")
     self.frames = []
     if self.timelapse_unit == "track":
         batchsize = self.units_per_frame
         # This splits a list into batches, ie
         # [1,2,3,4,5] -> [[1,2],[3,4],[5]]
         cumulative_tracks = []
         counter = 0
         print("Creating frames")
         startnums = xrange(0, len(tracks), batchsize)
         # The end number should be 1 more than might be expected,
         # because of the way python list slicing works
         batches = [(s, s + batchsize) for s in startnums]
         total = len(batches)
         for tracklist in (tracks[s:e] for (s, e) in batches):
             counter += 1
             if counter % 100 == 0 and total > 200:
                 print("\tCreated %s/%s frames" % (counter, total))
             cumulative_tracks.extend(tracklist)
             canvas = self._get_canvas(counter - 1)
             self.frames.append(Frame(canvas=canvas,
                                      tracks=deepcopy(cumulative_tracks),
                                      frame_number=counter-1))
     else:
         raise NotImplementedError("Don't know how to handle %s" %
                 self.timelapse_unit)
     self._frames_prepared = True
示例#2
0
    def add_track(self, path):
        tl = TrackLibrary()
        tl.add_track(path)
        if self.max_latitude:
            if tl[path].min_latitude > self.max_latitude or \
                    tl[path].max_latitude < self.min_latitude or \
                    tl[path].min_longitude > self.max_longitude or \
                    tl[path].max_longitude < self.min_longitude:
                #print("Outside our specified area")
                return
        min_date = self.config.get_min_date()
        max_date = self.config.get_max_date()
        if min_date or max_date:
            if min_date and tl[path].max_date < min_date:
                #print("Before the specified time range")
                return
            if max_date and tl[path].min_date > max_date:
                #print("After the specified time range")
                return

        # At this point we know the track is one that we want
        self.tracks.append(path)

        # If we only have one track, we use its bounds as our
        # auto-detected bounds
        if len(self.tracks) == 1:
            self.auto_min_latitude = tl[path].min_latitude
            self.auto_max_latitude = tl[path].max_latitude
            self.auto_min_longitude = tl[path].min_longitude
            self.auto_max_longitude = tl[path].max_longitude
            self.auto_min_elevation = tl[path].min_elevation
            self.auto_max_elevation = tl[path].max_elevation
            self.auto_min_speed = tl[path].min_speed
            self.auto_max_speed = tl[path].max_speed
            return

        # If we don't have a minimum latitude specified, grow our
        # auto-detected bounds accordingly
        if not self.min_latitude:
            if self.auto_min_latitude > tl[path].min_latitude:
                self.auto_min_latitude = tl[path].min_latitude
            if self.auto_max_latitude < tl[path].max_latitude:
                self.auto_max_latitude = tl[path].max_latitude
            if self.auto_min_longitude > tl[path].min_longitude:
                self.auto_min_longitude = tl[path].min_longitude
            if self.auto_max_longitude < tl[path].max_longitude:
                self.auto_max_longitude = tl[path].max_longitude

        # Likewise, grow the auto-elevation bounds
        if not self.min_elevation:
            if self.auto_min_elevation > tl[path].min_elevation:
                self.auto_min_elevation = tl[path].min_elevation
            if self.auto_max_elevation < tl[path].max_elevation:
                self.auto_max_elevation = tl[path].max_elevation

        # Likewise, grow the auto-speed bounds
        if self.min_speed is None:
            if self.auto_min_speed > tl[path].min_speed:
                self.auto_min_speed = tl[path].min_speed
            if self.auto_max_speed < tl[path].max_speed:
                self.auto_max_speed = tl[path].max_speed