Ejemplo n.º 1
0
    def test_io_dpred(self):

        pp_data = Data(survey=self.pp_survey, dobs=self.dobs)
        dpdp_data = Data(survey=self.dpdp_survey, dobs=self.dobs)

        filename = "dpred.dc"

        # Test for pole-pole
        write_dcip3d_ubc(
            filename, pp_data, "secondary_potential", "dpred", format_type="general"
        )
        data_loaded = read_dcip3d_ubc(filename, "secondary_potential")
        os.remove(filename)

        A = np.c_[
            self.pp_survey.locations_a,
            self.pp_survey.locations_b,
            self.pp_survey.locations_m,
            self.pp_survey.locations_n,
            self.dobs,
        ]

        B = np.c_[
            data_loaded.survey.locations_a,
            data_loaded.survey.locations_b,
            data_loaded.survey.locations_m,
            data_loaded.survey.locations_n,
            data_loaded.dobs,
        ]

        passed = np.all(np.isclose(A, B))
        self.assertTrue(passed, True)

        # Test for dipole-dipole
        write_dcipoctree_ubc(
            filename, dpdp_data, "volt", "dpred", format_type="general"
        )
        data_loaded = read_dcipoctree_ubc(filename, "volt")
        os.remove(filename)

        A = np.c_[
            self.dpdp_survey.locations_a,
            self.dpdp_survey.locations_b,
            self.dpdp_survey.locations_m,
            self.dpdp_survey.locations_n,
            self.dobs,
        ]

        B = np.c_[
            data_loaded.survey.locations_a,
            data_loaded.survey.locations_b,
            data_loaded.survey.locations_m,
            data_loaded.survey.locations_n,
            data_loaded.dobs,
        ]

        passed = np.all(np.isclose(A, B))
        self.assertTrue(passed, True)

        print("PREDICTED DATA FILE IO FOR DCIP3D PASSED")
Ejemplo n.º 2
0
    def test_io_dobs(self):

        pp_data = Data(survey=self.pp_survey,
                       dobs=self.dobs,
                       standard_deviation=self.std)
        dpdp_data = Data(survey=self.dpdp_survey,
                         dobs=self.dobs,
                         standard_deviation=self.std)

        filename = "dobs.dc"

        # Test for pole-pole
        write_dcip3d_ubc(filename,
                         pp_data,
                         "secondary_potential",
                         "dobs",
                         format_type="general")
        data_loaded = read_dcip3d_ubc(filename, "secondary_potential")
        os.remove(filename)

        A = np.c_[self.pp_survey.a_locations, self.pp_survey.b_locations,
                  self.pp_survey.m_locations, self.pp_survey.n_locations,
                  self.dobs, self.std, ]

        B = np.c_[data_loaded.survey.a_locations,
                  data_loaded.survey.b_locations,
                  data_loaded.survey.m_locations,
                  data_loaded.survey.n_locations, data_loaded.dobs,
                  data_loaded.standard_deviation, ]

        passed = np.all(np.isclose(A, B))
        self.assertTrue(passed, True)

        # Test for dipole-dipole
        write_dcipoctree_ubc(filename,
                             dpdp_data,
                             "volt",
                             "dobs",
                             format_type="general")
        data_loaded = read_dcipoctree_ubc(filename, "volt")
        os.remove(filename)

        A = np.c_[self.dpdp_survey.a_locations, self.dpdp_survey.b_locations,
                  self.dpdp_survey.m_locations, self.dpdp_survey.n_locations,
                  self.dobs, self.std, ]

        B = np.c_[data_loaded.survey.a_locations,
                  data_loaded.survey.b_locations,
                  data_loaded.survey.m_locations,
                  data_loaded.survey.n_locations, data_loaded.dobs,
                  data_loaded.standard_deviation, ]

        passed = np.all(np.isclose(A, B))
        self.assertTrue(passed, True)

        print("OBSERVATIONS FILE IO FOR DCIP3D PASSED")
