Determine a good value for nTrackIterations based on the misalignment between stream and orbit; just based on some rough experience for now
425764
def _determine_nTrackIterations(self,nTrackIterations):
        """"""
        if not nTrackIterations is None:
            self.nTrackIterations= nTrackIterations
            return None
        if numpy.fabs(self.misalignment(quantity=False)) < 1./180.*numpy.pi:
            self.nTrackIterations= 0
        elif numpy.fabs(self.misalignment(quantity=False)) >= 1./180.*numpy.pi \
                and numpy.fabs(self.misalignment(quantity=False)) < 3./180.*numpy.pi:
            self.nTrackIterations= 1
        elif numpy.fabs(self.misalignment(quantity=False)) >= 3./180.*numpy.pi:
            self.nTrackIterations= 2
        return None
706640
def _optimal_orientation_from_detector(detector_name, tc):
    

    d = Detector(detector_name)
    ra, dec = d.optimal_orientation(tc)

    return ra, dec
1208483
private void backward(TrellisNode[][] trellis) {
        int n = trellis.length - 1;
        TrellisNode[] tn = trellis[n];
        for (int i = 0; i < numClasses; i++) {
            tn[i].beta = 1.0;
        }

        for (int t = n; t-- > 0;) {
            TrellisNode[] tt = trellis[t];
            TrellisNode[] tt1 = trellis[t+1];
            for (int i = 0; i < numClasses; i++) {
                TrellisNode tti = tt[i];
                tti.beta = 0.0;
                for (int j = 0; j < numClasses; j++) {
                    tti.beta += tt1[j].expScores[i] * tt1[j].beta;
                }
            }

            // Normalize beta values since they increase quickly
            double sum = 0.0;
            for (int i = 0; i < numClasses; i++) {
                sum += tt[i].beta;
            }
            for (int i = 0; i < numClasses; i++) {
                tt[i].beta /= sum;
            }
        }
    }
344136
def get_adjusted_value(
            self,
            assets,
            field,
            dt,
            perspective_dt,
            data_frequency):
        '''
        
        '''
        return self.backend.get_spot_value(
            assets, field, dt, data_frequency, self.quantopian_compatible
        )
135647
function getValueAxisStart(baseAxis, valueAxis, stacked) {
    var extent = valueAxis.getGlobalExtent();
    var min;
    var max;
    if (extent[0] > extent[1]) {
        min = extent[1];
        max = extent[0];
    }
    else {
        min = extent[0];
        max = extent[1];
    }

    var valueStart = valueAxis.toGlobalCoord(valueAxis.dataToCoord(0));
    valueStart < min && (valueStart = min);
    valueStart > max && (valueStart = max);

    return valueStart;
}
664857
private boolean robustFitTrifocal(List<AssociatedTriple> associated) {
		// Fit a trifocal tensor to the observations robustly
		ransac.process(associated);

		inliers = ransac.getMatchSet();
		TrifocalTensor model = ransac.getModelParameters();
		if( verbose != null )
			verbose.println("Remaining after RANSAC "+inliers.size()+" / "+associated.size());

		// estimate using all the inliers
		// No need to re-scale the input because the estimator automatically adjusts the input on its own
		if( !trifocalEstimator.process(inliers,model) ) {
			if( verbose != null ) {
				verbose.println("Trifocal estimator failed");
			}
			return false;
		}
		return true;
	}
715486
function init$15() {

        /* Place parameters in static storage for common use
         -------------------------------------------------*/
        this.sin_p14 = Math.sin(this.lat0);
        this.cos_p14 = Math.cos(this.lat0);
        // Approximation for projecting points to the horizon (infinity)
        this.infinity_dist = 1000 * this.a;
        this.rc = 1;
    }
