mammos_entity#

Entity (Quantity and EMMO ontology label).

Exposes the primary components of the MaMMoS entity package, including the Entity class for ontology-linked physical quantities, pre-defined factory methods for common magnetic entities (Ms, A, Ku, H), and the loaded MaMMoS ontology object.

mammos_entity.A(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the exchange stiffness constant (A).

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to exchange stiffness. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘J/m’). If omitted, the SI unit from the ontology, i.e. J/m, will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labeled “ExchangeStiffnessConstant”.

Return type:

Entity

mammos_entity.B(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the magnetic flux density (B).

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to the magnetic flux density. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘T’). If omitted, the SI unit from the ontology, i.e. T, will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labelled “MagneticFluxDensity”.

Return type:

Entity

mammos_entity.BHmax(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the maximum energy product of the hysteresis loop.

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to the maximum energy product. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘J/m3’). If omitted, the SI unit from the ontology, i.e. J/m3, will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labelled “MaximumEnergyProduct”.

Return type:

Entity

class mammos_entity.Entity[source]#

Create a quantity (a value and a unit) linked to the EMMO ontology.

Represents a physical property or quantity that is linked to an ontology concept. It enforces unit compatibility with the ontology.

Parameters:
  • ontology_label – Ontology label

  • value – Value

  • unit – Unit

  • description – Description

Examples

>>> import mammos_entity as me
>>> import mammos_units as u
>>> Ms = me.Entity(ontology_label='SpontaneousMagnetization', value=8e5, unit='A / m')
>>> H = me.Entity("ExternalMagneticField", 1e4 * u.A / u.m)
>>> Tc_mK = me.Entity("CurieTemperature", 300, unit=u.mK)
>>> Tc_K = me.Entity("CurieTemperature", Tc_mK, unit=u.K)
>>> Tc_kuzmin = me.Entity("CurieTemperature", 0.1, description="Temperature estimated via Kuzmin model")
__init__(ontology_label, value=0, unit=None, description='')[source]#
Parameters:
property axis_label: str#

Return an ontology-based axis label for the plots.

The axis label consist of ontology label and unit: - The ontology label is split with spaces at all capital letters - The units are added in parentheses.

Returns:

A string for labelling the axis corresponding to the entity on a plot.

Examples

>>> import mammos_entity as me
>>> me.Entity("SpontaneousMagnetization").axis_label
'Spontaneous Magnetization (A / m)'
>>> me.Entity("DemagnetizingFactor").axis_label
'Demagnetizing Factor'
property description: str#

Additional description of the entity.

The description is a string containing any information relevant to the entity. This can include, e.g., whether it is an experimentally measured or a simulated quantity, what techniques were used in its calculation, or the experimental precision.

property ontology: owlready2.entity.ThingClass#

Retrieve the ontology class corresponding to the entity’s label.

Returns:

The ontology class from mammos_ontology that matches the entity’s label.

property ontology_iri: str#

The ontology IRI that links the entity to the EMMO ontology.

Retrieve the ontology IRI (Internationalized Resource Identifier) corresponding to the ThingClass that defines the given entity in ontology.

Returns:

The ontology IRI corresponding to the right ThingClass.

property ontology_label: str#

The ontology label that links the entity to the EMMO ontology.

Retrieve the ontology label corresponding to the ThingClass that defines the given entity in ontology.

Returns:

The ontology label corresponding to the right ThingClass.

property ontology_label_with_iri: str#

The ontology label with its IRI. Unique link to EMMO ontology.

Returns the self.ontology_label together with the IRI (a URL that points to the definition of this entity.) IRI stands for Internationalized Resource Identifier.

Returns:

The ontology label corresponding to the right ThingClass, together with the IRI.

property q: Quantity#

Quantity attribute, shorthand for .quantity.

property quantity: Quantity#

Return the value and unit of the entity as a Quantity.

Return a stand-alone Quantity object with the same value and unit, detached from the ontology link.

Returns:

A copy of this entity as a pure physical quantity.

to_hdf5(base, name)[source]#

Write an entity to an HDF5 dataset.

The value is added as data of the dataset; ontology_label, iri, unit and description are written to the dataset attributes.

Parameters:
  • base (File | Group | str | PathLike) – If it is an open HDF5 file or a group in an HDF5 file, data will be added to it as new dataset. If it is a str or PathLike a new HDF5 file with the given name will be created. If a file with that name exists already, it will be overwritten without notice.

  • name (str) – Name for the newly created dataset. If an element with that name exists already in base the function will fail.

