This an alternative way to generating sets of Delorean objects with
    DAILY stops
762634
def range_daily(start=None, stop=None, timezone='UTC', count=None):
    
    return stops(start=start, stop=stop, freq=DAILY, timezone=timezone, count=count)
493820
def stops(self):
    """"""
    stops = set()
    for stop_time in self.stop_times():
      stops |= stop_time.stops()
    return stops
1102008
def gen_centers(self):
        """"""

        '''x_track = self.cs.discrete_rollout()
        t = np.arange(len(x_track))*self.dt
        # choose the points in time we'd like centers to be at
        c_des = np.linspace(0, self.cs.run_time, self.bfs)
        self.c = np.zeros(len(c_des))
        for ii, point in enumerate(c_des): 
            diff = abs(t - point)
            self.c[ii] = x_track[np.where(diff == min(diff))[0][0]]'''

        # desired spacings along x
        # need to be spaced evenly between 1 and exp(-ax)
        # lowest number should be only as far as x gets 
        if self.bfs == 2:
            first = 0.5 # MODIFIED to handle a small number of basis (e.g. 3)
            last = 0.8
        elif self.bfs == 3:
            first = 0.4
            last = 0.8
        else:
            first = 0.2
            last = 0.8
        #first = np.exp(-self.cs.ax*self.cs.run_time) 
        #last = 1.05 - first
        des_c = np.linspace(first,last,self.bfs) 

        self.c = np.ones(len(des_c)) 
        for n in range(len(des_c)): 
            # x = exp(-c), solving for c
            self.c[n] = -np.log(des_c[n])
240865
def date_to_epoch(year, month, day):
    
    return int(date_to_delorean(year, month, day).epoch)
40838
private IntervalCategoryDataset createDataset() {
		TaskSeries ts = null;
		TaskSeriesCollection collection = new TaskSeriesCollection();
		if ( solver.getVariables().length == 0) {
			return collection;
		}

		ts = new TaskSeries("All");

		for (int i = 0; i < solver.getVariables().length ; i++) {
						
			String label = solver.getVariables()[i].getComponent(); //dn.getNodes().elementAt(i).getLabel();
			
			if ( this.selectedVariables == null || this.selectedVariables.contains( label ) ) {
			
				SymbolicTimeline tl1 = new SymbolicTimeline(solver,label);
	
				for (int j = 0 ; j < tl1.getPulses().length-1 ; j++  ) {
					
					if ( tl1.getValues()[j] != null ) {
						long startTime = tl1.getPulses()[j].longValue();
						long endTime =   startTime + tl1.getDurations()[j].longValue();					
						
						Date startTask = new Date(startTime);
						Date endTask = new Date(endTime);
						Task task;
						
						String value = tl1.getValues()[j].toString().replace("[", "").replace("]", "");
						if ( value.equals("true") )
							task = new Task(label, startTask, endTask);
						else
							task = new Task(label + " := " + value, startTask, endTask);
								
					
						ts.add(task);	
					}
				}
			}
		}
		
		collection.add(ts);

		return collection;
	}
211076
function(d) {
            return function(t) {
                var c = d.sets.map(function(set) {
                    var start = previous[set], end = circles[set];
                    if (!start) {
                        start = {x : width/2, y : height/2, radius : 1};
                    }
                    if (!end) {
                        end = {x : width/2, y : height/2, radius : 1};
                    }
                    return {'x' : start.x * (1 - t) + end.x * t,
                            'y' : start.y * (1 - t) + end.y * t,
                            'radius' : start.radius * (1 - t) + end.radius * t};
                });
                return intersectionAreaPath(c);
            };
        }