1230697
public Frustum setToProjection (
        double left, double right, double bottom, double top, double near,
        double far, IVector3 nearFarNormal, boolean ortho, boolean mirrored) {
        double nfnx = nearFarNormal.x(), nfny = nearFarNormal.y(), nfnz = nearFarNormal.z();
        if (ortho) {
            double nrz = -1f / nfnz;
            double xl = nfnx*left*nrz, xr = nfnx*right*nrz;
            double yb = nfny*bottom*nrz, yt = nfny*top*nrz;
            _vertices[0].set(left, bottom, xl + yb - near);
            _vertices[mirrored ? 3 : 1].set(right, bottom, xr + yb - near);
            _vertices[2].set(right, top, xr + yt - near);
            _vertices[mirrored ? 1 : 3].set(left, top, xl + yt - near);
            _vertices[4].set(left, bottom, xl + yb - far);
            _vertices[mirrored ? 7 : 5].set(right, bottom, xr + yb - far);
            _vertices[6].set(right, top, xr + yt - far);
            _vertices[mirrored ? 5 : 7].set(left, top, xl + yt - far);

        } else {
            double rn = 1f / near;
            double lrn = left * rn, rrn = right * rn;
            double brn = bottom * rn, trn = top * rn;

            double nz = near * nfnz;
            double z0 = nz / (nfnx*lrn + nfny*brn - nfnz);
            _vertices[0].set(-z0*lrn, -z0*brn, z0);
            double z1 = nz / (nfnx*rrn + nfny*brn - nfnz);
            _vertices[mirrored ? 3 : 1].set(-z1*rrn, -z1*brn, z1);
            double z2 = nz / (nfnx*rrn + nfny*trn - nfnz);
            _vertices[2].set(-z2*rrn, -z2*trn, z2);
            double z3 = nz / (nfnx*lrn + nfny*trn - nfnz);
            _vertices[mirrored ? 1 : 3].set(-z3*lrn, -z3*trn, z3);

            double fz = far * nfnz;
            double z4 = fz / (nfnx*lrn + nfny*brn - nfnz);
            _vertices[4].set(-z4*lrn, -z4*brn, z4);
            double z5 = fz / (nfnx*rrn + nfny*brn - nfnz);
            _vertices[mirrored ? 7 : 5].set(-z5*rrn, -z5*brn, z5);
            double z6 = fz / (nfnx*rrn + nfny*trn - nfnz);
            _vertices[6].set(-z6*rrn, -z6*trn, z6);
            double z7 = fz / (nfnx*lrn + nfny*trn - nfnz);
            _vertices[mirrored ? 5 : 7].set(-z7*lrn, -z7*trn, z7);
        }

        updateDerivedState();
        return this;
    }
