Puts the grid into a canonical orientation
189504
@Override
	protected void putGridIntoCanonical(Grid g ) {
		// first put it into a plausible solution
		if( g.columns != numCols ) {
			rotateGridCCW(g);
		}

		if( isClockWise(g)) {
			flipHorizontal(g);
		}

		// pick the solutin which puts (0,0) coordinate the closest to the top left corner to resolve ambiguity
		if( g.columns == g.rows ) {
			closestCorner[0] = g.get(0,0).center.normSq();
			closestCorner[1] = g.get(numRows-1,0).center.normSq();
			closestCorner[2] = g.get(numRows-1,numCols-1).center.normSq();
			closestCorner[3] = g.get(0,numCols-1).center.normSq();

			int best = 0;
			for (int i = 0; i < 4; i++) {
				if( closestCorner[i] < closestCorner[best]) {
					best = i;
				}
			}

			for (int i = 0; i < best; i++) {
				rotateGridCCW(g);
			}
		} else {
			double d00 = g.get(0,0).center.normSq();
			double d11 = g.get(numRows-1,numCols-1).center.normSq();

			if( d11 < d00 ) {
				rotateGridCCW(g);
				rotateGridCCW(g);
			}
		}
	}
1007256
def setOrientation( self, orientation ):
        
        super(XSplitterHandle, self).setOrientation(orientation)
        
        if ( orientation == Qt.Vertical ):
            self.layout().setDirection( QBoxLayout.LeftToRight )
            
            # update the widgets
            self._collapseBefore.setFixedSize(30, 10)
            self._collapseAfter.setFixedSize(30, 10)
            self._resizeGrip.setFixedSize(60, 10)
            
            self._collapseBefore.setArrowType(Qt.UpArrow)
            self._collapseAfter.setArrowType(Qt.DownArrow)
            
        elif ( orientation == Qt.Horizontal ):
            self.layout().setDirection( QBoxLayout.TopToBottom )
            
            # update the widgets
            self._collapseBefore.setFixedSize(10, 30)
            self._collapseAfter.setFixedSize(10, 30)
            self._resizeGrip.setFixedSize(10, 60)
            
            self._collapseBefore.setArrowType(Qt.LeftArrow)
            self._collapseAfter.setArrowType(Qt.RightArrow)
1266181
function drawVerticalGridLines() {
            maskGridLines = svg.select('.grid-lines-group')
                .selectAll('line.vertical-grid-line')
                .data(xScale.ticks(xTicks))
                .enter()
                 .append('line')
                  .attr('class', 'vertical-grid-line')
                  .attr('y1', (xAxisPadding.left))
                  .attr('y2', chartHeight)
                  .attr('x1', (d) => xScale(d))
                  .attr('x2', (d) => xScale(d));
        }
404764
def Grid(
    pos=(0, 0, 0),
    normal=(0, 0, 1),
    sx=1,
    sy=1,
    c="g",
    bc="darkgreen",
    lw=1,
    alpha=1,
    resx=10,
    resy=10,
):
    
    ps = vtk.vtkPlaneSource()
    ps.SetResolution(resx, resy)
    ps.Update()
    poly0 = ps.GetOutput()
    t0 = vtk.vtkTransform()
    t0.Scale(sx, sy, 1)
    tf0 = vtk.vtkTransformPolyDataFilter()
    tf0.SetInputData(poly0)
    tf0.SetTransform(t0)
    tf0.Update()
    poly = tf0.GetOutput()
    axis = np.array(normal) / np.linalg.norm(normal)
    theta = np.arccos(axis[2])
    phi = np.arctan2(axis[1], axis[0])
    t = vtk.vtkTransform()
    t.PostMultiply()
    t.RotateY(theta * 57.3)
    t.RotateZ(phi * 57.3)
    tf = vtk.vtkTransformPolyDataFilter()
    tf.SetInputData(poly)
    tf.SetTransform(t)
    tf.Update()
    pd = tf.GetOutput()
    actor = Actor(pd, c=c, bc=bc, alpha=alpha)
    actor.GetProperty().SetRepresentationToWireframe()
    actor.GetProperty().SetLineWidth(lw)
    actor.SetPosition(pos)
    settings.collectable_actors.append(actor)
    return actor
