Vertical contour for 1D model
510070
def vcontoursf1D(self, x1, x2, nx, levels, labels=False, decimals=0, color=None,
                     nudge=1e-6, newfig=True, figsize=None, layout=True, ax=None):
        
        naq = self.aq.naq
        xflow = np.linspace(x1 + nudge, x2 - nudge, nx)
        Qx = np.empty((naq, nx))
        for i in range(nx):
            Qx[:, i], Qydump = self.disvec(xflow[i], 0)
        zflow = np.empty(2 * naq)
        for i in range(self.aq.naq):
            zflow[2 * i] = self.aq.zaqtop[i]
            zflow[2 * i + 1] = self.aq.zaqbot[i]
        Qx = Qx[::-1] # set upside down
        Qxgrid = np.empty((2 * naq, nx))
        Qxgrid[0] = 0
        for i in range(naq - 1):
            Qxgrid[2 * i + 1] = Qxgrid[2 * i] - Qx[i]
            Qxgrid[2 * i + 2] = Qxgrid[2 * i + 1]
        Qxgrid[-1] = Qxgrid[-2] - Qx[-1]
        Qxgrid = Qxgrid[::-1] # index 0 at top
        if newfig:
            fig, ax = plt.subplots(1, 1, figsize=figsize)
        else:
            ax=ax
        cs = ax.contour(xflow, zflow, Qxgrid, levels, colors=color)
        if labels:
            fmt = '%1.' + str(decimals) + 'f'
            plt.clabel(cs, fmt=fmt)
1057752
def __f2d(frac_coords, v):
        
        # frac_coords = frac_coords % 1
        return np.array([int(frac_coords[0] * v.shape[0]),
                         int(frac_coords[1] * v.shape[1]),
                         int(frac_coords[2] * v.shape[2])])
476029
def grid_distortion(img, num_steps=10, xsteps=[], ysteps=[], interpolation=cv2.INTER_LINEAR,
                    border_mode=cv2.BORDER_REFLECT_101, value=None):
    
    height, width = img.shape[:2]

    x_step = width // num_steps
    xx = np.zeros(width, np.float32)
    prev = 0
    for idx, x in enumerate(range(0, width, x_step)):
        start = x
        end = x + x_step
        if end > width:
            end = width
            cur = width
        else:
            cur = prev + x_step * xsteps[idx]

        xx[start:end] = np.linspace(prev, cur, end - start)
        prev = cur

    y_step = height // num_steps
    yy = np.zeros(height, np.float32)
    prev = 0
    for idx, y in enumerate(range(0, height, y_step)):
        start = y
        end = y + y_step
        if end > height:
            end = height
            cur = height
        else:
            cur = prev + y_step * ysteps[idx]

        yy[start:end] = np.linspace(prev, cur, end - start)
        prev = cur

    map_x, map_y = np.meshgrid(xx, yy)
    map_x = map_x.astype(np.float32)
    map_y = map_y.astype(np.float32)
    img = cv2.remap(img, map_x, map_y, interpolation=interpolation, borderMode=border_mode, borderValue=value)
    return img
1111276
def plot_decision_boundary(model, X, y, step=0.1, figsize=(10, 8), alpha=0.4, size=20):
    

    x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
    y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
    xx, yy = np.meshgrid(np.arange(x_min, x_max, step),
                         np.arange(y_min, y_max, step))

    f, ax = plt.subplots(figsize=figsize)
    Z = model.predict(np.c_[xx.ravel(), yy.ravel()])
    Z = Z.reshape(xx.shape)

    ax.contourf(xx, yy, Z, alpha=alpha)
    ax.scatter(X[:, 0], X[:, 1], c=y, s=size, edgecolor='k')
    plt.show()
864249
def reshape_1d(df):
    """"""
    shape = df.shape
    if len(shape) == 1:
        return df.reshape(shape[0], 1)
    else:
        return df