392902
def point_to_t(self, point):
        """"""

        def in_range(min, max, val):
            return (min <= val) and (max >= val)

        # Single-precision floats have only 7 significant figures of
        # resolution, so test that we're within 6 sig figs.
        if np.isclose(point, self.start, rtol=0.0, atol=1e-6):
            return 0.0
        elif np.isclose(point, self.end, rtol=0.0, atol=1e-6):
            return 1.0

        if self.rotation != 0.0:
            raise ValueError("Arc.point_to_t() only works on non-rotated Arcs.")

        v = point - self.center
        distance_from_center = sqrt((v.real * v.real) + (v.imag * v.imag))
        min_radius = min(self.radius.real, self.radius.imag)
        max_radius = max(self.radius.real, self.radius.imag)
        if (distance_from_center < min_radius) and not np.isclose(distance_from_center, min_radius):
            return None
        if (distance_from_center > max_radius) and not np.isclose(distance_from_center, max_radius):
            return None

        # x = center_x + radius_x cos(radians(theta + t delta))
        # y = center_y + radius_y sin(radians(theta + t delta))
        #
        # For x:
        # cos(radians(theta + t delta)) = (x - center_x) / radius_x
        # radians(theta + t delta) = acos((x - center_x) / radius_x)
        # theta + t delta = degrees(acos((x - center_x) / radius_x))
        # t_x = (degrees(acos((x - center_x) / radius_x)) - theta) / delta
        #
        # Similarly for y:
        # t_y = (degrees(asin((y - center_y) / radius_y)) - theta) / delta

        x = point.real
        y = point.imag

        #
        # +Y points down!
        #
        # sweep mean clocwise
        # sweep && (delta > 0)
        # !sweep && (delta < 0)
        #
        # -180 <= theta_1 <= 180
        #
        # large_arc && (-360 <= delta <= 360)
        # !large_arc && (-180 < delta < 180)
        #

        end_angle = self.theta + self.delta
        min_angle = min(self.theta, end_angle)
        max_angle = max(self.theta, end_angle)

        acos_arg = (x - self.center.real) / self.radius.real
        if acos_arg > 1.0:
            acos_arg = 1.0
        elif acos_arg < -1.0:
            acos_arg = -1.0

        x_angle_0 = degrees(acos(acos_arg))
        while x_angle_0 < min_angle:
            x_angle_0 += 360.0
        while x_angle_0 > max_angle:
            x_angle_0 -= 360.0

        x_angle_1 = -1.0 * x_angle_0
        while x_angle_1 < min_angle:
            x_angle_1 += 360.0
        while x_angle_1 > max_angle:
            x_angle_1 -= 360.0

        t_x_0 = (x_angle_0 - self.theta) / self.delta
        t_x_1 = (x_angle_1 - self.theta) / self.delta

        asin_arg = (y - self.center.imag) / self.radius.imag
        if asin_arg > 1.0:
            asin_arg = 1.0
        elif asin_arg < -1.0:
            asin_arg = -1.0

        y_angle_0 = degrees(asin(asin_arg))
        while y_angle_0 < min_angle:
            y_angle_0 += 360.0
        while y_angle_0 > max_angle:
            y_angle_0 -= 360.0

        y_angle_1 = 180 - y_angle_0
        while y_angle_1 < min_angle:
            y_angle_1 += 360.0
        while y_angle_1 > max_angle:
            y_angle_1 -= 360.0

        t_y_0 = (y_angle_0 - self.theta) / self.delta
        t_y_1 = (y_angle_1 - self.theta) / self.delta

        t = None
        if np.isclose(t_x_0, t_y_0):
            t = (t_x_0 + t_y_0) / 2.0
        elif np.isclose(t_x_0, t_y_1):
            t= (t_x_0 + t_y_1) / 2.0
        elif np.isclose(t_x_1, t_y_0):
            t = (t_x_1 + t_y_0) / 2.0
        elif np.isclose(t_x_1, t_y_1):
            t = (t_x_1 + t_y_1) / 2.0
        else:
            # Comparing None and float yields a result in python2,
            # but throws TypeError in python3.  This fix (suggested by
            # @CatherineH) explicitly handles and avoids the case where
            # the None-vs-float comparison would have happened below.
            return None

        if (t >= 0.0) and (t <= 1.0):
            return t

        return None
289252
def pickAChannel(self, ra_deg, dec_deg):
        
        # Could improve speed by doing this in the projection plane
        # instead of sky coords
        cRa = self.currentRaDec[:, 3]  # Ra of each channel corner
        cDec = self.currentRaDec[:, 4]  # dec of each channel corner

        dist = cRa * 0
        for i in range(len(dist)):
            dist[i] = gcircle.sphericalAngSep(cRa[i], cDec[i], ra_deg, dec_deg)

        i = np.argmin(dist)
        return self.currentRaDec[i, 2]