398373
static Turn[] turns(Point2d[] points) {

        final Turn[] turns = new Turn[points.length];

        // cycle of size 6 is [1,2,3,4,5,6] not closed
        for (int i = 1; i <= points.length; i++) {
            Point2d prevXy = points[i - 1];
            Point2d currXy = points[i % points.length];
            Point2d nextXy = points[(i + 1) % points.length];
            int parity = (int) Math.signum(det(prevXy.x, prevXy.y,
                                               currXy.x, currXy.y,
                                               nextXy.x, nextXy.y));
            if (parity == 0) return null;
            turns[i % points.length] = parity < 0 ? Right : Turn.Left;
        }

        return turns;
    }
1338843
def downsample_trajectories(trajectories, downsampler, *args, **kwargs):
  '''
  '''
  X = np.vstack(trajectories)
  traj_lengths = list(map(len, trajectories))
  inds = np.sort(downsampler(X, *args, **kwargs))
  new_traj = []
  for stop in np.cumsum(traj_lengths):
    n = np.searchsorted(inds, stop)
    new_traj.append(X[inds[:n]])
    inds = inds[n:]
  return new_traj
1111842
function () {
			var series = this,
				dataMin = Number.MAX_VALUE,
				dataMax = Number.MIN_VALUE;
	
			series.generatePoints();
	
			each(series.data, function (point) {
				
				point.shapeType = 'path';
				point.shapeArgs = {
					d: series.translatePath(point.path)
				};
				
				// TODO: do point colors in drawPoints instead of point.init
				if (typeof point.y === 'number') {
					if (point.y > dataMax) {
						dataMax = point.y;
					} else if (point.y < dataMin) {
						dataMin = point.y;
					}
				}
			});
			
			series.translateColors(dataMin, dataMax);
		}
643812
function getSetJ(h, lw, phi, dec, n, M, L) {

    var w = hourAngle(h, phi, dec),
        a = approxTransit(w, lw, n);
    return solarTransitJ(a, M, L);
}
205427
def new_expiry(days=DEFAULT_PASTE_LIFETIME_DAYS):
    """"""
    now = delorean.Delorean()
    return now + datetime.timedelta(days=days)
647154
def imitate_path(self, y_des):
        

        # set initial state and goal
        if y_des.ndim == 1: 
            y_des = y_des.reshape(1,len(y_des))
        self.y0 = y_des[:,0].copy()
        self.y_des = y_des.copy()
        self.goal = self.gen_goal(y_des)
        
        self.check_offset()

        if not (self.timesteps == y_des.shape[1]):
            # generate function to interpolate the desired trajectory
            import scipy.interpolate
            path = np.zeros((self.dmps, self.timesteps))
            x = np.linspace(0, self.cs.run_time, y_des.shape[1])
            for d in range(self.dmps):
                path_gen = scipy.interpolate.interp1d(x, y_des[d])
                for t in range(self.timesteps):  
                    path[d, t] = path_gen(t * self.dt)
            y_des = path

        # calculate velocity of y_des
        dy_des = np.diff(y_des) / self.dt
        # add zero to the beginning of every row
        dy_des = np.hstack((np.zeros((self.dmps, 1)), dy_des))

        # calculate acceleration of y_des
        ddy_des = np.diff(dy_des) / self.dt
        # add zero to the beginning of every row
        ddy_des = np.hstack((np.zeros((self.dmps, 1)), ddy_des))

        f_target = np.zeros((y_des.shape[1], self.dmps))
        # find the force required to move along this trajectory
        for d in range(self.dmps):
            f_target[:,d] = ddy_des[d] - self.ay[d] * \
                            (self.by[d] * (self.goal[d] - y_des[d]) - \
                            dy_des[d])

        # efficiently generate weights to realize f_target
        self.gen_weights(f_target)

        '''# plot the basis function activations
        import matplotlib.pyplot as plt
        plt.figure()
        plt.subplot(211)
        plt.plot(psi_track)
        plt.title('psi_track')

        # plot the desired forcing function vs approx
        plt.subplot(212)
        plt.plot(f_target[:,0])
        plt.plot(np.sum(psi_track * self.w[0], axis=1))
        plt.legend(['f_target', 'w*psi'])
        plt.tight_layout()
        plt.show()'''

        self.reset_state()
        return y_des
