Beispiel #1
0
def createLocalProb(meshLocal, local_survey, global_weights, ind):
    """
        CreateLocalProb(rxLoc, global_weights, lims, ind)

        Generate a problem, calculate/store sensitivities for
        given data points
    """

    # Need to find a way to compute sensitivities only for intersecting cells
    activeCells_t = np.ones(
        meshLocal.nC,
        dtype='bool')  # meshUtils.modelutils.activeTopoLayer(meshLocal, topo)

    # Create reduced identity map
    if input_dict["inversion_type"].lower() in ['mvi', 'mvis']:
        nBlock = 3
    else:
        nBlock = 1

    tileMap = Maps.Tile((mesh, activeCells), (meshLocal, activeCells_t),
                        nBlock=nBlock)

    activeCells_t = tileMap.activeLocal

    if "adjust_clearance" in list(input_dict.keys()):

        print("Setting Z values of data to respect clearance height")

        r, c_ind = tree.query(local_survey.rxLoc)
        dz = input_dict["adjust_clearance"]

        z = mesh.gridCC[activeCells,
                        2][c_ind] + mesh.h_gridded[activeCells,
                                                   2][c_ind] / 2 + dz
        local_survey.srcField.rxList[0].locs[:, 2] = z

    if input_dict["inversion_type"].lower() == 'grav':
        prob = PF.Gravity.GravityIntegral(meshLocal,
                                          rhoMap=tileMap,
                                          actInd=activeCells_t,
                                          parallelized=parallelized,
                                          Jpath=outDir + "Tile" + str(ind) +
                                          ".zarr",
                                          maxRAM=max_ram,
                                          n_cpu=n_cpu,
                                          max_chunk_size=max_chunk_size)

    elif input_dict["inversion_type"].lower() == 'mag':
        prob = PF.Magnetics.MagneticIntegral(meshLocal,
                                             chiMap=tileMap,
                                             actInd=activeCells_t,
                                             parallelized=parallelized,
                                             Jpath=outDir + "Tile" + str(ind) +
                                             ".zarr",
                                             maxRAM=max_ram,
                                             n_cpu=n_cpu,
                                             max_chunk_size=max_chunk_size)

    elif input_dict["inversion_type"].lower() in ['mvi', 'mvis']:
        prob = PF.Magnetics.MagneticIntegral(meshLocal,
                                             chiMap=tileMap,
                                             actInd=activeCells_t,
                                             parallelized=parallelized,
                                             Jpath=outDir + "Tile" + str(ind) +
                                             ".zarr",
                                             maxRAM=max_ram,
                                             modelType='vector',
                                             n_cpu=n_cpu,
                                             max_chunk_size=max_chunk_size)

    local_survey.pair(prob)

    # Data misfit function
    local_misfit = DataMisfit.l2_DataMisfit(local_survey)
    local_misfit.W = 1. / local_survey.std

    wr = prob.getJtJdiag(np.ones(tileMap.shape[1]), W=local_misfit.W)

    activeCellsTemp = Maps.InjectActiveCells(mesh, activeCells, 1e-8)

    global_weights += wr

    del meshLocal

    if output_tile_files:
        if input_dict["inversion_type"].lower() == 'grav':

            Utils.io_utils.writeUBCgravityObservations(
                outDir + 'Survey_Tile' + str(ind) + '.dat', local_survey,
                local_survey.dobs)

        elif input_dict["inversion_type"].lower() == 'mag':

            Utils.io_utils.writeUBCmagneticsObservations(
                outDir + 'Survey_Tile' + str(ind) + '.dat', local_survey,
                local_survey.dobs)

        Mesh.TreeMesh.writeUBC(mesh,
                               outDir + 'Octree_Tile' + str(ind) + '.msh',
                               models={
                                   outDir + 'JtJ_Tile' + str(ind) + ' .act':
                                   activeCellsTemp * wr[:nC]
                               })

    return local_misfit, global_weights
