SPC Sampling for XBar Charts

Sepasoft MES Module Suite

SPC Sampling for XBar Charts

The XBar chart (also called the X̄-R or X̄-S chart) is a fundamental Statistical Process Control (SPC) tool used to monitor the mean and variability of a process over time. In Sepasoft MES, XBar chart sampling requires collecting multiple measurements per sample — referred to as a subgroup — rather than a single data point. This article explains why multiple measurements are required and how to configure and script multi-measurement sample collection.

See Below:


Why XBar Charts Require Multiple Measurements

Unlike individual (I-MR) charts that plot one measurement per sample, XBar charts work by plotting the average (mean) of a subgroup of measurements. This approach provides several statistical advantages:

  • Reduced noise: Averaging multiple values dampens the effect of random, short-term variation within a process, making it easier to detect real shifts in the process mean.

  • Better sensitivity: The XBar chart can detect smaller process shifts than individual charts when the subgroup size is appropriately chosen.

  • Separation of variation sources: The range (R) or standard deviation (S) portion of the chart captures within-subgroup variation, while the XBar chart captures between-subgroup (over time) variation.

  • Statistical validity: Control limits on XBar charts are derived from the distribution of subgroup means, which converge to a normal distribution faster than individual measurements (Central Limit Theorem).

A typical subgroup size for XBar charts is 3 to 5 measurements, though any consistent size can be used. The subgroup size is set in the Sample Definition's attribute Measurement Count field and must match the number of values submitted when collecting a sample via script.

Step 1: Configure the Sample Definition Attribute

Before scripting sample collection, the Sample Definition must be configured with the correct attribute settings for an XBar chart. The Measurement Count attribute field defines how many measurements constitute one full sample (the subgroup size).

To configure the attribute:

  • In the MES Sample Definition Component, select the target Sample Definition from the Definition List tree.

  • Under Sample Definition Settings, click Attribute List.

  • Select an existing attribute or click New to create one.

  • Set the ChartType to XBAR_R or XBAR_S.

  • Set the Measurement Count to the desired subgroup size (e.g., 3, 4, or 5).

  • Set the Datatype to an appropriate numeric type (Integer or Real).

  • Configure MinimumValue and MaximumValue as needed for validation.

Note The Measurement Count you configure here must match the number of values passed in the attribute data array when collecting samples via script. A mismatch will result in incomplete or invalid samples.

For full details on all available attribute settings, refer to the Sepasoft documentation: Sample Definition Attributes.

Key Attribute Settings for XBar Chart

Setting

Recommended Value

Description

ChartType

XBAR_R or XBAR_S

Determines the default chart type rendered in SPC components.

Datatype

Integer or Real

XBar charts require numeric datatypes.

MeasurementCount

3, 4, or 5 (typical)

Defines the subgroup size. Must match the array length passed in attributeData.

isRequired

True

Enforces that measurements are provided before saving. 

Step 2: Script Multi-Measurement Sample Collection

The system.mes.spc.sample.collect() function is used to submit SPC samples from script. For XBar charts, the key is passing an array of measurement values for each attribute rather than a single value.

How Multi-Measurement Arrays Work

The attributeData parameter accepts a Python dictionary where:

  • Each key is an attribute name (as configured in the Sample Definition).

  • For single-measurement attributes, the value is a primitive (number, string, etc.).

  • For multi-measurement attributes (XBar subgroups), the value is a list/array of values.

  • The index position in the array corresponds to the measurement number (measurement 1, 2, 3, ...).

  • The length of the array must exactly match the Measurement Count configured on the attribute.

Note Array index 0 = Measurement 1, index 1 = Measurement 2, and so on. Always ensure the array length equals the attribute's configured Measurement Count.

Function Signature

Python
system.mes.spc.sample.collect(
    defName,
    locationPath,
    [attributeData],
    [factorData],
    [takenBy],
    [note],
    [approved],
    [refNo],
    [tag],
    [productCode],
    [entryDateTime],
    [sampleTakenDateTime]
)

Key Parameters

Parameter

Type

Required

Description

defName

String

Required

Name of the existing Sample Definition to base the sample on.

locationPath

String

Required

Full path to the MES location where the sample is collected. Example: Enterprise\\Site 1\\Area 1\\Line 1

attributeData

PyDictionary

Optional

Dictionary of attribute name → value. For XBar, pass a list of measurements as the value. Each index is one measurement in the subgroup.

factorData

PyDictionary

Optional

Dictionary of factor name → primitive value (number, string, boolean).

takenBy

String

Optional

Username of the operator collecting the sample.

sampleTakenDateTime

Date

Optional

Timestamp of when the sample was physically taken. Defaults to current time. Available in MES 3.79.3 RC6 and later.

entryDateTime

Date

Optional

Timestamp used to calculate due/overdue state. Defaults to current time. Available in MES 3.79.3 RC6 and later.

approved

Boolean

Optional

Override the location's default auto-approve setting for this sample.


Code Examples

Example 1: Basic XBar Subgroup (3 Measurements)

This example collects a sample with a subgroup size of 3 for an attribute named PartDiameter. The list [12.01, 12.03, 11.98] represents three individual measurements taken from the same subgroup.

Python
# Three measurements forming one XBar subgroup
# Measurement Count on the 'PartDiameter' attribute must be set to 3
attributeData = {
    'PartDiameter': [12.01, 12.03, 11.98]
}

location_path = 'Enterprise\\Site 1\\Area 1\\Line 1'
timestamp = system.date.now()

system.mes.spc.sample.collect(
    'DimensionData',
    location_path,
    attributeData,
    sampleTakenDateTime=timestamp
)

Example 2: XBar Subgroup with 5 Measurements and takenBy

A subgroup of 5 measurements is common in manufacturing for better statistical sensitivity. This example also records the operator who collected the sample.

Python
# Five measurements forming one XBar subgroup
# Measurement Count on 'FillWeight' attribute must be set to 5
attributeData = {
    'FillWeight': [250.1, 249.8, 250.3, 250.0, 249.9]
}

location_path = 'Enterprise\\Site 1\\Filling\\Station 2'
operator = 'jsmith'
timestamp = system.date.now()

system.mes.spc.sample.collect(
    'FillWeightSPC',
    location_path,
    attributeData,
    takenBy=operator,
    sampleTakenDateTime=timestamp
)

Building Measurement Arrays Dynamically

In practice, measurements are often read from tags, sensor inputs, or operator entry rather than hardcoded. Below is a pattern for assembling the subgroup array dynamically before calling collect.

Python
# Read measurements from Ignition tags
meas1 = system.tag.readBlocking(['[default]SPC/Diameter/M1'])[0].value
meas2 = system.tag.readBlocking(['[default]SPC/Diameter/M2'])[0].value
meas3 = system.tag.readBlocking(['[default]SPC/Diameter/M3'])[0].value
meas4 = system.tag.readBlocking(['[default]SPC/Diameter/M4'])[0].value
meas5 = system.tag.readBlocking(['[default]SPC/Diameter/M5'])[0].value

# Assemble subgroup - index order matches measurement number
subgroup = [meas1, meas2, meas3, meas4, meas5]

attributeData = {
    'PartDiameter': subgroup
}

location_path = 'Enterprise\\Site 1\\Machining\\CNC 1'
timestamp = system.date.now()

system.mes.spc.sample.collect(
    'MachiningDimensions',
    location_path,
    attributeData,
    takenBy=system.security.getUsername(),
    sampleTakenDateTime=timestamp
)

References

system.mes.spc.sample.collect – Sepasoft Documentation

Sample Definition Attributes – Sepasoft Documentation

Sepasoft MES Module Suite