Returns:

If base is an open File or Group the newly created dataset. If base is a file name nothing is returned (because the file created internally will be closed before the function returns).

Return type:

Dataset | None

property unit: UnitBase#

Unit of the entity data.

property value: numpy.scalar | ndarray#

Numerical data of the entity.

class mammos_entity.EntityCollection[source]#

Container class storing entity-like objects.

An EntityCollection groups entities together. It can store Entity, Quantity and other objects (lists, tuples, arrays, etc.). We refer to all of these as entity-like.

Common use cases are reading/writing files and conversion to and from pandas.DataFrame.

EntityCollection provides access to entities via both attributes and a dictionary-like interface. Access via attribute is only possible if the entity name is a valid Python name and no property/method of EntityCollection shadows the entity. The dictionary interface does not have these limitations.

Entities can have arbitrary string names, with the exception that description is not allowed. Entities passed as keyword arguments when creating the collection must have valid Python names.

Examples

>>> import mammos_entity as me

When creating a new collection entities can be passed as keyword arguments:

>>> collection = me.EntityCollection("A description", Ms=me.Ms(), T=me.T())
>>> collection
EntityCollection(
    description='A description',
    Ms=Entity(ontology_label='SpontaneousMagnetization', value=np.float64(0.0), unit='A / m'),
    T=Entity(ontology_label='ThermodynamicTemperature', value=np.float64(0.0), unit='K'),
)

Entities in the collection can be accessed either via attribute or a dictionary-like interface:

>>> collection.Ms
Entity(ontology_label='SpontaneousMagnetization', value=np.float64(0.0), unit='A / m')
>>> collection["T"]
Entity(ontology_label='ThermodynamicTemperature', value=np.float64(0.0), unit='K')

Additional elements can be added using both interfaces (“private” elements, i.e. entity names starting with an underscore can only be set/retrieved using the dictionary-like interface):

>>> collection.A = [1, 2, 3]
>>> collection["B"] = me.B([4, 5, 6])

Checking if an entity name exists in a collection can be done with:

>>> "B" in collection
True
>>> "Js" in collection
False

Elements can be removed using:

>>> del collection.T
>>> del collection.B

The collection is iterable, elements are tuples (name, entity-like):

>>> list(collection)
[('Ms', Entity(ontology_label='SpontaneousMagnetization', value=np.float64(0.0), unit='A / m')), ('A', [1, 2, 3])]
__init__(description='', **kwargs)[source]#

Initialize EntityCollection, keywords become attributes of the class.

Parameters:
  • description (str) – Information string to assign to description attribute.

  • **kwargs (Entity | Quantity | ArrayLike) – entities to be stored in the collection.

property description: str#

Additional description of the entity collection.

The description is a string containing any information relevant to the entity collection. This can include, e.g., whether it is a set of experimental or simulation quantities or outline the overall workflow.

classmethod from_dataframe(dataframe, metadata)[source]#

Create EntityCollection from dataframe and metadata.