Beispiel #2
0
    def createLocalProb(rxLoc, wrGlobal, lims, ind):
        # createLocalProb(rxLoc, wrGlobal, lims, ind)
        # Generate a problem, calculate/store sensitivities for
        # given data points

        # Grab the data for current tile
        ind_t = np.all([
            rxLoc[:, 0] >= lims[0], rxLoc[:, 0] <= lims[1],
            rxLoc[:, 1] >= lims[2], rxLoc[:, 1] <= lims[3], surveyMask
        ],
                       axis=0)

        # Remember selected data in case of tile overlap
        surveyMask[ind_t] = False

        # Create new survey
        if driver["dataFile"][0] == 'GRAV':
            rxLoc_t = PF.BaseGrav.RxObs(rxLoc[ind_t, :])
            srcField = PF.BaseGrav.SrcField([rxLoc_t])
            survey_t = PF.BaseGrav.LinearSurvey(srcField)
            survey_t.dobs = survey.dobs[ind_t]
            survey_t.std = survey.std[ind_t]
            survey_t.ind = ind_t

            Utils.io_utils.writeUBCgravityObservations(
                workDir + dsep + outDir + "Tile" + str(ind) + '.dat', survey_t,
                survey_t.dobs)

        elif driver["dataFile"][0] == 'MAG':
            rxLoc_t = PF.BaseMag.RxObs(rxLoc[ind_t, :])
            srcField = PF.BaseMag.SrcField([rxLoc_t],
                                           param=survey.srcField.param)
            survey_t = PF.BaseMag.LinearSurvey(srcField)
            survey_t.dobs = survey.dobs[ind_t]
            survey_t.std = survey.std[ind_t]
            survey_t.ind = ind_t

            Utils.io_utils.writeUBCmagneticsObservations(
                workDir + dsep + outDir + "Tile" + str(ind) + '.dat', survey_t,
                survey_t.dobs)

        meshLocal = Utils.modelutils.meshBuilder(newTopo,
                                                 h,
                                                 padDist,
                                                 meshType='TREE',
                                                 meshGlobal=meshInput,
                                                 verticalAlignment='center')

        if topo is not None:
            meshLocal = Utils.modelutils.refineTree(meshLocal,
                                                    topo,
                                                    dtype='surface',
                                                    octreeLevels=octreeTopo,
                                                    finalize=False)

        # Refine the mesh around loc
        meshLocal = Utils.modelutils.refineTree(
            meshLocal,
            newTopo[ind_t, :],
            dtype='surface',
            octreeLevels=octreeObs,
            octreeLevels_XY=octreeLevels_XY,
            finalize=True)

        # Need to find a way to compute sensitivities only for intersecting cells
        activeCells_t = np.ones(
            meshLocal.nC, dtype='bool'
        )  # meshUtils.modelutils.activeTopoLayer(meshLocal, topo)

        # Create reduced identity map
        tileMap = Maps.Tile((mesh, activeCells), (meshLocal, activeCells_t))

        activeCells_t = tileMap.activeLocal

        print(activeCells_t.sum(), meshLocal.nC)
        if driver["dataFile"][0] == 'GRAV':
            prob = PF.Gravity.GravityIntegral(meshLocal,
                                              rhoMap=tileMap,
                                              actInd=activeCells_t,
                                              parallelized=parallelized,
                                              Jpath=workDir + dsep + outDir +
                                              "Tile" + str(ind) + ".zarr",
                                              maxRAM=maxRAM / n_cpu,
                                              n_cpu=n_cpu,
                                              n_chunks=n_chunks)

        elif driver["dataFile"][0] == 'MAG':
            prob = PF.Magnetics.MagneticIntegral(
                meshLocal,
                chiMap=tileMap,
                actInd=activeCells_t,
                parallelized=parallelized,
                Jpath=workDir + dsep + outDir + "Tile" + str(ind) + ".zarr",
                maxRAM=maxRAM / n_cpu,
                n_cpu=n_cpu,
                n_chunks=n_chunks)

        survey_t.pair(prob)

        # Write out local active and obs for validation
        Mesh.TreeMesh.writeUBC(
            meshLocal,
            workDir + dsep + outDir + dsep + 'Octree_Tile' + str(ind) + '.msh',
            models={
                workDir + dsep + outDir + dsep + 'ActiveGlobal_Tile' + str(ind) + ' .act':
                activeCells_t
            })

        if driver["dataFile"][0] == 'GRAV':

            Utils.io_utils.writeUBCgravityObservations(
                workDir + dsep + outDir + dsep + 'Tile' + str(ind) + '.dat',
                survey_t, survey_t.dobs)

        elif driver["dataFile"][0] == 'MAG':

            Utils.io_utils.writeUBCmagneticsObservations(
                workDir + dsep + outDir + dsep + 'Tile' + str(ind) + '.dat',
                survey_t, survey_t.dobs)

        # Data misfit function
        dmis = DataMisfit.l2_DataMisfit(survey_t)
        dmis.W = 1. / survey_t.std

        wr = prob.getJtJdiag(np.ones(tileMap.P.shape[1]), W=dmis.W)

        wrGlobal += wr

        del meshLocal

        # Create combo misfit function
        return dmis
