Orients layer lines from lowest y-axis value to largest y-axis value
351148
private List<List<Integer>> orientLayerLines(List<List<Integer>> layerLines) {
		Matrix4d transformation = helixAxisAligner.getTransformation();
		List<Point3d> centers = helixAxisAligner.getSubunits().getOriginalCenters();

		for (int i = 0; i < layerLines.size(); i++) {
			List<Integer> layerLine = layerLines.get(i);

			// get center of first subunit in layerline and transform to standard orientation (helix axis aligned with y-axis)
			int first = layerLine.get(0);
			Point3d firstSubunit = new Point3d(centers.get(first));
			transformation.transform(firstSubunit);

			// get center of last subunit in layerline and transform to standard orientation (helix axis aligned with y-axis)
			int last = layerLine.get(layerLine.size()-1);
			Point3d lastSubunit = new Point3d(centers.get(last));
			transformation.transform(lastSubunit);

			// a layerline should start at the lowest y-value, so all layerlines have a consistent direction from -y value to +y value
			if (firstSubunit.y > lastSubunit.y) {
//				System.out.println("reorienting layer line: " + layerLine);
				Collections.reverse(layerLine);
			}
		}
		return layerLines;
	}
166582
def _rolling_lstsq(x, y):
    """"""
    if x.ndim == 2:
        # Treat everything as 3d and avoid AxisError on .swapaxes(1, 2) below
        # This means an original input of:
        #     array([0., 1., 2., 3., 4., 5., 6.])
        # becomes:
        # array([[[0.],
        #         [1.],
        #         [2.],
        #         [3.]],
        #
        #        [[1.],
        #         [2.],
        #         ...
        x = x[:, :, None]
    elif x.ndim <= 1:
        raise np.AxisError("x should have ndmi >= 2")
    return np.squeeze(
        np.matmul(
            np.linalg.inv(np.matmul(x.swapaxes(1, 2), x)),
            np.matmul(x.swapaxes(1, 2), np.atleast_3d(y)),
        )
    )
1320436
function tileToPixelCoords(x, y, v) {
         var ret = v || new me.Vector2d();
         return ret.set((x - y) * this.hTilewidth + this.originX, (x + y) * this.hTileheight);
       }
1056247
function (plot, axis, noTicks) {
        var ticks = [],
            minIdx = -1,
            maxIdx = -1,
            surface = plot.getCanvas(),
            logTickValues = PREFERRED_LOG_TICK_VALUES,
            min = clampAxis(axis, plot),
            max = axis.max;

        if (!noTicks) {
            noTicks = 0.3 * Math.sqrt(axis.direction === "x" ? surface.width : surface.height);
        }

        PREFERRED_LOG_TICK_VALUES.some(function (val, i) {
            if (val >= min) {
                minIdx = i;
                return true;
            } else {
                return false;
            }
        });

        PREFERRED_LOG_TICK_VALUES.some(function (val, i) {
            if (val >= max) {
                maxIdx = i;
                return true;
            } else {
                return false;
            }
        });

        if (maxIdx === -1) {
            maxIdx = PREFERRED_LOG_TICK_VALUES.length - 1;
        }

        if (maxIdx - minIdx <= noTicks / 4 && logTickValues.length !== EXTENDED_LOG_TICK_VALUES.length) {
            //try with multiple of 5 for tick values
            logTickValues = EXTENDED_LOG_TICK_VALUES;
            minIdx *= 2;
            maxIdx *= 2;
        }

        var lastDisplayed = null,
            inverseNoTicks = 1 / noTicks,
            tickValue, pixelCoord, tick;

        // Count the number of tick values would appear, if we can get at least
        // nTicks / 4 accept them.
        if (maxIdx - minIdx >= noTicks / 4) {
            for (var idx = maxIdx; idx >= minIdx; idx--) {
                tickValue = logTickValues[idx];
                pixelCoord = (Math.log(tickValue) - Math.log(min)) / (Math.log(max) - Math.log(min));
                tick = tickValue;

                if (lastDisplayed === null) {
                    lastDisplayed = {
                        pixelCoord: pixelCoord,
                        idealPixelCoord: pixelCoord
                    };
                } else {
                    if (Math.abs(pixelCoord - lastDisplayed.pixelCoord) >= inverseNoTicks) {
                        lastDisplayed = {
                            pixelCoord: pixelCoord,
                            idealPixelCoord: lastDisplayed.idealPixelCoord - inverseNoTicks
                        };
                    } else {
                        tick = null;
                    }
                }

                if (tick) {
                    ticks.push(tick);
                }
            }
            // Since we went in backwards order.
            ticks.reverse();
        } else {
            var tickSize = plot.computeTickSize(min, max, noTicks),
                customAxis = {min: min, max: max, tickSize: tickSize};
            ticks = $.plot.linearTickGenerator(customAxis);
        }

        return ticks;
    }