1178848
private static int[][] calculateBlackPoints(byte[] luminances,
                                              int subWidth,
                                              int subHeight,
                                              int width,
                                              int height) {
    int maxYOffset = height - BLOCK_SIZE;
    int maxXOffset = width - BLOCK_SIZE;
    int[][] blackPoints = new int[subHeight][subWidth];
    for (int y = 0; y < subHeight; y++) {
      int yoffset = y << BLOCK_SIZE_POWER;
      if (yoffset > maxYOffset) {
        yoffset = maxYOffset;
      }
      for (int x = 0; x < subWidth; x++) {
        int xoffset = x << BLOCK_SIZE_POWER;
        if (xoffset > maxXOffset) {
          xoffset = maxXOffset;
        }
        int sum = 0;
        int min = 0xFF;
        int max = 0;
        for (int yy = 0, offset = yoffset * width + xoffset; yy < BLOCK_SIZE; yy++, offset += width) {
          for (int xx = 0; xx < BLOCK_SIZE; xx++) {
            int pixel = luminances[offset + xx] & 0xFF;
            sum += pixel;
            // still looking for good contrast
            if (pixel < min) {
              min = pixel;
            }
            if (pixel > max) {
              max = pixel;
            }
          }
          // short-circuit min/max tests once dynamic range is met
          if (max - min > MIN_DYNAMIC_RANGE) {
            // finish the rest of the rows quickly
            for (yy++, offset += width; yy < BLOCK_SIZE; yy++, offset += width) {
              for (int xx = 0; xx < BLOCK_SIZE; xx++) {
                sum += luminances[offset + xx] & 0xFF;
              }
            }
          }
        }

        // The default estimate is the average of the values in the block.
        int average = sum >> (BLOCK_SIZE_POWER * 2);
        if (max - min <= MIN_DYNAMIC_RANGE) {
          // If variation within the block is low, assume this is a block with only light or only
          // dark pixels. In that case we do not want to use the average, as it would divide this
          // low contrast area into black and white pixels, essentially creating data out of noise.
          //
          // The default assumption is that the block is light/background. Since no estimate for
          // the level of dark pixels exists locally, use half the min for the block.
          average = min / 2;

          if (y > 0 && x > 0) {
            // Correct the "white background" assumption for blocks that have neighbors by comparing
            // the pixels in this block to the previously calculated black points. This is based on
            // the fact that dark barcode symbology is always surrounded by some amount of light
            // background for which reasonable black point estimates were made. The bp estimated at
            // the boundaries is used for the interior.

            // The (min < bp) is arbitrary but works better than other heuristics that were tried.
            int averageNeighborBlackPoint =
                (blackPoints[y - 1][x] + (2 * blackPoints[y][x - 1]) + blackPoints[y - 1][x - 1]) / 4;
            if (min < averageNeighborBlackPoint) {
              average = averageNeighborBlackPoint;
            }
          }
        }
        blackPoints[y][x] = average;
      }
    }
    return blackPoints;
  }
623752
def dx_orbit_sys(t, X):
    '''
    '''
    (m1x, m1y,
     m2x, m2y,
     m3x, m3y,
     m4x, m4y,
     m1vx, m1vy,
     m2vx, m2vy,
     m3vx, m3vy,
     m4vx, m4vy) = X
    m_moon1 = 7.342*(10**22)  # kg
    m_moon2 = 7.342*(10**22)  # kg
    m_moon3 = 7.342*(10**22)  # kg
    m_moon4 = 7.342*(10**22)  # kg
    G = 6.67408*(10**-11)  # m**3 kg**−1 s**−2
    dm12 = sqrt((m1x - m2x)**2 + (m1y - m2y)**2)
    dm13 = sqrt((m1x - m3x)**2 + (m1y - m3y)**2)
    dm14 = sqrt((m1x - m4x)**2 + (m1y - m4y)**2)
    dm23 = sqrt((m2x - m3x)**2 + (m2y - m3y)**2)
    dm24 = sqrt((m2x - m4x)**2 + (m2y - m4y)**2)
    dm34 = sqrt((m3x - m4x)**2 + (m3y - m4y)**2)
    f12 = G * m_moon1 * m_moon2 / (dm12 * dm12)
    f13 = G * m_moon1 * m_moon3 / (dm13 * dm13)
    f14 = G * m_moon1 * m_moon4 / (dm14 * dm14)
    f23 = G * m_moon2 * m_moon3 / (dm23 * dm23)
    f24 = G * m_moon2 * m_moon4 / (dm24 * dm24)
    f34 = G * m_moon3 * m_moon4 / (dm34 * dm34)
    dr12 = atan2(m2y - m1y, m2x - m1x)
    dr13 = atan2(m3y - m1y, m3x - m1x)
    dr14 = atan2(m4y - m1y, m4x - m1x)
    dr23 = atan2(m3y - m2y, m3x - m2x)
    dr24 = atan2(m4y - m2y, m4x - m2x)
    dr34 = atan2(m4y - m3y, m4x - m3x)
    f1x = f12 * cos(dr12) + f13 * cos(dr13) + f14 * cos(dr14)
    f1y = f12 * sin(dr12) + f13 * sin(dr13) + f14 * sin(dr14)
    f2x = f12 * cos(dr12 + pi) + f23 * cos(dr23) + f24 * cos(dr24)
    f2y = f12 * sin(dr12 + pi) + f23 * sin(dr23) + f24 * sin(dr24)
    f3x = f13 * cos(dr13 + pi) + f23 * cos(dr23 + pi) + f34 * cos(dr34)
    f3y = f13 * sin(dr13 + pi) + f23 * sin(dr23 + pi) + f34 * sin(dr34)
    f4x = f14 * cos(dr14 + pi) + f24 * cos(dr24 + pi) + f34 * cos(dr34 + pi)
    f4y = f14 * sin(dr14 + pi) + f24 * sin(dr24 + pi) + f34 * sin(dr34 + pi)
    dX = [
            m1vx,
            m1vy,
            m2vx,
            m2vy,
            m3vx,
            m3vy,
            m4vx,
            m4vy,
            f1x / m_moon1,
            f1y / m_moon1,
            f2x / m_moon2,
            f2y / m_moon2,
            f3x / m_moon3,
            f3y / m_moon3,
            f4x / m_moon4,
            f4y / m_moon4,
            ]
    return dX
