示例#1
0
    def add_defs(self, deftxt='', getcol=False, lmod=None):
        """ Add geophysical definitions and make them editable"""

        if lmod is not None:
            self.islmod1 = False
        else:
            lmod = self.lmod1
            self.islmod1 = True

        if not lmod.lith_list:
            self.max_lith_index = -1
        else:
            lmod.update_lith_list_reverse()
            self.max_lith_index = max(lmod.lith_list_reverse.keys())

        defnum = self.lw_param_defs.count()
        if deftxt == '':
            deftxt = 'Generic ' + str(defnum)

        lmod.lith_list[deftxt] = grvmag3d.GeoData(self.parent, lmod.numx,
                                                  lmod.numy, lmod.numz,
                                                  lmod.dxy, lmod.d_z, lmod.mht,
                                                  lmod.ght)

        litho = lmod.lith_list['Background']
        lithn = lmod.lith_list[deftxt]
        lithn.hintn = litho.hintn
        lithn.finc = litho.finc
        lithn.fdec = litho.fdec
        lithn.zobsm = litho.zobsm
        lithn.bdensity = litho.bdensity
        lithn.zobsg = litho.zobsg

        self.max_lith_index += 1
        lithn.lith_index = self.max_lith_index

        if deftxt == 'Background':
            lithn.susc = 0
            lithn.density = lithn.bdensity

        if getcol is True:
            col = QtWidgets.QColorDialog.getColor()
            lmod.mlut[lithn.lith_index] = [col.red(), col.green(), col.blue()]

# setup list widgets
        misc.update_lith_lw(self.lmod1, self.lw_param_defs)

        if defnum == 0:
            lithn.susc = 0
            lithn.density = lithn.bdensity

        self.lw_index_change()
示例#2
0
    def add_defs(self, deftxt='', getcol=False, lmod=None):
        """
        Add geophysical definitions and make them editable.

        Parameters
        ----------
        deftxt : str, optional
            Definition text. The default is ''.
        getcol : bool, optional
            Get column. The default is False.
        lmod : LithModel, optional
            3D model. The default is None.

        Returns
        -------
        None.

        """
        if lmod is not None:
            self.islmod1 = False
        else:
            lmod = self.lmod1
            self.islmod1 = True

        new_lith_index = 0
        if lmod.lith_list:
            lmod.update_lith_list_reverse()
            new_lith_index = max(lmod.lith_list_reverse.keys())+1

        defnum = self.lw_param_defs.count()
        if deftxt == '':
            deftxt = 'Generic '+str(defnum)

        lmod.lith_list[deftxt] = grvmag3d.GeoData(
            self.parent, lmod.numx, lmod.numy, lmod.numz, lmod.dxy, lmod.d_z,
            lmod.mht, lmod.ght)

        litho = lmod.lith_list['Background']
        lithn = lmod.lith_list[deftxt]
        lithn.hintn = litho.hintn
        lithn.finc = litho.finc
        lithn.fdec = litho.fdec
        lithn.zobsm = litho.zobsm
        lithn.bdensity = litho.bdensity
        lithn.zobsg = litho.zobsg

        lithn.lith_index = new_lith_index

        if deftxt == 'Background':
            lithn.susc = 0
            lithn.density = lithn.bdensity

        if getcol is True:
            col = QtWidgets.QColorDialog.getColor(parent=self.parent)
            lmod.mlut[lithn.lith_index] = [col.red(), col.green(), col.blue()]

# setup list widgets
        misc.update_lith_lw(self.lmod1, self.lw_param_defs)

        if defnum == 0:
            lithn.susc = 0
            lithn.density = lithn.bdensity

        self.lw_index_change()
