FAIRmat-NFDI / AreaA-data_modeling_and_schemas

The ELN custom schemas from synthesis experiments
https://fairmat-nfdi.github.io/AreaA-Documentation/
11 stars 6 forks source link

Automatic composition #206

Closed ka-sarthak closed 1 week ago

ka-sarthak commented 1 week ago

Use MSection.m_setdefault method to automatically compose the sub-section using the definition. This is helpful when these schemas are used as a parent for a more specialized section. The automatic composition will pick whatever sub-section is defined in the specialized data model.

For example, let's assume we define SpecializedELNUVVisNIRTransmission using ELNUVVisNIRTransmission as an inheriting section, and compose another specialized results sections in it.

class SpecializedUVVisNirTransmissionResult(UVVisNirTransmissionResult):
  # some special code

class SpecializedELNUVVisNIRTransmission(ELNUVVisNIRTransmission):
  results = SubSection(section_def=SpecializedUVVisNirTransmissionResult, repeats=True)

Because of the automatic composition based on m_setdefault, when SpecializedELNUVVisNIRTransmission.normalize() runs, it will pick the SpecializedUVVisNirTransmissionResult to compose the results. It removes the need to redefine the composition in the normalization of the specialized section. One can efficiently reuse the normalize method of the parent to work with the new composition.