Beispiel #3
0
def createLocalProb(rxLoc, wrGlobal, lims, ind):

    # Grab the data for current tile
    ind_t = np.all([
        rxLoc[:, 0] >= lims[0], rxLoc[:, 0] <= lims[1], rxLoc[:, 1] >= lims[2],
        rxLoc[:, 1] <= lims[3], surveyMask
    ],
                   axis=0)

    # Remember selected data in case of tile overlap
    surveyMask[ind_t] = False

    # Create new survey
    rxLoc_t = PF.BaseGrav.RxObs(rxLoc[ind_t, :])
    srcField = PF.BaseGrav.SrcField([rxLoc_t])
    survey_t = PF.BaseGrav.LinearSurvey(srcField)
    survey_t.dobs = survey.dobs[ind_t]
    survey_t.std = survey.std[ind_t]
    survey_t.ind = ind_t

    meshLocal = Utils.modelutils.meshBuilder(rxLoc,
                                             h,
                                             padDist,
                                             meshType='TREE',
                                             meshGlobal=meshInput,
                                             verticalAlignment='center')

    if topo is not None:
        meshLocal = Utils.modelutils.refineTree(meshLocal,
                                                topo,
                                                dtype='surface',
                                                nCpad=octreeTopo,
                                                finalize=False)

    # Refine the mesh around loc
    meshLocal = Utils.modelutils.refineTree(meshLocal,
                                            rxLoc[ind_t, :],
                                            dtype='surface',
                                            nCpad=octreeObs,
                                            finalize=True)

    actv_t = np.ones(meshLocal.nC, dtype='bool')

    Mesh.TreeMesh.writeUBC(
        meshLocal,
        work_dir + out_dir + 'OctreeMesh' + str(tt) + '.msh',
        models={work_dir + out_dir + 'Active' + str(tt) + '.act': actv_t})

    print(meshLocal.nC)
    # Create reduced identity map
    tileMap = Maps.Tile((mesh, actv), (meshLocal, actv_t))

    # Create the forward model operator
    prob = PF.Gravity.GravityIntegral(meshLocal,
                                      rhoMap=tileMap,
                                      actInd=actv_t,
                                      parallelized=True,
                                      Jpath=work_dir + out_dir + "Tile" +
                                      str(ind) + ".zarr")

    survey_t.pair(prob)

    # Data misfit function
    dmis = DataMisfit.l2_DataMisfit(survey_t)
    dmis.W = 1. / survey_t.std

    wrGlobal += prob.getJtJdiag(np.ones(tileMap.P.shape[1]), W=dmis.W)

    del meshLocal

    # Create combo misfit function
    return dmis, wrGlobal
Beispiel #4
0
    shift = np.squeeze(mesh.gridCC[ind, :]) - center

    mesh_t.x0 += shift
    mesh_t.number()

    # Extract model from global to local mesh
#    if driver.topofile is not None:
#        topo = np.genfromtxt(work_dir + driver.topofile,
#                             skip_header=1)
#        actv_t = Utils.surface2ind_topo(mesh_t, topo, 'N')
#        # actv_t = np.asarray(np.where(mkvc(actv))[0], dtype=int)
#    else:
    actv_t = np.ones(mesh_t.nC, dtype='bool')

    # Create reduced identity map
    tileMap = Maps.Tile((mesh, actv), (mesh_t, actv_t))
    tileMap.nCell = 27
    tileMap.nBlock = 3
    # Create the forward model operator
    prob = PF.Magnetics.MagneticVector(mesh_t, chiMap=tileMap, actInd=actv_t)
    survey_t.pair(prob)

    # Data misfit function
    dmis = DataMisfit.l2_DataMisfit(survey_t)
    dmis.W = 1./survey_t.std
