Skip to main content

Library for simulating XMCD projection signal

Project description

XMCD Projection

Documentation Status DOI PyPi version

Projection simulation of the PEEM structures

Installation

The project is available on PyPi:

pip install xmcd-projection

In order to run the example notebooks, jupyter also needs to be installed:

pip install jupyter

Usage

See the docs for details and examples:

If running in Jupyter, make sure you use qt gui for the visualizer to work:

%gui qt
%matplotlib qt

From GMSH .msh file and magnetisation in .csv exported from Magnumfe data

To do this, have .msh file exported by GMSH and the magnetisation data by importing the data in Paraview and going to Save Data... and exporting to .csv. See examples/example_script.py:

    from xmcd_projection import *

    msh_file = "example_mesh.msh"
    mag_file = "mag_data.csv"

    # get the mesh
    msh = Mesh.from_file(msh_file)
    # get the projection vector
    p = get_projection_vector(90, 16)

    # prepare raytracing object
    raytr = RayTracing(msh, p)
    raytr.get_piercings()
    struct = raytr.struct
    struct_projected = raytr.struct_projected

    # load magnetization and make sure the indices are not shuffled
    magnetisation, mag_points = load_mesh_magnetisation(mag_file)
    shuffle_indx = msh.get_shuffle_indx(mag_points)
    magnetisation = magnetisation[shuffle_indx, :]

    # get the colours and xmcd values
    xmcd_value = raytr.get_xmcd(magnetisation)
    mag_colors = get_struct_face_mag_color(struct, magnetisation)

    # define the visualizer parameters and show
    azi = 90
    center_struct = [0, 0, 0]
    dist_struct = 2e4
    center_peem = [0, -1000, 0]
    dist_peem = 2e5

    vis = MeshVisualizer(struct, struct_projected,
                        projected_xmcd=xmcd_value, struct_colors=mag_colors)
    vis.show(azi=azi, center=center_peem, dist=dist_peem)
    vis.start()

From .vtk generated from Mumax data

Import .vtk file in Paraview, go to Saving Data... and export to .vtu format for the mesh, and .csv format for the magnetization. Ensure that you are only exporting the part with nonzero magnetization. This can be achieved by setting a threshold in Paraview. Then, it is very similar to Magnum.fe, only care needs to be taken to set the appropriate scale. See examples/mumax_example_script.py:

    from xmcd_projection import *

    msh_file = "mumax_mesh.vtu"
    mag_file = "mumax_mag.csv"
    # need to scale points to get them in nm
    scale = 1e9

    # get the mesh
    msh = Mesh.from_file(msh_file, scale=scale)
    print(msh.cells)
    # get the projection vector
    p = get_projection_vector(90, 16)

    # prepare raytracing object
    raytr = RayTracing(msh, p)
    raytr.get_piercings()
    struct = raytr.struct
    struct_projected = raytr.struct_projected

    # load magnetization and make sure the indices are not shuffled
    magnetisation, mag_points = load_mesh_magnetisation(mag_file, scale=scale)
    shuffle_indx = msh.get_shuffle_indx(mag_points)
    magnetisation = magnetisation[shuffle_indx, :]

    # get the colours and xmcd values
    xmcd_value = raytr.get_xmcd(magnetisation)
    mag_colors = get_struct_face_mag_color(struct, magnetisation)

    # define the visualizer parameters and show
    azi = 90
    center_struct = [0, 0, 0]
    dist_struct = 1e4
    center_peem = [100, -200, 0]
    dist_peem = 8e4

    vis = MeshVisualizer(struct, struct_projected,
                        projected_xmcd=xmcd_value, struct_colors=mag_colors)
    vis.show(azi=azi, center=center_peem, dist=dist_peem)
    vis.start()

From STL file and magnetisation as numpy array

This is older version of the library, so might not work as well. Here just in case it is needed in the future

%gui qt
%matplotlib qt
from  xmcd_projection import *
from xmcd_projection.stl_visualisation import *
import trimesh
structure_file = r"testing\SOL6-1-3.stl"
magnetisation_file = r"testing\SOL6-1-3_uniform_mag.p"

struct = trimesh.load(structure_file)
magnetisation = np.zeros(struct.vertices.shape)
magnetisation[:, 1] = 1

# define projection vector
p = get_projection_vector(90, 15)

# create visualisation
v = Visualizer(struct, magnetisation, p)
v.generate_view()
v.show()
v.save_render('test1.png')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

XMCD Projection-1.0.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

XMCD_Projection-1.0.1-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file XMCD Projection-1.0.1.tar.gz.

File metadata

  • Download URL: XMCD Projection-1.0.1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for XMCD Projection-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7c1dd73060a93002a9222a67e770d3073ffe4487d84ba0d423711a2519dae871
MD5 46ea51f9350f51eb19c87ab2a0c569f8
BLAKE2b-256 71ba36d099f6ff887458b585f75f938102337a4bac762bc075c4c3e1cc861716

See more details on using hashes here.

File details

Details for the file XMCD_Projection-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: XMCD_Projection-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for XMCD_Projection-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 16be388d368cc07578629b3d654a997f110c23adce4311eca2ac758c21de3014
MD5 3d3cab3f035c4341d816e1bd7d257dba
BLAKE2b-256 bc36438f89b8f8a8ee3badf01775e85c791b763c27959b85ec2dc6e30f1c3b49

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page