Ejemplo n.º 3
0
    def test_io_survey(self):

        pp_data = Data(survey=self.pp_survey)
        dpdp_data = Data(survey=self.dpdp_survey)

        filename = "survey.dc"

        # Test for pole-pole
        write_dcip3d_ubc(filename,
                         pp_data,
                         "secondary_potential",
                         "survey",
                         format_type="general")
        data_loaded = read_dcip3d_ubc(filename, "secondary_potential")
        os.remove(filename)

        A = np.c_[self.pp_survey.a_locations, self.pp_survey.b_locations,
                  self.pp_survey.m_locations, self.pp_survey.n_locations, ]

        B = np.c_[data_loaded.survey.a_locations,
                  data_loaded.survey.b_locations,
                  data_loaded.survey.m_locations,
                  data_loaded.survey.n_locations, ]

        passed = np.all(np.isclose(A, B))
        self.assertTrue(passed, True)

        # Test for dipole-dipole
        write_dcipoctree_ubc(filename,
                             dpdp_data,
                             "volt",
                             "survey",
                             format_type="general")
        data_loaded = read_dcipoctree_ubc(filename, "volt")
        os.remove(filename)

        A = np.c_[self.dpdp_survey.a_locations, self.dpdp_survey.b_locations,
                  self.dpdp_survey.m_locations, self.dpdp_survey.n_locations, ]

        B = np.c_[data_loaded.survey.a_locations,
                  data_loaded.survey.b_locations,
                  data_loaded.survey.m_locations,
                  data_loaded.survey.n_locations, ]

        passed = np.all(np.isclose(A, B))
        self.assertTrue(passed, True)

        print("SURVEY FILE IO FOR DCIP3D PASSED")
Ejemplo n.º 4
0
    def test_io_dobs(self):

        data_object = Data(survey=self.survey,
                           dobs=self.dobs,
                           standard_deviation=self.std)
        filename = "dpred.mag"

        write_magnetics_3d_ubc(filename, data_object)
        data_loaded = read_magnetics_3d_ubc(filename)
        os.remove(filename)

        passed = np.all(
            np.isclose(
                np.c_[self.survey.receiver_locations, self.dobs, self.std],
                np.c_[data_loaded.survey.receiver_locations, data_loaded.dobs,
                      data_loaded.standard_deviation, ],
            ))
        self.assertTrue(passed, True)

        passed = np.all(
            np.isclose(
                self.survey.source_field.parameters,
                data_loaded.survey.source_field.parameters,
            ))
        self.assertTrue(passed, True)

        print("OBSERVED DATA FILE IO FOR MAG3D PASSED")
Ejemplo n.º 5
0
    def test_io_dpred(self):

        data_object = Data(survey=self.survey, dobs=self.dobs)
        filename = "dpred.mag"

        write_mag3d_ubc(filename, data_object)
        data_loaded = read_mag3d_ubc(filename)
        os.remove(filename)

        passed = np.all(
            np.isclose(
                np.c_[self.survey.receiver_locations, self.dobs],
                np.c_[data_loaded.survey.receiver_locations, data_loaded.dobs],
            )
        )
        self.assertTrue(passed, True)

        passed = np.all(
            np.isclose(
                self.survey.source_field.parameters,
                data_loaded.survey.source_field.parameters,
            )
        )
        self.assertTrue(passed, True)

        print("PREDICTED DATA FILE IO FOR MAG3D PASSED")
Ejemplo n.º 6
0
    def test_io_survey(self):

        data_object = Data(survey=self.survey)
        filename = "survey.mag"

        write_mag3d_ubc(filename, data_object)
        data_loaded = read_mag3d_ubc(filename)
        os.remove(filename)

        passed = np.all(
            np.isclose(
                self.survey.receiver_locations, data_loaded.survey.receiver_locations
            )
        )
        self.assertTrue(passed, True)

        passed = np.all(
            np.isclose(
                self.survey.source_field.parameters,
                data_loaded.survey.source_field.parameters,
            )
        )
        self.assertTrue(passed, True)

        print("SURVEY FILE IO FOR MAG3D PASSED")