#    ncell = Utils.mkvc(np.sum(prob.chiMap.deriv(0) > 0, axis=1))
#    ncell[ncell>0] = (1./ncell[ncell>0]).copy()
#    SCALE = Utils.sdiag(mesh_t.vol**(0))
    for ii in range(prob.F.shape[0]):
        wrGlobal += ((prob.F[ii, :])*(prob.chiMap.deriv(0)))**2.
Beispiel #5
0
    def createLocalProb(rxLoc, wrGlobal, lims, ind):
        # createLocalProb(rxLoc, wrGlobal, lims, ind)
        # Generate a problem, calculate/store sensitivities for
        # given data points

        # Grab the data for current tile
        ind_t = np.all([
            rxLoc[:, 0] >= lims[0], rxLoc[:, 0] <= lims[1],
            rxLoc[:, 1] >= lims[2], rxLoc[:, 1] <= lims[3], surveyMask
        ],
                       axis=0)

        # Remember selected data in case of tile overlap
        surveyMask[ind_t] = False

        # Create new survey
        rxLoc_t = PF.BaseMag.RxObs(rxLoc[ind_t, :])
        srcField = PF.BaseMag.SrcField([rxLoc_t], param=survey.srcField.param)
        survey_t = PF.BaseMag.LinearSurvey(srcField)
        survey_t.dobs = survey.dobs[ind_t]
        survey_t.std = survey.std[ind_t]
        survey_t.ind = ind_t

        Utils.io_utils.writeUBCmagneticsObservations(
            out_dir + 'Tile' + str(tt) + 'dat', survey_t, survey_t.dobs)

        meshLocal = Utils.modelutils.meshBuilder(newTopo,
                                                 h,
                                                 padDist,
                                                 meshType='TREE',
                                                 meshGlobal=meshInput,
                                                 verticalAlignment='center')

        if topo is not None:
            meshLocal = Utils.modelutils.refineTree(meshLocal,
                                                    topo,
                                                    dtype='surface',
                                                    octreeLevels=octreeTopo,
                                                    finalize=False)

        # Refine the mesh around loc
        meshLocal = Utils.modelutils.refineTree(
            meshLocal,
            newTopo[ind_t, :],
            dtype='surface',
            octreeLevels=octreeObs,
            octreeLevels_XY=octreeObs_XY,
            finalize=True,
        )

        actv_t = np.ones(meshLocal.nC, dtype='bool')

        # Create reduced identity map
        tileMap = Maps.Tile((mesh, actv), (meshLocal, actv_t), nBlock=3)

        actv_t = tileMap.activeLocal

        if homogenizeMref:
            # Interpolate the geo model
            _, ind = tree.query(meshLocal.gridCC)

            mgeo_t = ((actvMap * mref)[ind])[actv_t]

            # Build list of indecies for the geounits
            index = []
            for unit in geoUnits:
                index += [mgeo_t == unit]

            # Creat reduced identity map
            homogMap_t = Maps.SurjectUnits(index)
            homogMap.nBlock = 3

            if modelDecomposition:
                # Create Sum map
                mapping = Maps.SumMap(
                    [homogMap_t * wires.h**o, tileMap * wires.hetero])

            else:
                mapping = homogMap_t * wires.h**o

        else:
            mapping = tileMap

        # Create the forward model operator
        prob = PF.Magnetics.MagneticIntegral(meshLocal,
                                             chiMap=mapping,
                                             actInd=actv_t,
                                             parallelized=parallelized,
                                             Jpath=out_dir + "Tile" +
                                             str(ind) + ".zarr",
                                             maxRAM=maxRAM,
                                             modelType='vector',
                                             n_cpu=np.ceil(n_cpu / nTiles))

        survey_t.pair(prob)

        # Data misfit function
        dmis = DataMisfit.l2_DataMisfit(survey_t)
        dmis.W = 1. / survey_t.std

        wr = prob.getJtJdiag(np.ones(int(mapping.shape[1])), W=dmis.W)

        actvMap_t = Maps.InjectActiveCells(meshLocal, actv_t, 1e-8)
        nC_t = int(actv_t.sum())
        Mesh.TreeMesh.writeUBC(
            meshLocal,
            out_dir + 'OctreeMesh' + str(tt) + '.msh',
            models={
                out_dir + 'Wr_' + str(tt) + '.act':
                actvMap_t * np.sum(
                    (tileMap * wr).reshape(nC_t, 3, order='F')**2., axis=1)**
                0.5
            })
        wrGlobal += wr

        del meshLocal
        # Create combo misfit function
        return dmis, wrGlobal