154012
public static void vertical(BorderIndex1D border , WlCoef_I32 coefficients ,
								GrayI input , GrayI output ) {

		UtilWavelet.checkShape(input,output);

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

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

		boolean isLarger = output.height > input.height;

		for( int x = 0; x < input.width; x++) {
			for( int y = 0; y < input.height; y += 2 ) {
				int scale = 0;
				int wavelet = 0;

				for( int i = 0; i < alpha.length; i++ ) {
					int yy = border.getIndex(y+i+offsetA);
					if( isLarger && yy >= input.height )
						continue;
					scale += input.get(x,yy)*alpha[i];
				}
				for( int i = 0; i < beta.length; i++ ) {
					int yy = border.getIndex(y+i+offsetB);
					if( isLarger && yy >= input.height )
						continue;
					wavelet += input.get(x,yy)*beta[i];
				}

				int outY = y/2;

				scale = 2*scale/coefficients.denominatorScaling;
				wavelet = 2*wavelet/coefficients.denominatorWavelet;

				output.set(x , outY,scale);
				output.set(x , output.height/2 + outY , wavelet );
			}
		}
	}
999664
function mesh1D(array, level) {
  var zc = zeroCrossings(array, level)
  var n = zc.length
  var npos = new Array(n)
  var ncel = new Array(n)
  for(var i=0; i<n; ++i) {
    npos[i] = [ zc[i] ]
    ncel[i] = [ i ]
  }
  return {
    positions: npos,
    cells: ncel
  }
}
405274
def get_xy_1D(ds, stride=1, getval=False):
    
    gt = ds.GetGeoTransform()
    #stride = stride_m/gt[1]
    pX = np.arange(0, ds.RasterXSize, stride)
    pY = np.arange(0, ds.RasterYSize, stride)
    mX, dummy = pixelToMap(pX, pY[0], gt)
    dummy, mY = pixelToMap(pX[0], pY, gt)
    return mX, mY
490179
public static void vertical(GrayS16 input, GrayI16 output, int radius, @Nullable IWorkArrays work) {
		InputSanityCheck.checkSameShape(input , output);

		Kernel1D_S32 kernel = FactoryKernel.table1D_I32(radius);
		ConvolveJustBorder_General_SB.vertical(kernel,ImageBorderValue.wrap(input,0),output);
		if(BoofConcurrency.USE_CONCURRENT ) {
			ImplConvolveBox_MT.vertical(input, output, radius, work);
		} else {
			ImplConvolveBox.vertical(input, output, radius, work);
		}
	}
621921
def _vmomentsurfaceIntegrand(vR,vT,R,az,df,n,m,sigmaR1,sigmaT1,t,initvmoment):
    """"""
    o= Orbit([R,vR*sigmaR1,vT*sigmaT1,az])
    return vR**n*vT**m*df(o,t)/initvmoment
452127
def as_contours(self):
        """"""
        contours = dict()
        for byte_value in self.__byte_values:
            if byte_value == 0:
                continue
            mask = (self.__array == byte_value) * 255
            found_contours = find_contours(mask, 254, fully_connected='high') # a list of array
            contours[byte_value] = ContourSet(found_contours)
        return contours
1282811
def invcdf(x):
    """"""
    x_flat = np.ravel(x)
    x_trans = np.array([flib.ppnd16(y, 1) for y in x_flat])
    return np.reshape(x_trans, np.shape(x))
1322098
def _deep_copy_contours(self, ufo, parent, component, transformation):
        """"""

        for nested in component.components:
            self._deep_copy_contours(
                ufo,
                parent,
                ufo[nested.baseGlyph],
                transformation.transform(nested.transformation),
            )

        if component != parent:
            pen = TransformPen(parent.getPen(), transformation)

            # if the transformation has a negative determinant, it will reverse
            # the contour direction of the component
            xx, xy, yx, yy = transformation[:4]
            if xx * yy - xy * yx < 0:
                pen = ReverseContourPen(pen)

            component.draw(pen)