339091
def align_subplots(N,M,xlim=None, ylim=None):
    """"""
    #find sensible xlim,ylim
    if xlim is None:
        xlim = [np.inf,-np.inf]
        for i in range(N*M):
            plt.subplot(N,M,i+1)
            xlim[0] = min(xlim[0],plt.xlim()[0])
            xlim[1] = max(xlim[1],plt.xlim()[1])
    if ylim is None:
        ylim = [np.inf,-np.inf]
        for i in range(N*M):
            plt.subplot(N,M,i+1)
            ylim[0] = min(ylim[0],plt.ylim()[0])
            ylim[1] = max(ylim[1],plt.ylim()[1])

    for i in range(N*M):
        plt.subplot(N,M,i+1)
        plt.xlim(xlim)
        plt.ylim(ylim)
        if (i)%M:
            plt.yticks([])
        else:
            removeRightTicks()
        if i<(M*(N-1)):
            plt.xticks([])
        else:
            removeUpperTicks()
793895
public AffineTransform metersToTilePixelsTransform(int tx, int ty, int zoomLevel) {
        AffineTransform result = new AffineTransform();
        double scale = 1.0 / resolution(zoomLevel);
        int nTiles = 2 << (zoomLevel - 1);
        int px = tx * -256;
        int py = (nTiles - ty) * -256;
        // flip y for upper-left origin
        result.scale(1, -1);
        result.translate(px, py);
        result.scale(scale, scale);
        result.translate(originShift, originShift);
        return result;
    }
53026
public static void verticalInverse(BorderIndex1D border , WlBorderCoef<WlCoef_F32> inverseCoef , GrayF32 input , GrayF32 output ) {

		UtilWavelet.checkShape(output,input);

		float []trends = new float[ output.height ];
		float []details = new float[ output.height ];

		boolean isLarger = input.height > output.height;
		int paddedHeight = output.height + output.height%2;

		final int lowerBorder = inverseCoef.getLowerLength()*2;
		final int upperBorder = output.height - inverseCoef.getUpperLength()*2;

		border.setLength(output.height+output.height%2);

		WlCoef_F32 coefficients;

		for( int x = 0; x < output.width; x++) {

			for( int i = 0; i < details.length; i++ ) {
				details[i] = 0;
				trends[i] = 0;
			}

			for( int y = 0; y < output.height; y += 2 ) {
				float a = input.get(x,y/2);
				float d = input.get(x,y/2+input.height/2);

				if( y < lowerBorder ) {
					coefficients = inverseCoef.getBorderCoefficients(y);
				} else if( y >= upperBorder ) {
					coefficients = inverseCoef.getBorderCoefficients(y-paddedHeight);
				} else {
					coefficients = inverseCoef.getInnerCoefficients();
				}

				final int offsetA = coefficients.offsetScaling;
				final int offsetB = coefficients.offsetWavelet;
				final float[] alpha = coefficients.scaling;
				final float[] beta = coefficients.wavelet;

				// add the 'average' signal
				for( int i = 0; i < alpha.length; i++ ) {
					// if an odd image don't update the outer edge
					int yy = border.getIndex(y+offsetA+i);
					if( isLarger && yy >= output.height )
						continue;
					trends[yy] += a*alpha[i];
				}

				// add the detail signal
				for( int i = 0; i < beta.length; i++ ) {
					int yy = border.getIndex(y+offsetB+i);
					if( isLarger && yy >= output.height )
						continue;
					details[yy] += d*beta[i];
				}
			}

			for( int y = 0; y < output.height; y++ ) {
				output.set(x,y, trends[y] + details[y]);
			}
		}
	}
