def test_downloads(self): url = "https://storage.googleapis.com/simpeg/Chile_GRAV_4_Miller/" cloudfiles = [ "LdM_grav_obs.grv", "LdM_mesh.mesh", "LdM_topo.topo", "LdM_input_file.inp", ] url1 = url + cloudfiles[0] url2 = url + cloudfiles[1] file_names = download([url1, url2], folder="./test_urls", overwrite=True) # or file_name = download(url1, folder="./test_url", overwrite=True) # where assert isinstance(file_names, list) assert len(file_names) == 2 assert isinstance(file_name, str) # clean up shutil.rmtree(os.path.expanduser("./test_urls")) shutil.rmtree(os.path.expanduser("./test_url"))
def download_and_unzip_data( url="https://storage.googleapis.com/simpeg/bookpurnong/bookpurnong_inversion.tar.gz", ): """ Download the data from the storage bucket, unzip the tar file, return the directory where the data are """ # download the data downloads = utils.download(url) # directory where the downloaded files are directory = downloads.split(".")[0] # unzip the tarfile tar = tarfile.open(downloads, "r") tar.extractall() tar.close() return downloads, directory
def download_and_unzip_data( url="https://storage.googleapis.com/simpeg/em_examples/tdem_groundedsource/tdem_groundedsource.tar", ): """ Download the data from the storage bucket, unzip the tar file, return the directory where the data are """ # download the data downloads = utils.download(url) # directory where the downloaded files are directory = downloads.split(".")[0] # unzip the tarfile tar = tarfile.open(downloads, "r") tar.extractall() tar.close() return downloads, directory
def test_surface2ind_topo(self): file_url = ( "https://storage.googleapis.com/simpeg/tests/utils/vancouver_topo.xyz" ) file2load = download(file_url) vancouver_topo = np.loadtxt(file2load) mesh_topo = discretize.TensorMesh( [[(500.0, 24)], [(500.0, 20)], [(10.0, 30)]], x0="CCC") indtopoCC = surface2ind_topo(mesh_topo, vancouver_topo, gridLoc="CC", method="nearest") indtopoN = surface2ind_topo(mesh_topo, vancouver_topo, gridLoc="N", method="nearest") assert len(np.where(indtopoCC)[0]) == 8729 assert len(np.where(indtopoN)[0]) == 8212
def NMOstackSingle(data, tintercept, v, timeFile): dx = 20.0 xorig = np.arange(38) * dx timdat = download(timeFile, verbose=False) time = np.load(timdat) singletrace = NMOstack(data, xorig, time, v) _, ax = plt.subplots(1, 1, figsize=(7, 8)) kwargs = { "skipt": 1, "scale": 2.0, "lwidth": 1.0, "sampr": 0.004, "ax": ax, "clip": 10, } extent = [singletrace.min(), singletrace.max(), time.max(), time.min()] ax.invert_yaxis() ax.axis(extent) wiggle(singletrace.reshape([1, -1]), **kwargs) ax.set_xlabel("Amplitude") ax.set_ylabel("Time (s)")
# ----------------- # # Here we provide the file paths to assets we need to run the inversion. The # path to the true model conductivity and chargeability models are also # provided for comparison with the inversion results. These files are stored as a # tar-file on our google cloud bucket: # "https://storage.googleapis.com/simpeg/doc-assets/dcip3d.tar.gz" # # # # storage bucket where we have the data data_source = "https://storage.googleapis.com/simpeg/doc-assets/dcip3d.tar.gz" # download the data downloaded_data = utils.download(data_source, overwrite=True) # unzip the tarfile tar = tarfile.open(downloaded_data, "r") tar.extractall() tar.close() # path to the directory containing our data dir_path = downloaded_data.split(".")[0] + os.path.sep # files to work with topo_filename = dir_path + "topo_xyz.txt" dc_data_filename = dir_path + "dc_data.xyz" ip_data_filename = dir_path + "ip_data.xyz" ########################################################
def setUp(self): url = "https://storage.googleapis.com/simpeg/tests/em_utils/currents.npy" self.basePath = download(url)
def run(plotIt=True, cleanAfterRun=True): # Start by downloading files from the remote repository # directory where the downloaded files are url = "https://storage.googleapis.com/simpeg/Chile_GRAV_4_Miller/Chile_GRAV_4_Miller.tar.gz" downloads = download(url, overwrite=True) basePath = downloads.split(".")[0] # unzip the tarfile tar = tarfile.open(downloads, "r") tar.extractall() tar.close() input_file = basePath + os.path.sep + "LdM_input_file.inp" # %% User input # Plotting parameters, max and min densities in g/cc vmin = -0.6 vmax = 0.6 # weight exponent for default weighting wgtexp = 3.0 # %% # Read in the input file which included all parameters at once # (mesh, topo, model, survey, inv param, etc.) driver = GravityDriver_Inv(input_file) # %% # Now we need to create the survey and model information. # Access the mesh and survey information mesh = driver.mesh # survey = driver.survey data_object = driver.data # [survey, data_object] = driver.survey # define gravity survey locations rxLoc = survey.source_field.receiver_list[0].locations # define gravity data and errors d = data_object.dobs # Get the active cells active = driver.activeCells nC = len(active) # Number of active cells # Create active map to go from reduce set to full activeMap = maps.InjectActiveCells(mesh, active, -100) # Create static map static = driver.staticCells dynamic = driver.dynamicCells staticCells = maps.InjectActiveCells(None, dynamic, driver.m0[static], nC=nC) mstart = driver.m0[dynamic] # Get index of the center midx = int(mesh.nCx / 2) # %% # Now that we have a model and a survey we can build the linear system ... # Create the forward model operator simulation = gravity.simulation.Simulation3DIntegral(survey=survey, mesh=mesh, rhoMap=staticCells, actInd=active) # %% Create inversion objects reg = regularization.Sparse(mesh, indActive=active, mapping=staticCells, gradientType="total") reg.mref = driver.mref[dynamic] reg.norms = np.c_[0.0, 1.0, 1.0, 1.0] # reg.norms = driver.lpnorms # Specify how the optimization will proceed opt = optimization.ProjectedGNCG( maxIter=20, lower=driver.bounds[0], upper=driver.bounds[1], maxIterLS=10, maxIterCG=20, tolCG=1e-4, ) # Define misfit function (obs-calc) dmis = data_misfit.L2DataMisfit(data=data_object, simulation=simulation) # create the default L2 inverse problem from the above objects invProb = inverse_problem.BaseInvProblem(dmis, reg, opt) # Specify how the initial beta is found betaest = directives.BetaEstimate_ByEig(beta0_ratio=1e-2) # IRLS sets up the Lp inversion problem # Set the eps parameter parameter in Line 11 of the # input file based on the distribution of model (DEFAULT = 95th %ile) IRLS = directives.Update_IRLS(f_min_change=1e-4, max_irls_iterations=40, coolEpsFact=1.5, beta_tol=5e-1) # Preconditioning refreshing for each IRLS iteration update_Jacobi = directives.UpdatePreconditioner() sensitivity_weights = directives.UpdateSensitivityWeights() # Create combined the L2 and Lp problem inv = inversion.BaseInversion( invProb, directiveList=[sensitivity_weights, IRLS, update_Jacobi, betaest]) # %% # Run L2 and Lp inversion mrec = inv.run(mstart) if cleanAfterRun: os.remove(downloads) shutil.rmtree(basePath) # %% if plotIt: # Plot observed data # The sign of the data is flipped here for the change of convention # between Cartesian coordinate system (internal SimPEG format that # expects "positive up" gravity signal) and traditional gravity data # conventions (positive down). For example a traditional negative # gravity anomaly is described as "positive up" in Cartesian coordinates # and hence the sign needs to be flipped for use in SimPEG. plot2Ddata(rxLoc, -d) # %% # Write output model and data files and print misfit stats. # reconstructing l2 model mesh with air cells and active dynamic cells L2out = activeMap * invProb.l2model # reconstructing lp model mesh with air cells and active dynamic cells Lpout = activeMap * mrec # %% # Plot out sections and histograms of the smooth l2 model. # The ind= parameter is the slice of the model from top down. yslice = midx + 1 L2out[L2out == -100] = np.nan # set "air" to nan plt.figure(figsize=(10, 7)) plt.suptitle("Smooth Inversion: Depth weight = " + str(wgtexp)) ax = plt.subplot(221) dat1 = mesh.plotSlice( L2out, ax=ax, normal="Z", ind=-16, clim=(vmin, vmax), pcolorOpts={"cmap": "bwr"}, ) plt.plot( np.array([mesh.vectorCCx[0], mesh.vectorCCx[-1]]), np.array([mesh.vectorCCy[yslice], mesh.vectorCCy[yslice]]), c="gray", linestyle="--", ) plt.scatter(rxLoc[0:, 0], rxLoc[0:, 1], color="k", s=1) plt.title("Z: " + str(mesh.vectorCCz[-16]) + " m") plt.xlabel("Easting (m)") plt.ylabel("Northing (m)") plt.gca().set_aspect("equal", adjustable="box") cb = plt.colorbar(dat1[0], orientation="vertical", ticks=np.linspace(vmin, vmax, 4)) cb.set_label("Density (g/cc$^3$)") ax = plt.subplot(222) dat = mesh.plotSlice( L2out, ax=ax, normal="Z", ind=-27, clim=(vmin, vmax), pcolorOpts={"cmap": "bwr"}, ) plt.plot( np.array([mesh.vectorCCx[0], mesh.vectorCCx[-1]]), np.array([mesh.vectorCCy[yslice], mesh.vectorCCy[yslice]]), c="gray", linestyle="--", ) plt.scatter(rxLoc[0:, 0], rxLoc[0:, 1], color="k", s=1) plt.title("Z: " + str(mesh.vectorCCz[-27]) + " m") plt.xlabel("Easting (m)") plt.ylabel("Northing (m)") plt.gca().set_aspect("equal", adjustable="box") cb = plt.colorbar(dat1[0], orientation="vertical", ticks=np.linspace(vmin, vmax, 4)) cb.set_label("Density (g/cc$^3$)") ax = plt.subplot(212) mesh.plotSlice( L2out, ax=ax, normal="Y", ind=yslice, clim=(vmin, vmax), pcolorOpts={"cmap": "bwr"}, ) plt.title("Cross Section") plt.xlabel("Easting(m)") plt.ylabel("Elevation") plt.gca().set_aspect("equal", adjustable="box") cb = plt.colorbar( dat1[0], orientation="vertical", ticks=np.linspace(vmin, vmax, 4), cmap="bwr", ) cb.set_label("Density (g/cc$^3$)") # %% # Make plots of Lp model yslice = midx + 1 Lpout[Lpout == -100] = np.nan # set "air" to nan plt.figure(figsize=(10, 7)) plt.suptitle("Compact Inversion: Depth weight = " + str(wgtexp) + ": $\epsilon_p$ = " + str(round(reg.eps_p, 1)) + ": $\epsilon_q$ = " + str(round(reg.eps_q, 2))) ax = plt.subplot(221) dat = mesh.plotSlice( Lpout, ax=ax, normal="Z", ind=-16, clim=(vmin, vmax), pcolorOpts={"cmap": "bwr"}, ) plt.plot( np.array([mesh.vectorCCx[0], mesh.vectorCCx[-1]]), np.array([mesh.vectorCCy[yslice], mesh.vectorCCy[yslice]]), c="gray", linestyle="--", ) plt.scatter(rxLoc[0:, 0], rxLoc[0:, 1], color="k", s=1) plt.title("Z: " + str(mesh.vectorCCz[-16]) + " m") plt.xlabel("Easting (m)") plt.ylabel("Northing (m)") plt.gca().set_aspect("equal", adjustable="box") cb = plt.colorbar(dat[0], orientation="vertical", ticks=np.linspace(vmin, vmax, 4)) cb.set_label("Density (g/cc$^3$)") ax = plt.subplot(222) dat = mesh.plotSlice( Lpout, ax=ax, normal="Z", ind=-27, clim=(vmin, vmax), pcolorOpts={"cmap": "bwr"}, ) plt.plot( np.array([mesh.vectorCCx[0], mesh.vectorCCx[-1]]), np.array([mesh.vectorCCy[yslice], mesh.vectorCCy[yslice]]), c="gray", linestyle="--", ) plt.scatter(rxLoc[0:, 0], rxLoc[0:, 1], color="k", s=1) plt.title("Z: " + str(mesh.vectorCCz[-27]) + " m") plt.xlabel("Easting (m)") plt.ylabel("Northing (m)") plt.gca().set_aspect("equal", adjustable="box") cb = plt.colorbar(dat[0], orientation="vertical", ticks=np.linspace(vmin, vmax, 4)) cb.set_label("Density (g/cc$^3$)") ax = plt.subplot(212) dat = mesh.plotSlice( Lpout, ax=ax, normal="Y", ind=yslice, clim=(vmin, vmax), pcolorOpts={"cmap": "bwr"}, ) plt.title("Cross Section") plt.xlabel("Easting (m)") plt.ylabel("Elevation (m)") plt.gca().set_aspect("equal", adjustable="box") cb = plt.colorbar(dat[0], orientation="vertical", ticks=np.linspace(vmin, vmax, 4)) cb.set_label("Density (g/cc$^3$)")