Example #1
0
 def calculate_geomap(self, interpdata=None, plot=True):
     '''
     Args:
         interpdata:
         plot:
     Returns:
     '''
     if interpdata:
         geomap, fault = gp.compute_model_at(self.surface_coordinates[0],
                                             interpdata)
     else:
         geomap, fault = gp.compute_model_at(self.surface_coordinates[0],
                                             self.interp_data)
     geomap = geomap[0].reshape(
         self.dem_zval.shape)  # resolution of topo gives much better map
     geomap = np.flip(
         geomap,
         axis=0)  #to match the orientation of the other plotting options
     if plot:
         plt.imshow(geomap,
                    origin="lower",
                    cmap=gp.plotting.colors.cmap,
                    norm=gp.plotting.colors.norm)  # set extent
         plt.title("Geological map", fontsize=15)
     return geomap
Example #2
0
    def render_frame(self, outfile=None):
        if self.cmap == None:
            plotter = gempy.PlotData2D(self.model._geo_data)
            self.cmap = plotter._cmap
            self.norm = plotter._norm
            self.lot = plotter._color_lot

        lith_block, fault_block = gempy.compute_model_at(
            self.depth_grid, self.model)
        block = lith_block[0].reshape(
            (self.associated_calibration.calibration_data['y_lim'][1] -
             self.associated_calibration.calibration_data['y_lim'][0],
             self.associated_calibration.calibration_data['x_lim'][1] -
             self.associated_calibration.calibration_data['x_lim'][0]))
        h = (self.associated_calibration.calibration_data['y_lim'][1] -
             self.associated_calibration.calibration_data['y_lim'][0]) / 100.0
        w = (self.associated_calibration.calibration_data['x_lim'][1] -
             self.associated_calibration.calibration_data['x_lim'][0]) / 100.0

        fig = plt.figure(figsize=(w, h), dpi=100, frameon=False)
        ax = plt.Axes(fig, [0., 0., 1., 1.])
        ax.set_axis_off()
        fig.add_axes(ax)
        ax.pcolormesh(block, cmap=self.cmap, norm=self.norm)

        if outfile == None:
            plt.show()
            plt.close()
        else:
            plt.savefig(outfile, pad_inches=0)
            plt.close(fig)
Example #3
0
def get_surflith(dem, dema, interp_data, output_filename='DEMxyz.csv'):
    '''Reshape DEM and use it to compute the lithology values of the GemPy model at the land surface.
    Returns an array of lith values at the surface z elevation for each xy point.
    
    dem:                dem object returned by importDEM() or dem = gdal.Open(filename)
    dema:               dem array returned by importDEM() or dema = dem.ReadAsArray()
    interp_data:        interpolated data returned by gempy.InterpolatorData()
    output_filename:    string to name gdal's output csv file (can be a throw-away - not used again)
    
    returns:
    surflith:           an array of lith values at the surface z elevation for each xy point, dim (yres,xres)'''

    #Get an array with xyz values from the DEM:
    #can this be streamlined to avoid having to export and re-import?
    translate_options = gdal.TranslateOptions(
        options=['format'], format="XYZ")  #set options for gdal.Translate()
    gdal.Translate(
        output_filename, dem, options=translate_options
    )  #convert dem to a csv with one column of points, each with an xyz value
    xyz = pn.read_csv(output_filename, header=None,
                      sep=' ')  #read xyz csv with pandas
    demlist = xyz.as_matrix(
    )  #convert to np array of (x,y,z) values with dim (ncol*nrow, 3)

    #Format the geologic data:
    surflith, fault2 = gp.compute_model_at(
        demlist, interp_data
    )  #compute the model values at the locations specified (aka the land surface) (why is fault a required output?)
    surflith = surflith[0].reshape(
        dema.shape
    )  #reshape lith block (a list) to an array with same dimensions as dem (yres,xres,zres) (note: xres*yres must equal length of lith)
    #now we have a discretized array with the same resolution as the dem, with a value for the lithology at the surface elevation for each xy point
    return surflith
 def plot_map(self, iteration=1, **kwargs):
     self._change_input_data(iteration)
     # geomap = self.topography.calculate_geomap(interpdata = self.interp_data, plot=True)
     geomap, faultmap = gp.compute_model_at(
         self.topography.surface_coordinates[0], self.interp_data)
     # gp.plotting.plot_map(geomap)
     gp.plotting.plot_map(self.geo_data,
                          geomap=geomap[0].reshape(
                              self.topography.dem_zval.shape),
                          **kwargs)
 def all_post_maps(self):
     all_maps = []
     for i in range(0, self.n_iter):
         # print(i)
         self._change_input_data(i)
         # geomap = self.topography.calculate_geomap(interpdata = self.interp_data, plot=True)
         geomap, faultmap = gp.compute_model_at(
             self.topography.surface_coordinates[0], self.interp_data)
         all_maps.insert(i, geomap[0])
     return all_maps