示例#3
0
    def import_ascii_xyz_model(self, filename):
        """
        Use to import ASCII XYZ Models of the form x,y,z,label.

        Parameters
        ----------
        filename : str
            Input filename.

        Returns
        -------
        None.

        """
        if filename.find('.csv') > -1:
            tmp = np.genfromtxt(filename, delimiter=',', dtype=np.str)
        else:
            tmp = np.genfromtxt(filename, dtype=np.str)

        x = tmp[:, 0].astype(np.float)
        y = tmp[:, 1].astype(np.float)
        z = tmp[:, 2].astype(np.float)
        label = tmp[:, 3]
        labelu = np.unique(label)

        idx = np.unique(x, return_index=True)[1]
        x_u = x[np.sort(idx)]
        dx_u = np.diff(x_u)
        idx = np.unique(y, return_index=True)[1]
        y_u = y[np.sort(idx)]
        dy_u = np.diff(y_u)
        idx = np.unique(z, return_index=True)[1]
        z_u = z[np.sort(idx)]
        dz_u = np.diff(z_u)

        if dx_u[0] < 0:
            dx_u *= -1
        if dy_u[0] < 0:
            dy_u *= -1
        if dz_u[0] < 0:
            dz_u *= -1

        xcell = np.max(dx_u)
        ycell = np.max(dy_u)
        zcell = np.max(dz_u)

        lmod = self.lmod

        lmod.dxy = min(xcell, ycell)
        lmod.d_z = zcell
        lmod.xrange = [x_u.min() - lmod.dxy / 2., x_u.max() + lmod.dxy / 2.]
        lmod.yrange = [y_u.min() - lmod.dxy / 2., y_u.max() + lmod.dxy / 2.]
        lmod.zrange = [z_u.min() - lmod.d_z / 2., z_u.max() + lmod.d_z / 2.]
        lmod.numx = int(np.ptp(lmod.xrange) / lmod.dxy + 1)
        lmod.numy = int(np.ptp(lmod.yrange) / lmod.dxy + 1)
        lmod.numz = int(np.ptp(lmod.zrange) / lmod.d_z + 1)

        # Section to load lithologies.
        if 'Generic 1' in lmod.lith_list:
            lmod.lith_list.pop('Generic 1')

        lindx = 0
        for itxt in labelu:
            lindx += 1
            lmod.mlut[lindx] = [
                np.random.randint(0, 255),
                np.random.randint(0, 255),
                np.random.randint(0, 255)
            ]
            lmod.lith_list[itxt] = grvmag3d.GeoData(self.parent,
                                                    ncols=lmod.numx,
                                                    nrows=lmod.numy,
                                                    numz=lmod.numz,
                                                    dxy=lmod.dxy,
                                                    d_z=lmod.d_z)

            lmod.lith_list[itxt].lith_index = lindx
            lmod.lith_list[itxt].modified = True
            lmod.lith_list[itxt].set_xyz12()

        lmod.lith_index = None
        lmod.update(lmod.numx, lmod.numy, lmod.numz, lmod.xrange[0],
                    lmod.yrange[1], lmod.zrange[1], lmod.dxy, lmod.d_z)
        lmod.update_lith_list_reverse()

        for i, xi in enumerate(x):
            col = int((xi - lmod.xrange[0]) / lmod.dxy)
            row = int((lmod.yrange[1] - y[i]) / lmod.dxy)
            layer = int((lmod.zrange[1] - z[i]) / lmod.d_z)
            lmod.lith_index[col, row, layer] = \
                lmod.lith_list[label[i]].lith_index