Beispiel #6
0
    def createLocalProb(rxLoc, wrGlobal, lims, ind):

        # Grab the data for current tile
        ind_t = np.all([
            rxLoc[:, 0] >= lims[0], rxLoc[:, 0] <= lims[1],
            rxLoc[:, 1] >= lims[2], rxLoc[:, 1] <= lims[3], surveyMask
        ],
                       axis=0)

        # Remember selected data in case of tile overlap
        surveyMask[ind_t] = False

        # Create new survey
        rxLoc_t = PF.BaseMag.RxObs(rxLoc[ind_t, :])
        srcField = PF.BaseMag.SrcField([rxLoc_t], param=survey.srcField.param)
        survey_t = PF.BaseMag.LinearSurvey(srcField)
        survey_t.dobs = survey.dobs[ind_t]
        survey_t.std = survey.std[ind_t]
        survey_t.ind = ind_t

        meshLocal = meshutils.mesh_builder_xyz(topo,
                                               h,
                                               padding_distance=padDist,
                                               mesh_type='TREE',
                                               base_mesh=meshInput,
                                               depth_core=depth_core)

        if topo is not None:
            meshLocal = meshutils.refine_tree_xyz(meshLocal,
                                                  topo,
                                                  method='surface',
                                                  octree_levels=octreeTopo,
                                                  finalize=False)

        meshLocal = meshutils.refine_tree_xyz(
            meshLocal,
            rxLoc[ind_t, :],
            method='surface',
            max_distance=maxDist,
            octree_levels=octreeObs,
            octree_levels_padding=octreeObs_XY,
            finalize=True,
        )

        actv_t = np.ones(meshLocal.nC, dtype='bool')

        # Create reduced identity map
        tileMap = Maps.Tile((mesh, actv), (meshLocal, actv_t))

        actv_t = tileMap.activeLocal

        print(actv_t.sum(), meshLocal.nC)
        # Create the forward model operator
        prob = PF.Magnetics.MagneticIntegral(meshLocal,
                                             chiMap=tileMap,
                                             actInd=actv_t,
                                             parallelized='dask',
                                             Jpath=work_dir + out_dir +
                                             "Tile" + str(ind) + ".zarr",
                                             store_zarr=True)

        survey_t.pair(prob)

        # Data misfit function
        dmis = DataMisfit.l2_DataMisfit(survey_t)
        dmis.W = 1. / survey_t.std

        wr = prob.getJtJdiag(np.ones(tileMap.P.shape[1]), W=dmis.W)
        localMap = Maps.InjectActiveCells(meshLocal, actv_t, 1e-8)
        Mesh.TreeMesh.writeUBC(
            mesh,
            work_dir + out_dir + 'OctreeMesh' + str(tt) + '.msh',
            models={
                work_dir + out_dir + 'Wr_' + str(tt) + '.act': actvMap * wr
            })

        Mesh.TreeMesh.writeUBC(
            meshLocal,
            work_dir + out_dir + 'OctreeMesh' + str(tt) + '.msh',
            models={
                work_dir + out_dir + 'Wr_' + str(tt) + '.act':
                localMap * tileMap * wr
            })
        #    localMap = Maps.InjectActiveCells(meshLocal, actv_t, 1e-8)
        #    Mesh.TreeMesh.writeUBC(
        #                      meshLocal, work_dir + out_dir + 'OctreeMesh' + str(tt) + '.msh',
        #                      models={work_dir + out_dir + 'Wr_' + str(tt) + '.act': localMap*wr}
        #                    )
        #
        wrGlobal += wr

        del meshLocal

        # Create combo misfit function
        return dmis, wrGlobal