1137906
protected void orderNodeGrid(SquareGrid grid, int row, int col) {
		SquareNode node = grid.get(row,col);

		if(grid.rows==1 && grid.columns==1 ) {
			for (int i = 0; i < 4; i++) {
				ordered[i] = node.square.get(i);
			}
		} else if( grid.columns==1 ) {
			if (row == grid.rows - 1) {
				orderNode(node, grid.get(row - 1, col), false);
				rotateTwiceOrdered();
			} else {
				orderNode(node, grid.get(row + 1, col), false);
			}
		} else {
			if( col == grid.columns-1) {
				orderNode(node, grid.get(row, col-1), true);
				rotateTwiceOrdered();
			} else {
				orderNode(node, grid.get(row, col+1), true);
			}
		}
	}
654187
def _vertical_x(axis, ticks=None, max_width=5):
    """"""
    if ticks is None:
        ticks = axis.get_xticks()
    if (np.array(ticks) == np.rint(ticks)).all():
        ticks = np.rint(ticks).astype(np.int)
    if max([len(str(tick)) for tick in ticks]) > max_width:
        axis.set_xticklabels(ticks, rotation='vertical')
430868
def plot_grid(self, **kwargs):
        
        fig, ax = plt.subplots(1, 1)
        self.plot_grid_to_ax(ax, **kwargs)
        return fig, ax
1255970
def _get_default_grid():
    """"""
    s = """
    time,0A 1A,0A   0B,0A   1B,0A
    0A,1A   time,1A 0B,1A   1B,1A
    0A,0B   1A,0B   time,0B 1B,0B
    0A,1B   1A,1B   0B,1B   time,1B
    """.strip()
    dims = [[_ for _ in re.split(' +', line.strip())]
            for line in s.splitlines()]
    return dims
1329471
def coord_grid(self):
        """"""

        import math,ephem
        ra2=math.pi*2
        ra1=0
        dec1=-1*math.pi/2.0
        dec2=math.pi/2.0

        
        ## grid space choices
        ## ra space in hours
        ra_grids=["06:00:00",
                  "03:00:00",
                  "01:00:00",
                  "00:30:00",
                  "00:15:00",
                  "00:05:00",
                  "00:01:00",
                  "00:00:30",
                  "00:00:15",
                  "00:00:05"]
        dec_grids=["45:00:00",
                   "30:00:00",
                   "15:00:00",
                   "05:00:00",
                   "01:00:00",
                   "00:15:00",
                   "00:05:00",
                   "00:01:00",
                   "00:00:30"]
        dra=(self.x2-self.x1)/3.0
        ddec=(self.y2-self.y1)/3.0
        for ra_grid in ra_grids:
            if self.hours(ra_grid)<math.fabs(dra):
                break
        ra_grid=self.hours(ra_grid)

        for dec_grid in dec_grids:
            if self.degrees(dec_grid)<math.fabs(ddec):
                break
        dec_grid=self.degrees(dec_grid)
        
        ra=ra1
        n=0
        import Tkinter,ephem
        while (ra<=ra2):
            (cx1,cy1)=self.p2c((ra,dec1))
            ly=cy1-30
            (cx2,cy2)=self.p2c((ra,dec2))
            self.create_line(cx1,cy1,cx2,cy2)
            lx=cx1
            n=n+1
            if n==2:
                dec=dec1
                k=2
                while ( dec <= dec2 ):
                    (lx,ly)=self.p2c((ra,dec))
                    (cx1,cy1)=self.p2c((ra1,dec))
                    (cx2,cy2)=self.p2c((ra2,dec))
                    self.create_line(cx1,cy1,cx2,cy2)
                    k=k+1
                    if k==3:
                        self.create_text(lx-45,ly-12,text=str(ephem.hours(ra)),fill='green')
                        self.create_text(lx+40,ly-12,text=str(ephem.degrees(dec)),fill='brown')
                        self.create_point(ra,dec,color='black',size=3)
                        k=0
                    dec=dec+dec_grid
                n=0
            ra=ra+ra_grid
304691
function(){
			var oThis = this,
				w = 0;
			this.firstColumn = true;

			$.each(this.gridCompColumnArr,function(){
				if(this.options.visible){
					w+=parseInt(this.options.width);
					this.firstColumn = oThis.firstColumn;
					oThis.firstColumn = false;
					oThis.lastVisibleColumn = this;
					oThis.lastVisibleColumnWidth = this.options.width;
				}
			});
			this.contentRealWidth = w;
		}
