Create a table describing a material.
The table are saved as csv files in the material section of the documentation.
Source code in src\vimseo\utilities\generate_material_description_table.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 | def create_material_description_table(
material_lib_dir: Path, material_name: str
) -> pd.DataFrame:
"""Create a table describing a material.
The table are saved as csv files in the material section of the documentation.
"""
grammar = JSONGrammar(
material_name, material_lib_dir / f"{material_name}_grammar.json"
)
material = Material.from_json(material_lib_dir / f"{material_name}.json")
name_to_attributes = {}
for rel in material.material_relations:
for prop in rel.properties:
raw_description = grammar.schema["properties"][prop.name]["description"]
attributes = PropertyAttributes()
description = raw_description
if "{{" in raw_description and "}}" in raw_description:
attributes.unit = raw_description.split("{{")[1].split("}}")[0]
description = description.split("{{")[0]
if "[" in raw_description and "]" in raw_description:
attributes.category = raw_description.split("[")[1].split("]")[0]
description = description.split("]")[1]
attributes.description = description.strip()
attributes.material_relation = rel.name
attributes.default_value = prop.value
if prop.distribution.name != "":
attributes.distribution = prop.distribution.name
name_to_attributes[prop.name] = attributes
attribute_name_to_value = defaultdict(list)
for name, attributes in name_to_attributes.items():
attribute_name_to_value["name"].append(name)
for name, value in asdict(attributes).items():
attribute_name_to_value[name].append(value)
df = pd.DataFrame.from_dict(attribute_name_to_value)
df.to_csv(
Path.cwd() / PATH_TO_MATERIAL_DOC_SUBDIR / f"{material_name}_properties.csv",
sep=SEP,
)
return df
|