Ejemplo n.º 7
0
    def test_io_dobs(self):

        data_object = Data(
            survey=self.survey, dobs=self.dobs, standard_deviation=self.std
        )
        filename = "dpred.gg"

        write_gg3d_ubc(filename, data_object)
        data_loaded = read_gg3d_ubc(filename)
        os.remove(filename)

        passed = np.all(
            np.isclose(
                self.survey.receiver_locations, data_loaded.survey.receiver_locations
            )
        )
        self.assertTrue(passed, True)

        passed = np.all(np.isclose(self.dobs, data_loaded.dobs))
        self.assertTrue(passed, True)

        passed = np.all(np.isclose(self.std, data_loaded.standard_deviation))
        self.assertTrue(passed, True)

        print("OBSERVED DATA FILE IO FOR GG3D PASSED")
Ejemplo n.º 8
0
    def test_io_survey(self):

        data_object = Data(survey=self.survey)
        filename = "survey.grv"

        write_gravity_3d_ubc(filename, data_object)
        data_loaded = read_gravity_3d_ubc(filename)
        os.remove(filename)

        passed = np.all(
            np.isclose(self.survey.receiver_locations,
                       data_loaded.survey.receiver_locations))
        self.assertTrue(passed, True)

        print("SURVEY FILE IO FOR GRAV3D PASSED")
Ejemplo n.º 9
0
    def test_io_dpred(self):

        data_object = Data(survey=self.survey, dobs=self.dobs)
        filename = "dpred.grv"

        write_gravity_3d_ubc(filename, data_object)
        data_loaded = read_gravity_3d_ubc(filename)
        os.remove(filename)

        passed = np.all(
            np.isclose(
                np.c_[self.survey.receiver_locations, self.dobs],
                np.c_[data_loaded.survey.receiver_locations, data_loaded.dobs],
            ))
        self.assertTrue(passed, True)

        print("PREDICTED DATA FILE IO FOR GRAV3D PASSED")
    def run_inversion_cg(
        self,
        maxIter=60,
        m0=0.0,
        mref=0.0,
        percentage=5,
        floor=0.1,
        chifact=1,
        beta0_ratio=1.0,
        coolingFactor=1,
        coolingRate=1,
        alpha_s=1.0,
        alpha_x=1.0,
        use_target=False,
    ):
        sim = self.get_simulation()
        data = Data(sim.survey,
                    dobs=self.data,
                    relative_error=percentage,
                    noise_floor=floor)
        self.uncertainty = data.uncertainty

        m0 = np.ones(self.M) * m0
        mref = np.ones(self.M) * mref
        reg = regularization.Tikhonov(self.mesh,
                                      alpha_s=alpha_s,
                                      alpha_x=alpha_x,
                                      mref=mref)
        dmis = data_misfit.L2DataMisfit(data=data, simulation=sim)

        opt = optimization.InexactGaussNewton(maxIter=maxIter, maxIterCG=20)
        opt.remember("xc")
        opt.tolG = 1e-10
        opt.eps = 1e-10
        invProb = inverse_problem.BaseInvProblem(dmis, reg, opt)
        save = directives.SaveOutputEveryIteration()
        beta_schedule = directives.BetaSchedule(coolingFactor=coolingFactor,
                                                coolingRate=coolingRate)
        target = directives.TargetMisfit(chifact=chifact)

        if use_target:
            directs = [
                directives.BetaEstimate_ByEig(beta0_ratio=beta0_ratio),
                beta_schedule,
                target,
                save,
            ]
        else:
            directs = [
                directives.BetaEstimate_ByEig(beta0_ratio=beta0_ratio),
                beta_schedule,
                save,
            ]
        inv = inversion.BaseInversion(invProb, directiveList=directs)
        mopt = inv.run(m0)
        model = opt.recall("xc")
        model.append(mopt)
        pred = []
        for m in model:
            pred.append(sim.dpred(m))
        return model, pred, save