Beispiel #7
0
def createLocalProb(rxLoc, wrGlobal, ind_t, ind):
    # createLocalProb(rxLoc, wrGlobal, lims, ind)
    # Generate a problem, calculate/store sensitivities for
    # given data points

    # Grab the data for current tile
    # ind_t = np.all([rxLoc[:, 0] >= lims[0], rxLoc[:, 0] <= lims[1],
    #                 rxLoc[:, 1] >= lims[2], rxLoc[:, 1] <= lims[3],
    #                 surveyMask], axis=0)

    # Remember selected data in case of tile overlap
    surveyMask[ind_t] = False

    # Create new survey
    if input_dict["inversion_type"].lower() == 'grav':
        rxLoc_t = PF.BaseGrav.RxObs(rxLoc[ind_t, :])
        srcField = PF.BaseGrav.SrcField([rxLoc_t])
        survey_t = PF.BaseGrav.LinearSurvey(srcField)
        survey_t.dobs = survey.dobs[ind_t]
        survey_t.std = survey.std[ind_t]
        survey_t.ind = ind_t

        Utils.io_utils.writeUBCgravityObservations(outDir + "Tile" + str(ind) + '.dat', survey_t, survey_t.dobs)

    elif input_dict["inversion_type"].lower() in ['mag', 'mvi']:
        rxLoc_t = PF.BaseMag.RxObs(rxLoc[ind_t, :])
        srcField = PF.BaseMag.SrcField([rxLoc_t], param=survey.srcField.param)
        survey_t = PF.BaseMag.LinearSurvey(srcField)
        survey_t.dobs = survey.dobs[ind_t]
        survey_t.std = survey.std[ind_t]
        survey_t.ind = ind_t

        Utils.io_utils.writeUBCmagneticsObservations(outDir + "Tile" + str(ind) + '.dat', survey_t, survey_t.dobs)

    meshLocal = meshutils.mesh_builder_xyz(
        newTopo, core_cell_size, padding_distance=padding_distance, mesh_type='TREE', base_mesh=meshInput,
        depth_core=depth_core
    )

    if topo is not None:
        meshLocal = meshutils.refine_tree_xyz(
            meshLocal, topo, method='surface',
            octree_levels=octree_levels_topo, finalize=False
        )

    meshLocal = meshutils.refine_tree_xyz(
        meshLocal, rxLoc[ind_t, :], method='surface',
        max_distance=max_distance,
        octree_levels=octree_levels_obs,
        octree_levels_padding=octree_levels_padding,
        finalize=True,
    )

    # Need to find a way to compute sensitivities only for intersecting cells
    activeCells_t = np.ones(meshLocal.nC, dtype='bool')  # meshUtils.modelutils.activeTopoLayer(meshLocal, topo)

    # Create reduced identity map
    if input_dict["inversion_type"].lower() == 'mvi':
        nBlock = 3
    else:
        nBlock = 1

    tileMap = Maps.Tile((mesh, activeCells), (meshLocal, activeCells_t), nBlock=nBlock)

    activeCells_t = tileMap.activeLocal

    print(activeCells_t.sum(), meshLocal.nC)
    if input_dict["inversion_type"].lower() == 'grav':
        prob = PF.Gravity.GravityIntegral(
            meshLocal, rhoMap=tileMap, actInd=activeCells_t,
            parallelized=parallelized,
            Jpath=outDir + "Tile" + str(ind) + ".zarr",
            maxRAM=max_ram,
            n_cpu=n_cpu,
            )

    elif input_dict["inversion_type"].lower() == 'mag':
        prob = PF.Magnetics.MagneticIntegral(
            meshLocal, chiMap=tileMap, actInd=activeCells_t,
            parallelized=parallelized,
            Jpath=outDir + "Tile" + str(ind) + ".zarr",
            maxRAM=max_ram,
            n_cpu=n_cpu,
            )

    elif input_dict["inversion_type"].lower() == 'mvi':
        prob = PF.Magnetics.MagneticIntegral(
            meshLocal, chiMap=tileMap, actInd=activeCells_t,
            parallelized=parallelized,
            Jpath=outDir + "Tile" + str(ind) + ".zarr",
            maxRAM=max_ram,
            modelType='vector',
            n_cpu=n_cpu
        )

    survey_t.pair(prob)

    # Write out local active and obs for validation
    Mesh.TreeMesh.writeUBC(
      meshLocal, outDir + 'Octree_Tile' + str(ind) + '.msh',
      models={outDir + 'ActiveGlobal_Tile' + str(ind) + ' .act': activeCells_t}
    )

    # Data misfit function
    dmis = DataMisfit.l2_DataMisfit(survey_t)
    dmis.W = 1./survey_t.std

    wr = prob.getJtJdiag(np.ones(tileMap.shape[1]), W=dmis.W)

    wrGlobal += wr

    del meshLocal

    # Create combo misfit function
    return dmis
