예제 #1
0
    def add_fault_displacements(self, cmap='rainbow', **kwargs):
        """Add a block model painted by the fault displacement magnitude

        Calls fault.displacementfeature.evaluate_value(points) for all faults

        Parameters
        ----------
        cmap : matplotlib cmap, optional
            colourmap name or object from mpl

        Notes
        ------
        It is sensible to increase the viewer step sizes before running this function to
        increase the resolution of the model as its not possible to interpolate a discrete
        colourmap and this causes the model to look like a lego block.
        You can update the model resolution by changing the attribute nsteps
        >>> viewer.nsteps = np.array([100,100,100])

        """

        name = kwargs.get('name', 'fault_displacements')
        points, tri = create_box(self.bounding_box, self.nsteps)

        surf = self.lv.triangles(name)
        surf.vertices(self.model.rescale(points))
        surf.indices(tri)
        vals = self.model.evaluate_fault_displacements(points)
        surf.values(vals, 'displacement')
        surf["colourby"] = 'displacement'

        vmin = kwargs.get('vmin', np.nanmin(vals))
        vmax = kwargs.get('vmax', np.nanmax(vals))
        surf.colourmap(cmap, range=(vmin, vmax))
예제 #2
0
    def add_scalar_field(self, geological_feature, **kwargs):
        """

        Parameters
        ----------
        geological_feature : GeologicalFeature
            the geological feature to colour the scalar field by
        kwargs
            kwargs for lavavu

        Returns
        -------

        """
        name = kwargs.get('name', geological_feature.name + '_scalar_field')
        points, tri = create_box(self.bounding_box, self.nsteps)

        surf = self.lv.triangles(name)
        surf.vertices(self.model.rescale(points))
        surf.indices(tri)
        val = geological_feature.evaluate_value(self.model.scale(points))
        surf.values(val, geological_feature.name)
        surf["colourby"] = geological_feature.name
        cmap = kwargs.get('cmap', lavavu.cubehelix(100))

        logger.info("Adding scalar field of %s to viewer. Min: %f, max: %f" %
                    (geological_feature.name, geological_feature.min(),
                     geological_feature.max()))
        vmin = kwargs.get('vmin', np.nanmin(val))
        vmax = kwargs.get('vmax', np.nanmax(val))
        surf.colourmap(cmap, range=(vmin, vmax))
예제 #3
0
    def add_model(self, cmap=None, **kwargs):
        """Add a block model painted by stratigraphic id to the viewer

        Calls self.model.evaluate_model() for a cube surrounding the model.

        Parameters
        ----------
        cmap : matplotlib cmap, optional
            colourmap name or object from mpl

        Notes
        ------
        It is sensible to increase the viewer step sizes before running this function to
        increase the resolution of the model as its not possible to interpolate a discrete
        colourmap and this causes the model to look like a lego block.
        You can update the model resolution by changing the attribute nsteps
        >>> viewer.nsteps = np.array([100,100,100])

        """
        import matplotlib.colors as colors
        from matplotlib import cm

        name = kwargs.get('name', 'geological_model')
        points, tri = create_box(self.bounding_box, self.nsteps)

        surf = self.lv.triangles(name)
        surf.vertices(self.model.rescale(points))
        surf.indices(tri)
        val = self.model.evaluate_model(points, scale=True)
        surf.values(val, 'model')
        surf["colourby"] = 'model'

        if cmap is None:
            import matplotlib.colors as colors
            colours = []
            boundaries = []
            data = []
            for g in self.model.stratigraphic_column.keys():
                if g == 'faults':
                    continue
                for u, v in self.model.stratigraphic_column[g].items():
                    data.append((v['id'], v['colour']))
                    colours.append(v['colour'])
                    boundaries.append(v['id'])  #print(u,v)
            cmap = colors.ListedColormap(colours).colors
        # else:
        # cmap = cm.get_cmap(cmap,n_units)

        # logger.info("Adding scalar field of %s to viewer. Min: %f, max: %f" % (geological_feature.name,
        #                                                                        geological_feature.min(),
        #                                                                        geological_feature.max()))
        vmin = kwargs.get('vmin', np.nanmin(val))
        vmax = kwargs.get('vmax', np.nanmax(val))
        surf.colourmap(cmap, range=(vmin, vmax))