910940
function getAdjustedTileIndex({x, y, z}, adjustedZ) {
  const m = Math.pow(2, z - adjustedZ);
  return {
    x: Math.floor(x / m),
    y: Math.floor(y / m),
    z: adjustedZ
  };
}
537409
def max_projection(self, axis=2):
        
        if axis >= size(self.value_shape):
            raise Exception('Axis for projection (%s) exceeds '
                            'image dimensions (%s-%s)' % (axis, 0, size(self.value_shape)-1))

        new_value_shape = list(self.value_shape)
        del new_value_shape[axis]
        return self.map(lambda x: amax(x, axis), value_shape=new_value_shape)
81921
protected void findLocalScaleSpaceMax(PyramidFloat<T> ss, int layerID) {
		int index0 = spaceIndex;
		int index1 = (spaceIndex + 1) % 3;
		int index2 = (spaceIndex + 2) % 3;

		List<Point2D_I16> candidates = maximums[index1];
		ImageBorder_F32 inten0 = (ImageBorder_F32) FactoryImageBorderAlgs.value(intensities[index0], 0);
		GrayF32 inten1 = intensities[index1];
		ImageBorder_F32 inten2 = (ImageBorder_F32) FactoryImageBorderAlgs.value(intensities[index2], 0);

		float scale0 = (float) ss.scale[layerID - 1];
		float scale1 = (float) ss.scale[layerID];
		float scale2 = (float) ss.scale[layerID + 1];

		float sigma0 = (float) ss.getSigma(layerID - 1);
		float sigma1 = (float) ss.getSigma(layerID);
		float sigma2 = (float) ss.getSigma(layerID + 1);

		// not sure if this is the correct way to handle the change in scale
		float ss0 = (float) (Math.pow(sigma0, scalePower)/scale0);
		float ss1 = (float) (Math.pow(sigma1, scalePower)/scale1);
		float ss2 = (float) (Math.pow(sigma2, scalePower)/scale2);

		for (Point2D_I16 c : candidates) {
			float val = ss1 * inten1.get(c.x, c.y);

			// find pixel location in each image's local coordinate
			int x0 = (int) (c.x * scale1 / scale0);
			int y0 = (int) (c.y * scale1 / scale0);

			int x2 = (int) (c.x * scale1 / scale2);
			int y2 = (int) (c.y * scale1 / scale2);

			if (checkMax(inten0, val / ss0, x0, y0) && checkMax(inten2, val / ss2, x2, y2)) {
				// put features into the scale of the upper image
				foundPoints.add(new ScalePoint(c.x * scale1, c.y * scale1, sigma1));
			}
		}
	}
912153
function scanSpans(e0, e1, ymin, ymax, scanLine) {
  var y0 = Math.max(ymin, Math.floor(e1.y0)),
      y1 = Math.min(ymax, Math.ceil(e1.y1));

  // sort edges by x-coordinate
  if ((e0.x0 == e1.x0 && e0.y0 == e1.y0)
      ? (e0.x0 + e1.dy / e0.dy * e0.dx < e1.x1)
      : (e0.x1 - e1.dy / e0.dy * e0.dx < e1.x0)) {
    var t = e0; e0 = e1; e1 = t;
  }

  // scan lines!
  var m0 = e0.dx / e0.dy,
      m1 = e1.dx / e1.dy,
      d0 = e0.dx > 0, // use y + 1 to compute x0
      d1 = e1.dx < 0; // use y + 1 to compute x1
  for (var y = y0; y < y1; y++) {
    var x0 = m0 * Math.max(0, Math.min(e0.dy, y + d0 - e0.y0)) + e0.x0,
        x1 = m1 * Math.max(0, Math.min(e1.dy, y + d1 - e1.y0)) + e1.x0;
    scanLine(Math.floor(x1), Math.ceil(x0), y);
  }
}
88539
def flip(self, axis=0, preserve_centroid=False):
        '''
        

        '''
        self.v[:, axis] *= -1

        if preserve_centroid:
            self.v[:, axis] -= 2 * self.centroid[0]

        self.flip_faces()
