Skip to main content
Summarise (roll up) test results into new statistical data records. In this example, the tests are stored in Tensile Test Data table and the statistical data is stored in Tensile Statistical Data. Since the sample data is arranged by specimen, the mean and other statistics will be stored by specimen in the new record. Statistical data is commonly stored using meta-attributes. Here, we store the mean of each property as the attribute value, and statistical results (Minimum, Maximum, Median, Range and Standard Deviation) as its meta-attributes whenever possible.

Define a function which rolls up an attribute

Create a function to calculate statistics for, and store the values on the meta-attributes of, a target attribute. The rollup_point_attribute() method below is a general example which will work whether meta-attributes are present or not, or if the number of samples is too small to provide meaningful statistics. It checks if each named meta-attribute exists, then sets existing meta-attributes and updates them by calling Record.set_attributes(). To simplify your own roll-up, you can:
  • Make sure there are meta-attributes for roll-up statistics on all relevant attributes when setting up a Granta MI schema.
  • Make sure all the target attributes in your script have the same meta-attributes.
  • Set up a workflow where all statistical data records are created new.

Define a function which copies attribute values

Define a copy_attribute() function which copies an attribute value from the source records, for example a Specimen ID stored in a short-text attribute, or a test temperature. This example supports several attribute types, and could easily be extended to support others such as discrete or hyperlink.

Get test data from Granta MI

Composite data in Granta MI is stored according to layup orientation and Specimen ID. The roll-up process retains the overall structure of the records, but creates a single new record for each specimen. Connect to Granta MI and fetch the folder corresponding to the composite 3M, S-Glass Unitape S2/SP381:
Previous cell output:
To make processing easier, convert the structure of the data from
to a dictionary with each layer indexed by name (removing the redundant layers):
Although this structure is sufficient for this example, a network library or tree wrapper class might be better suited to dealing with advanced tree-traversal.
Define the attributes you want to calculate statistics for, and those you want to copy from the test records. To fetch large numbers of records or attributes efficiently, use the table.bulk_fetch() method (see Performance optimization).
Create box-plots for three of the specimens using the seaborn plotting libraries, first ‘flattening’ the data into a usable list of numpy arrays. Alternatively, you could convert the data into a pandas DataFrame at this point (useful if you needed to process the data further).
png Perform the roll-up by creating the new records and iterating through the attributes defined above, copying or rolling up as required. Here we have used the table.path_from() method to create a folder path for each orientation, and table.create_record() for each new roll-up record. Finally, use Session.update() to write the new record to the server, then set and update links between the new statistical data record and the test records it summarises.
Previous cell output: