<commit_before>from SimPEG import *
import SimPEG.EM as EM

import matplotlib.pyplot as plt  
from matplotlib.colors import LogNorm

x = np.arange(-100.5,100.5,step = 1.) #(avoid putting measurement points where source is located)
y = np.r_[0]
z = x

sig = 1.
freq = 1. 

XYZ = Utils.ndgrid(x,y,z)


def run(XYZ=XYZ,sig=sig,freq=freq,orientation='Z', plotIt=True):
    """
        EM: Magnetic Dipole in a Whole-Space
        ====================================

        Here we plot the magnetic flux density from a harmonic dipole in a wholespace. 

    """

    Bx, By, Bz = EM.Analytics.FDEM.MagneticDipoleWholeSpace(XYZ, np.r_[0.,0.,0.], sig, freq,orientation=orientation)
    absB = np.sqrt(Bx*Bx.conj()+By*By.conj()+Bz*Bz.conj()).real


    if plotIt: 
        fig, ax = plt.subplots(1,1,figsize=(6,5))
        bxplt = Bx.reshape(x.size,z.size)
        bzplt = Bz.reshape(x.size,z.size)
        pc = ax.pcolor(x,z,absB.reshape(x.size,z.size),norm=LogNorm())
        ax.streamplot(x,z,bxplt.real,bzplt.real,color='k',density=1)
        ax.set_xlim([x.min(),x.max()])
        ax.set_ylim([z.min(),z.max()])
        ax.set_xlabel('x')
        ax.set_ylabel('z')
        cb = plt.colorbar(pc,ax = ax)
        cb.set_label('|B| (T)')
        plt.show()

        return fig, ax

if __name__ == '__main__':
    run()<commit_msg>Clean up init code, put inside run, remove mpl from TL import.<commit_after>from SimPEG import *
import SimPEG.EM as EM

def run(XYZ=None, sig=1.0, freq=1.0, orientation='Z', plotIt=True):
    """
        EM: Magnetic Dipole in a Whole-Space
        ====================================

        Here we plot the magnetic flux density from a harmonic dipole in a wholespace.

    """

    if XYZ is None:
        x = np.arange(-100.5,100.5,step = 1.) #(avoid putting measurement points where source is located)
        y = np.r_[0]
        z = x
        XYZ = Utils.ndgrid(x,y,z)


    Bx, By, Bz = EM.Analytics.FDEM.MagneticDipoleWholeSpace(XYZ, np.r_[0.,0.,0.], sig, freq, orientation=orientation)
    absB = np.sqrt(Bx*Bx.conj()+By*By.conj()+Bz*Bz.conj()).real


    if plotIt:
        import matplotlib.pyplot as plt
        from matplotlib.colors import LogNorm
        fig, ax = plt.subplots(1,1,figsize=(6,5))
        bxplt = Bx.reshape(x.size,z.size)
        bzplt = Bz.reshape(x.size,z.size)
        pc = ax.pcolor(x,z,absB.reshape(x.size,z.size),norm=LogNorm())
        ax.streamplot(x,z,bxplt.real,bzplt.real,color='k',density=1)
        ax.set_xlim([x.min(),x.max()])
        ax.set_ylim([z.min(),z.max()])
        ax.set_xlabel('x')
        ax.set_ylabel('z')
        cb = plt.colorbar(pc,ax = ax)
        cb.set_label('|B| (T)')
        plt.show()

        return fig, ax

if __name__ == '__main__':
    run()

{'fraction_non_alphanumeric': 0.18307301126044315, 'fraction_numerical': 0.015256084271703597, 'mean_word_length': 2.7520435967302452, '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': '132881', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1052, 'n_words': 208}