示例#4
0
    def dict2lmod(self, indict, pre=''):
        """
        Convert a dictionary to a LithModel

        Parameters
        ----------
        indict : dictionary
            Imported dictionary.
        pre : str, optional
            Text. The default is ''.

        Returns
        -------
        None.

        """
        lithkeys = indict[pre + 'lithkeys']

        lmod = self.lmod

        lmod.gregional = indict[pre + 'gregional']
        lmod.ght = indict[pre + 'ght']
        lmod.mht = indict[pre + 'mht']
        lmod.numx = indict[pre + 'numx']
        lmod.numy = indict[pre + 'numy']
        lmod.numz = indict[pre + 'numz']
        lmod.dxy = indict[pre + 'dxy']
        lmod.d_z = indict[pre + 'd_z']
        lmod.lith_index = indict[pre + 'lith_index']
        lmod.xrange = np.array(indict[pre + 'xrange']).tolist()
        lmod.yrange = np.array(indict[pre + 'yrange']).tolist()
        lmod.zrange = np.array(indict[pre + 'zrange']).tolist()
        if pre + 'custprofx' in indict:
            lmod.custprofx = indict[pre + 'custprofx'].item()
        else:
            lmod.custprofx = {0: (lmod.xrange[0], lmod.xrange[1])}
        if pre + 'custprofy' in indict:
            lmod.custprofy = indict[pre + 'custprofy'].item()
        else:
            lmod.custprofy = {0: (lmod.yrange[0], lmod.yrange[0])}

        lmod.mlut = indict[pre + 'mlut'].item()
        lmod.init_calc_grids()

        lmod.griddata = indict[pre + 'griddata'].item()

        for i in lmod.griddata:
            lmod.griddata[i].data = np.ma.array(lmod.griddata[i].data)

        # This gets rid of a legacy variable name
        for i in lmod.griddata:
            if not hasattr(lmod.griddata[i], 'dataid'):
                lmod.griddata[i].dataid = ''
            if hasattr(lmod.griddata[i], 'bandid'):
                if lmod.griddata[i].dataid == '':
                    lmod.griddata[i].dataid = lmod.griddata[i].bandid
                del lmod.griddata[i].bandid
            if not hasattr(lmod.griddata[i], 'extent'):
                rows, cols = lmod.griddata[i].data.shape

                xmin = lmod.griddata[i].tlx
                ymax = lmod.griddata[i].tly
                ymin = ymax - rows * lmod.griddata[i].ydim
                xmax = xmin + cols * lmod.griddata[i].xdim

                lmod.griddata[i].extent = [xmin, xmax, ymin, ymax]
                del lmod.griddata[i].tlx
                del lmod.griddata[i].tly

        wktfin = None
        for i in lmod.griddata:
            wkt = lmod.griddata[i].wkt
            if wkt != '' and wkt is not None:
                wktfin = wkt

        if wktfin is not None:
            for i in lmod.griddata:
                wkt = lmod.griddata[i].wkt
                if wkt == '' or wkt is None:
                    lmod.griddata[i].wkt = wktfin


# Section to load lithologies.
        lmod.lith_list['Background'] = grvmag3d.GeoData(self.parent)

        for itxt in lithkeys:
            if itxt != 'Background':
                lmod.lith_list[itxt] = grvmag3d.GeoData(self.parent)

            lmod.lith_list[itxt].hintn = indict[pre + itxt + '_hintn'].item()
            lmod.lith_list[itxt].finc = indict[pre + itxt + '_finc'].item()
            lmod.lith_list[itxt].fdec = indict[pre + itxt + '_fdec'].item()
            lmod.lith_list[itxt].zobsm = indict[pre + itxt + '_zobsm'].item()
            lmod.lith_list[itxt].susc = indict[pre + itxt + '_susc'].item()
            lmod.lith_list[itxt].mstrength = indict[pre + itxt +
                                                    '_mstrength'].item()
            lmod.lith_list[itxt].qratio = indict[pre + itxt + '_qratio'].item()
            lmod.lith_list[itxt].minc = indict[pre + itxt + '_minc'].item()
            lmod.lith_list[itxt].mdec = indict[pre + itxt + '_mdec'].item()
            lmod.lith_list[itxt].density = indict[pre + itxt +
                                                  '_density'].item()
            lmod.lith_list[itxt].bdensity = indict[pre + itxt +
                                                   '_bdensity'].item()
            lmod.lith_list[itxt].lith_index = indict[pre + itxt +
                                                     '_lith_index'].item()
            lmod.lith_list[itxt].g_cols = indict[pre + itxt + '_numx'].item()
            lmod.lith_list[itxt].g_rows = indict[pre + itxt + '_numy'].item()
            lmod.lith_list[itxt].numz = indict[pre + itxt + '_numz'].item()
            lmod.lith_list[itxt].g_dxy = indict[pre + itxt + '_dxy'].item()
            lmod.lith_list[itxt].dxy = indict[pre + itxt + '_dxy'].item()
            lmod.lith_list[itxt].d_z = indict[pre + itxt + '_d_z'].item()
            lmod.lith_list[itxt].zobsm = indict[pre + itxt + '_zobsm'].item()
            lmod.lith_list[itxt].zobsg = indict[pre + itxt + '_zobsg'].item()
            if pre + itxt + '_lithcode' in indict:
                lmod.lith_list[itxt].lithcode = indict[pre + itxt +
                                                       '_lithcode'].item()
            if pre + itxt + '_lithnotes' in indict:
                lmod.lith_list[itxt].lithnotes = indict[pre + itxt +
                                                        '_lithnotes'].item()

            lmod.lith_list[itxt].modified = True
            lmod.lith_list[itxt].set_xyz12()