797434
public void configure( int width , int height , int gridRows , int gridCols ) {

		// need to maintain the same ratio of pixels in the grid as in the regular image for similarity and rigid
		// to work correctly
		int s = Math.max(width,height);
		scaleX = s/(float)(gridCols-1);
		scaleY = s/(float)(gridRows-1);
		if( gridRows > gridCols ) {
			scaleY /= (gridCols-1)/ (float) (gridRows-1);
		} else {
			scaleX /= (gridRows-1)/ (float) (gridCols-1);
		}

		this.gridRows = gridRows;
		this.gridCols = gridCols;

		grid.resize(gridCols*gridRows);
		reset();
	}
1359972
function () {
        var self = this, style, rect;

        style = self.getEl().style;
        rect = self._layoutRect;

        style.left = rect.x + 'px';
        style.top = rect.y + 'px';
        style.zIndex = 0xFFFF + 0xFFFF;
      }
653388
function() {
        var buffer = this.buffer + 1;
        while(true) {
            var tlTile = this.grid[0][0];
            var tlViewPort = {
                x: tlTile.position.x +
                    this.map.layerContainerOriginPx.x,
                y: tlTile.position.y +
                    this.map.layerContainerOriginPx.y
            };
            var ratio = this.getServerResolution() / this.map.getResolution();
            var tileSize = {
                w: Math.round(this.tileSize.w * ratio),
                h: Math.round(this.tileSize.h * ratio)
            };
            if (tlViewPort.x > -tileSize.w * (buffer - 1)) {
                this.shiftColumn(true, tileSize);
            } else if (tlViewPort.x < -tileSize.w * buffer) {
                this.shiftColumn(false, tileSize);
            } else if (tlViewPort.y > -tileSize.h * (buffer - 1)) {
                this.shiftRow(true, tileSize);
            } else if (tlViewPort.y < -tileSize.h * buffer) {
                this.shiftRow(false, tileSize);
            } else {
                break;
            }
        }
    }
