Skip to content

Line Profiles

A line profile is a common method used to extract the variation of a field's value along a specified line through the data. In the context of MICRESS simulations, a line profile can be generated to analyze the distribution of elements or phase fractions across specific spatial coordinates.

The figure below illustrates a line profile extracted from a simulated iron (Fe) concentration field.

  • Left: A 2D color map representing the spatial distribution of Fe concentration. The dashed line represents the path along which the line profile is taken.
  • Right: The corresponding line profile taken along the dashed line. The x-axis represents the distance along the path in micrometers, while the y-axis represents the Fe concentration in atomic percent.

In this section, we will walk you through the process of generating line profiles from MICRESS binary files using MicPy and visualizing the result using Matplotlib.

Step 1: Loading the Field Data

To begin, we need to load the MICRESS binary files containing the simulation data. In this example, we will load the iron (Fe) and carbon (C) concentration fields from the corresponding binary files.

1
2
3
4
5
6
7
from micpy import bin

with bin.File("A001_Delta_Gamma.conc1") as fe_file:
    fe_field = fe_file.read_field(-1)

with bin.File("A001_Delta_Gamma.conc2") as c_file:
    c_field = c_file.read_field(-1)

At this stage, the fe_field and c_field variables contain the Fe and C concentration fields at the last time step, respectively.

Step 2: Defining the Line Path

Next, we define the coordinates of the path along which we will extract the line profile. In this case, we want to create a profile along a line in the x-direction along the length of the domain.

(x0, x1), (y0, y1), (z0, z1) = (0, 499), (0, 0), (1200, 1200)

You can modify these coordinates based on the specific region of interest in your simulation.

Step 3: Generating the Line Points

We now generate the line points by interpolating between the start and end coordinates. The number of points along the line is set to 1000 to ensure a high-resolution profile. You can adjust this value based on the desired level of detail.

import numpy as np

points = 1000
x = np.linspace(x0, x1, points)
y = np.linspace(y0, y1, points)
z = np.linspace(z0, z1, points)

x, y, and z are now arrays containing the interpolated coordinates along the line.

Step 4: Calculating the Distance Along the Line

Next, we compute the distance from (x0, y0, z0) for each point along the line. This is done by calculating the Euclidean distance between consecutive points and summing them up.

# Calculate the distances between consecutive points
consecutive_distances = np.sqrt(np.diff(x)**2 + np.diff(y)**2 + np.diff(z)**2)

# Calculate the spacing between grid points in micrometers
spacing = 1e4 * fe_field.spacing[0] # cm to µm

# Calculate the cumulative distances along the line in micrometers
distances = spacing * np.insert(np.cumsum(consecutive_distances), 0, 0)

The result is an array distances, which holds the distance of each point along the line from the starting point.

Step 5: Extracting the Field Data Along the Line

Now we extract the Fe and C concentration values along the specified line by using the rounded x, y, and z coordinates as indices.

# Round the coordinates to the nearest integer
xi = np.round(x).astype(int)
yi = np.round(y).astype(int)
zi = np.round(z).astype(int)

# Extract the Fe and C concentration profiles along the line
fe_profile = fe_field[zi, yi, xi]
c_profile = c_field[zi, yi, xi]

The result are the Fe and C concentration profiles along the specified line.

Step 6: Plotting the Line Profiles

Finally, we visualize the line profiles using Matplotlib:

import matplotlib.pyplot as plt

# Create a figure and axis
fig, ax = plt.subplots()

# Plot the Fe and C concentration profiles
ax.plot(distances, fe_profile, label="Fe", color="blue", linestyle="--")
ax.plot(distances, c_profile, label="C", color="green")

# Set the plot title, labels, and legend as well as grid
ax.set_title(f"Concentration profile from ({x0}, {y0}, {z0}) to ({x1}, {y1}, {z1})")
ax.set_xlabel("Distance [μm]")
ax.set_ylabel("Concentration [at%]")
ax.legend()
ax.grid(True)

The resulting plot shows the variation of Fe and C concentrations along the specified line path from (x=0, z=1200) to (x=499, z=1200).

Extracting Multiple Element Concentration Profiles

In this example, we will extract the concentration profiles of multiple elements along a line in the x-direction at z=250 from a set of MICRESS binary files.

First, we define a helper function to plot the field profiles along the specified line:

import numpy as np
import matplotlib.pyplot as plt
from micpy import bin

def plot_fields_profile(fields, labels, x_range, y_range, z_range, points=1000):
    (x0, x1), (y0, y1), (z0, z1) = x_range, y_range, z_range

    x = np.linspace(x0, x1, points)
    y = np.linspace(y0, y1, points)
    z = np.linspace(z0, z1, points)

    consecutive_distances = np.sqrt(np.diff(x)**2 + np.diff(y)**2 + np.diff(z)**2)
    spacing = 1e4 * fields[0].spacing[0] # cm to µm
    distances = spacing * np.insert(np.cumsum(consecutive_distances), 0, 0)

    xi = np.round(x).astype(int)
    yi = np.round(y).astype(int)
    zi = np.round(z).astype(int)

    fig, ax = plt.subplots()

    for field, label in zip(fields, labels):
        profile = field[zi, yi, xi]
        ax.plot(distances, profile, label=label)

    ax.set_title(f"Field profiles from ({x0}, {y0}, {z0}) to ({x1}, {y1}, {z1})")
    ax.set_xlabel("Distance [μm]")
    ax.set_ylabel("Field value")
    ax.legend(frameon=False, loc="upper right", bbox_to_anchor=(1.2, 1))
    ax.grid(True)

    return fig, ax

Next, we load the concentration fields of multiple elements from the binary files and plot the concentration profiles along the x-axis at z=250:

file_paths = [ f"A006_CMSX4.conc{i}" for i in range(1, 10) ]

fields = []
for file_path in file_paths:
    with bin.File(file_path) as file:
        field = file.read_field(-1)
        fields.append(field)

labels = ["Ni", "Cr", "Co", "Mo", "W", "Ta", "Al", "Ti", "Re"]
x_range, y_range, z_range = (0, 499), (0, 0), (250, 250)
fig, ax = plot_fields_profile(fields, labels, x_range, y_range, z_range)

ax.set_title("Concentration along the x-axis at z=250")
ax.set_ylabel("Concentration [at%]")

The resulting plot shows the concentration profiles of multiple elements along the specified line path.