Reading¶
MicPy provides several approaches to read data from MICRESS binary files. You can read all fields, specific fields by index, or fields based on a condition. Below are examples demonstrating the available options.
Return Type
The read()
method returns a Series
object irrespective of the number of fields read. In particular, if you read a single field, the result is still a Series
object of shape (1, z, y, x)
.
Reading All Fields¶
To read all fields from a binary file, you can use the read()
method without any arguments.
Reading a Single Field¶
If you want to read a specific field by its index, you can pass the index as an argument to the read()
method. For example, the following code reads the 10th field.
Reading Multiple Fields¶
You can also read multiple fields by providing a slice or list of indices to the read()
method. For example, the following code reads the first, second, second-to-last, and last fields.
from micpy import bin
with bin.File("A001_Delta_Gamma.conc1") as file:
series = file.read([0, 1, -2, -1])
Reading Fields Based on a Condition¶
For more advanced use cases, MicPy allows you to read fields based on a condition. The condition is a lambda
function that takes a field as an argument and returns a boolean value. If the function returns True
, the field is included in the result; otherwise, it is excluded. Below is an example that reads fields with a time between 10
and 20
.
from micpy import bin
with bin.File("A001_Delta_Gamma.conc1") as file:
condition = lambda field: field.time >= 10 and field.time < 20
series = file.read(condition)