Module: micpy.bin¶
The micpy.bin module provides methods to read and write binary files.
Chunk dataclass ¶
A chunk of uncompressed binary data.
iterate(file, chunk_size, compressed=True, offset=0, decompressobj=None) staticmethod ¶
Yield chunks of uncompressed binary data.
Field ¶
Bases: ndarray
A field.
dimensions(shape) staticmethod ¶
Get the number of dimensions of a shape.
from_bytes(data, shape=None, spacing=None) staticmethod ¶
Create a new time step from bytes.
read(position, shape=None, spacing=None) staticmethod ¶
Read a field from a binary file.
to_bytes() ¶
Convert the field to bytes.
to_file(file, geometry=True) ¶
Write the field to a binary file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file | IO[bytes] | Binary file. | required |
geometry | bool |
| True |
write(filename, compressed=True, geometry=True) ¶
Write the field to a binary file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | Filename of the binary file. | required |
compressed | bool |
| True |
geometry | bool |
| True |
File ¶
A binary file.
__init__(filename, chunk_size=Chunk.DEFAULT_SIZE, verbose=True) ¶
Initialize a binary file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | File name. | required |
chunk_size | int | Chunk size in bytes. Defaults to | DEFAULT_SIZE |
verbose | bool | Verbose output. Defaults to | True |
Raises:
| Type | Description |
|---|---|
`FileNotFoundError` | If file is not found. |
close() ¶
Close the file.
create_index() ¶
Create an index of the file.
find_geometry(compressed=None) ¶
Find geometry file and read it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compressed | bool | True if file is compressed, False otherwise. Defaults to | None |
Raises:
| Type | Description |
|---|---|
`GeometryFileNotFoundError` | If no geometry file is found. |
`MultipleGeometryFilesError` | If multiple geometry files are found. |
index() ¶
Get the index of the file.
iterate() ¶
Iterate over fields in the file.
Returns:
| Type | Description |
|---|---|
Generator[Field, None, None] | A generator of fields. |
open() ¶
Open the file.
print_geometry() ¶
Get a string representation of the geometry.
read(key=None) ¶
read_field(field_id) ¶
Read a field from the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_id | int | Field ID. | required |
Returns:
| Type | Description |
|---|---|
Field | Field. |
read_geometry(filename, compressed=None) ¶
Read geometry from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | Filename of a geometry file. | required |
compressed | bool |
| None |
set_geometry(shape, spacing) ¶
Set the geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape | Tuple[int, int, int] | Shape of the geometry (z, y, x). | required |
spacing | Tuple[float, float, float] | Spacing of the geometry (dz, dy, dx) in μm. | required |
times() ¶
Get the times of the fields in the file.
Returns:
| Type | Description |
|---|---|
List[float] | List of times. |
update_index() ¶
Update the index of the file.
Header ¶
PlotArgs dataclass ¶
Arguments for plotting a field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title | str | Title of the plot. Defaults to | None |
xlabel | str | Label of the x-axis. Defaults to | None |
ylabel | str | Label of the y-axis. Defaults to | None |
figsize | Tuple[float, float] | Figure size. Defaults to | None |
dpi | int | Figure DPI. Defaults to | None |
aspect | str | Aspect ratio. Defaults to | 'equal' |
ax | Axes | Axes of the plot. Defaults to | None |
cax | Axes | Axes of the color bar. Defaults to | None |
vmin | float | Minimum value of the color bar. Defaults to | None |
vmax | float | Maximum value of the color bar. Defaults to | None |
cmap | str | Colormap. Defaults to | 'micpy' |
alpha | float | Transparency of the plot. Defaults to | 1.0 |
interpolation | str | Interpolation method. Defaults to | 'none' |
extent | Tuple[float, float, float, float] | Extent of the plot. | None |
Position dataclass ¶
A field position in a binary file.
iterate(file=None, compressed=True, chunk_size=Chunk.DEFAULT_SIZE, position=None) staticmethod ¶
Yield positions of fields in a binary file.
Series ¶
Bases: ndarray
get_field(index) ¶
Get a field from the series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index | int | Index of the field. | required |
Returns:
| Type | Description |
|---|---|
Field | Field. |
get_series(key) ¶
Get a series of fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | Union[int, slice, list] | Key to list of field IDs, a slice object, or a list of field IDs. | required |
Returns:
| Type | Description |
|---|---|
Series | Series of fields. |
iter_field() ¶
Iterate over fields in the series.
Yields:
| Type | Description |
|---|---|
| Field. |
write(filename, compressed=True, geometry=True) ¶
Write the series to a binary file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | Filename of the binary file. | required |
compressed | bool |
| True |
geometry | bool |
| True |
plot(field, axis='y', index=0, args=None) ¶
Plot a slice of the field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field | Field | Field to plot. | required |
axis | str | Axis to plot. Possible values are | 'y' |
index | int | Index of the slice. Defaults to | 0 |
args | PlotArgs | Arguments for plotting. Defaults to | None |
Returns:
| Type | Description |
|---|---|
Tuple[Figure, Axes] | Matplotlib figure, axes, and color bar. |