mmt_multipole_inversion.magnetic_sample#

Module Contents#

Classes#

MagneticSample

Class for the specification of a scan grid detecting the out plane flux of

Functions#

dipole_field(dip_r, dip_m, pos_r)

Compute the dipole field at the pos_r position(s), from a group of N

ran_sphere(n, ran_generator)

Random number generator

mmt_multipole_inversion.magnetic_sample.dipole_field(dip_r, dip_m, pos_r)#

Compute the dipole field at the pos_r position(s), from a group of N particles located at the dip_r dipole_positions, and which have magnetic dipole moments given in the dip_m array. For these arrays, N > 1.

Parameters
dip_r

N x 3 array with dipole dipole_positions (m)

dip_m

N x 3 array with dipole moments (Am^2)

pos_r

1 x 3 array (m)

Returns
dipole_field as N x 3 array, in Tesla units
mmt_multipole_inversion.magnetic_sample.ran_sphere(n, ran_generator)#

Random number generator

Parameters
ran_generator

A Numpy RandomState object to generate random numbers

class mmt_multipole_inversion.magnetic_sample.MagneticSample(Hz, Sx, Sy, Sdx, Sdy, Lx, Ly, Lz, sensor_origin=(0.0, 0.0), bz_field_module='spherical_harmonics_basis')#

Bases: object

Class for the specification of a scan grid detecting the out plane flux of the magnetic field generated by an arbitrary number of magnetic sources. The magnetic sources can be dipoles, quadrupoles or octupoles. The scan grid is defined in the XY plane, at a given height above the magnetic sample containing the point sources.

This class calculates the magnetic field from the point sources and adds them to generate the total flux at every area of the scan grid mesh.

                   Sdx
                ___/___
               /      /            Scan Grid
         _     ______________________________
  Sdy_ /     /       /      /       /       /
      /_    /_______/______/_______/_______/__      _
           /       /      /       /       /   /|     |
          / ______/______/_______/_______/   / |     |_ Lz
         /       /      /       /       /   /  |     |
     _  /_______/______/_______/_______/   /   |     |
Hx _|     /                O              /  O |    _|
    |_   /______________________________ /    /
        |                               |    /
        |            O                  |   /
        |   O                           |  /
        |    dipole               O     | /
        |_______________________________|/  Sample
get_metadict(self)#

Generate a dictionary with the keys defined in the _metadict variable. Values are obtained by calling the class instance attributes defined in the _metadict values. Because scan origin is a sequence, it is split in x and y components. This method is used to export sample properties as a json file.

generate_random_particles(self, N_particles=100, Ms=480000.0, seed=42, rmin=[0.1, 0.1, 0.1], rmax=[0.9, 0.9, 0.9])#

Generate a sample of dipole particles randomly distributed across the sample region. The dipole moments of the particles are randomly generated based on the saturation magnetization value Ms

Parameters
N_particles

Number of particles

Ms

Saturation magnetisation

seed

random number generator seed

rmin, rmax

minimum and maximum scale factors for the limits of the locations of the particles. The factors scale the sample dimensions in every dimension. For example, particles spread over the sample but close to the surface can be modelled by

rmin = [0.1, 0.1, 0.7] rmax = [0.9, 0.9, 0.9]

This means particle positions in the x-direction will vary between 0.1 and 0.9 of Lx, and so on.

generate_particles_from_array(self, positions, dipole_moments, volumes, quadrupole_moments=None, octupole_moments=None)#

Generate particles in the sample from arrays specified manually

Parameters
positions

N x 3 array (m units)

dipole_moments

N x 3 array (A m^2 unitS)

volumes

N x 3 array (m^3 units)

quadrupole_moments

N x 5 array with quadrupole moments

octupole_moments

N x 7 array with octupole moments

Notes

The multipole options need to be redefined (it depends on the basis we are expressing the multipole expansion)

generate_measurement_mesh(self)#

Generate the magnetic flux array at the scan surface, i.e. calculate the total Bz contribution from the particles at every grid point of the scan surface

generate_noised_Bz_array(self, std_dev, seed=4242)#

Add uncorrelated noise to the magnetic flux (Bz array). The new array is stored in self.Bz_array_noised Update the seed if necessar. For the seed a random number generator can be passed instead of an int.

save_data(self, filename='TIME_STAMP', basedir='', noised_array=False)#

Save the system properties as a json file and relevant arrays in a npz file: Bz_array, particle_positions, magnetization and volumes.

Parameters
filename

Name appended to the dictionary and arrays base name

basedir

An optional directory to which data is going to be stored

noised_array

Save the noised Bz_array instead of the original array

plot_sample(self, ax, contours=30, contourlines=15, contourf_args=dict(cmap='RdYlBu'), contour_args=dict(colors='k', linewidths=0.2), scatter_args=dict(c='k'), dimension_scale=1.0, data_scale=1.0, noised_array=False, imshow_args=None)#

(WILL BE REMOVED IN FUTURE) Plot the scan surface and the particles beneath using their xy position

Optional:

If imshow_args is specified, this functions uses imshow instead of contourf to plot the colored background with Bz_array. In this case, all the contourf args are ignored

Returns :: cf, c1, c2

where cf is the contour plot object showing Bz, c1 its contour lines and c2 the scatter plot with the particle positions