140093
function ( startX, startY, endX, endY ) {
        var gapH = Math.max( startX, endX ) - Math.min( startX, endX ),
            gapV = Math.max( startY, endY ) - Math.min( startY, endY );

        if ( gapH > gapV ) {
            return 'horizontal';
        } else if ( gapH < gapV ) {
            return 'vertical';
        } else {
            return 'none';
        }
    }
1115775
def autoscale_y(ax,margin=0.1):
    """"""
    # Thanks to http://stackoverflow.com/questions/29461608/matplotlib-fixing-x-axis-scale-and-autoscale-y-axis for inspiring this!
    
    import numpy as np

    def get_bottom_top(line,lo,hi):
        xd = line.get_xdata()
        yd = line.get_ydata()
        y_displayed = yd[((xd>lo) & (xd<hi))]
        if len(y_displayed)==0:
            #No plotted data is inside the xlims
            return None, None
        else:
            h = np.max(y_displayed) - np.min(y_displayed)
            bot = np.min(y_displayed)-margin*h
            top = np.max(y_displayed)+margin*h
            return bot,top

    lines = ax.get_lines()
     
    lo,hi = ax.get_xlim()
    
    # Do a quick check to see if the x-axis has been inverted
    if lo>hi: # Reverse them for now
        lo,hi = hi,lo
        
    # Initialize limits
    bot,top = np.inf, -np.inf

    for line in lines:
        new_bot, new_top = get_bottom_top(line,lo,hi)
        if new_bot is not None:
            if new_bot < bot: bot = new_bot
            if new_top > top: top = new_top

    # Check to see if it is appropriate to change the boundaries
    if bot !=np.inf and top != -np.inf:    
        ax.set_ylim(bot,top)
    
    return ax
1335534
def y_pos(self, yval):
        ""
        off = self.y_coord.get_canvas_pos(self.size[1], yval,
                                          self.y_range[0], self.y_range[1])
        return self.loc[1] + off
1320761
function getMouseCoordinates(e) {
			var coordinates = {
				xAxis: [],
				yAxis: []
			};
			each(axes, function (axis) {
				var translate = axis.translate,
					isXAxis = axis.isXAxis,
					isHorizontal = inverted ? !isXAxis : isXAxis;

				coordinates[isXAxis ? 'xAxis' : 'yAxis'].push({
					axis: axis,
					value: translate(
						isHorizontal ?
							e.chartX - plotLeft  :
							plotHeight - e.chartY + plotTop,
						true
					)
				});
			});
			return coordinates;
		}
782114
function () {
		
		// Call uber method		
		axisProto.setAxisTranslation.call(this);
			
		// Set transA and minPixelPadding
		if (this.center) { // it's not defined the first time
			if (this.isCircular) {
				
				this.transA = (this.endAngleRad - this.startAngleRad) / 
					((this.max - this.min) || 1);
					
				
			} else { 
				this.transA = (this.center[2] / 2) / ((this.max - this.min) || 1);
			}
			
			if (this.isXAxis) {
				this.minPixelPadding = this.transA * this.minPointOffset;
			} else {
				// This is a workaround for regression #2593, but categories still don't position correctly.
				// TODO: Implement true handling of Y axis categories on gauges.
				this.minPixelPadding = 0; 
			}
		}
	}