ogstools.materiallib.core.material module#

class ogstools.materiallib.core.material.Material[source]#

Bases: Mapping[str, MaterialProperty]

Represents a single material.

  • Can be constructed directly from YAML raw data.

  • Provides access to all properties.

  • Supports filtering by process schemas or property names.

__init__(name, raw_data)[source]#
classmethod from_file(file_path)[source]#

Create a Material from a YAML file or return None if invalid.

Return type:

Material | None

to_file(file_path)[source]#

Write this Material to a YAML file.

Return type:

None

__getitem__(key)[source]#
Return type:

MaterialProperty

property property_names: list[str]#

Returns a list of all property names of this material.

get_property(key)[source]#
Return type:

MaterialProperty

filter_process(process_schema)[source]#

Filter self, to only contain properties required by a given process.

Return type:

None

filter_properties(allowed, key='name')[source]#

Filter self, to only contain properties in ‘allowed’, preserving all extra fields (e.g. scope, unit).

Parameters:
  • allowed (set[str] | str) – values to filter for

  • key (str) – attribute to filter for (e.g. ‘name’ or ‘type’)

Return type:

None

property duplicates: list[MaterialProperty]#

Returns all material properties with multiple definitions.

copy(selection=None)[source]#

Return a deep copy, optionally with a filtered selection.

Parameters:

selection (dict[str, dict[str, str | Pattern]] | None) –

Maps restrictions to different properties. They will be only present in the resulting copy, if the properties named in selection adhere to the given constraint. The values can be regular expressions. Shape: {“propertynames”: {“attributes”: “values”}}

Example:

{“saturation”: {“type”: re.compile(“SaturationVan.*”)}, “density”: {“type”: “Constant”, “source”: re.compile(“.*2018.*”)}}

Return type:

Material