Beispiel #8
0
        def createLocalProb(rxLoc, wrGlobal, lims, tileID):

            # Grab the data for current tile
            ind_t = np.all([rxLoc[:, 0] >= lims[0], rxLoc[:, 0] <= lims[1],
                            rxLoc[:, 1] >= lims[2], rxLoc[:, 1] <= lims[3],
                            surveyMask], axis=0)

            # Remember selected data in case of tile overlap
            surveyMask[ind_t] = False

            # Create new survey
            rxLoc_t = PF.BaseGrav.RxObs(rxLoc[ind_t, :])
            srcField = PF.BaseGrav.SrcField([rxLoc_t])
            survey_t = PF.BaseGrav.LinearSurvey(srcField)
            survey_t.dobs = survey.dobs[ind_t]
            survey_t.std = survey.std[ind_t]
            survey_t.ind = ind_t

            meshLocal = Utils.modelutils.meshBuilder(
                rxLoc, h, padDist, meshType='TREE', meshGlobal=meshInput,
                verticalAlignment='center'
            )

            if topo is not None:
                meshLocal = Utils.modelutils.refineTree(
                    meshLocal, topo, dtype='surface',
                    nCpad=octreeTopo, finalize=False
                )

            # Refine the mesh around loc
            meshLocal = Utils.modelutils.refineTree(
                meshLocal, rxLoc[ind_t, :], dtype='surface',
                nCpad=octreeObs, finalize=True
            )

            actv_t = np.ones(meshLocal.nC, dtype='bool')

            Mesh.TreeMesh.writeUBC(
                  meshLocal,
                  out_dir + 'OctreeMesh' + str(tt) + '.msh',
                  models={
                    out_dir + 'Active' + str(tileID) + '.act':
                    actv_t
                    }
                )

            # Create reduced identity map
            tileMap = Maps.Tile((mesh, actv), (meshLocal, actv_t))

            actv_t = tileMap.activeLocal

            # Interpolate the geo model
            _, ind = tree.query(meshLocal.gridCC)

            mgeo_t = ((fullMap * mgeo)[ind])[actv_t]

            # Build list of indecies for the geounits
            index = []
            for unit in geoUnits:
                index += [mgeo_t == unit]

            # Creat reduced identity map
            homogMap_t = Maps.SurjectUnits(index)

            # Create Sum map
            sumMap = Maps.SumMap([homogMap_t*wires.h**o, tileMap*wires.hetero])

            # Create the forward model operator
            prob = PF.Gravity.GravityIntegral(
                meshLocal, rhoMap=sumMap,
                actInd=actv_t,
                parallelized=parallization,
                Jpath=out_dir + "Tile" + str(tileID) + ".zarr",
                n_cpu=n_cpu
                )

            survey_t.pair(prob)

            # Data misfit function
            dmis = DataMisfit.l2_DataMisfit(survey_t)
            dmis.W = 1./survey_t.std

            wrGlobal += prob.getJtJdiag(np.ones(wires.h**o.shape[1]), W=dmis.W)

            del meshLocal

            # Create combo misfit function
            return dmis, wrGlobal