1291950
public void orizzonte7( double delta, int quadrata, double beta, double alfa, RandomIter elevImageIterator,
            WritableRaster curvatureImage, int[][] shadow ) {
        int rows = curvatureImage.getHeight();
        int cols = curvatureImage.getWidth();
        /*=====================*/

        int y, I, J;
        double zenith;

        /*======================*/

        for( int i = quadrata - 1; i >= 0; i-- ) {
            I = -1;
            J = -1;
            y = 0;
            for( int ii = i; ii < quadrata - 1; ii++ ) {
                for( int j = (int) floor(1 / tan(beta) * (ii - i)); j <= (int) floor(1 / tan(beta) * (ii - i + 1)) - 1
                        && j < cols; j++ ) {
                    if (ii >= (rows + 2 * cols) && !isNovalue(elevImageIterator.getSampleDouble(j, ii - (rows + 2 * cols), 0))) {
                        /*shadow.element[ii-(Z0.nrh+2*Z0.nch)][j]=i;}}}}*/
                        if (curvatureImage.getSampleDouble(j, ii - (rows + 2 * cols), 0) == 1 && I == -1) {
                            I = ii - (rows + 2 * cols);
                            J = j;
                            y = 1;
                        } else if (curvatureImage.getSampleDouble(j, ii - (rows + 2 * cols), 0) == 1 && I != -1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, ii
                                    - (rows + 2 * cols), 0))
                                    / sqrt(pow((double) (I - (ii - (rows + 2 * cols))) * (double) delta, (double) 2)
                                            + pow((double) (J - j) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[ii - (rows + 2 * cols)][j] = 0;
                                I = ii - (rows + 2 * cols);
                                J = j;
                            } else {
                                shadow[ii - (rows + 2 * cols)][j] = 1;
                            }
                        } else if (curvatureImage.getSampleDouble(j, ii - (rows + 2 * cols), 0) == 0 && y == 1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(j, ii
                                    - (rows + 2 * cols), 0))
                                    / sqrt(pow((double) (I - (ii - (rows + 2 * cols))) * (double) delta, (double) 2)
                                            + pow((double) (J - j) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[ii - (rows + 2 * cols)][j] = 0;
                                y = 0;
                            } else {
                                shadow[ii - (rows + 2 * cols)][j] = 1;
                            }
                        }
                    }
                }
            }
        }

    }
195776
def _fit_strel_to_im_2d(im, strel, r, x, y):
    
    """
    elem = strel.copy()
    x_dim, y_dim = im.shape
    x_min = x-r
    x_max = x+r+1
    y_min = y-r
    y_max = y+r+1
    if x_min < 0:
        x_adj = -x_min
        elem = elem[x_adj:, :]
        x_min = 0
    elif x_max > x_dim:
        x_adj = x_max - x_dim
        elem = elem[:-x_adj, :]
    if y_min < 0:
        y_adj = -y_min
        elem = elem[:, y_adj:]
        y_min = 0
    elif y_max > y_dim:
        y_adj = y_max - y_dim
        elem = elem[:, :-y_adj]
    ex, ey = elem.shape
    im[x_min:x_min+ex, y_min:y_min+ey] += elem
    return im
419406
def step(self):
        """"""
        # Assign attributes to local variables for convenience.
        u = self._u
        gI = self._data
        dgI = self._ddata
        theta = self._theta
        v = self._v
        
        if u is None:
            raise ValueError("the levelset is not set (use set_levelset)")
        
        res = np.copy(u)
        
        # Balloon.
        if v > 0:
            aux = binary_dilation(u, self.structure)
        elif v < 0:
            aux = binary_erosion(u, self.structure)
        if v!= 0:
            res[self._threshold_mask_v] = aux[self._threshold_mask_v]
        
        # Image attachment.
        aux = np.zeros_like(res)
        dres = np.gradient(res)
        for el1, el2 in zip(dgI, dres):
            aux += el1*el2
        res[aux > 0] = 1
        res[aux < 0] = 0
        
        # Smoothing.
        for i in range(self.smoothing):
            res = curvop(res)
        
        self._u = res
516225
function contoursTransform(contours, transforms) {
    if (!contours || !contours.length || !transforms || !transforms.length) {
        return contours;
    }

    contours.forEach(function (p) {
        for (var i = 0, l = transforms.length; i < l; i++) {
            var transform = transforms[i];
            var params = transform.params;
            switch (transform.name) {
                case 'translate':
                    pathAdjust(p, 1, 1, params[0], params[1]);
                    break;
                case 'scale':
                    pathAdjust(p, params[0], params[1]);
                    break;
                case 'matrix':
                    pathTransform(p, params[0], params[1], params[2], params[3], params[4], params[5]);
                    break;
            }
        }
    });

    return contours;
}