示例#5
0
    def import_leapfrog_csv(self, filename):
        """
        Imports leapfrog csv block models.

        Parameters
        ----------
        filename : str
            Input filename.

        Returns
        -------
        None.

        """
        piter = self.pbars.iter

        with open(filename) as fno:
            tmp = fno.readlines()

        while tmp[0][0] == '#':
            tmp.pop(0)

        if not tmp:
            return

        header = tmp.pop(0).split(',')
        header = header[7:]

        mtmp = MessageCombo(header)
        mtmp.exec_()
        datindx = mtmp.master.currentIndex()

        x = []
        y = []
        z = []
        label = []
        xcell = float(tmp[0].split(',')[3])
        ycell = float(tmp[0].split(',')[4])
        zcell = float(tmp[0].split(',')[5])

        for i in piter(tmp):
            i2 = i.split(',')
            x.append(float(i2[0]))
            y.append(float(i2[1]))
            z.append(float(i2[2]))
            label.append(i2[7 + datindx])

        x = np.array(x)
        y = np.array(y)
        z = np.array(z)

        x_u = np.unique(x)
        y_u = np.unique(y)
        z_u = np.unique(z)
        labelu = np.unique(label)
        labelu[labelu == 'blank'] = 'Background'

        lmod = self.lmod

        lmod.numx = x_u.shape[0]
        lmod.numy = y_u.shape[0]
        lmod.numz = z_u.shape[0]
        lmod.dxy = max(xcell, ycell)
        lmod.d_z = zcell
        lmod.xrange = [x_u.min() - lmod.dxy / 2., x_u.max() + lmod.dxy / 2.]
        lmod.yrange = [y_u.min() - lmod.dxy / 2., y_u.max() + lmod.dxy / 2.]
        lmod.zrange = [z_u.min() - lmod.d_z / 2., z_u.max() + lmod.d_z / 2.]

        lindx = 0
        for itxt in labelu:
            lindx += 1
            if itxt == 'Background':
                lmod.lith_list[itxt] = grvmag3d.GeoData(self.parent,
                                                        ncols=lmod.numx,
                                                        nrows=lmod.numy,
                                                        numz=lmod.numz,
                                                        dxy=lmod.dxy,
                                                        d_z=lmod.d_z)
                lmod.lith_list[itxt].lith_index = 0
                lmod.mlut[0] = [
                    np.random.randint(0, 255),
                    np.random.randint(0, 255),
                    np.random.randint(0, 255)
                ]
            else:
                lmod.lith_list[itxt] = grvmag3d.GeoData(self.parent,
                                                        ncols=lmod.numx,
                                                        nrows=lmod.numy,
                                                        numz=lmod.numz,
                                                        dxy=lmod.dxy,
                                                        d_z=lmod.d_z)
                lmod.lith_list[itxt].lith_index = lindx
                lmod.mlut[lindx] = [
                    np.random.randint(0, 255),
                    np.random.randint(0, 255),
                    np.random.randint(0, 255)
                ]

            lmod.lith_list[itxt].modified = True
            lmod.lith_list[itxt].set_xyz12()

        lmod.lith_index = None
        lmod.update(lmod.numx,
                    lmod.numy,
                    lmod.numz,
                    lmod.xrange[0],
                    lmod.yrange[1],
                    lmod.zrange[1],
                    lmod.dxy,
                    lmod.d_z,
                    usedtm=True)
        lmod.update_lith_list_reverse()

        for i in piter(range(len(x))):
            xi = x[i]
            col = int((xi - lmod.xrange[0]) / lmod.dxy)
            row = int((lmod.yrange[1] - y[i]) / lmod.dxy)
            layer = int((lmod.zrange[1] - z[i]) / lmod.d_z)
            if label[i] == 'blank':
                lmod.lith_index[col, row, layer] = \
                    lmod.lith_list['Background'].lith_index
            else:
                lmod.lith_index[col, row, layer] = \
                    lmod.lith_list[label[i]].lith_index