def __init__(self, ax=None, model=None, modelgrid=None, line=None, extent=None, geographic_coords=False): super(_StructuredCrossSection, self).__init__(ax=ax, model=model, modelgrid=modelgrid, geographic_coords= geographic_coords) if line is None: s = 'line must be specified.' raise Exception(s) linekeys = [linekeys.lower() for linekeys in list(line.keys())] if len(linekeys) != 1: s = 'only row, column, or line can be specified in line dictionary.\n' s += 'keys specified: ' for k in linekeys: s += '{} '.format(k) raise AssertionError(s) if ax is None: self.ax = plt.gca() else: self.ax = ax onkey = list(line.keys())[0] eps = 1.e-4 xedge, yedge = self.mg.xyedges self.__geographic_xpts = None # un-translate model grid into model coordinates self.xcellcenters, self.ycellcenters = \ geometry.transform(self.mg.xcellcenters, self.mg.ycellcenters, self.mg.xoffset, self.mg.yoffset, self.mg.angrot_radians, inverse=True) if 'row' in linekeys: self.direction = 'x' ycenter = self.ycellcenters.T[0] pts = [(xedge[0] + eps, ycenter[int(line[onkey])] - eps), (xedge[-1] - eps, ycenter[int(line[onkey])] + eps)] elif 'column' in linekeys: self.direction = 'y' xcenter = self.xcellcenters[0, :] pts = [(xcenter[int(line[onkey])] + eps, yedge[0] - eps), (xcenter[int(line[onkey])] - eps, yedge[-1] + eps)] else: self.direction = 'xy' verts = line[onkey] xp = [] yp = [] for [v1, v2] in verts: xp.append(v1) yp.append(v2) xp, yp = self.mg.get_local_coords(xp, yp) pts = [(xt, yt) for xt, yt in zip(xp, yp)] # for now set offset to zero, since we do not have # information on projection from the user # convert pts list to numpy array self.pts = np.array(pts) # get points along the line self.xpts = plotutil.line_intersect_grid(self.pts, self.mg.xyedges[0], self.mg.xyedges[1]) if len(self.xpts) < 2: s = 'cross-section cannot be created\n.' s += ' less than 2 points intersect the model grid\n' s += ' {} points intersect the grid.'.format(len(self.xpts)) raise Exception(s) # set horizontal distance d = [] for v in self.xpts: d.append(v[2]) self.d = np.array(d) self.idomain = self.mg.idomain if self.mg.idomain is None: self.idomain = np.ones((self.mg.nlay, self.mg.nrow, self.mg.ncol), dtype=int) self.ncb = 0 self.laycbd = [] if self.model is not None: if self.model.laycbd is not None: self.laycbd = self.model.laycbd for l in self.laycbd: if l > 0: self.ncb += 1 self.active = np.ones((self.mg.nlay + self.ncb), dtype=np.int) kon = 0 if len(self.laycbd) > 0: for k in range(self.mg.nlay): if self.laycbd[k] > 0: kon += 1 self.active[kon] = 0 kon += 1 top = self.mg.top botm = self.mg.botm elev = [top.copy()] for k in range(self.mg.nlay + self.ncb): elev.append(botm[k, :, :]) self.elev = np.array(elev) self.layer0 = 0 self.layer1 = self.mg.nlay + self.ncb + 1 zpts = [] for k in range(self.layer0, self.layer1): zpts.append(plotutil.cell_value_points(self.xpts, self.mg.xyedges[0], self.mg.xyedges[1], self.elev[k, :, :])) self.zpts = np.array(zpts) xcentergrid, zcentergrid = self.get_centergrids(self.xpts, self.zpts) self.xcentergrid = xcentergrid self.zcentergrid = zcentergrid geo_xcentergrid, _ = self.get_centergrids(self.geographic_xpts, self.zpts) self.geographic_xcentergrid = geo_xcentergrid # Create cross-section extent if extent is None: self.extent = self.get_extent() else: self.extent = extent # Set axis limits self.ax.set_xlim(self.extent[0], self.extent[1]) self.ax.set_ylim(self.extent[2], self.extent[3]) return
def __init__(self, ax=None, model=None, modelgrid=None, line=None, extent=None): super(_StructuredCrossSection, self).__init__(ax=ax, model=model, modelgrid=modelgrid) if line is None: s = 'line must be specified.' raise Exception(s) linekeys = [linekeys.lower() for linekeys in list(line.keys())] if len(linekeys) != 1: s = 'only row, column, or line can be specified in line dictionary.\n' s += 'keys specified: ' for k in linekeys: s += '{} '.format(k) raise AssertionError(s) if ax is None: self.ax = plt.gca() else: self.ax = ax onkey = list(line.keys())[0] eps = 1.e-4 xedge, yedge = self.mg.xyedges # un-translate model grid into model coordinates self.xcellcenters, self.ycellcenters = \ geometry.transform(self.mg.xcellcenters, self.mg.ycellcenters, self.mg.xoffset, self.mg.yoffset, self.mg.angrot_radians, inverse=True) if 'row' in linekeys: self.direction = 'x' ycenter = self.ycellcenters.T[0] pts = [(xedge[0] + eps, ycenter[int(line[onkey])] - eps), (xedge[-1] - eps, ycenter[int(line[onkey])] + eps)] elif 'column' in linekeys: self.direction = 'y' xcenter = self.xcellcenters[0, :] pts = [(xcenter[int(line[onkey])] + eps, yedge[0] - eps), (xcenter[int(line[onkey])] - eps, yedge[-1] + eps)] else: self.direction = 'xy' verts = line[onkey] xp = [] yp = [] for [v1, v2] in verts: xp.append(v1) yp.append(v2) xp, yp = self.mg.get_local_coords(xp, yp) pts = [(xt, yt) for xt, yt in zip(xp, yp)] # convert pts list to numpy array self.pts = np.array(pts) # get points along the line self.xpts = plotutil.line_intersect_grid(self.pts, self.mg.xyedges[0], self.mg.xyedges[1]) if len(self.xpts) < 2: s = 'cross-section cannot be created\n.' s += ' less than 2 points intersect the model grid\n' s += ' {} points intersect the grid.'.format(len(self.xpts)) raise Exception(s) # set horizontal distance d = [] for v in self.xpts: d.append(v[2]) self.d = np.array(d) self.idomain = self.mg.idomain if self.mg.idomain is None: self.idomain = np.ones((self.mg.nlay, self.mg.nrow, self.mg.ncol), dtype=int) self.ncb = 0 self.laycbd = [] if self.model is not None: if self.model.laycbd is not None: self.laycbd = self.model.laycbd for l in self.laycbd: if l > 0: self.ncb += 1 self.active = np.ones((self.mg.nlay + self.ncb), dtype=np.int) kon = 0 if len(self.laycbd) > 0: for k in range(self.mg.nlay): if self.laycbd[k] > 0: kon += 1 self.active[kon] = 0 kon += 1 top = self.mg.top botm = self.mg.botm elev = [top.copy()] for k in range(self.mg.nlay + self.ncb): elev.append(botm[k, :, :]) self.elev = np.array(elev) self.layer0 = 0 self.layer1 = self.mg.nlay + self.ncb + 1 zpts = [] for k in range(self.layer0, self.layer1): zpts.append(plotutil.cell_value_points(self.xpts, self.mg.xyedges[0], self.mg.xyedges[1], self.elev[k, :, :])) self.zpts = np.array(zpts) xcentergrid = [] zcentergrid = [] nz = 0 if self.mg.nlay == 1: for k in range(0, self.zpts.shape[0]): nz += 1 nx = 0 for i in range(0, self.xpts.shape[0], 2): try: xp = 0.5 * (self.xpts[i][2] + self.xpts[i + 1][2]) zp = self.zpts[k, i] xcentergrid.append(xp) zcentergrid.append(zp) nx += 1 except: break else: for k in range(0, self.zpts.shape[0] - 1): nz += 1 nx = 0 for i in range(0, self.xpts.shape[0], 2): try: xp = 0.5 * (self.xpts[i][2] + self.xpts[i + 1][2]) zp = 0.5 * (self.zpts[k, i] + self.zpts[k + 1, i + 1]) xcentergrid.append(xp) zcentergrid.append(zp) nx += 1 except: break self.xcentergrid = np.array(xcentergrid).reshape((nz, nx)) self.zcentergrid = np.array(zcentergrid).reshape((nz, nx)) # Create cross-section extent if extent is None: self.extent = self.get_extent() else: self.extent = extent # Set axis limits self.ax.set_xlim(self.extent[0], self.extent[1]) self.ax.set_ylim(self.extent[2], self.extent[3]) return