<jupyter_start><jupyter_text>Get file paths<jupyter_code>msh_file = "DW_MeshConv4nm_25nmSep.vtu"
mag_file = "DW_MeshConv4nm_25nmSep.csv"
# scale for the points
scale = 1e9<jupyter_output><empty_output><jupyter_text>Generate raytracing - skip if generated<jupyter_code># get the mesh, scale the points to nm
msh = Mesh.from_file(msh_file, scale=scale)<jupyter_output><empty_output><jupyter_text>Make sure that the projection vector is correct and that the structure is oriented well<jupyter_code># get the projection vector
p = get_projection_vector(90, 0) # direction of xrays
n = [0, 1, 1] # normal to the projection plane
x0 = [-100, 0, 0] # point on the projection plane

# prepare raytracing object
raytr = RayTracing(msh, p, n=n, x0=x0)
struct = raytr.struct
struct_projected = raytr.struct_projected
vis = MeshVisualizer(struct, struct_projected)
vis.set_camera(dist=2e5)
vis.show()<jupyter_output><empty_output><jupyter_text>If raytracing file generated - skip if not<jupyter_code># load raytracing if exists
raytr = np.load("raytracing.npy", allow_pickle=True).item()
struct = raytr.struct
struct_projected = raytr.struct_projected<jupyter_output><empty_output><jupyter_text>Generate and save raytracing<jupyter_code>raytr.get_piercings()
# np.save("raytracing.npy", raytr, allow_pickle=True)<jupyter_output>100%|███████████████████████████████████████████████████████████████████████████████| 56592/56592 [07:29<00:00, 125.99it/s]<jupyter_text>Get the xmcd  Get magnetisation, fix vertex shufflingNote: sometimes if the mesh file has multiple parts, the paraview export and the original mesh coordinates are not in the same order. I add a function to fix that when necessary<jupyter_code>magnetisation, mag_points = load_mesh_magnetisation(mag_file, scale=scale)
shuffle_file = "shuffle_indx.npy"
try:
    shuffle_indx = np.load(shuffle_file)
except FileNotFoundError:
    print('File not found. Generating shuffle indx')
    shuffle_indx = msh.get_shuffle_indx(mag_points)
    np.save(shuffle_file, shuffle_indx)
magnetisation = magnetisation[shuffle_indx, :]
magnetisation, mag_points = load_mesh_magnetisation(mag_file, scale=scale)
shuffle_indx = msh.get_shuffle_indx(mag_points)
magnetisation = magnetisation[shuffle_indx, :]<jupyter_output><empty_output><jupyter_text>Get the colours and XMCD values<jupyter_code>xmcd_value = raytr.get_xmcd(magnetisation)
mag_colors = get_struct_face_mag_color(struct, magnetisation)
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)
Image.fromarray(vis.get_image_np())<jupyter_output><empty_output><jupyter_text>View different parts of the image separately  Both<jupyter_code>vis.update_colors(xmcd_value, mag_colors)
vis.view_both(azi=azi, center=center_peem, dist=dist_peem)
Image.fromarray(vis.get_image_np())<jupyter_output><empty_output><jupyter_text>Projection<jupyter_code>vis.view_projection(azi=azi, center=center_peem, dist=dist_peem)
Image.fromarray(vis.get_image_np())<jupyter_output><empty_output><jupyter_text>Structure<jupyter_code>center_struct = [75, 50, 0]
dist_struct = 1e4
vis.view_struct(azi=azi, center=center_struct, dist=dist_struct)
Image.fromarray(vis.get_image_np())<jupyter_output><empty_output><jupyter_text>Blurred image<jupyter_code>vis.view_projection(azi=azi, center=center_peem, dist=dist_peem)
Image.fromarray((vis.get_blurred_image(desired_background=0.7)*255).astype(np.uint8))<jupyter_output><empty_output><jupyter_text>Saving one render<jupyter_code>vis.view_both(azi=azi, center=center_peem, dist=dist_peem)
vis.save_render('mumax_shadow.png')
vis.view_projection()
blurred = vis.get_blurred_image(desired_background=0.7)
imsave('mumax_shadow_blurred.png', (blurred*255).astype(np.uint8), check_contrast=False)

vis.view_struct(azi=azi, center=center_struct, dist=dist_struct)
vis.save_render('mumax_structure_view.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12472160356347439, 'fraction_numerical': 0.02103439742637961, 'mean_word_length': 9.693121693121693, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 48, '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}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '1929', 'license': 'MIT', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1527, 'n_words': 255, 'path': 'testing/mumax_projection-Copy1.ipynb', 'repo_name': 'Skoricius/xmcd-projection', 'size': '4041'}