947687
def create_traj_ranges(start, stop, N):
    
    steps = (1.0/(N-1)) * (stop - start)
    if np.isscalar(steps):
        return steps*np.arange(N) + start
    else:
        return steps[:, None]*np.arange(N) + start[:, None]
7350
function generate() {
  for(const i in Routes) {
    if(!Routes[i].generated) {
      Routes[i] = generateController(path.controllers, Routes[i]);
    }
  }

  for(const i in MiddleWares) {
    MiddleWares[i] = generateController(path.middlewares, MiddleWares[i]);
  }

  for(const i in GlobalMiddleWares) {
    GlobalMiddleWares[i] = generateController(path.middlewares, GlobalMiddleWares[i]);
  }

  for(const i in ErrorsHandler) {
    ErrorsHandler[i] = generateController(path.errorHandler, ErrorsHandler[i]);
  }

  for(const i in Services) {
    Services[i] = generateService(path.services, Services[i]);
  }
}
972264
void run(boolean hullonly) {
    if(points.size() < 3) {
      throw new UnsupportedOperationException("There is no delaunay triangulation for less than three objects!");
    }
    int len = points.size() - 1;
    hull = new LinkedList<>();
    tris = hullonly ? null : new ArrayList<Triangle>(len);

    // 1. Seed point x_0
    final double[] seed;
    final int seedid = 0;

    final double[] sortd = new double[len];
    final int[] sorti = new int[len];
    Arrays.fill(sorti, -42); // To cause errors
    // TODO: remove duplicates.

    // 2. sort by squared Euclidean distance
    {
      Iterator<double[]> iter = points.iterator();
      seed = iter.next();
      for(int i = 0, j = 1; iter.hasNext(); j++, i++) {
        double dist = quadraticEuclidean(seed, iter.next());
        if(dist <= 0.) { // Duplicate.
          --len; // Decrease candidate set size
          --i; // Increase j, but not i.
          continue;
        }
        sortd[i] = dist;
        sorti[i] = j;
      }
      DoubleIntegerArrayQuickSort.sort(sortd, sorti, len);
    }
    // Detect some degenerate situations:
    if(len < 2) {
      hull.add(new IntIntPair(seedid, -1));
      if(len == 1) {
        hull.add(new IntIntPair(sorti[0], -1));
      }
      return;
    }
    assert (sortd[0] > 0);
    // final double[] seed2 = points.get(sort[0].second);
    final int seed2id = sorti[0];

    // 3. Find minimal triangle for these two points:
    Triangle besttri = findSmallest(seedid, seed2id, sortd, sorti, len);
    if(besttri == null) { // Degenerate
      hull.add(new IntIntPair(seedid, -1));
      hull.add(new IntIntPair(seed2id, -1));
      return;
    }
    // Note: sortd no longer accurate, recompute below!
    int start = 2; // First two points have already been processed.

    // 5. Make right-handed:
    besttri.makeClockwise(points);
    // Seed triangulation
    if(!hullonly) {
      tris.add(besttri);
    }
    // Seed convex hull (point, triangle)
    hull.add(new IntIntPair(besttri.a, 0));
    hull.add(new IntIntPair(besttri.b, 0));
    hull.add(new IntIntPair(besttri.c, 0));

    if(LOG.isDebuggingFinest()) {
      debugHull();
    }

    // 6. Resort from triangle circumcircle center
    double[] center = besttri.m;
    for(int i = start; i < len; i++) {
      sortd[i] = quadraticEuclidean(center, points.get(sorti[i]));
    }
    DoubleIntegerArrayQuickSort.sort(sortd, sorti, start, len);

    // Grow hull and triangles
    for(int i = start; i < len; i++) {
      final int pointId = sorti[i];
      final double[] newpoint = points.get(pointId);

      LinkedList<Triangle> newtris = hullonly ? null : new LinkedList<Triangle>();
      // We identify edges by their starting point. -1 is invalid.
      int hstart = -1, hend = -1;
      // Find first and last consecutive visible edge, backwards:
      {
        Iterator<IntIntPair> iter = hull.descendingIterator();
        IntIntPair next = hull.getFirst();
        double[] nextV = points.get(next.first);
        for(int pos = hull.size() - 1; iter.hasNext(); pos--) {
          IntIntPair prev = iter.next();
          double[] prevV = points.get(prev.first);
          // Not yet visible:
          if(hend < 0) {
            if(leftOf(prevV, nextV, newpoint)) {
              hstart = hend = pos;
              if(!hullonly) {
                // Clockwise, A is new point!
                Triangle tri = new Triangle(pointId, next.first, prev.first);
                assert (tri.isClockwise(points));
                assert (prev.second >= 0);
                tri.updateCircumcircle(points);
                tri.bc = prev.second;
                newtris.addFirst(tri);
              }
            }
          }
          else {
            if(leftOf(prevV, nextV, newpoint)) {
              hstart = pos;
              // Add triad:
              if(!hullonly) {
                // Clockwise, A is new point!
                Triangle tri = new Triangle(pointId, next.first, prev.first);
                assert (tri.isClockwise(points));
                assert (prev.second >= 0);
                tri.updateCircumcircle(points);
                tri.bc = prev.second;
                newtris.addFirst(tri);
              }
            }
            else {
              break;
            }
          }
          next = prev;
          nextV = prevV;
        }
      }
      // If the last edge was visible, we also need to scan forwards:
      if(hend == hull.size() - 1) {
        Iterator<IntIntPair> iter = hull.iterator();
        IntIntPair prev = iter.next();
        double[] prevV = points.get(prev.first);
        while(iter.hasNext()) {
          IntIntPair next = iter.next();
          double[] nextV = points.get(next.first);
          if(leftOf(prevV, nextV, newpoint)) {
            hend++;
            // Add triad:
            if(!hullonly) {
              // Clockwise, A is new point!
              Triangle tri = new Triangle(pointId, next.first, prev.first);
              assert (tri.isClockwise(points));
              assert (prev.second >= 0);
              tri.updateCircumcircle(points);
              tri.bc = prev.second;
              newtris.addLast(tri);
            }
          }
          else {
            break;
          }
          prev = next;
          prevV = nextV;
        }
      }
      assert (hstart >= 0 && hend >= hstart);
      // Note that hend can be larger than hull.size() now, interpret as
      // "hend % hull.size()"
      // Update hull, remove points
      final int firsttri, lasttri;
      if(hullonly) {
        firsttri = lasttri = -1;
      }
      else {
        final int tristart = tris.size();
        firsttri = tristart;
        lasttri = tristart + newtris.size() - 1;
      }
      final int hullsize = hull.size();
      if(LOG.isDebuggingFinest()) {
        LOG.debugFinest("Size: " + hullsize + " start: " + hstart + " end: " + hend);
      }
      if(hend < hullsize) {
        ListIterator<IntIntPair> iter = hull.listIterator();
        int p = 0;
        // Skip
        for(; p <= hstart; p++) {
          iter.next();
        }
        // Remove
        for(; p <= hend; p++) {
          iter.next();
          iter.remove();
        }
        // Insert, and update edge->triangle mapping
        iter.add(new IntIntPair(pointId, lasttri));
        iter.previous();
        if(!hullonly) {
          (iter.hasPrevious() ? iter.previous() : hull.getLast()).second = firsttri;
        }
      }
      else {
        ListIterator<IntIntPair> iter = hull.listIterator();
        // Remove end
        int p = hullsize;
        for(; p <= hend; p++) {
          iter.next();
          iter.remove();
        }
        // Insert
        iter.add(new IntIntPair(pointId, lasttri));
        // Wrap around
        p -= hullsize;
        IntIntPair pre = null;
        for(; p <= hstart; p++) {
          pre = iter.next();
        }
        assert (pre != null);
        pre.second = firsttri;
        // Remove remainder
        while(iter.hasNext()) {
          iter.next();
          iter.remove();
        }
      }
      if(LOG.isDebuggingFinest()) {
        debugHull();
      }
      if(!hullonly) {
        final int tristart = tris.size();
        // Connect triads (they are ordered)
        Iterator<Triangle> iter = newtris.iterator();
        for(int o = 0; iter.hasNext(); o++) {
          // This triangle has num tristart + o.
          Triangle cur = iter.next();
          cur.ca = o > 0 ? tristart + o - 1 : -1; // previously added triangle
          cur.ab = iter.hasNext() ? tristart + o + 1 : -1; // next triangle
          // cur.bc was set upon creation
          assert (cur.bc >= 0);
          Triangle other = tris.get(cur.bc);
          Orientation orient = cur.findOrientation(other);
          assert (orient != null) : "Inconsistent triangles: " + cur + " " + other;
          switch(orient){
          case ORIENT_BC_BA:
            assert (other.ab == -1) : "Inconsistent triangles: " + cur + " " + other;
            other.ab = tristart + o;
            break;
          case ORIENT_BC_CB:
            assert (other.bc == -1) : "Inconsistent triangles: " + cur + " " + other;
            other.bc = tristart + o;
            break;
          case ORIENT_BC_AC:
            assert (other.ca == -1) : "Inconsistent triangles: " + cur + " " + other;
            other.ca = tristart + o;
            break;
          default:
            assert (cur.isClockwise(points));
            assert (other.isClockwise(points));
            throw new RuntimeException("Inconsistent triangles: " + cur + " " + other + " size:" + tris.size());
          }
          tris.add(cur);
        }
        assert (tris.size() == lasttri + 1);
      }
    }
    // Now check for triangles that need flipping.
    if(!hullonly) {
      final int size = tris.size();
      long[] flippedA = BitsUtil.zero(size), flippedB = BitsUtil.zero(size);
      // Initial flip
      if(flipTriangles(flippedA) > 0) {
        for(int iterations = 1; iterations < 1000; iterations += 2) {
          if(LOG.isDebuggingFinest()) {
            debugHull();
          }
          if(flipTriangles(flippedA, flippedB) == 0) {
            break;
          }
          if(LOG.isDebuggingFinest()) {
            debugHull();
          }
          if(flipTriangles(flippedB, flippedA) == 0) {
            break;
          }
        }
      }
    }
  }
1204111
def _generate_collection(group, ax, ctype, colors):
    ''''''
    color = TREE_COLOR[ctype]

    # generate segment collection
    collection = PolyCollection(group, closed=False, antialiaseds=True,
                                edgecolors='face', facecolors=color)

    # add it to the axes
    ax.add_collection(collection)

    # dummy plot for the legend
    if color not in colors:
        label = str(ctype).replace('NeuriteType.', '').replace('_', ' ').capitalize()
        ax.plot((0., 0.), (0., 0.), c=color, label=label)
        colors.add(color)
1157426
def GetNearestStops(self, lat, lon, n=1):
    """"""
    dist_stop_list = []
    for s in self.stops.values():
      # TODO: Use util.ApproximateDistanceBetweenStops?
      dist = (s.stop_lat - lat)**2 + (s.stop_lon - lon)**2
      if len(dist_stop_list) < n:
        bisect.insort(dist_stop_list, (dist, s))
      elif dist < dist_stop_list[-1][0]:
        bisect.insort(dist_stop_list, (dist, s))
        dist_stop_list.pop()  # Remove stop with greatest distance
    return [stop for dist, stop in dist_stop_list]