Skip to main content

A package for reading MATLAB .mat files, with support for MATLAB datatypes like table and string

Project description

Mat-IO Module

The mat-io module provides tools for loading and saving MAT-files, including MATLAB's classdef-based datatypes such as datetime, table and string. It supports almost all MATLAB object types, including user-defined objects and handle class objects. Additionally, it includes utilities to convert the following MATLAB datatypes into their respective Pythonic objects, and vice versa:

  • string
  • datetime, duration and calendarDuration
  • table and timetable
  • containers.Map and dictionary
  • categorical
  • Enumeration Instance Arrays

MAT-file versions v6, v7 and v7.3 are supported.

  • Versions v6 and v7 uses a modified version of scipy.io under the hood
  • Version v7.3 uses h5py to write in the HDF5 format.

Data is returned in the same format as scipy.io.loadmat does.

Installation

pip install mat-io

Usage

Loading MAT-files

from matio import load_from_mat

file_path = "path/to/your/file.mat"
data = load_from_mat(
    file_path,
    raw_data=False,
    add_table_attrs=False,
    mdict=None,
    variable_names=None,
)
  • raw_data: If True, returns raw property maps of Opaque class objects.
  • add_table_attrs: If True, adds custom Matlab Table or Timetable properties as pandas.DataFrame attributes.
  • mdict: If provided, this dictionary will be updated with the data from a MAT-file.
  • variable_names: A list of variable names to load from file.

Saving MAT-files

from matio import save_to_mat

file_path = "path/to/your/file.mat"
mdict = {"var1": data1, "var2": data2}
save_to_mat(
    file_path,
    mdict=mdict,
    version="v7.3",
    global_vars=None,
    oned_as="col",
    do_compression=True,
)
  • file_path: The file to save data.
  • mdict: A dictionary of {var_name: var_data} to write to MAT-files.
  • version: The MAT-file version to save to. Supported versions are v7.3 and v7. Defaults to v7.3 which is based on the HDF5 format.
  • global_vars: A list of variable names that are to be marked as global variables.
  • saveobj_classes: A list of class names that implement saveobj methods.
  • oned_as: The 2D shape to apply to unit numpy.ndarrays. Either row or col. Defaults to col.
  • do_compression: If False, does not compress data when saving.

List variables in a MAT-file

from matio import whosmat

file_path = "path/to/your/file.mat"
vars = whosmat(file_path)
# Returns (variable_name, dims, datatype/classname)
print(vars)

Opaque Class Objects

Opaque class objects are what MATLAB calls object instances. Opaque objects have different types. The most common is MCOS, which is used for all user-defined classdefs, enumeration classes, as well as most MATLAB datatypes like string, datetime and table.

Opaque objects are returned as an instance of class MatlabOpaque with the following attributes:

  • classname: The class name, including namespace qualifiers (if any).
  • type_system: An interal MATLAB type identifier. Usually MCOS, but could also be java or handle.
  • properties: A dictionary containing the property names and property values.
  • class_alias: This is an optional attribute containing class aliases, if any.

If the raw_data parameter is set to False, then load_from_mat converts these objects into a corresponding Pythonic datatype, if available. For a list of conversion rules between MATLAB and Python datatypes, see the documentation.

When writing objects, matio tries to guess the class name of the object. For example, pandas.DataFrames could be read in as table or timetable. User-defined objects must contain a dictionary of property name, value pairs wrapped around a MatlabOpaque instance.

from matio import save_to_mat
from matio.utils import MatlabOpaque

prop_map = {"prop1": val1, "prop2": val2}
mat_obj = MatlabOpaque(properties=prop_map, classname="MyClass")
mdict = {"var1": mat_obj}
data = save_to_mat(file_path="temp.mat", mdict=mdict)

If the class implements a custom saveobj method, this can be specified in the saveobj_classes argument in save_to_mat. The property map for such classes must contain a single property called any. Typically, the value of this property would be in a format output by the saveobj method. This would be the input for the loadobj method in the class, if defined. More information here.

Wrapper Classes

This package uses wrapper classes to represent Matlab object data to help distinguish from basic datatypes. These are as follows:

  • MatlabOpaque: A wrapper class for all opaque objects with three attributes: properties, classname, type_system. properties is a name-value pair dictionary for each property of the class saved to a MAT-file
  • MatlabOpaqueArray: A wrapper class subclassed from numpy.ndarray to represent object arrays. Each item in this array is a MatlabOpaque object.
  • MatlabEnumerationArray: A wrapper class subclassed from numpy.ndarray to represent enumeration instance arrays. Each item in this array is of type enum.Enum.
  • MatlabContainerMap: A wrapper class subclassed from collections.UserDict to represent container.Map objects. During save, dictionaries are converted to a struct. Wrap dictionaries around MatlabContainerMap to write to container.Map instead.

