### Build and Install LoopStructural Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Run the makefile to install the project. ```bash make all ``` -------------------------------- ### Setup development environment with Conda Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/getting_started/contributors_guide.rst Commands to activate the environment and install project dependencies. ```bash conda activate pip install -r requirements.txt conda list ``` -------------------------------- ### Install LoopStructural via Pip Source: https://github.com/loop3d/loopstructural/blob/master/README.md Standard installation command for the library. ```bash pip install loopstructural ``` -------------------------------- ### Install LoopStructural with Visualization Environment Source: https://github.com/loop3d/loopstructural/blob/master/README.md Installs the library and the necessary dependencies for 3D visualization. ```bash conda install -c conda-forge -c loop3d loopstructural loopstructuralvisualisation pyvista trame trame-vtk trame-vuetify ``` -------------------------------- ### Install Python dependencies and build library Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/ubuntu_install.rst Command executed by 'make all' to install requirements and build the extension modules. ```bash pip3 install -r requirements.txt && python3 setup.py install build_ext --inplace ``` -------------------------------- ### Install LoopStructural with Optional Dependencies Source: https://github.com/loop3d/loopstructural/blob/master/README.md Installs the library along with all optional dependencies. ```bash pip install loopstructural[all] ``` -------------------------------- ### Install system dependencies Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/ubuntu_install.rst Commands to install required system-level packages for LoopStructural on Ubuntu and Fedora. ```bash sudo apt-get install python3 python3-dev python3-venv pybind11-dev mesa-common-dev mesa-utils libgl1-mesa-dev gcc g++ ``` ```bash sudo dnf install python3 python3-devel pybind11-devel mesa-libGL-devel gcc g++ ``` -------------------------------- ### Build documentation locally Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/getting_started/contributors_guide.rst Commands to install documentation dependencies and generate HTML files. ```bash pip install -r docs/requirements.txt make -C ./docs html ``` -------------------------------- ### Install LoopStructural with Pip Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/getting_started/installation.rst Install the base package or with all optional dependencies using pip. ```bash pip install LoopStructural ``` ```bash pip install LoopStructural[all] ``` -------------------------------- ### Install LoopStructural Dependencies Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Install required system packages for building LoopStructural. ```bash sudo apt-get update && sudo apt-get install python3 python3-venv python3-dev make pybind11-dev mesa-common-dev mesa-utils libgl1-mesa-dev gcc g++ ``` -------------------------------- ### Define Repository Path Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Example path for cloning the LoopStructural repository on Windows. ```text C:/Users/{username}/Documents/Repositories/LoopStructural ``` -------------------------------- ### Start Jupyter Notebook Server (No Browser) Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Start a Jupyter notebook server without automatically opening a browser window. You will need to manually navigate to the specified port. ```bash jupyter-notebook --no-browser ``` -------------------------------- ### Benchmark LoopStructural Solver Performance Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/interpolation_options.rst Example of creating a foliation, updating the builder, and recording solver performance metrics. ```python strati = model.create_and_add_foliation('strati',nelements=nel,solver=solver,interpolatortype='FDI') strati.builder.update() results[solver]['time'].append(time.time()-start) results[solver]['nx'].append(strati.interpolator.nx) results[solver]['nel'].append(nel) # optional save out the solution # np.save('scalar_field/{}_{}.npy'.format(solver,nel),strati.interpolator.c) ``` -------------------------------- ### Run Jupyter Notebook Server Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Execute this command from the LoopStructural folder to start a Jupyter notebook server. Navigate to the provided URL in your browser to access the notebooks. ```bash make notebook ``` -------------------------------- ### Upgrade LoopStructural Installation Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Follow these steps to upgrade your LoopStructural installation. This involves changing to the LoopStructural directory, uninstalling the current version, and rebuilding the package. ```bash cd LoopStructural pip uninstall LoopStructural make build ``` -------------------------------- ### Install LoopStructural with Conda Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/getting_started/installation.rst Install LoopStructural using the conda package manager from conda-forge. ```bash conda install -c conda-forge -c loop3d loopstructural ``` -------------------------------- ### Compile LoopStructural from Source Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/getting_started/installation.rst Clone the repository and install LoopStructural as an editable package. ```bash git clone https://github.com/Loop3D/LoopStructural.git cd LoopStructural pip install -e . ``` -------------------------------- ### Benchmarking Solvers with Claudius Dataset Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/interpolation_options.rst This example benchmarks the performance of different solvers on the Claudius dataset with varying mesh element counts. ```python from LoopStructural import GeologicalModel from LoopStructural.datasets import load_claudius import time data, bb = load_claudius() # load data model = GeologicalModel(bb[0,:],bb[1,:]) model.set_model_data(data) strati = model.create_and_add_foliation('strati',nelements=1e5,solver='pyamg',interpolatortype='FDI') results= {} for solver in ['pyamg','chol','cg','lu','lsqr']: results[solver] = {'nx':[],'nel':[],'time':[],'c':[]} for nel in np.arange(1e3,1e5,5e3): start = time.time() ``` -------------------------------- ### Install LoopStructural via pip Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/windows_install.rst Use this command to install the precompiled version of LoopStructural into an active Python virtual environment. ```bash pip install LoopStructural ``` -------------------------------- ### Run LoopStructural Docker Container Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/docker.rst Starts a Jupyter notebook server within the LoopStructural Docker container, accessible at localhost:8888. Changes to notebooks within the container will not be saved to local versions. ```console run -i -t -p 8888:8888 loop ``` -------------------------------- ### Install Linux dependencies for LavaVu Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/getting_started/contributors_guide.rst System-level packages required for the LavaVu library on Linux systems. ```bash sudo apt install build-essential libgl1-mesa-dev libx11-dev zlib1g-dev ``` -------------------------------- ### Update and Upgrade Linux Packages Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Update the package manager and upgrade installed packages in the Linux terminal. ```bash sudo apt-get update && sudo apt-get upgrade ``` -------------------------------- ### Add points and arrows to a Loop3DView Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/what_is_a_geological_model.rst This snippet demonstrates how to add points and arrows to a Loop3DView for visualizing geological data. Ensure LoopStructural and its dependencies are installed. ```python import numpy as np import pandas as pd from LoopStructural.visualisation import Loop3DView x = np.linspace(0, 1, 10) y = np.zeros(10) z = np.ones(10) v = np.zeros(10) data = pd.DataFrame({"X": x, "Y": y, "Z": z, "val": v}) vector = pd.DataFrame( [[0.5, 0, 1.0, 0, 1, 0]], columns=["X", "Y", "Z", "nx", "ny", "nz"] ) view = Loop3DView() view.add_points(data[["X", "Y", "Z"]].values) view.add_arrows( vector[["X", "Y", "Z"]].values, vector[["nx", "ny", "nz"]].values, ) view.show() ``` -------------------------------- ### Create a Basic Geological Model Source: https://github.com/loop3d/loopstructural/blob/master/README.md Demonstrates initializing a model, adding a foliation feature, and evaluating the scalar field and gradient. ```Python from LoopStructural import GeologicalModel from LoopStructural.datatypes import BoundingBox from LoopStructural.visualisation import Loop3DView from LoopStructural.datasets import load_claudius import numpy as np data, bb = load_claudius() #bb constaints origin and maximum of axis aligned bounding box #data is a pandas dataframe with X,Y,Z,val,nx,ny,nz, feature_name model = GeologicalModel(bb[0,:],bb[1,:]) model.data = data # nelements specifies the number of discrete interpolation elements # 'stratí' is the feature name in the data dataframe model.create_and_add_foliation('strati',nelements=1e5) model.update() # get the value of the interpolator at some random locations locations = np.array( [ np.random.uniform(bb[0, 0], bb[1, 0],5), np.random.uniform(bb[0, 1], bb[1, 1],5), np.random.uniform(bb[0, 2], bb[1, 2],5), ] ).T val = model.evaluate_feature_value('strati', locations) # get the gradient of the interpolator gradient = model.evaluate_feature_gradient('strati',locations) #Plot the scalar field of the model model['strati'].scalar_field().plot() ``` -------------------------------- ### Navigate to Home Directory Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Change the current directory to the user home folder. ```bash cd ~ ``` -------------------------------- ### Create Foliation with Different Solvers Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/interpolation_options.rst Demonstrates how to create a foliation using different solver options available in LoopStructural. ```python model.create_and_add_foliation('my_foliation',solver='lu') ``` ```python model.create_and_add_foliation('my_foliation',solver='chol') ``` ```python model.create_and_add_foliation('my_foliation',solver='cg') ``` ```python model.create_and_add_foliation('my_foliation',solver='lsqr') ``` ```python model.create_and_add_foliation('my_foliation',solver='pyamg') ``` -------------------------------- ### Navigate to Repository Directory Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Change the current directory to the location of the cloned repository in WSL. ```bash cd /mnt/c/Users/{username}/Documents/Repositories/LoopStructural ``` -------------------------------- ### Assemble Interpolators with InterpolatorBuilder Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/index.rst Shows how to manually assemble an interpolator using value and gradient constraints, then evaluate it on a structured grid. ```python from LoopStructural import BoundingBox, InterpolatorBuilder from LoopStructural.utils import EuclideanTransformation from LoopStructural.datasets import load_claudius # load in a dataframe with x,y,z,val,nx,ny,nz to constrain the value and # gradient normal of the interpolator data, bb = load_claudius() # Find the bounding box of the data by finding the extent bounding_box = BoundingBox().fit(data[["X", "Y", "Z"]]) # assemble an interpolator using the bounding box and the data interpolator = ( InterpolatorBuilder( interpolatortype="FDI", bounding_box=bounding_box.with_buffer(0.1) ) .add_value_constraints(data.loc[data["val"].notna(), ["X", "Y", "Z", "val"]].values) .add_normal_constraints( data.loc[data["nx"].notna(), ["X", "Y", "Z", "nx", "ny", "nz"]].values ) .build() ) # Set the number of elements in the bounding box to 10000 and create a structured grid bounding_box.nelements = 10000 mesh = bounding_box.structured_grid() # add the interpolated values to the mesh at the nodes mesh.properties["v"] = interpolator.evaluate_value(mesh.nodes) # or the cell centres # mesh.cell_properties["v"] = interpolator.evaluate_value(mesh.cell_centres) # visualise the scalar value mesh.plot() # We can also add gradient properties and visualise these mesh.properties["grad"] = interpolator.evaluate_gradient(mesh.nodes) mesh.vtk().glyph(orient="grad").plot() ``` -------------------------------- ### Initialize a GeologicalModel Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/geological_model.rst Create a new model instance by defining the origin and maximum coordinates. ```python model = GeologicalModel(origin,maximum) ``` -------------------------------- ### Build LoopStructural Docker Image Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/docker.rst Builds the Docker image for LoopStructural. Ensure you are in the root directory of the cloned repository. ```console docker build -t=loop . ``` -------------------------------- ### Create Symbolic Link Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Create a symbolic link to the repository in the home directory for easier access. ```bash ln -s /mnt/c/Users/{username}/Documents/Repository/LoopStructural LoopStructural ``` -------------------------------- ### Configure Environment Variables and Aliases Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Add these lines to the end of your .bashrc file to set the environment path and create a shortcut command. ```bash export LOOP_ENV=/mnt/c/Users/{username}/Documents/Repository/LoopStructural/venv alias LoopStructural='. $LOOP_ENV/bin/activate' ``` -------------------------------- ### Create Python Virtual Environment Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Create a virtual environment named venv within the current directory. ```bash python3 -m venv venv ``` -------------------------------- ### Run Ruff linting Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/getting_started/contributors_guide.rst Execute the Ruff linter on the LoopStructural package directory. ```bash ruff LoopStructural ``` -------------------------------- ### Navigate to LoopStructural Directory Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Change the current directory into the LoopStructural folder. ```bash cd LoopStructural ``` -------------------------------- ### Documenting functions with NumPy docstrings Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/getting_started/contributors_guide.rst Use this template to document functions, ensuring all parameters and return values are clearly defined. ```python def new_function(a, b, c=None,d=None): """[summary] [extended_summary] Parameters ---------- a : [type] [description] b : [type] [description] c : [type], optional [description], by default None d : [type], optional [description], by default None Returns ------- results : [type] [description] """ ``` -------------------------------- ### Using an External Custom Solver Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/interpolation_options.rst Shows how to integrate a custom solver function using the 'external' keyword in LoopStructural. ```python def mysolver(A,B): from scipy.sparse.linalg import gmres x = gmres(A,B) return x[0] model.create_and_add_foliation('my_foliation',solver='external',external=mysolver) ``` -------------------------------- ### Activate LoopStructural Environment Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Before running a Jupyter notebook server from another directory, activate the LoopStructural Python environment using this command. ```bash LoopStructural ``` -------------------------------- ### Enable Windows Subsystem for Linux Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Run this command in PowerShell as Administrator to enable the WSL feature. ```PowerShell Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux ``` -------------------------------- ### Edit Bash Configuration Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Open the .bashrc file using the nano text editor. ```bash nano ~/.bashrc ``` -------------------------------- ### Run LoopStructural Docker with Local Data Volume Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/docker.rst Runs the LoopStructural Docker container and mounts a local directory (LOCALDIRPATH) to the container's shared volume at /home/jovyan/shared_volume. This allows the container to access your local data. ```console docker run -i -t -p 8888:8888 -v LOCALDIRPATH:/home/jovyan/shared_volume loop ``` -------------------------------- ### Accessing Solver Solution Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/interpolation_options.rst Illustrates how to access the solution vector computed by the solver from the interpolator object. ```python model.create_and_add_foliation('my_foliation',solver='pyamg') pyamg_solution = model['my_foliation'].interpolator.c[model['my_foliation'].interpolator.region] ``` -------------------------------- ### Makefile Execution Commands Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst The sequence of commands executed by the make all target. ```bash . ${LOOP_ENV}/bin/activate && pip3 install -r requirements.txt && python3 setup.py install build_ext --inplace; ``` -------------------------------- ### Retrieve a regular grid Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/geological_model.rst Generates a regular grid within the model bounding box. The rescale parameter toggles between model and real-world coordinates. ```python regular_grid = model.regular_grid(nsteps=(50,50,25),shuffle=True,rescale=False) ``` -------------------------------- ### Build an interpolator with value and normal constraints Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/what_is_a_geological_model.rst This snippet shows how to build an interpolator using InterpolatorBuilder with FDI type, fitting value and normal constraints within a specified bounding box. The interpolator is then used to evaluate a scalar field on a structured grid. ```python import numpy as np import pandas as pd from LoopStructural import InterpolatorBuilder, BoundingBox from LoopStructural.visualisation import Loop3DView bounding_box = BoundingBox(np.array([-2, -2, -2]), np.array([2, 2, 2])) interpolator = ( InterpolatorBuilder( interpolatortype="FDI", nelements=1e4, bounding_box=bounding_box ).add_value_constraints(data.values) .add_normal_constraints(vector.values).setup_interpolator() .build() ) mesh = bounding_box.structured_grid() mesh.properties['val'] = interpolator.evaluate_value(mesh.nodes) view = Loop3DView() view.add_mesh(mesh.vtk()) view.show() ``` -------------------------------- ### Configure LOOP_ENV environment variable Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/ubuntu_install.rst Add this export command to your .bashrc file to define the path for the virtual environment. ```bash export LOOP_ENV=$YOUR_PATH_TO_VIRTUAL_ENVIRONMENT ``` -------------------------------- ### Visualize Isosurface in LoopStructural Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/debugging.rst Adds an isosurface to the current view and triggers the interactive visualization window. ```python view.add_isosurface(model['fault'][0],0) view.interactive() ``` -------------------------------- ### Configure SurfE Interpolator Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/interpolation_options.rst Set the interpolator type to 'surfe' to utilize the SurfE library for geological feature interpolation. ```python interpolatortype = 'surfe' ``` -------------------------------- ### Visualise Geological Model Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/visualisation.rst Methods for automatically visualising stratigraphic units and fault surfaces. ```python view.plot_block_model() ``` ```python view.plot_model_surfaces(faults=True,strati=True) ``` -------------------------------- ### Conventional commit message format Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/getting_started/contributors_guide.rst Standard structure for commit messages used to generate the project changelog. ```text [optional scope]: [optional body] [optional footer(s)] ``` -------------------------------- ### Configure Model Bounding Box Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/visualisation.rst Adjust the resolution of scalar fields or isosurfacing by modifying the bounding box steps or element count. ```python model.bounding_box.nsteps = np.array([nx,ny,nz]) print(model.bounding_box.nsteps) model.bounding_box.nelements = 1e6 print(model.bounding_box.nsteps) ``` -------------------------------- ### Visualize Fault Displacement Vectors Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/debugging.rst Add vector fields to visualize fault displacement direction and magnitude. This is useful for debugging issues with the fault displacement vector. ```python view = LavaVuModelViewer(model) view.add_vector_field(model['fault'][1],locations=model.regular_grid()[::200]) #random 200 locations ``` -------------------------------- ### Extract GeologicalFeatures Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/geological_model.rst Demonstrates various methods to access a GeologicalFeature from the model, including by name, index, or helper methods. ```python myfeature = model.create_and_add_feature('myfeature') myfeature_also = model['myfeature'] myfeature_by_index = model.features[0] myfeature_by_name = model.get_feature_by_name('myfeature') ``` -------------------------------- ### Add Points and Arrows to View Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/what_is_a_geological_model.rst Adds points and arrows to the visualization, then removes the scalar bar and sets the view to YZ. ```python view.add_points(data[["X", "Y", "Z"]].values) view.add_arrows( vector[["X", "Y", "Z"]].values, vector[["nx", "ny", "nz"]].values, ) view.remove_scalar_bar() view.view_yz() view.show() ``` -------------------------------- ### Interpolator with Value Constraints Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/what_is_a_geological_model.rst Builds an interpolator using value constraints from pandas DataFrame. Requires LoopStructural and pandas libraries. ```python import numpy as np import pandas as pd from LoopStructural import InterpolatorBuilder, BoundingBox from LoopStructural.visualisation import Loop3DView x = np.linspace(0, 1, 10) y = np.zeros(10) z = np.ones(10) v = np.zeros(10) data = pd.concat( [ pd.DataFrame({"X": x, "Y": y, "Z": z, "val": v}), pd.DataFrame({"X": x, "Y": y + 0.5, "Z": z, "val": v + 0.5}), ] ) bounding_box = BoundingBox(np.array([-2, -2, -2]), np.array([2, 2, 2])) interpolator = ( InterpolatorBuilder( interpolatortype="FDI", nelements=1e4, bounding_box=bounding_box ) .add_value_constraints(data.values) .setup_interpolator() .build() ) mesh = bounding_box.structured_grid() mesh.properties["val"] = interpolator.evaluate_value(mesh.nodes) view = Loop3DView() view.add_mesh(mesh.vtk().contour([0, 0.5]), opacity=0.4) view.remove_scalar_bar() view.add_points(data[["X", "Y", "Z"]].values, scalars=data["val"].values) view.remove_scalar_bar() view.view_yz() view.show() ``` -------------------------------- ### Access Jupyter Notebook Server Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_static/wls_install.rst Once the Jupyter notebook server is running, access it through your web browser using this address. ```text localhost:8888 ``` -------------------------------- ### Visualise Input Data Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/visualisation.rst Methods for adding geological feature data, points, or vectors to the viewer. ```python view.plot_data(geological_feature,value=True,vector=True,scale=10,pyvista_kwargs={}) ``` ```python view.add_points(xyz) ``` ```python view.add_points(xyz,scalars=np.array(values)) ``` ```python view.add_arrows(xyz,direction) ``` -------------------------------- ### List Faults in a Feature Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/debugging.rst Print the names of faults associated with a faulted feature to verify that the correct faults have been added or are being considered in the model. ```python print([f.name for f in faulted_feature.faults]) ``` -------------------------------- ### Add a fault Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/geological_model.rst Incorporate a fault into the model by specifying the feature name and displacement. ```python model.create_and_add_fault(feature_name, displacement) ``` -------------------------------- ### Pytest Fixture for Interpolator Generation Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/getting_started/loopstructural_design.rst This pytest fixture generates different discrete interpolators (FiniteDifferenceInterpolator and PiecewiseLinearInterpolator) with specified grid parameters. It is used to test interpolator functionality. ```python from LoopStructural.interpolators import FiniteDifferenceInterpolator as FDI, PiecewiseLinearInterpolator as PLI from LoopStructural.interpolators import StructuredGrid, TetMesh import pytest import numpy as np @pytest.fixture(params=['FDI','PLI']) def interpolator(request): interpolator = request.param origin = np.array([-0.1,-0.1,-0.1]) maximum = np.array([1.1,1.1,1.1]) nsteps = np.array([20,20,20]) step_vector = (maximum-origin)/nsteps if interpolator == 'FDI': grid = StructuredGrid(origin=origin,nsteps=nsteps,step_vector=step_vector) interpolator = FDI(grid) return interpolator elif interpolator == 'PLI': grid = TetMesh(origin=origin,nsteps=nsteps,step_vector=step_vector) interpolator = PLI(grid) return interpolator else: raise ValueError(f'Invalid interpolator: {interpolator}') ``` -------------------------------- ### Initialize Toggle Functionality Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/_templates/page.html Initializes jQuery toggle behavior for elements with the toggle class. Requires jQuery to be loaded in the environment. ```javascript $(document).ready(function() { $(".toggle > *").hide(); $(".toggle .header").show(); $(".toggle .header").click(function() { $(this).parent().children().not(".header").toggle(400); $(this).parent().children(".header").toggleClass("open"); }) }); ``` -------------------------------- ### Visualize Fault Displacement Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/debugging.rst Add scalar fields for faults to visualize their interpolated geometry and check for correct values. This helps in debugging issues with fault frame interpolation. ```python view.add_scalar_field(fault[0]) view.add_scalar_field(fault[1]) view.add_scalar_field(fault[2]) ``` -------------------------------- ### Compare scalar fields with different gradient norms Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/what_is_a_geological_model.rst This snippet compares two scalar fields generated with different gradient norms (vector scaled by 1 and 2). It visualizes the isovalues (-1, 0, 1) for both fields, colored red and blue respectively, to show the effect of gradient norm on the distance between surfaces. ```python vector["nx", "ny", "nz"] = vector["nx", "ny", "nz"]*2 bounding_box = BoundingBox(np.array([-2, -2, -2]), np.array([2, 2, 2])) interpolator = ( InterpolatorBuilder( interpolatortype="FDI", nelements=1e4, bounding_box=bounding_box ).add_value_constraints(data.values) .add_normal_constraints(vector.values).setup_interpolator() .build() ) mesh2 = bounding_box.structured_grid() mesh2.properties['val'] = interpolator.evaluate_value(mesh2.nodes) view = Loop3DView() view.add_mesh(mesh2.vtk().contour([-1, 0, 1]),color='red') view.add_mesh(mesh.vtk().contour([-1, 0, 1]),color='blue') ``` -------------------------------- ### Add a fault to a geological model Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/fault_modelling.rst Use this method to integrate a fault into the model by specifying displacement and optional geometric parameters. ```python model.create_and_add_fault(feature_name, displacement, fault_slip_vector=None, fault_center = None, fault_major_axis = None, fault_minor_axis = None, fault_intermediate_axis = None, faultfunction = None, **kwargs ) ``` -------------------------------- ### Update the geological model Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/geological_model.rst Solves the implicit function for all features in the model. The verbose flag provides debugging information such as degrees of freedom and solve time. ```python model.update(verbose=False) ``` -------------------------------- ### Visualize fault geometry with an isosurface Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/what_is_a_geological_model.rst This snippet visualizes the geometry of a fault by extracting an isosurface at value 0 from the scalar field generated by the interpolator. It also adds the original data points and normal vectors for reference. ```python view = Loop3DView() view.add_mesh(mesh.vtk().contour([0])) view.add_points(data[["X", "Y", "Z"]].values) view.add_arrows( vector[["X", "Y", "Z"]].values, vector[["nx", "ny", "nz"]].values, ) view.show() ``` -------------------------------- ### Visualise Geological Features Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/visualisation.rst Methods for plotting scalar fields, surfaces, vector fields, and cross-sections of geological features. ```python view.plot_scalar_field(geological_feature) ``` ```python view.plot_surface(geological_feature,value=0) ``` ```python view.plot_surface(geological_feature) ``` ```python view.add_section(geological_feature,axis='x',value=0) ``` -------------------------------- ### Evaluate fault displacement magnitude Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/geological_model.rst Evaluates the fault function for every fault in the model at the provided pointset. ```python regular_grid = model.regular_grid(shuffle=False,rescale=False) fault_displacement = model.evaluate_fault_displacements('myfeature',regular_grid,scale=False) ``` -------------------------------- ### Set model data Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/geological_model.rst Assign a pandas DataFrame containing geological data to the model. ```python model.set_model_data(data) ``` -------------------------------- ### Visualize Data Polarity Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/debugging.rst Plot data points with vectors to check their polarity, which is crucial for fold modeling in LoopStructural. Incorrect polarity can lead to erroneous fold geometry. ```python view.add_data(folded_foliation,vectors=True) ``` -------------------------------- ### Custom Visualisation with LambdaGeologicalFeature Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/visualisation.rst Define custom geological features using functions to represent values or vector fields at specific locations. ```python from LoopStructural.modelling.features import LambdaGeologicalFeature def x_function(xyz): return xyz[:,0] custom_feature = LambdaGeologicalFeature(x_function,name='x feature') view.plot_surface(custom_feature,value) view.plot_scalar_field(custom_feature) ``` -------------------------------- ### Add a foliation Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/geological_model.rst Create and add a foliation feature to the model using the specified feature name and interpolation parameters. ```python model.create_and_add_foliation(feature_name, interpolatortype = 'PLI', nelements = 1e5, buffer = 0.2, solver = 'cg', damp = True) ``` -------------------------------- ### Visualize isovalues of a scalar field Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/what_is_a_geological_model.rst This snippet visualizes multiple isovalues (-1, 0, 1) of the scalar field to show the distance between surfaces. It also adds data points and normal vectors, and then rotates the view to the YZ plane. ```python view = Loop3DView() view.add_mesh(mesh.vtk().contour([-1, 0, 1])) view.remove_scalar_bar() view.add_points(data[["X", "Y", "Z"]].values) view.add_arrows( vector[["X", "Y", "Z"]].values, vector[["nx", "ny", "nz"]].values, ) view.remove_scalar_bar() view.view_yz() view.show() ``` -------------------------------- ### Add an unconformity Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/geological_model.rst Add an unconformity to the model, either as a new feature or by using an existing geological feature. ```python model.create_and_add_unconformity(feature_name) ``` ```python model.add_unconformity(feature, value) ``` ```python model.add_onlap_unconformity(feature, value) ``` -------------------------------- ### Evaluate lithology ID Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/geological_model.rst Evaluates the model to retrieve the lithology ID based on the defined stratigraphic column. ```python regular_grid = model.regular_grid(shuffle=False,rescale=False) litho = model.evaluate_model('myfeature',regular_grid,scale=False) ``` -------------------------------- ### Test GeologicalInterpolator Subclass Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/getting_started/loopstructural_design.rst This test function verifies that the interpolators generated by the 'interpolator' fixture are indeed subclasses of GeologicalInterpolator. It ensures that the core interpolator interface is correctly implemented. ```python from LoopStructural.interpolators import GeologicalInterpolator def test_interpolator(interpolator): """Test whether the discrete interpolators are a subclass of GeologicalInterpolator """ assert isinstance(interpolator, GeologicalInterpolator) ``` -------------------------------- ### Define a stratigraphic column Source: https://github.com/loop3d/loopstructural/blob/master/docs/source/user_guide/geological_model.rst Defines the stratigraphic structure as a dictionary and applies it to the model. The first entry name is checked for 'fault' to determine if it should be excluded from stratigraphic evaluation. ```python stratrigraphic column = {'group': #must be the GeologicalFeature name {'series1': # name that will appear on legend {'min':0., 'max':10.,'id':0,'colour':} } } model.set_stratigraphic_column(stratigraphic_column) ```