The EntityCollection is created by combining metadata with data from the dataframe matching key/column names. The available metadata determines whether an element becomes an Entity`, a mammos_units.Quantity or a numpy array.

All column names in the dataframe must also exist as keys in metadata and vice versa.

In addition metadata can have a key description containing a description for the collection.

Parameters:
  • dataframe (pd.DataFrame) – A dataframe containing the values for the individual entities.

  • metadata (dict[str, dict]) – A dictionary with the structure similar to the one defined in metadata(). The keys unit and description for an :py:class`~mammos_entity.Entity` are however optional. If not present, default units from the ontology and an empty description are used.

Return type:

EntityCollection

metadata()[source]#

Get entity metadata as dictionary.

This method creates a dictionary containing metadata for all entities in the collection. Keys are names of the (entities) attributes of the collection, values are dictionaries with: - keys ontology_label, unit and description if the attribute is an

entity

  • key unit if the attribute is a quantity

  • an empty dictionary otherwise

In addition there is one key-value pair description for the collection description.

Example: >>> import mammos_entity as me >>> import mammos_units as u >>> col = me.EntityCollection(“The description”, Tc=me.Tc(), x=1 * u.m, a=0) >>> col.metadata() {‘description’: ‘The description’, ‘Tc’: {‘ontology_label’: ‘CurieTemperature’, ‘unit’: ‘K’, ‘description’: ‘’}, ‘x’: {‘unit’: ‘m’}, ‘a’: {}}

Return type:

dict[str, str | dict[str, str]]

to_csv(filename)[source]#

Write collection to CSV file.

CSV files contain data in normal CSV format and additional metadata lines at the top of the file. Some of the lines are commented with #. This structure is fixed and additional comment lines or inline comments in the data table are not allowed.

The lines are, in order:

  • (commented) the file version in the form mammos csv v<VERSION> (matching regex vd+)

  • (commented, optional) a description of the file, appearing delimited by dashed lines

  • (optional, only for entities) the preferred ontology label

  • (optional, only for entities) a description string

  • (optional, only for entities) the ontology IRI

  • (optional, for entities and quantities) units

  • the short labels used to refer to individual columns when working with the data, e.g. in a pandas.DataFrame (omitting spaces in this string is advisable; ideally this string is the short ontology label)

  • all remaining lines contain data.

Elements in a line are separated by a comma without any surrounding whitespace. A trailing comma is not permitted. Line continuation is OS dependent (rn on Windows, n on Unix).

In columns without ontology the lines containing labels, IRIs, and description are empty.

Similarly, columns without units (with or without ontology entry) have empty units line.

For any column, the description line can be empty. Only entities can store descriptions, i.e., if the ontology-related lines are empty, the description string will not be read.

Added in version v2: The optional description of the file.

Added in version v3: Additional description metadata row containing a description for each column.

Changed in version v3: Ontology labels, entity descriptions, IRIs, and units are no longer commented.

Parameters:

filename (str | PathLike) – Name of the generated file. An existing file with the same name is overwritten without notice.

Raises:
  • ValueError – If the entities are not tabular. CSV files can only be written for collections in which all entities are either scalar or one-dimenisional with the same length.

  • ValueError – If elements of the collection are of type EntityCollection (nested collections are not supported in CSV) or if the collection is empty.

Return type:

None

Example

Here is an example with five columns:

  • an index with no units or ontology label

  • the entity spontaneous magnetization with an entry in the ontology and a description

  • a made-up quantity alpha with a unit but no ontology label

  • demagnetizing factor with an ontology entry but no unit

  • a column comment containing a string comment without units or ontology label

The file has a description reading “Test data”.

>>> from pathlib import Path
>>> import mammos_entity as me
>>> import mammos_units as u
>>> collection = me.EntityCollection(
...     description="Test data",
...     index=[0, 1, 2],
...     Ms=me.Entity("SpontaneousMagnetization", [1e2, 1e2, 1e2], "kA/m", description="Magnetization at 0 Kelvin"),
...     alpha=[1.2, 3.4, 5.6] * u.s**2,
...     DemagnetizingFactor=me.Entity("DemagnetizingFactor", [1, 0.5, 0.5]),
...     comment=[
...         "Comment in the first row",
...         "Comment in the second row",
...         "Comment in the third row",
...     ],
... )
>>> collection.to_csv("example.csv")

The new file has the following content:

>>> print(Path("example.csv").read_text())
# mammos csv v3
#----------------------------------------
# Test data
#----------------------------------------
,SpontaneousMagnetization,,DemagnetizingFactor,
,Magnetization at 0 Kelvin,,,
,https://w3id.org/emmo/domain/magnetic-materials#EMMO_032731f8-874d-5efb-9c9d-6dafaa17ef25,,https://w3id.org/emmo/domain/magnetic-materials#EMMO_0f2b5cc9-d00a-5030-8448-99ba6b7dfd1e,
,kA / m,s2,,
index,Ms,alpha,DemagnetizingFactor,comment
0,100.0,1.2,1.0,Comment in the first row
1,100.0,3.4,0.5,Comment in the second row
2,100.0,5.6,0.5,Comment in the third row

Finally, remove the file.

>>> Path("example.csv").unlink()
to_dataframe(include_units=False)[source]#

Convert values to dataframe.

Parameters:

include_units (bool) – If true, include units in the dataframe column names.

Return type:

DataFrame

to_hdf5(base, name=None)[source]#

Write a collection to an HDF5 group.

Entities of the collection become datasets in the group. The collection description is added to the group attributes.

Parameters:
  • base (File | Group | str | PathLike) – If it is an open HDF5 file or a group in an HDF5 file, data will be added to it as new group. If it is a str or PathLike a new HDF5 file with the given name will be created. If a file with that name exists already, it will be overwritten without notice.

  • name (str | None) – Name for the newly created group. If an element with that name exists already in base the function will fail. If name is None entities of the collection will be added directly to base and the collection description will be added to base attributes.

Returns:

If base is an open File or Group the newly created group. If base is a file name nothing is returned (because the file created internally will be closed before the function returns).

Return type:

Group | None

to_yaml(filename)[source]#

Write collection to YAML file.

MaMMoS YAML files have the following format:

  • one commented line at the top of the file containing the mammos format version in the form # mammos yaml v<version-number>.

  • a mapping with three top-level keys metadata, description and data

  • metadata is currently unused and should be empty

  • the description key contains a (multi-line) string with arbitrary content describing the top-level collection

  • data contains one key per element in the collection. Each entry is either an entity-like entry or a nested collection node.

Collection nodes are recursive and have two keys description and data:

  • description: a (multi-line) string with arbitrary content

  • data: mapping from entry names to entity-like entries or nested collection nodes

Entity-like entries have the following keys:

  • For Entity:

    • ontology_label: label in the ontology

    • description: description string

    • ontology_iri: IRI of the entity

    • unit: unit of the entity ("" for dimensionless)

    • value: value of the data

  • For Quantity:

    • unit: unit of the quantity

    • value: value of the data

  • For any other value:

    • value: value of the data

Added in version v2: The description key for each object.

Changed in version v2:

  • The version of the file is now stored in the first commented line, previously it was stored in metadata:description.

  • The top-level collection description is stored under description (next to metadata and data). Previously it was stored in metadata:description.

  • Non-entity entries no longer store null-valued ontology keys.

  • Nested collections are supported recursively.

Parameters:

filename (str | PathLike) – Name of the generated file. An existing file with the same name is overwritten without notice.

Raises:

ValueError – If the top-level collection is empty.

Return type:

None

Example

Here is an example with six entries:

  • an index with no units or ontology label

  • the entity spontaneous magnetization with an entry in the ontology and a description

  • a made-up quantity alpha with a unit but no ontology label

  • demagnetizing factor with an ontology entry but no unit

  • a column comment containing a string comment without units or ontology label

  • an element Tc with only a single value

The file has a description reading “Test data”.

>>> from pathlib import Path
>>> import mammos_entity as me
>>> import mammos_units as u
>>> collection = me.EntityCollection(
...     description="Test data",
...     index=[0, 1, 2],
...     Ms=me.Entity("SpontaneousMagnetization", [1e2, 1e2, 1e2], "kA/m", description="Magnetization at 0 Kelvin"),
...     alpha=[1.2, 3.4, 5.6] * u.s**2,
...     DemagnetizingFactor=me.Entity("DemagnetizingFactor", [1, 0.5, 0.5]),
...     comment=[
...         "Comment in the first row",
...         "Comment in the second row",
...         "Comment in the third row",
...     ],
...     Tc=me.Tc(300, "K"),
... )
>>> collection.to_yaml("example.yaml")

The new file has the following content:

>>> print(Path("example.yaml").read_text())
# mammos yaml v2
metadata: null
description: Test data
data:
  index:
    value: [0, 1, 2]
  Ms:
    ontology_label: SpontaneousMagnetization
    description: Magnetization at 0 Kelvin
    ontology_iri: https://w3id.org/emmo/domain/magnetic-materials#EMMO_032731f8-874d-5efb-9c9d-6dafaa17ef25
    unit: kA / m
    value: [100.0, 100.0, 100.0]
  alpha:
    unit: s2
    value: [1.2, 3.4, 5.6]
  DemagnetizingFactor:
    ontology_label: DemagnetizingFactor
    description: ''
    ontology_iri: https://w3id.org/emmo/domain/magnetic-materials#EMMO_0f2b5cc9-d00a-5030-8448-99ba6b7dfd1e
    unit: ''
    value: [1.0, 0.5, 0.5]
  comment:
    value: [Comment in the first row, Comment in the second row, Comment in the third
        row]
  Tc:
    ontology_label: CurieTemperature
    description: ''
    ontology_iri: https://w3id.org/emmo#EMMO_6b5af5a8_a2d8_4353_a1d6_54c9f778343d
    unit: K
    value: 300.0
>>> Path("example.yaml").unlink()

Here is a second example with one outer and one inner collection:

>>> properties = me.EntityCollection(
...     description="material properties",
...     Ms=me.Ms(1.3e3, "kA/m"),
...     Tc=me.Tc(1043, "K"),
... )
>>> measurement = me.EntityCollection(
...     description="measurement with device X",
...     sample=properties,
...     T=me.T(300, "K", description="Measurement conditions"),
...     H=me.H([0, 50, 100], "kA/m"),
...     M=me.M([100, 300, 500], "kA/m"),
... )
>>> measurement.to_yaml("nested_example.yaml")
>>> print(Path("nested_example.yaml").read_text())
# mammos yaml v2
metadata: null
description: measurement with device X
data:
  sample:
    description: material properties
    data:
      Ms:
        ontology_label: SpontaneousMagnetization
        description: ''
        ontology_iri: https://w3id.org/emmo/domain/magnetic-materials#EMMO_032731f8-874d-5efb-9c9d-6dafaa17ef25
        unit: kA / m
        value: 1300.0
      Tc:
        ontology_label: CurieTemperature
        description: ''
        ontology_iri: https://w3id.org/emmo#EMMO_6b5af5a8_a2d8_4353_a1d6_54c9f778343d
        unit: K
        value: 1043.0
  T:
    ontology_label: ThermodynamicTemperature
    description: Measurement conditions
    ontology_iri: https://w3id.org/emmo#EMMO_affe07e4_e9bc_4852_86c6_69e26182a17f
    unit: K
    value: 300.0
  H:
    ontology_label: ExternalMagneticField
    description: ''
    ontology_iri: https://w3id.org/emmo/domain/magnetic-materials#EMMO_da08f0d3-fe19-58bc-8fb6-ecc8992d5eb3
    unit: kA / m
    value: [0.0, 50.0, 100.0]
  M:
    ontology_label: Magnetization
    description: ''
    ontology_iri: https://w3id.org/emmo#EMMO_b23e7251_a488_4732_8268_027ad76d7e37
    unit: kA / m
    value: [100.0, 300.0, 500.0]
>>> Path("nested_example.yaml").unlink()
mammos_entity.H(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the external magnetic field (H).

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to the external magnetic field. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘T’ for Tesla). If omitted, the SI unit from the ontology, i.e. T, will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labeled “ExternalMagneticField”.

Return type:

Entity

mammos_entity.Hc(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the external coercive field (Hc).

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to the external coercive field. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘A/m’). If omitted, the SI unit from the ontology, i.e. A/m, will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labeled “CoercivityHcExternal”.

Return type:

Entity

mammos_entity.J(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the magnetic polarisation (J).

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to magnetic polarisation. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘J/(A m2)’ or ‘T’). If omitted, the SI unit from the ontology, i.e. J/(A m2), will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labeled “MagneticPolarisation”.

Return type:

Entity

mammos_entity.Js(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the spontaneous magnetic polarisation (Js).

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to spontaneous magnetic polarisation. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘J/(A m2)’ or ‘T’). If omitted, the SI unit from the ontology, i.e. ‘J/(A m2)’, will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labeled “SpontaneousMagneticPolarisation”.

Return type:

Entity

mammos_entity.K1(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the magnetocrystalline anisotropy constant K1.

This is the first magnetocrystalline anisotropy constant for tetragonal or hexagonal crystals. For cubic crystals, please use the label MagnetocrystallineAnisotropyConstantK1c instead.

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to the magnetocrystalline anisotropy constant. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘J/m^3’). If omitted, the SI unit from the ontology, i.e. J/m^3 will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labeled “MagnetocrystallineAnisotropyConstantK1”.

Return type:

Entity

mammos_entity.K2(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the magnetocrystalline anisotropy constant K2.

This is the second magnetocrystalline anisotropy constant for tetragonal or hexagonal crystals. For cubic crystals, please use the label MagnetocrystallineAnisotropyConstantK2c instead.

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to the magnetocrystalline anisotropy constant. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘J/m^3’). If omitted, the SI unit from the ontology, i.e. J/m^3 will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labeled “MagnetocrystallineAnisotropyConstantK2”.

Return type:

Entity

mammos_entity.Ku(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the uniaxial anisotropy constant (Ku).

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to the uniaxial anisotropy constant. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘J/m^3’). If omitted, the SI unit from the ontology, i.e. J/m^3 will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labeled “UniaxialAnisotropyConstant”.

Return type:

Entity

mammos_entity.M(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the magnetization.

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to the magnetization of the material. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘A/m’). If omitted, the SI unit from the ontology, i.e. A/m, will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labelled “Magnetization”.

Return type:

Entity

mammos_entity.Mr(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the remanent magnetisation (Mr).

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to the remanent magnetisation. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘A/m’). If omitted, the SI unit from the ontology, i.e. A/m, will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labelled “Remanence”.

Return type:

Entity

mammos_entity.Ms(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the spontaneous magnetization (Ms).

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to spontaneous magnetization. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘A/m’). If omitted, the SI unit from the ontology, i.e. A/m, will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labelled “SpontaneousMagnetization”.

Return type:

Entity

mammos_entity.T(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the temperature (T).

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to the temperature. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘K’). If omitted, the SI unit from the ontology, i.e. K, will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labelled “ThermodynamicTemperature”.

Return type:

Entity

mammos_entity.Tc(value=0, unit=None, **kwargs)[source]#

Create an Entity representing the Curie temperature (Tc).

Parameters:
  • value (int | float | ArrayLike) – Numeric value corresponding to the Curie temperature. It can also be a Numpy array.

  • unit (None | str) – Unit of measure for the value (e.g., ‘K’ for Kelvin). If omitted, the SI unit from the ontology, i.e. K, will be inferred.

  • **kwargs – Additional keyword arguments passed to Entity.

Returns:

An Entity object labelled “CurieTemperature”.

Return type:

Entity

mammos_entity.from_csv(filename)[source]#

Read MaMMoS CSV file.

The required file format is described in to_csv().

Parameters:

filename (str | Path) – Name of the file to read. The file is read as CSV no matter the file extension.

Returns:

A collection object providing access to all entities saved in the file.

Return type:

EntityCollection

mammos_entity.from_hdf5(element, decode_bytes=True)[source]#

Read HDF5 file, group or dataset and convert to Entity or EntityCollection.

Datasets are converted to Entity, Quantity, or a numpy array or other builtin datatype depending on their associated metadata and shape.

Groups are converted to EntityCollection. Arbitrary nesting of groups is supported and produces nested collections.

Parameters:
  • element (File | Group | Dataset | str | PathLike) – If it is a str or PathLike the entire file is read from disk. If it is an open HDF5 File, Group or Dataset only that part of the file is read.

  • decode_bytes (bool) – If True data of all datasets of type object is converted to strings (if scalar) or numpy arrays of strings (if vector). If False the bytes object (or array of bytes objects) is returned.

Returns:

All data in the given HDF5 file/group/dataset as (nested) EntityCollection and/or entity-like object.

Return type:

Entity | Quantity | ArrayLike | EntityCollection

mammos_entity.from_yaml(filename)[source]#

Read MaMMoS YAML file.

The required file format is described in to_yaml().

Parameters:

filename (str | Path) – Name of the file to read. The file is read as YAML no matter the file extension.

Returns:

A collection object providing access to all entities saved in the file.

Return type:

EntityCollection

mammos_entity.search_labels(text, auto_wildcard=True)[source]#

Search entity labels by name.

The string text is searched into label, prefLabel, and altLabel of all entities. The match is case sensitive. The returned label is always the prefLabel.

This function uses internally the method .search() of mammos_entity.mammos_ontology.

Parameters:
  • text (str) – String to match.

  • auto_wildcard (bool) –

    If True, the wildcard * is added at the beginning and at the end of the string text. This allows partial matches, finding labels containing text. If False, only labels identical to text are returned.

    Passing "text", auto_wildcard=True is identical to passing "*text*", auto_wildcard=False.

Return type:

list[str]

Examples

>>> import mammos_entity as me
>>> me.search_labels("ShapeAnisotropy")
['ShapeAnisotropy', 'ShapeAnisotropyConstant']
>>> me.search_labels("Magnetization")
['MagneticMomentPerUnitMass', 'Magnetization', 'MassMagnetizationUnit', 'Remanence', 'SaturationMagnetization', 'SpontaneousMagnetization']

'MagneticMomentPerUnitMass' appears because 'MassMagnetization' is in its altLabel.

>>> me.search_labels("Magnetization", auto_wildcard=False)
['Magnetization']

Modules

operations

Entities operations.