To save these types to a MAT-file, data must be wrapped around the relevant wrapper class. These can be imported from matio.utils. An example is shown below:

# Save dictionary as container.Map
from matio.utils import MatlabContainerMap
from matio import save_to_mat

map = {"a": 1, "b": 2}
map = MatlabContainerMap(map)
var_dict = {"myVar": map}
save_to_mat("file.mat", var_dict)

Contribution

Feel free to create a PR if you'd like to add something, or open up an issue if you'd like to discuss!

Acknowledgement

Huge thanks to mahalex for their breakdown of MAT-files. A lot of this wouldn't be possible without it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mat_io-0.7.1.tar.gz (588.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mat_io-0.7.1-cp313-cp313-win_amd64.whl (438.8 kB view details)

Uploaded CPython 3.13Windows x86-64

mat_io-0.7.1-cp313-cp313-win32.whl (424.7 kB view details)

Uploaded CPython 3.13Windows x86

mat_io-0.7.1-cp313-cp313-musllinux_1_2_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

mat_io-0.7.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

mat_io-0.7.1-cp313-cp313-macosx_11_0_arm64.whl (452.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

mat_io-0.7.1-cp312-cp312-win_amd64.whl (439.7 kB view details)

Uploaded CPython 3.12Windows x86-64

mat_io-0.7.1-cp312-cp312-win32.whl (425.1 kB view details)

Uploaded CPython 3.12Windows x86

mat_io-0.7.1-cp312-cp312-musllinux_1_2_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

mat_io-0.7.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

mat_io-0.7.1-cp312-cp312-macosx_11_0_arm64.whl (453.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

mat_io-0.7.1-cp311-cp311-win_amd64.whl (441.6 kB view details)

Uploaded CPython 3.11Windows x86-64

mat_io-0.7.1-cp311-cp311-win32.whl (427.5 kB view details)

Uploaded CPython 3.11Windows x86

mat_io-0.7.1-cp311-cp311-musllinux_1_2_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

mat_io-0.7.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

mat_io-0.7.1-cp311-cp311-macosx_11_0_arm64.whl (455.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file mat_io-0.7.1.tar.gz.

File metadata

  • Download URL: mat_io-0.7.1.tar.gz
  • Upload date:
  • Size: 588.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mat_io-0.7.1.tar.gz
Algorithm Hash digest
SHA256 6c82ad9ecc4f4f704b824ce7a7e998a34ba6a5ddb508b8d5b211f64087c249d6
MD5 92dceb3dbab9740f8539d2d86f7715ca
BLAKE2b-256 a7e7811b22745fd080276b50c5a48fe6dd9876641a94840db443ed2d025f378a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1.tar.gz:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: mat_io-0.7.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 438.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mat_io-0.7.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d6b18b1eb2117554ce7f36009fda2ae6d3d2ad7c3afca9bee9e332f275bd0eea
MD5 3d4d6217e431a72690ed126d1ad516d7
BLAKE2b-256 eb18f74ca51ea8d4cf4a3aa12869f656390bb16155ceb4b8210296d64a186d6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp313-cp313-win_amd64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp313-cp313-win32.whl.

File metadata

  • Download URL: mat_io-0.7.1-cp313-cp313-win32.whl
  • Upload date:
  • Size: 424.7 kB
  • Tags: CPython 3.13, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mat_io-0.7.1-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 985fdb34f30ab22a14aac8f924831f41c90cb01034ba32ef3bdab4b6224aa895
MD5 243b5961b4c199c81cface26bace0dac
BLAKE2b-256 6609968dff4ed3c05d58c062393cddca616df33ce3099ca1abaf488bb62d82e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp313-cp313-win32.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for mat_io-0.7.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 969f550a041bee2d561a6de553cfbc29527d67ea171e3fb7ebba1bab4c1a5322
MD5 747dbc449b85b4725a287c6a8ca51ea4
BLAKE2b-256 6d7c2fcea5594feab62c6e59906102c8e67969d939932b1c9b114b0870862ea0

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mat_io-0.7.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8c7a22457c3ae84e2902434784bae39eb8b4d6a76f9c1dffb2b48daca699d0ec
MD5 ba6c044243427feff22e57f7252b5a95
BLAKE2b-256 6d27861138d059cbc47b5a8a109718ac22f3fbf2bfca5898f8d3a157ae91817a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mat_io-0.7.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b076a8b9d11f49069c6c897a206e7e6e3ed98336a79f1aec5bcc6381b871eff
MD5 69ad7b5d00d594ff1f03a0702e5fe94c
BLAKE2b-256 a6c19b47ffe499f28f2fc229b286bed54d742a43315740fc201b65a31edf62d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: mat_io-0.7.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 439.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mat_io-0.7.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7bdca571aa85c439f90fd782ad3d989e76c714819aebe651ef59068d18342366
MD5 f112b5eb3d0a6dad98a91bce9fe6a5a0
BLAKE2b-256 5047b2bb6e5611e5e37cfaf24eb0ff862d6409baf92a7075a5d00ae7d9da0bb4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp312-cp312-win_amd64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp312-cp312-win32.whl.

File metadata

  • Download URL: mat_io-0.7.1-cp312-cp312-win32.whl
  • Upload date:
  • Size: 425.1 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mat_io-0.7.1-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 644ccb4e7a23a504934f3a047502f36ade83668374209700b5d2b0d78f7edab6
MD5 bcf06a5b7b4978e6a25d881f56e6a572
BLAKE2b-256 b4ca5203d5b489a10d2d48cb4a64727de3a88db3d12c207fb568cab0b6dc75c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp312-cp312-win32.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for mat_io-0.7.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1fa32534be9e2a05fc6765916e2f4c3a8cc313685224ae31b1c42b39e085999d
MD5 710d19b21f22fa98dcf9dc21d87a8122
BLAKE2b-256 17639f608bebdb1d697dcd5e14ca4f3e543ede13b3e0f2023a51c5f0e3293612

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mat_io-0.7.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8fa9288bd14c5578f1a0900b68796f51861df9b7f576d6100a5f80f4d927120f
MD5 2288c64822fedfe2cbd6cb716ff180a0
BLAKE2b-256 15e7189ca9a4def404c0ad9b8806c9390d946cebde99f9642d1111b9bab4033e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mat_io-0.7.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8d2d21fca4f61a5bf192359227a94b636e673bd99a9d70176186f2ce1589739d
MD5 236fc316c97ca8dc6ff98fd323d493ea
BLAKE2b-256 bf5e49e7c58bcbea0a41b36627d21fffdfd290739d026b6d5a1bc0f346606de4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: mat_io-0.7.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 441.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mat_io-0.7.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bf353869dd7cc74c8b2f35facbfe9d543d03f410b7b656ddeda5e2727cf832a4
MD5 74985ed770fbe96b81ea8fdb03b394e9
BLAKE2b-256 b993b61fae914eb8cd815a4eb6075466edd9f9f8f7bf72480319df0ca9649dbf

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp311-cp311-win_amd64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp311-cp311-win32.whl.

File metadata

  • Download URL: mat_io-0.7.1-cp311-cp311-win32.whl
  • Upload date:
  • Size: 427.5 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mat_io-0.7.1-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 52c4682382de482006b6ee9c64b401b52d838ab0b08b0270984ba2df5efe63ee
MD5 0662e7ebeb7fcab794638fbb706c9b44
BLAKE2b-256 504b14974bda8b4523049ee871f3ee7876c8f5bf7be5233fc1ca6ae89ad905db

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp311-cp311-win32.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for mat_io-0.7.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c4f5e94a5d38f584f4e69c945bf185010b55e9d09312286c4b0e911028a44ef9
MD5 b2cc57b83217dd444ac29e63e3c5680c
BLAKE2b-256 b656b528e974a6fc404550373801ad60e506db1c98b4110bdfca9c5c5d862608

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mat_io-0.7.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 883990fa5380c7f9b80bc33c4109b7d4109836491b24c0e9fe79489325b0eb1f
MD5 57ba89f8ef918e235ad33e022c3dd846
BLAKE2b-256 b5c9937f59b074ae74c80555e10dffb762ba6bdddf6426daa8ef5229e3a90ea1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mat_io-0.7.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mat_io-0.7.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c566665fd01b28416e14471e6d6b63e983bba451e6b44e2be6c0c324b2d02e2
MD5 ccbfd2950dde83247a2b985923e09e58
BLAKE2b-256 3b700c5f3cdaca92ea8227d2fe74335214e08d52aa1b902c1eb78b1df9ac11ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for mat_io-0.7.1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on foreverallama/matio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page