Example #6
0
def test_rgeomod_integration(theano_f):
    geo_data=gp.create_data(extent=[612000, 622000, 2472000, 2480000, -1000, 1000],
                            resolution=[50, 50, 50],
                            path_f=input_path+"/gempy_foliations.csv",
                            path_i=input_path+"/gempy_interfaces.csv")



    formation_order = ["Unit4", "Unit3", "Unit2", "Unit1"]



    gp.set_series(geo_data, {"Default series": formation_order},
                 order_formations = formation_order, verbose=1)



    gp.plot_data(geo_data, direction="z")


    #interp_data = gp.InterpolatorData(geo_data, compile_theano=True)
    interp_data = theano_f
    interp_data.update_interpolator(geo_data)

    lith_block, fault_block = gp.compute_model(interp_data)
    print("3-D geological model calculated.")


    gp.plot_section(geo_data, lith_block[0], 25, direction='y', plot_data=False)
    #plt.savefig("../data/cross_section_NS_25.pdf", bbox_inches="tight")

    gp.plot_section(geo_data, lith_block[0], 25, direction='x', plot_data=False)
    #plt.savefig("../data/cross_section_EW_25.pdf", bbox_inches="tight")

    vertices, simplices = gp.get_surfaces(interp_data, potential_lith=lith_block[1], step_size=2)

    fig = plt.figure(figsize=(13,10))
    ax = fig.add_subplot(111, projection='3d')
    cs = ["lightblue", "pink", "lightgreen", "orange"]
    for i in range(4):
        surf = ax.plot_trisurf(vertices[i][:,0], vertices[i][:,1], vertices[i][:,2],
                               color=cs[i], linewidth=0, alpha=0.65, shade=False)
    #plt.savefig("../data/surfaces_3D.pdf", bbox_inches="tight")

    # try:
    #     gp.plot_surfaces_3D(geo_data, vertices, simplices)
    # except NameError:
    #     print("3-D visualization library vtk not installed.")

    # load the digital elevation model
    geotiff_filepath = input_path+"/dome_sub_sub_utm.tif"
    raster = gdal.Open(geotiff_filepath)
    dtm = raster.ReadAsArray()
    dtmp = plt.imshow(dtm, origin='upper', cmap="viridis");
    plt.title("Digital elevation model");
    plt.colorbar(dtmp, label="Elevation [m]");
    plt.savefig(input_path+"/DTM.pdf")

    # To be able to use gempy plotting functionality we need to create a dummy geo_data object with the
    # resoluion we want. In this case resolution=[339, 271, 1]
    import copy
    geo_data_dummy = copy.deepcopy(geo_data)
    geo_data_dummy.resolution = [339, 271, 1]



    # convert the dtm to a gempy-suitable raveled grid
    points = rgeomod.convert_dtm_to_gempy_grid(raster, dtm)


    # Now we can use the function `compute_model_at` to get the lithology values at a specific location:

    # In[17]:


    # interp_data_geomap = gp.InterpolatorInput(geo_data, dtype="float64")
    lith_block, fault_block = gp.compute_model_at(points, interp_data)


    # <div class="alert alert-info">
    # **Your task:** Create a visual representation of the geological map in a 2-D plot (note: result is also again saved to the `../data`-folder):
    # </div>
    #
    # And here **the geological map**:

    # In[18]:


    gp.plot_section(geo_data_dummy, lith_block[0], 0, direction='z', plot_data=False)
    plt.title("Geological map");
    #plt.savefig("../geological_map.pdf")


    # ### Export the map for visualization in GoogleEarth

    # <div class="alert alert-info">
    # **Your task:** Execute the following code to export a GeoTiff of the generated geological map, as well as `kml`-files with your picked points inside the data folder. Open these files in GoogleEarth and inspect the generated map:
    # </div>
    #
    #
    # <div class="alert alert-warning">
    # **Note (1)**: Use the normal `File -> Open..` dialog in GoogleEarth to open the data - no need to use the `Import` method, as the GeoTiff contains the correct coordinates in the file.
    # </div>
    #
    #
    # <div class="alert alert-warning">
    # **Note (2)**: For a better interpretation of the generated map, use the transparency feature (directly after opening the map, or using `right-click -> Get Info` on the file).
    # </div>

    # In[19]:


    geo_map = lith_block[0].copy().reshape((339,271))
    geo_map = geo_map.astype('int16')  # change to int for later use


    # In[20]:


    rgeomod.export_geotiff(input_path+"/geomap.tif", geo_map, gp.plotting.colors.cmap, geotiff_filepath)


    # Export the interface data points:

    # In[21]:


    t = input_path+"/templates/ge_template_raw_interf.xml"
    pt = input_path+"/templates/ge_placemark_template_interf.xml"
    rgeomod.gempy_export_points_to_kml(input_path, geo_data, pt, t, gp.plotting.colors.cmap)


    # Export the foliation data:



    t = input_path+"/templates/ge_template_raw_fol.xml"
    pt = input_path+"/templates/ge_placemark_template_fol.xml"
    rgeomod.gempy_export_fol_to_kml(input_path+"/dips.kml", geo_data, pt, t)
    def render_frame(self, depth, outfile=None):
        t0 = time.clock()
        self.update_grid(depth)
        if self.cmap is None:
            self.set_cmap()
        if self.lock is not None:
            self.lock.acquire()
            sol = gempy.compute_model_at(self.depth_grid, self.model)
            #lith_block, fault_block =
            self.lock.release()
        else:
            sol = gempy.compute_model_at(self.depth_grid, self.model)
        scalar_field = sol.scalar_field_lith.reshape(
            (self.output_res[1], self.output_res[0]))
        block = sol.lith_block.reshape(
            (self.output_res[1], self.output_res[0]))
        h = self.associated_calibration.calibration_data['scale_factor'] * (
            self.output_res[1]) / 100.0
        w = self.associated_calibration.calibration_data['scale_factor'] * (
            self.output_res[0]) / 100.0

        fig = plt.figure(figsize=(w, h), dpi=100, frameon=False)
        ax = plt.Axes(fig, [0., 0., 1., 1.])
        ax.set_axis_off()
        fig.add_axes(ax)
        ax.pcolormesh(block, cmap=self.cmap, norm=self.norm)

        if self.show_faults is True:
            plt.contour(sol.fault_blocks[0].reshape(
                (self.output_res[1], self.output_res[0])),
                        levels=self.fault_contours,
                        linewidths=3.0,
                        colors=[(1.0, 1.0, 1.0, 1.0)])

        if self.contours is True:
            x = range(self.output_res[0])
            y = range(self.output_res[1])
            z = self.depth_grid.reshape(
                (self.output_res[1], self.output_res[0], 3))[:, :, 2]
            sub_contours = plt.contour(x,
                                       y,
                                       z,
                                       levels=self.sub_contours,
                                       linewidths=0.5,
                                       colors=[(0, 0, 0, 0.8)])
            main_contours = plt.contour(x,
                                        y,
                                        z,
                                        levels=self.main_contours,
                                        linewidths=1.0,
                                        colors=[(0, 0, 0, 1.0)])
            # plt.contour(lith_block[1].reshape((self.output_res[1], self.output_res[0])) levels=main_levels, linewidths=1.0, colors=[(0, 0, 0, 1.0)])
            plt.clabel(main_contours, inline=0, fontsize=15, fmt='%3.0f')

        if self.scalar_contours is True:
            x = range(self.output_res[0])
            y = range(self.output_res[1])
            z = scalar_field
            sub_contours = plt.contour(x,
                                       y,
                                       z,
                                       levels=self.scalar_sub_contours,
                                       linewidths=0.5,
                                       colors=[(0, 0, 0, 0.8)])
            main_contours = plt.contour(x,
                                        y,
                                        z,
                                        levels=self.scalar_main_contours,
                                        linewidths=1.0,
                                        colors=[(0, 0, 0, 1.0)])
            # plt.contour(lith_block[1].reshape((self.output_res[1], self.output_res[0])) levels=main_levels, linewidths=1.0, colors=[(0, 0, 0, 1.0)])
            plt.clabel(main_contours, inline=0, fontsize=15, fmt='%3.0f')

        if outfile == None:
            plt.show()
            plt.close()
        else:
            plt.savefig(outfile, pad_inches=0)
            plt.close(fig)
        t1 = time.clock()
        if self.show_framerate is True:
            print("frame took " + str(t1 - t0) + " s")