448680
function getBottomPrice(hOptions, vOptions) {
  const centerOffset = getCenteringPrice(vOptions)
  const sideOffset =  Math.max(0, hOptions.tPos + hOptions.tDim + hOptions.oDim - hOptions.wDim)
  return centerOffset + sideOffset
}
39731
def b_neg(self):
        '''
        
        '''
        nb = Point(self.center)

        if self.xAxisIsMinor:
            nb.x -= self.minorRadius
        else:
            nb.y -= self.minorRadius
        return nb
569741
def sample_lonlat(self, n):
        
        # From http://en.wikipedia.org/wiki/Ellipse#General_parametric_form
        # However, Martin et al. (2009) use PA theta "from North to East"
        # Definition of phi (position angle) is offset by pi/4
        # Definition of t (eccentric anamoly) remains the same (x,y-frame usual)
        # In the end, everything is trouble because we use glon, glat...

        radius = self.sample_radius(n)
        a = radius; b = self.jacobian * radius

        t = 2. * np.pi * np.random.rand(n)
        cost,sint = np.cos(t),np.sin(t)
        phi = np.pi/2. - np.deg2rad(self.theta)
        cosphi,sinphi = np.cos(phi),np.sin(phi)
        x = a*cost*cosphi - b*sint*sinphi
        y = a*cost*sinphi + b*sint*cosphi
        
        if self.projector  is None:
            logger.debug("Creating AITOFF projector for sampling")
            projector = Projector(self.lon,self.lat,'ait')
        else:
            projector = self.projector
        lon, lat = projector.imageToSphere(x, y)
        return lon, lat
