Datasets:
Formats:
csv
Languages:
English
Size:
1K - 10K
Tags:
process-control
pid-controller
statistical-process-control
roller-compaction
pharmaceutical-manufacturing
time-series
License:
| """ | |
| IPA Roll Compactor Control Performance Synthetic Dataset Generator v1.0 | |
| ======================================================================= | |
| Generates synthetic time-series process data simulating PID control behavior | |
| of roll compactors during dry granulation, grounded in the control performance | |
| concepts from: | |
| Szappanos-Csordás, K. (2018). "Impact of material properties, process | |
| parameters and roll compactor design on roll compaction." Chapter 3.1: | |
| Control performance of the different types of roll compactors. | |
| Key concepts modeled: | |
| - PID controller behavior (P, I, D terms) for SCF and gap width control | |
| - Settling time after setpoint changes (material- and design-dependent) | |
| - Steady-state deviation from setpoint (mean ± SD, CV%) | |
| - Control architecture differences: | |
| * No gap control (AlexanderWerk BT120-type): high GW variability | |
| * PID with GW + screw speed control (Hosokawa-type): moderate control | |
| * PID with SCF + GW control (Bohle/Gerteis-type): best control | |
| - Material-dependent control difficulty: MCC (plastic, compressible) is | |
| easier to control than mannitol (brittle, less compressible) | |
| - Overshoot, oscillation, and disturbance rejection behavior | |
| - Twin feed screw advantage: reduced feed fluctuation → lower SCF variance | |
| THIS IS SYNTHETIC EDUCATIONAL DATA. NOT REAL CUSTOMER OR LAB DATA. | |
| Generated by Innovative Process Applications (IPA) for teaching process | |
| control, PID tuning, and SPC concepts. | |
| """ | |
| import numpy as np | |
| import pandas as pd | |
| rng = np.random.default_rng(seed=2026) | |
| # ============================================================================= | |
| # CONTROL ARCHITECTURES (from Chapter 3.1 / Table 1 of the dissertation) | |
| # ============================================================================= | |
| CONTROL_CONFIGS = { | |
| "no_gap_control": { | |
| "label": "No Gap Control (HP setpoint only)", | |
| "description": "Hydraulic pressure setpoint, no closed-loop gap control", | |
| "has_scf_pid": False, | |
| "has_gw_pid": False, | |
| "scf_settling_base_s": 15.0, | |
| "gw_settling_base_s": 50.0, # gap drifts until material equilibrates | |
| "scf_noise_base": 0.012, # CV fraction — higher without PID | |
| "gw_noise_base": 0.030, # high GW variability (3% CV from Table 2) | |
| "overshoot_factor": 0.08, | |
| "feed_type": "single_screw", | |
| }, | |
| "pid_gw_screw": { | |
| "label": "PID: GW + Screw Speed Control", | |
| "description": "Gap width controlled via PID adjusting screw speed", | |
| "has_scf_pid": False, | |
| "has_gw_pid": True, | |
| "scf_settling_base_s": 12.0, | |
| "gw_settling_base_s": 20.0, | |
| "scf_noise_base": 0.010, | |
| "gw_noise_base": 0.015, | |
| "overshoot_factor": 0.12, # GW PID can overshoot on fast changes | |
| "feed_type": "single_screw", | |
| }, | |
| "pid_scf_gw": { | |
| "label": "PID: SCF + GW Control", | |
| "description": "Both SCF and GW controlled via independent PID loops", | |
| "has_scf_pid": True, | |
| "has_gw_pid": True, | |
| "scf_settling_base_s": 8.0, | |
| "gw_settling_base_s": 10.0, | |
| "scf_noise_base": 0.006, # best control performance | |
| "gw_noise_base": 0.008, | |
| "overshoot_factor": 0.05, | |
| "feed_type": "single_screw", | |
| }, | |
| "pid_scf_gw_twin_screw": { | |
| "label": "PID: SCF + GW Control + Twin Feed Screw", | |
| "description": "Dual PID loops with twin feed screw for uniform feeding", | |
| "has_scf_pid": True, | |
| "has_gw_pid": True, | |
| "scf_settling_base_s": 6.0, | |
| "gw_settling_base_s": 8.0, | |
| "scf_noise_base": 0.004, # twin screw reduces feed fluctuation | |
| "gw_noise_base": 0.006, | |
| "overshoot_factor": 0.04, | |
| "feed_type": "twin_screw", | |
| }, | |
| } | |
| # ============================================================================= | |
| # MATERIALS (control difficulty varies with deformation behavior) | |
| # ============================================================================= | |
| MATERIALS = { | |
| "MCC_101": { | |
| "label": "MCC 101 (Plastic)", | |
| "control_difficulty": 0.8, # easier — plastic deformation is smoother | |
| "settling_multiplier": 0.9, | |
| "disturbance_sensitivity": 0.7, | |
| }, | |
| "Mannitol_SD": { | |
| "label": "Mannitol (Brittle)", | |
| "control_difficulty": 1.3, # harder — brittle fragmentation causes spikes | |
| "settling_multiplier": 1.3, | |
| "disturbance_sensitivity": 1.4, | |
| }, | |
| "MCC_Mannitol_Mix": { | |
| "label": "1:1 Mixture", | |
| "control_difficulty": 1.0, | |
| "settling_multiplier": 1.0, | |
| "disturbance_sensitivity": 1.0, | |
| }, | |
| } | |
| # ============================================================================= | |
| # SETPOINT CHANGE SCENARIOS (from Table 2/3 patterns in the dissertation) | |
| # ============================================================================= | |
| SCENARIOS = [ | |
| {"scf_from": 4.0, "scf_to": 4.0, "gw_from": 2.0, "gw_to": 2.0, | |
| "label": "steady_state_baseline"}, | |
| {"scf_from": 4.0, "scf_to": 8.0, "gw_from": 2.0, "gw_to": 2.0, | |
| "label": "scf_step_up"}, | |
| {"scf_from": 8.0, "scf_to": 4.0, "gw_from": 2.0, "gw_to": 2.0, | |
| "label": "scf_step_down"}, | |
| {"scf_from": 6.0, "scf_to": 6.0, "gw_from": 3.0, "gw_to": 1.5, | |
| "label": "gw_step_down"}, | |
| {"scf_from": 6.0, "scf_to": 6.0, "gw_from": 1.5, "gw_to": 3.0, | |
| "label": "gw_step_up"}, | |
| {"scf_from": 4.0, "scf_to": 8.0, "gw_from": 3.0, "gw_to": 1.5, | |
| "label": "simultaneous_change"}, | |
| {"scf_from": 12.0, "scf_to": 12.0, "gw_from": 2.0, "gw_to": 2.0, | |
| "label": "high_force_steady"}, | |
| {"scf_from": 2.0, "scf_to": 2.0, "gw_from": 4.0, "gw_to": 4.0, | |
| "label": "low_force_wide_gap"}, | |
| ] | |
| # ============================================================================= | |
| # TIME-SERIES GENERATION | |
| # ============================================================================= | |
| SAMPLE_RATE_HZ = 2.0 # 2 samples/second (0.5s intervals) | |
| RUN_DURATION_S = 180.0 # 3-minute runs — enough to see settling + steady state | |
| SETPOINT_CHANGE_AT_S = 30.0 # setpoint changes at t=30s | |
| def pid_response(t, setpoint_from, setpoint_to, change_time, | |
| settling_time, overshoot_factor, noise_cv, | |
| has_pid, disturbance_sensitivity, rng_local): | |
| """ | |
| Simulate PID controller response to a setpoint change. | |
| Without PID: parameter drifts slowly toward equilibrium with high noise. | |
| With PID: second-order underdamped response (overshoot + settling). | |
| """ | |
| n = len(t) | |
| values = np.zeros(n) | |
| step_size = setpoint_to - setpoint_from | |
| for i, ti in enumerate(t): | |
| if ti < change_time: | |
| # Pre-change: at old setpoint with noise | |
| base = setpoint_from | |
| else: | |
| elapsed = ti - change_time | |
| if has_pid and abs(step_size) > 0.01: | |
| # Underdamped PID: exponential decay with overshoot | |
| tau = settling_time / 4.0 # time constant | |
| zeta = 0.4 + rng_local.uniform(-0.05, 0.05) # damping ratio | |
| omega_n = 1.0 / tau | |
| omega_d = omega_n * np.sqrt(1 - zeta**2) if zeta < 1 else omega_n | |
| decay = np.exp(-zeta * omega_n * elapsed) | |
| oscillation = np.cos(omega_d * elapsed) | |
| overshoot_amp = overshoot_factor * abs(step_size) | |
| response = 1.0 - decay * (oscillation + (zeta/np.sqrt(1-zeta**2)) * | |
| np.sin(omega_d * elapsed)) if zeta < 1 else \ | |
| 1.0 - (1 + omega_n * elapsed) * np.exp(-omega_n * elapsed) | |
| response = np.clip(response, -0.5, 1.5) | |
| base = setpoint_from + step_size * response | |
| elif not has_pid and abs(step_size) > 0.01: | |
| # No PID: slow exponential approach, never quite gets there | |
| tau = settling_time / 2.0 | |
| response = 1.0 - np.exp(-elapsed / tau) | |
| # Steady-state offset (no integral term to eliminate it) | |
| offset = 0.03 * step_size * disturbance_sensitivity | |
| base = setpoint_from + step_size * response * 0.95 + offset | |
| else: | |
| base = setpoint_to | |
| # Process noise (proportional to setpoint magnitude) | |
| noise = rng_local.normal(0, noise_cv * abs(base) + 0.01) | |
| # Occasional disturbances (feed fluctuations, powder bridging) | |
| if rng_local.random() < 0.02 * disturbance_sensitivity: | |
| noise += rng_local.normal(0, 0.05 * abs(base)) | |
| values[i] = base + noise | |
| return values | |
| def compute_run_metrics(t, scf_actual, gw_actual, scf_setpoint, gw_setpoint, | |
| change_time): | |
| """Compute the control performance metrics from Chapter 3.1.""" | |
| # Steady-state region: last 60 seconds of the run | |
| ss_mask = t >= (t[-1] - 60.0) | |
| # Settling region: after change, before steady state | |
| settling_mask = (t >= change_time) & (t < change_time + 90.0) | |
| # SCF metrics | |
| scf_ss = scf_actual[ss_mask] | |
| scf_mean = np.mean(scf_ss) | |
| scf_std = np.std(scf_ss) | |
| scf_cv = (scf_std / abs(scf_mean) * 100) if abs(scf_mean) > 0.1 else 0.0 | |
| scf_deviation_pct = abs(scf_mean - scf_setpoint) / scf_setpoint * 100 \ | |
| if scf_setpoint > 0.1 else 0.0 | |
| # GW metrics | |
| gw_ss = gw_actual[ss_mask] | |
| gw_mean = np.mean(gw_ss) | |
| gw_std = np.std(gw_ss) | |
| gw_cv = (gw_std / abs(gw_mean) * 100) if abs(gw_mean) > 0.1 else 0.0 | |
| gw_deviation_pct = abs(gw_mean - gw_setpoint) / gw_setpoint * 100 \ | |
| if gw_setpoint > 0.1 else 0.0 | |
| # Settling time: time after change until value stays within ±2% of final | |
| scf_settled_s = _find_settling_time(t, scf_actual, scf_setpoint, | |
| change_time, tolerance=0.02) | |
| gw_settled_s = _find_settling_time(t, gw_actual, gw_setpoint, | |
| change_time, tolerance=0.02) | |
| # Overshoot | |
| post_change = scf_actual[t >= change_time] | |
| if len(post_change) > 0 and scf_setpoint > 0.1: | |
| scf_overshoot_pct = (max(post_change) - scf_setpoint) / scf_setpoint * 100 | |
| else: | |
| scf_overshoot_pct = 0.0 | |
| return { | |
| "scf_ss_mean": round(scf_mean, 3), | |
| "scf_ss_std": round(scf_std, 4), | |
| "scf_ss_cv_pct": round(scf_cv, 2), | |
| "scf_deviation_from_setpoint_pct": round(scf_deviation_pct, 2), | |
| "scf_settling_time_s": round(scf_settled_s, 1), | |
| "scf_overshoot_pct": round(max(scf_overshoot_pct, 0), 2), | |
| "gw_ss_mean_mm": round(gw_mean, 4), | |
| "gw_ss_std_mm": round(gw_std, 4), | |
| "gw_ss_cv_pct": round(gw_cv, 2), | |
| "gw_deviation_from_setpoint_pct": round(gw_deviation_pct, 2), | |
| "gw_settling_time_s": round(gw_settled_s, 1), | |
| } | |
| def _find_settling_time(t, values, setpoint, change_time, tolerance=0.02): | |
| """Find time after change when value stays within tolerance band.""" | |
| if abs(setpoint) < 0.1: | |
| return 0.0 | |
| band = tolerance * abs(setpoint) | |
| post_mask = t >= change_time | |
| post_t = t[post_mask] | |
| post_v = values[post_mask] | |
| # Walk backwards from end to find last excursion outside band | |
| for i in range(len(post_v) - 1, -1, -1): | |
| if abs(post_v[i] - setpoint) > band: | |
| if i < len(post_v) - 1: | |
| return post_t[i+1] - change_time | |
| else: | |
| return post_t[-1] - change_time | |
| return 0.0 # already settled | |
| # ============================================================================= | |
| # GENERATE ALL RUNS | |
| # ============================================================================= | |
| t = np.arange(0, RUN_DURATION_S, 1.0 / SAMPLE_RATE_HZ) | |
| n_samples = len(t) | |
| summary_rows = [] | |
| timeseries_rows = [] | |
| run_id = 0 | |
| for ctrl_key, ctrl in CONTROL_CONFIGS.items(): | |
| for mat_key, mat in MATERIALS.items(): | |
| for scenario in SCENARIOS: | |
| run_id += 1 | |
| # Adjusted settling times and noise for material | |
| scf_settling = (ctrl["scf_settling_base_s"] * | |
| mat["settling_multiplier"]) | |
| gw_settling = (ctrl["gw_settling_base_s"] * | |
| mat["settling_multiplier"]) | |
| scf_noise = ctrl["scf_noise_base"] * mat["control_difficulty"] | |
| gw_noise = ctrl["gw_noise_base"] * mat["control_difficulty"] | |
| # Twin screw reduces feed fluctuation → lower noise | |
| if ctrl["feed_type"] == "twin_screw": | |
| scf_noise *= 0.75 | |
| gw_noise *= 0.80 | |
| # Generate time series | |
| scf_actual = pid_response( | |
| t, scenario["scf_from"], scenario["scf_to"], | |
| SETPOINT_CHANGE_AT_S, scf_settling, | |
| ctrl["overshoot_factor"], scf_noise, | |
| ctrl["has_scf_pid"], mat["disturbance_sensitivity"], rng | |
| ) | |
| gw_actual = pid_response( | |
| t, scenario["gw_from"], scenario["gw_to"], | |
| SETPOINT_CHANGE_AT_S, gw_settling, | |
| ctrl["overshoot_factor"] * 0.7, gw_noise, | |
| ctrl["has_gw_pid"], mat["disturbance_sensitivity"], rng | |
| ) | |
| # Clip to physical limits | |
| scf_actual = np.clip(scf_actual, 0.5, 25.0) | |
| gw_actual = np.clip(gw_actual, 0.5, 8.0) | |
| # Roll speed: constant within a run (not PID-controlled here) | |
| rs_setpoint = 3.0 + rng.uniform(-1, 1) | |
| rs_actual = rs_setpoint + rng.normal(0, 0.02 * rs_setpoint, n_samples) | |
| # Screw speed: varies if GW PID adjusts it | |
| ss_base = 30.0 + rng.uniform(-5, 5) | |
| if ctrl["has_gw_pid"]: | |
| # Screw speed adapts inversely to gap error | |
| gw_error = scenario["gw_to"] - gw_actual | |
| ss_actual = ss_base + 5.0 * gw_error + rng.normal(0, 0.5, n_samples) | |
| else: | |
| ss_actual = ss_base + rng.normal(0, 0.3, n_samples) | |
| # Store time-series (subsample to every 2s for manageable file size) | |
| subsample = np.arange(0, n_samples, 4) # every 2 seconds | |
| for idx in subsample: | |
| timeseries_rows.append({ | |
| "run_id": run_id, | |
| "time_s": round(t[idx], 1), | |
| "scf_setpoint_kN_per_cm": scenario["scf_to"] if t[idx] >= SETPOINT_CHANGE_AT_S else scenario["scf_from"], | |
| "scf_actual_kN_per_cm": round(scf_actual[idx], 3), | |
| "gw_setpoint_mm": scenario["gw_to"] if t[idx] >= SETPOINT_CHANGE_AT_S else scenario["gw_from"], | |
| "gw_actual_mm": round(gw_actual[idx], 4), | |
| "roll_speed_rpm": round(rs_actual[idx], 2), | |
| "screw_speed_rpm": round(ss_actual[idx], 1), | |
| }) | |
| # Compute summary metrics | |
| metrics = compute_run_metrics( | |
| t, scf_actual, gw_actual, | |
| scenario["scf_to"], scenario["gw_to"], | |
| SETPOINT_CHANGE_AT_S | |
| ) | |
| # Classify control quality | |
| total_cv = metrics["scf_ss_cv_pct"] + metrics["gw_ss_cv_pct"] | |
| if total_cv < 2.0 and metrics["scf_deviation_from_setpoint_pct"] < 1.0: | |
| control_quality = "Excellent" | |
| elif total_cv < 5.0 and metrics["scf_deviation_from_setpoint_pct"] < 3.0: | |
| control_quality = "Good" | |
| elif total_cv < 10.0: | |
| control_quality = "Acceptable" | |
| else: | |
| control_quality = "Poor" | |
| summary_rows.append({ | |
| "run_id": run_id, | |
| "control_architecture": ctrl_key, | |
| "control_label": ctrl["label"], | |
| "feed_type": ctrl["feed_type"], | |
| "has_scf_pid": ctrl["has_scf_pid"], | |
| "has_gw_pid": ctrl["has_gw_pid"], | |
| "material": mat_key, | |
| "scenario": scenario["label"], | |
| "scf_setpoint_kN_per_cm": scenario["scf_to"], | |
| "gw_setpoint_mm": scenario["gw_to"], | |
| **metrics, | |
| "control_quality_grade": control_quality, | |
| }) | |
| # ============================================================================= | |
| # SAVE | |
| # ============================================================================= | |
| df_summary = pd.DataFrame(summary_rows) | |
| df_timeseries = pd.DataFrame(timeseries_rows) | |
| df_summary.to_csv("control_performance_summary_v1.0.csv", index=False) | |
| df_timeseries.to_csv("control_performance_timeseries_v1.0.csv", index=False) | |
| print(f"Summary: {len(df_summary)} runs, {len(df_summary.columns)} columns") | |
| print(f"Time series: {len(df_timeseries)} rows, {len(df_timeseries.columns)} columns") | |
| print() | |
| print("=== Control quality distribution ===") | |
| print(df_summary["control_quality_grade"].value_counts()) | |
| print() | |
| print("=== Mean SCF CV% by architecture ===") | |
| print(df_summary.groupby("control_architecture")["scf_ss_cv_pct"].mean().round(2)) | |
| print() | |
| print("=== Mean GW CV% by architecture ===") | |
| print(df_summary.groupby("control_architecture")["gw_ss_cv_pct"].mean().round(2)) | |
| print() | |
| print("=== Mean SCF settling time by architecture ===") | |
| print(df_summary.groupby("control_architecture")["scf_settling_time_s"].mean().round(1)) | |