Skip to content

Introduction

MICRESS binary files store data related to the microstructural evolution of materials over time, comprising a time series of 3-dimensional fields that represent a specific property, such as the concentration of elements. In this guide, you will learn how to read MICRESS binary files using MicPy.

Importing the Module

To read MICRESS binary files in MicPy, you need to import the micpy.bin module. This module provides a set of classes and functions to handle binary files.

from micpy import bin

Initializing the File Object

Create an instance of the bin.File class by providing the path to the binary file. This initializes the file object attempting to process the corresponding geometry file.

file = bin.File("A001_Delta_Gamma.conc1")
Geometry: 2-Dimensional Grid
Grid Size [μm]: (500.0, 1.0, 1500.0)
Grid Shape (Cell Count): (500, 1, 1500)
Grid Spacing (Cell Size) [μm]: (1.0, 1.0, 1.0)

Output Verbosity

Per default, the File class prints information during various operations. For example, during initialization, it prints the geometry of the grid, the grid size, the grid shape, and the grid spacing. You can disable this behavior by setting the verbose parameter to False when creating the file object.

Opening the File

Next, open the file using the open() method. This prepares the file for reading.

file.open()
Indexing: Field 21. Elapsed Time: 0.66s. Average Time/Field: 0.03s

Reading the Time Series

After opening the file, you can read the time series from the binary file using the read() method.

series = file.read()
Reading: Field 21. Elapsed Time: 1.94s. Average Time/Field: 0.09s

The read() method returns a Series object. The Series object is a 4D NumPy array of shape (n, z, y, x), where n is the number of fields in the series, and (z, y, x) represents the shape of the fields.

You can check the shape of a Series object using the shape attribute.

print(series.shape)
(21, 500, 1, 1500)

The output indicates that there is a total of 21 time steps, and each field has a shape of (500, 1, 1500).

Accessing Fields

You can access individual fields from the Series object using the get_field() method. The get_field() method takes the index of a field as an argument and returns a Field object. For example, to access the 10th field in the series, call the get_field() method with the index 10.

field = series.get_field(10)
print(repr(field))
Field([[[0.3702711, 0.3702713, 0.3702719, ..., 0.3755523, 0.3755527, 0.3755528]],
       [[0.3702759, 0.3702761, 0.3702767, ..., 0.3755698, 0.3755702, 0.3755703]],
       [[0.3702879, 0.3702881, 0.3702887, ..., 0.3756004, 0.3756008, 0.3756009]],
       ...,
       [[1.0000001, 1.0000001, 1.0000001, ..., 1.0000001, 1.0000001, 1.0000001]],
       [[1.0000001, 1.0000001, 1.0000001, ..., 1.0000001, 1.0000001, 1.0000001]],
       [[1.0000001, 1.0000001, 1.0000001, ..., 1.0000001, 1.0000001, 1.0000001]]])

Extracting a field from the Series object returns a Field object, which is a 3D NumPy array of shape (z, y, x).

Analyzing the Data

You can perform various NumPy operations on both the Series and Field objects. For example, you can calculate the mean values using the mean() method.

mean_series = series.mean()
print(f"Mean value of the series: {mean_series}")
Mean value of the series: 1.006071
mean_field = field.mean()
print(f"Mean value of the field: {mean_field}")
Mean value of the field: 0.9999374

NumPy Integration

Both the Series and Field objects are subclassed from NumPy arrays, which means you can use any NumPy function or method to process the data. In contrast to standard NumPy arrays, the Series and Field objects provide additional MICRESS-specific metadata and auxiliary methods. For example, each Field object has attributes such as time and spacing, which store the corresponding values for the field.

Visualizing the Data

MicPy provides a built-in plotting function to visualize the field data.

fig, ax = bin.plot(field)

The plot() method returns a Matplotlib Figure and Axes object, which you can use to customize the plot further.

Closing the File

After finishing the reading process, it's important to close the file using the close() method.

file.close()

Context Manager

In this guide, we explicitly opened and closed the file using the open() and close() methods. Alternatively, you can use a context manager to handle the file more efficiently. For more information, refer to the Context Manager section.

Summary

By following these steps, you can read and access data from MICRESS binary files using MicPy. This process involves importing the necessary module, opening the binary file, reading the fields, and closing the file after completing the operations. You can analyze the field data using NumPy arrays and visualize it using the built-in plotting function.

Next Steps

Now that you have learned how to read MICRESS binary files using MicPy, you can explore more advanced features. Use the navigation menu on the left to access other sections of the user guide.