예제 #4
0
    def add_scalar_field(self,
                         geological_feature,
                         name=None,
                         cmap='rainbow',
                         vmin=None,
                         vmax=None,
                         **kwargs):
        """Add a block the size of the model area painted with the scalar field value

        Parameters
        ----------
        geological_feature : GeologicalFeature
            the geological feature to colour the scalar field by
        name : string, optional
            Name of the object for lavavu, needs to be unique for the viewer object, by default uses feature name
        cmap : str, optional
            mpl colourmap reference, by default 'rainbow'
        vmin : double, optional
            minimum value of the colourmap, by default None
        vmax : double, optional
            maximum value of the colourmap, by default None
        """
        if name == None:
            if geological_feature is None:
                name = 'unnamed scalar field'
            else:
                name = geological_feature.name + '_scalar_field'

        points, tri = create_box(self.bounding_box, self.nsteps)

        surf = self.lv.triangles(name)
        surf.vertices(self.model.rescale(points))
        surf.indices(tri)
        val = geological_feature.evaluate_value(self.model.scale(points))
        surf.values(val, geological_feature.name)
        surf["colourby"] = geological_feature.name
        logger.info("Adding scalar field of %s to viewer. Min: %f, max: %f" %
                    (geological_feature.name, geological_feature.min(),
                     geological_feature.max()))
        if vmin == None:
            vmin = np.nanmin(val)
        if vmax == None:
            vmax = np.nanmax(val)
        surf.colourmap(cmap, range=(vmin, vmax))
예제 #5
0
    def add_support_box(self, geological_feature, paint=False, **kwargs):
        name = kwargs.get('name', geological_feature.name + '_support')
        box = np.vstack([
            geological_feature.interpolator.support.origin,
            geological_feature.interpolator.support.maximum
        ])
        points, tri = create_box(box, self.nsteps)

        surf = self.lv.triangles(name)
        surf.vertices(self.model.rescale(points))
        surf.indices(tri)
        if paint:
            val = geological_feature.evaluate_value(self.model.scale(points))
            surf.values(val, geological_feature.name)
            surf["colourby"] = geological_feature.name
            cmap = kwargs.get('cmap', lavavu.cubehelix(100))

            logger.info(
                "Adding scalar field of %s to viewer. Min: %f, max: %f" %
                (geological_feature.name, geological_feature.min(),
                 geological_feature.max()))
            vmin = kwargs.get('vmin', np.nanmin(val))
            vmax = kwargs.get('vmax', np.nanmax(val))
            surf.colourmap(cmap, range=(vmin, vmax))
예제 #6
0
def _write_cubeface_evtk(model,
                         file_name,
                         data_label,
                         nsteps,
                         real_coords=True):
    """
    Writes out the model as a cuboid with six rectangular surfaces in VTK unstructured grid format

    Parameters
    ----------
    model : GeologicalModel object
        Geological model to export
    file_name : string
        Name of file that model is exported to, including path, but without the file extension
    data_label : string
        A data label to insert into export file
    nsteps : np.array([num-x-steps, num-y-steps, num-z-steps])
        3d array dimensions

    Returns
    -------
    True if successful

    """
    # Evaluate model at points
    points, tri = create_box(model.bounding_box, nsteps)
    val = model.evaluate_model(points, scale=False)
    if real_coords:
        model.rescale(points)

    # Define vertices
    x = np.zeros(points.shape[0])
    y = np.zeros(points.shape[0])
    z = np.zeros(points.shape[0])
    for i in range(points.shape[0]):
        x[i], y[i], z[i] = points[i][0], points[i][1], points[i][2]

    # Define connectivity or vertices that belongs to each element
    conn = np.zeros(tri.shape[0] * 3)
    for i in range(tri.shape[0]):
        conn[i * 3], conn[i * 3 + 1], conn[i * 3 +
                                           2] = tri[i][0], tri[i][1], tri[i][2]

    # Define offset of last vertex of each element
    offset = np.zeros(tri.shape[0])
    for i in range(tri.shape[0]):
        offset[i] = (i + 1) * 3

    # Define cell types
    ctype = np.full(tri.shape[0], VtkTriangle.tid)

    try:
        unstructuredGridToVTK(
            file_name,
            x,
            y,
            z,
            connectivity=conn,
            offsets=offset,
            cell_types=ctype,
            cellData=None,
            pointData={data_label: val},
        )
    except Exception as e:
        logger.warning(
            f"Cannot export cuboid surface to VTK file {file_name}: {e}")
        return False
    return True