1360179
function(v) {
				var t = this.data, //refers to the element's _gsTransform object
					ang = -t.rotation * _DEG2RAD,
					skew = ang + t.skewX * _DEG2RAD,
					rnd = 100000,
					a = ((Math.cos(ang) * t.scaleX * rnd) | 0) / rnd,
					b = ((Math.sin(ang) * t.scaleX * rnd) | 0) / rnd,
					c = ((Math.sin(skew) * -t.scaleY * rnd) | 0) / rnd,
					d = ((Math.cos(skew) * t.scaleY * rnd) | 0) / rnd,
					style = this.t.style,
					cs = this.t.currentStyle,
					filters, val;
				if (!cs) {
					return;
				}
				val = b; //just for swapping the variables an inverting them (reused "val" to avoid creating another variable in memory). IE's filter matrix uses a non-standard matrix configuration (angle goes the opposite way, and b and c are reversed and inverted)
				b = -c;
				c = -val;
				filters = cs.filter;
				style.filter = ""; //remove filters so that we can accurately measure offsetWidth/offsetHeight
				var w = this.t.offsetWidth,
					h = this.t.offsetHeight,
					clip = (cs.position !== "absolute"),
					m = "progid:DXImageTransform.Microsoft.Matrix(M11=" + a + ", M12=" + b + ", M21=" + c + ", M22=" + d,
					ox = t.x + (w * t.xPercent / 100),
					oy = t.y + (h * t.yPercent / 100),
					dx, dy;

				//if transformOrigin is being used, adjust the offset x and y
				if (t.ox != null) {
					dx = ((t.oxp) ? w * t.ox * 0.01 : t.ox) - w / 2;
					dy = ((t.oyp) ? h * t.oy * 0.01 : t.oy) - h / 2;
					ox += dx - (dx * a + dy * b);
					oy += dy - (dx * c + dy * d);
				}

				if (!clip) {
					m += ", sizingMethod='auto expand')";
				} else {
					dx = (w / 2);
					dy = (h / 2);
					//translate to ensure that transformations occur around the correct origin (default is center).
					m += ", Dx=" + (dx - (dx * a + dy * b) + ox) + ", Dy=" + (dy - (dx * c + dy * d) + oy) + ")";
				}
				if (filters.indexOf("DXImageTransform.Microsoft.Matrix(") !== -1) {
					style.filter = filters.replace(_ieSetMatrixExp, m);
				} else {
					style.filter = m + " " + filters; //we must always put the transform/matrix FIRST (before alpha(opacity=xx)) to avoid an IE bug that slices part of the object when rotation is applied with alpha.
				}

				//at the end or beginning of the tween, if the matrix is normal (1, 0, 0, 1) and opacity is 100 (or doesn't exist), remove the filter to improve browser performance.
				if (v === 0 || v === 1) if (a === 1) if (b === 0) if (c === 0) if (d === 1) if (!clip || m.indexOf("Dx=0, Dy=0") !== -1) if (!_opacityExp.test(filters) || parseFloat(RegExp.$1) === 100) if (filters.indexOf("gradient(" && filters.indexOf("Alpha")) === -1) {
					style.removeAttribute("filter");
				}

				//we must set the margins AFTER applying the filter in order to avoid some bugs in IE8 that could (in rare scenarios) cause them to be ignored intermittently (vibration).
				if (!clip) {
					var mult = (_ieVers < 8) ? 1 : -1, //in Internet Explorer 7 and before, the box model is broken, causing the browser to treat the width/height of the actual rotated filtered image as the width/height of the box itself, but Microsoft corrected that in IE8. We must use a negative offset in IE8 on the right/bottom
						marg, prop, dif;
					dx = t.ieOffsetX || 0;
					dy = t.ieOffsetY || 0;
					t.ieOffsetX = Math.round((w - ((a < 0 ? -a : a) * w + (b < 0 ? -b : b) * h)) / 2 + ox);
					t.ieOffsetY = Math.round((h - ((d < 0 ? -d : d) * h + (c < 0 ? -c : c) * w)) / 2 + oy);
					for (i = 0; i < 4; i++) {
						prop = _margins[i];
						marg = cs[prop];
						//we need to get the current margin in case it is being tweened separately (we want to respect that tween's changes)
						val = (marg.indexOf("px") !== -1) ? parseFloat(marg) : _convertToPixels(this.t, prop, parseFloat(marg), marg.replace(_suffixExp, "")) || 0;
						if (val !== t[prop]) {
							dif = (i < 2) ? -t.ieOffsetX : -t.ieOffsetY; //if another tween is controlling a margin, we cannot only apply the difference in the ieOffsets, so we essentially zero-out the dx and dy here in that case. We record the margin(s) later so that we can keep comparing them, making this code very flexible.
						} else {
							dif = (i < 2) ? dx - t.ieOffsetX : dy - t.ieOffsetY;
						}
						style[prop] = (t[prop] = Math.round( val - dif * ((i === 0 || i === 2) ? 1 : mult) )) + "px";
					}
				}
			}
127936
def bbox_vert_aligned_center(box1, box2):
    
    if not (box1 and box2):
        return False
    return abs(((box1.right + box1.left) / 2.0) - ((box2.right + box2.left) / 2.0)) <= 5