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.
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.
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.
Reading the Time Series¶
After opening the file, you can read the time series from the binary file using the read()
method.
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.
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([[[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.
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.
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.
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.