<commit_before>from __future__ import print_function
import unittest
from SimPEG.EM import FDEM, Analytics, mu_0
import numpy as np
from SimPEG import Mesh, Maps, Utils
import warnings

TOL = 0.5 # relative tolerance (to norm of soln)
plotIt = False

import matplotlib
matplotlib.use('Agg')

import matplotlib.pyplot as plt


class TestSimpleSourcePropertiesTensor(unittest.TestCase):

    def setUp(self):
        cs = 10.
        ncx, ncy, ncz = 30., 30., 30.
        npad = 10.
        hx = [(cs, npad, -1.5), (cs, ncx), (cs, npad, 1.5)]
        hy = [(cs, npad, -1.5), (cs, ncy), (cs, npad, 1.5)]
        hz = [(cs, npad, -1.5), (cs, ncz), (cs, npad, 1.5)]
        self.mesh = Mesh.TensorMesh([hx, hy, hz], 'CCC')
        mapping = Maps.ExpMap(self.mesh)

        self.freq = 1.

        self.prob_e = FDEM.Problem3D_e(self.mesh, sigmaMap=mapping)
        self.prob_b = FDEM.Problem3D_b(self.mesh, sigmaMap=mapping)
        self.prob_h = FDEM.Problem3D_h(self.mesh, sigmaMap=mapping)
        self.prob_j = FDEM.Problem3D_j(self.mesh, sigmaMap=mapping)

        loc = np.r_[0., 0., 0.]
        self.loc = Utils.mkvc(
            self.mesh.gridCC[Utils.closestPoints(self.mesh, loc, 'CC'), :]
        )

    def test_MagDipole(self):

        print('\ntesting MagDipole assignments')

        for orient in ['x', 'y', 'z', 'X', 'Y', 'Z']:
            src = FDEM.Src.MagDipole(
                [], freq=self.freq, loc=np.r_[0., 0., 0.], orientation=orient
            )

            # test assignments
            assert np.all(src.loc == np.r_[0., 0., 0.])
            assert src.freq == self.freq

            if orient.upper() == 'X':
                orient_vec = np.r_[1., 0., 0.]
            elif orient.upper() == 'Y':
                orient_vec = np.r_[0., 1., 0.]
            elif orient.upper() == 'Z':
                orient_vec = np.r_[0., 0., 1.]

            print (
                ' {0} component. src: {1}, expected: {2}'.format(
                    orient, src.orientation, orient_vec
                )
            )
            assert np.all(src.orientation == orient_vec)

    def test_MagDipoleSimpleFail(self):

        print('\ntesting MagDipole error handling')
        with self.assertRaises(Exception):
            FDEM.Src.MagDipole([], freq=self.freq, loc=np.r_[0., 0., 0.],
                               orientation=np.r_[2., 3., 2.])

        with warnings.catch_warnings(record=True):
            FDEM.Src.MagDipole([], freq=self.freq, loc=np.r_[0., 0., 0.],
                               orientation=np.r_[1., 0., 0.])
<commit_msg>whitespace cleanup<commit_after>from __future__ import print_function
import unittest

import matplotlib
matplotlib.use('Agg')

from SimPEG.EM import FDEM, Analytics, mu_0
import numpy as np
from SimPEG import Mesh, Maps, Utils
import warnings

TOL = 0.5 # relative tolerance (to norm of soln)
plotIt = False

import matplotlib.pyplot as plt


class TestSimpleSourcePropertiesTensor(unittest.TestCase):

    def setUp(self):
        cs = 10.
        ncx, ncy, ncz = 30., 30., 30.
        npad = 10.
        hx = [(cs, npad, -1.5), (cs, ncx), (cs, npad, 1.5)]
        hy = [(cs, npad, -1.5), (cs, ncy), (cs, npad, 1.5)]
        hz = [(cs, npad, -1.5), (cs, ncz), (cs, npad, 1.5)]
        self.mesh = Mesh.TensorMesh([hx, hy, hz], 'CCC')
        mapping = Maps.ExpMap(self.mesh)

        self.freq = 1.

        self.prob_e = FDEM.Problem3D_e(self.mesh, sigmaMap=mapping)
        self.prob_b = FDEM.Problem3D_b(self.mesh, sigmaMap=mapping)
        self.prob_h = FDEM.Problem3D_h(self.mesh, sigmaMap=mapping)
        self.prob_j = FDEM.Problem3D_j(self.mesh, sigmaMap=mapping)

        loc = np.r_[0., 0., 0.]
        self.loc = Utils.mkvc(
            self.mesh.gridCC[Utils.closestPoints(self.mesh, loc, 'CC'), :]
        )

    def test_MagDipole(self):

        print('\ntesting MagDipole assignments')

        for orient in ['x', 'y', 'z', 'X', 'Y', 'Z']:
            src = FDEM.Src.MagDipole(
                [], freq=self.freq, loc=np.r_[0., 0., 0.], orientation=orient
            )

            # test assignments
            assert np.all(src.loc == np.r_[0., 0., 0.])
            assert src.freq == self.freq

            if orient.upper() == 'X':
                orient_vec = np.r_[1., 0., 0.]
            elif orient.upper() == 'Y':
                orient_vec = np.r_[0., 1., 0.]
            elif orient.upper() == 'Z':
                orient_vec = np.r_[0., 0., 1.]

            print (
                ' {0} component. src: {1}, expected: {2}'.format(
                    orient, src.orientation, orient_vec
                )
            )
            assert np.all(src.orientation == orient_vec)

    def test_MagDipoleSimpleFail(self):

        print('\ntesting MagDipole error handling')
        with self.assertRaises(Exception):
            FDEM.Src.MagDipole(
                [], freq=self.freq, loc=np.r_[0., 0., 0.],
               orientation=np.r_[2., 3., 2.]
            )

        with warnings.catch_warnings(record=True):
            FDEM.Src.MagDipole(
                [], freq=self.freq, loc=np.r_[0., 0., 0.],
                orientation=np.r_[1., 0., 0.]
        )

{'fraction_non_alphanumeric': 0.15384615384615385, 'fraction_numerical': 0.02441387328037202, 'mean_word_length': 1.84878587196468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4429886', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1778, 'n_words': 407}