254125
def homogenize_grid(grid_old, dx, dy):
    

    # 1 line fit
    x = grid_old.electrodes[:, 0]
    y = grid_old.electrodes[:, 1]
    sort_indices = np.argsort(x)
    x_sort = x[sort_indices]
    y_sort = y[sort_indices]
    p = np.polyfit(x_sort, y_sort, 1)

    # 2. rotate around first electrode
    offsetx = x_sort[0]
    offsety = y_sort[0]

    alpha = -np.arctan2(p[0], 1.0)  # * 180 / np.pi

    xn = []
    yn = []
    for xc, yc in zip(x, y):
        rotx, roty = rotate_point(offsetx, offsety, xc, yc, alpha)
        xn.append(rotx + offsetx)
        yn.append(roty + offsety)

    new_coordinates = np.vstack((xn, yn)).T

    # move vertically

    # this line is a horizontal line
    p_rot = np.polyfit(
        new_coordinates[:, 0],
        new_coordinates[:, 1],
        1
    )
    y_rot = np.polyval(
        p_rot,
        new_coordinates[:, 0],
    )
    ymax = y_rot[0]

    new_coordinates_trans = np.copy(new_coordinates)
    new_coordinates_trans[:, 1] -= ymax

    #
    fig, ax = plt.subplots(1, 1)
    ax.scatter(x, y, color='r', label='original')

    ax.plot(
        x,
        np.polyval(p, x),
        '-',
        label='fit',
        color='r',
    )

    ax.scatter(
        xn, yn,
        color='c',
        label='rotated',
    )

    ax.plot(
        xn,
        y_rot,
        '-',
        label='fit',
        color='c',
    )

    ax.scatter(
        new_coordinates_trans[:, 0],
        new_coordinates_trans[:, 1],
        label='homog',
    )

    # plot the line through the new coordintes
    pnew = np.polyfit(
        new_coordinates_trans[:, 0],
        new_coordinates_trans[:, 1],
        1
    )
    ax.plot(
        new_coordinates_trans[:, 0],
        np.polyval(pnew, new_coordinates_trans[:, 0]),
        '-',
        label='fit homogenized',
    )

    ax.legend(loc='best')

    ax.set_xlabel('x [m]')
    ax.set_ylabel('y [m]')

    fig.tight_layout()
    fig.savefig('output_electrodes.png', dpi=300)

    # electrodes = np.hstack((
    # boundaries
    bx = new_coordinates_trans[sort_indices, 0]
    by = new_coordinates_trans[sort_indices, 1]
    btype = [12 for i in bx]

    # add boundary
    # get deepest boundary coordinate
    y1 = by[-1] - dy
    y2 = by[0] - dy

    ymin = min(y1, y2)

    bx = np.hstack(
        (bx[0] - dx,
         bx,
         [bx[-1] + dx, bx[-1] + dx, bx[0] - dx])
    )

    by = np.hstack(
        (by[0],
         by,
         [by[-1], ymin, ymin]
         )
    )

    btype = np.hstack((12,
                       btype,
                       [11, 11, 11]))

    boundaries = np.vstack((bx, by, btype)).T

    # fig, ax = plt.subplots(1, 1)
    # ax.scatter(bx, by)
    # ax.set_aspect('equal')
    # fig.tight_layout()
    # fig.savefig('boundaries.png', dpi=300)

    grid_new = grid_container(None, None, grid_old.char_length_file)
    grid_new.boundaries = np.copy(boundaries)
    grid_new.electrodes = np.copy(new_coordinates_trans)

    fig, ax = plt.subplots(1, 1)
    ax.scatter(bx, by, color='g', label='boundaries')
    ax.scatter(new_coordinates[:, 0], new_coordinates[:, 1], color='g',
               label='electrodes')
    ax.set_aspect('equal')
    ax.legend()
    fig.tight_layout()
    fig.savefig('output_boundaries.png', dpi=300)

    def transform_back(data):
        new_data = np.copy(data)
        new_data[:, 1] += ymax
        new_data[:, 0] -= offsetx
        new_data[:, 1] -= offsety

        tmpx = (new_data[:, 0]) * np.cos(-alpha) - (new_data[:, 1]) * np.sin(
            -alpha)
        tmpy = (new_data[:, 0]) * np.sin(-alpha) + (new_data[:, 1]) * np.cos(
            -alpha)
        tmpx += offsetx
        tmpy += offsety
        return tmpx, tmpy

    shell_script = ''
    shell_script += '#!/bin/bash\n'
    shell_script += 'cr_trig_create grid\n'

    cmd1 = ''.join((
        'grid_translate -e grid/elem.dat ',
        '--dx {0} --dz {1} -o elem_trans1.dat'.format(
            offsetx, ymax - offsety)
    ))
    cmd2 = ''.join((
        'grid_rotate -e elem_trans1.dat ',
        '-a {0} -o elem_trans1_rot1.dat'.format(-alpha * 180 / np.pi)
    ))
    cmd3 = ''.join((
        'grid_translate -e elem_trans1_rot1.dat ',
        '--dx {0} --dz {1} -o elem_trans1_rot1_trans2.dat'.format(
            offsetx, offsety)
    ))
    shell_script += cmd1 + '\n'
    shell_script += cmd2 + '\n'
    shell_script += cmd3 + '\n'

    shell_script += ''.join((
        'grid_plot_wireframe --fancy -t grid/elec.dat ',
        '-e elem_trans1_rot1_trans2.dat -o trans1_rot1_trans2.png'
    ))

    grid_new.script = shell_script

    tmpx, tmpy = transform_back(grid_new.electrodes)
    bx, by = transform_back(grid_new.boundaries[:, 0:2])

    grid_map = grid_container(char_length_file=grid_old.char_length_file)
    grid_map.electrodes = np.vstack((tmpx, tmpy)).T
    grid_map.boundaries = np.vstack((bx, by, grid_new.boundaries[:, 2])).T

    fig, ax = plt.subplots(1, 1)
    ax.scatter(tmpx, tmpy, color='r', label='new')
    ax.scatter(x, y, color='b', label='old')
    ax.scatter(bx, by, color='g', label='boundaries')
    ax.set_aspect('equal')
    ax.legend()
    fig.tight_layout()
    fig.savefig('output_map.png', dpi=300)

    return grid_new, grid_map
1297753
public void createCubicGrid() {
        //		logger.debug("	CREATE CUBIC GRID");
        gridGenerator.setDimension(findGridBoundaries(), true);
        gridGenerator.generateGrid();
        this.grid = gridGenerator.getGrid();
    }
581429
def set_longitude_grid(self, degrees):
        
        number = (360.0 / degrees) + 1
        locs = np.linspace(-np.pi, np.pi, number, True)[1:]
        locs[-1] -= 0.01 # Workaround for "back" gridlines showing.
        self.xaxis.set_major_locator(FixedLocator(locs))
        self._logitude_degrees = degrees
        self.xaxis.set_major_formatter(self.ThetaFormatter(degrees))
469539
def _generate_grid(self):
        """"""
        grid_axes = []
        for _, param in self.tunables:
            grid_axes.append(param.get_grid_axis(self.grid_width))

        return grid_axes