def test_create_stratigraphy_PLI_pyamg(): data, bb = load_claudius() model = GeologicalModel(bb[0, :], bb[1, :]) model.set_model_data(data) s0 = model.create_and_add_foliation("s0", interpolatortype="PLI", nelements=1000, solver="pyamg", damp=True)
def test_remove_constraints_PLI(): data, bb = load_claudius() model = GeologicalModel(bb[0, :], bb[1, :]) model.set_model_data(data) s0 = model.create_and_add_foliation("s0", interpolatortype="FDI", nelements=1000, solver="cg", damp=False)
def test_create_stratigraphy_PLI_lu(): data, bb = load_claudius() model = GeologicalModel(bb[0, :], bb[1, :]) model.set_model_data(data) s0 = model.create_and_add_foliation('s0', interpolatortype='PLI', nelements=1000, solver='lu', damp=True)
def test_access_feature_model(): data, bb = load_claudius() model = GeologicalModel(bb[0, :], bb[1, :]) model.set_model_data(data) s0 = model.create_and_add_foliation("s0", interpolatortype="FDI", nelements=1000, solver="fake", damp=False) assert s0 == model["s0"]
def test_no_fold_frame(): mdata = pd.concat([data[:100], data[data['feature_name'] == 's1']]) model = GeologicalModel(boundary_points[0, :], boundary_points[1, :]) model.set_model_data(mdata) fold_frame = model.create_and_add_fold_frame('s1', nelements=10000) stratigraphy = model.create_and_add_folded_foliation( 's0', # fold_frame, nelements=10000, # av_fold_axis=True fold_axis=[-6.51626577e-06, -5.00013645e-01, -8.66017526e-01], limb_wl=1)
def test_average_fold_axis(): mdata = pd.concat([data[:100], data[data["feature_name"] == "s1"]]) model = GeologicalModel(boundary_points[0, :], boundary_points[1, :]) model.set_model_data(mdata) fold_frame = model.create_and_add_fold_frame("s1", nelements=10000) stratigraphy = model.create_and_add_folded_foliation( "s0", fold_frame, nelements=10000, av_fold_axis=True # fold_axis=[-6.51626577e-06, -5.00013645e-01, -8.66017526e-01], # limb_wl=1 )
def average_axis(): data, bb = load_laurent2016() model = GeologicalModel(bb[0, :], bb[1, :]) model.set_model_data(data) s2 = model.create_and_add_fold_frame("s2", nelements=10000) s1 = model.create_and_add_folded_fold_frame( "s1", limb_wl=0.4, av_fold_axis=True, nelements=50000 ) s0 = model.create_and_add_folded_fold_frame( "s0", limb_wl=1.0, av_fold_axis=True, nelements=50000 )
def build_model(m2l_data, evaluate=True, skip_faults=False, unconformities=False, fault_params=None, foliation_params=None, rescale=True, skip_features=[], **kwargs): """[summary] [extended_summary] Parameters ---------- m2l_data : dict [description] skip_faults : bool, optional [description], by default False fault_params : dict, optional [description], by default None foliation_params : dict, optional [description], by default None Returns ------- [type] [description] """ from LoopStructural import GeologicalModel boundary_points = np.zeros((2, 3)) boundary_points[0, 0] = m2l_data["bounding_box"]["minx"] boundary_points[0, 1] = m2l_data["bounding_box"]["miny"] boundary_points[0, 2] = m2l_data["bounding_box"]["lower"] boundary_points[1, 0] = m2l_data["bounding_box"]["maxx"] boundary_points[1, 1] = m2l_data["bounding_box"]["maxy"] boundary_points[1, 2] = m2l_data["bounding_box"]["upper"] model = GeologicalModel(boundary_points[0, :], boundary_points[1, :], rescale=rescale) # m2l_data['data']['val'] /= model.scale_factor model.set_model_data(m2l_data["data"]) if not skip_faults: faults = [] for f in m2l_data["max_displacement"].keys(): if model.data[model.data["feature_name"] == f].shape[0] == 0: continue if f in skip_features: continue fault_id = f overprints = [] try: overprint_id = m2l_data["fault_fault"][ m2l_data["fault_fault"][fault_id] == 1]["fault_id"].to_numpy() for i in overprint_id: overprints.append(i) logger.info("Adding fault overprints {}".format(f)) except: logger.info("No entry for %s in fault_fault_relations" % f) # continue fault_center = m2l_data["stratigraphic_column"]["faults"][f][ "FaultCenter"] fault_influence = m2l_data["stratigraphic_column"]["faults"][f][ "InfluenceDistance"] fault_extent = m2l_data["stratigraphic_column"]["faults"][f][ "HorizontalRadius"] fault_vertical_radius = m2l_data["stratigraphic_column"]["faults"][ f]["VerticalRadius"] fault_slip_vector = m2l_data["stratigraphic_column"]["faults"][f][ "FaultSlip"] faults.append( model.create_and_add_fault( f, -m2l_data["max_displacement"][f], faultfunction="BaseFault", fault_slip_vector=fault_slip_vector, fault_center=fault_center, fault_extent=fault_extent, fault_influence=fault_influence, fault_vectical_radius=fault_vertical_radius, # overprints=overprints, **fault_params, )) # for f in m2l_data['fault_intersection_angles']: # if f in m2l_data['max_displacement'].keys(): # f1_norm = m2l_data['stratigraphic_column']['faults'][f]['FaultNorm'] # for intersection in m2l_data['fault_intersection_angles'][f]: # if intersection[0] in m2l_data['max_displacement'].keys(): # f2_norm = m2l_data['stratigraphic_column']['faults'][intersection[0]]['FaultNorm'] # if intersection[2] < 30 and np.dot(f1_norm,f2_norm)>0: # logger.info('Adding splay {} to {}'.format(intersection[0],f)) # if model[f] is None: # logger.error('Fault {} does not exist, cannot be added as splay') # elif model[intersection[0]] is None: # logger.error('Fault {} does not exist') # else: # model[intersection[0]].builder.add_splay(model[f]) # else: # logger.info('Adding abut {} to {}'.format(intersection[0],f)) # model[intersection[0]].add_abutting_fault(model[f]) faults = m2l_data.get("fault_graph", None) if faults: for f in faults.nodes: f1_norm = m2l_data["stratigraphic_column"]["faults"][f][ "FaultNorm"] for e in faults.edges(f): data = faults.get_edge_data(*e) f2_norm = m2l_data["stratigraphic_column"]["faults"][ e[1]]["FaultNorm"] if float(data["angle"]) < 30 and np.dot(f1_norm, f2_norm) > 0: if model[f] is None or model[e[1]] is None: logger.error( "Fault {} does not exist, cannot be added as splay" ) elif model[e[1]] is None: logger.error("Fault {} does not exist") else: region = model[e[1]].builder.add_splay(model[f]) model[e[1]].splay[model[f].name] = region else: if model[f] is None or model[e[1]] is None: continue logger.info("Adding abut {} to {}".format(e[1], f)) model[e[1]].add_abutting_fault(model[f]) ## loop through all of the groups and add them to the model in youngest to oldest. group_features = [] for i in np.sort(m2l_data["groups"]["group number"].unique()): g = (m2l_data["groups"].loc[m2l_data["groups"]["group number"] == i, "group"].unique()[0]) group_features.append( model.create_and_add_foliation(g, **foliation_params)) # if the group was successfully added (not null) then lets add the base (0 to be unconformity) if group_features[-1] and unconformities: model.add_unconformity(group_features[-1], 0) model.set_stratigraphic_column(m2l_data["stratigraphic_column"]) if evaluate: model.update(verbose=True) return model
from LoopStructural import log_to_file import pandas as pd import numpy as np ################################################################################################## # Specify a log file # ~~~~~~~~~~~~~~~~~~~~ log_to_file('logging_demo_log.log') ################################################################################################## # Create model # ~~~~~~~~~~~~~~~~~~~~ data, bb = load_claudius() model = GeologicalModel(bb[0,:],bb[1,:]) model.set_model_data(data) vals = [0,60,250,330,600] strat_column = {'strati':{}} for i in range(len(vals)-1): strat_column['strati']['unit_{}'.format(i)] = {'min':vals[i],'max':vals[i+1],'id':i} model.set_stratigraphic_column(strat_column) strati = model.create_and_add_foliation("strati", interpolatortype="FDI", # try changing this to 'PLI' nelements=1e4, # try changing between 1e3 and 5e4 buffer=0.3, solver='pyamg', damp=True ) viewer = LavaVuModelViewer(model,background="white") viewer.add_model_surfaces()
def loop2LoopStructural(thickness_file,orientation_file,contacts_file,bbox): from LoopStructural import GeologicalModel from LoopStructural.visualisation import LavaVuModelViewer import lavavu df = pd.read_csv(thickness_file) thickness = {} for f in df['formation'].unique(): thickness[f] = np.mean(df[df['formation']==f]['thickness']) #display(thickness) order = ['P__TKa_xs_k','P__TKo_stq','P__TKk_sf','P__TK_s', 'A_HAu_xsl_ci', 'A_HAd_kd', 'A_HAm_cib', 'A_FOj_xs_b', 'A_FO_xo_a', 'A_FO_od', 'A_FOu_bbo', 'A_FOp_bs', 'A_FOo_bbo', 'A_FOh_xs_f', 'A_FOr_b'] strat_val = {} val = 0 for o in order: if o in thickness: strat_val[o] = val val+=thickness[o] #display(strat_val) orientations = pd.read_csv(orientation_file) contacts = pd.read_csv(contacts_file) contacts['val'] = np.nan for o in strat_val: contacts.loc[contacts['formation']==o,'val'] = strat_val[o] data = pd.concat([orientations,contacts],sort=False) data['type'] = np.nan for o in order: data.loc[data['formation']==o,'type'] = 's0' data boundary_points = np.zeros((2,3)) boundary_points[0,0] = bbox[0] boundary_points[0,1] = bbox[1] boundary_points[0,2] = -20000 boundary_points[1,0] = bbox[2] boundary_points[1,1] = bbox[3] boundary_points[1,2] = 1200 model = GeologicalModel(boundary_points[0,:],boundary_points[1,:]) model.set_model_data(data) strati = model.create_and_add_foliation('s0', #identifier in data frame interpolatortype="FDI", #which interpolator to use nelements=400000, # how many tetras/voxels buffer=0.1, # how much to extend nterpolation around box solver='external', external=solve_pyamg ) #viewer = LavaVuModelViewer() viewer = LavaVuModelViewer(model) viewer.add_data(strati['feature']) viewer.add_isosurface(strati['feature'], # nslices=10, slices= strat_val.values(), # voxet={'bounding_box':boundary_points,'nsteps':(100,100,50)}, paint_with=strati['feature'], cmap='tab20' ) #viewer.add_scalar_field(model.bounding_box,(100,100,100), # 'scalar', ## norm=True, # paint_with=strati['feature'], # cmap='tab20') viewer.add_scalar_field(strati['feature']) viewer.set_viewer_rotation([-53.8190803527832, -17.1993350982666, -2.1576387882232666]) #viewer.save("fdi_surfaces.png") viewer.interactive()
# Testing data density # ~~~~~~~~~~~~~~~~~~~~ # # - Use the toggle bar to change the amount of data used by the # interpolation algorithm. # - How does the shape of the fold change as we remove data points? # - Now what happens if we only consider data from the map view? # # **HINT** you can view the strike and dip data by unchecking the scalar # field box. # # **The black arrows are the normal vector to the folded surface** # npoints = 20 model = GeologicalModel(boundary_points[0,:],boundary_points[1,:]) model.set_model_data(data[:npoints]) stratigraphy = model.create_and_add_foliation("s0",interpolatortype="PLI",nelements=5000,buffer=0.3,cgw=0.1)#.2) viewer = LavaVuModelViewer(model,background="white") # viewer.add_scalar_field(model.bounding_box,(38,55,30), # 'box', # paint_with=stratigraphy, # cmap='prism') viewer.add_data(stratigraphy) viewer.add_isosurface(stratigraphy, ) viewer.rotate([-85.18760681152344, 42.93233871459961, 0.8641873002052307]) viewer.display() ###################################################################### # Modelling folds using structural geology
def build_model(m2l_data, skip_faults=False, unconformities=False, fault_params=None, foliation_params=None, rescale=True, **kwargs): """[summary] [extended_summary] Parameters ---------- m2l_data : dict [description] skip_faults : bool, optional [description], by default False fault_params : dict, optional [description], by default None foliation_params : dict, optional [description], by default None Returns ------- [type] [description] """ from LoopStructural import GeologicalModel boundary_points = np.zeros((2, 3)) boundary_points[0, 0] = m2l_data['bounding_box']['minx'] boundary_points[0, 1] = m2l_data['bounding_box']['miny'] boundary_points[0, 2] = m2l_data['bounding_box']['lower'] boundary_points[1, 0] = m2l_data['bounding_box']['maxx'] boundary_points[1, 1] = m2l_data['bounding_box']['maxy'] boundary_points[1, 2] = m2l_data['bounding_box']['upper'] model = GeologicalModel(boundary_points[0, :], boundary_points[1, :], rescale=rescale) # m2l_data['data']['val'] /= model.scale_factor model.set_model_data(m2l_data['data']) if not skip_faults: faults = [] for f in m2l_data['max_displacement'].keys(): if model.data[model.data['feature_name'] == f].shape[0] == 0: continue fault_id = f overprints = [] try: overprint_id = m2l_data['fault_fault'][ m2l_data['fault_fault'][fault_id] == 1]['fault_id'].to_numpy() for i in overprint_id: overprints.append(i) logger.info('Adding fault overprints {}'.format(f)) except: logger.info('No entry for %s in fault_fault_relations' % f) # continue faults.append( model.create_and_add_fault( f, -m2l_data['max_displacement'][f], faultfunction='BaseFault', overprints=overprints, **fault_params, )) ## loop through all of the groups and add them to the model in youngest to oldest. group_features = [] for i in np.sort(m2l_data['groups']['group number'].unique()): g = m2l_data['groups'].loc[m2l_data['groups']['group number'] == i, 'group'].unique()[0] group_features.append( model.create_and_add_foliation(g, **foliation_params)) # if the group was successfully added (not null) then lets add the base (0 to be unconformity) if group_features[-1] and unconformities: model.add_unconformity(group_features[-1], 0) model.set_stratigraphic_column(m2l_data['stratigraphic_column']) return model
import glob import numpy as np import logging logging.getLogger().setLevel(logging.INFO) data, bb = load_claudius()#claudius.get_data() bb[1,0]+=200 bb[0,0]-=200 bb[1,1]+=200 bb[0,1]-=200 bb[1,2]+=200 bb[0,2]-=200 model = GeologicalModel(bb[0,:],bb[1,:]) data['random'] = np.random.random(data.shape[0]) model.set_model_data(data[data['random'] < 0.01])#[np.isnan(data['val'])]) strati = model.create_and_add_foliation("strati", interpolatortype="surfe", method='single_surface' ) print(strati.evaluate_value(model.regular_grid((10,10,10)))) viewer = LavaVuModelViewer(model,background="white") # determine the number of unique surfaces in the model from # the input data and then calculate isosurfaces for this unique = np.unique(strati.interpolator.get_value_constraints()[:,3]) viewer.add_isosurface(model.features[0], slices=unique, cmap='prism', paint_with=model.features[0]) #
def test_add_data(): data, bb = load_claudius() model = GeologicalModel(bb[0, :], bb[1, :]) model.set_model_data(data)