@datagrok/compute 0.6.3 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/export-funccall.ts +102 -162
- package/src/function-editor/function-editor.ts +304 -225
- package/src/package.ts +9 -38
- package/scripts/pMax.js +0 -191
- package/scripts/vMaxJS.js +0 -208
- package/src/outliers-selection/outliers-selection.ts +0 -281
package/src/package.ts
CHANGED
|
@@ -3,7 +3,6 @@ import * as grok from 'datagrok-api/grok';
|
|
|
3
3
|
import * as ui from 'datagrok-api/ui';
|
|
4
4
|
import * as DG from 'datagrok-api/dg';
|
|
5
5
|
import {ModelHandler} from './model-handler';
|
|
6
|
-
import {selectOutliersManually} from './outliers-selection/outliers-selection';
|
|
7
6
|
import {exportFuncCall} from './export-funccall';
|
|
8
7
|
import {_functionParametersGrid} from './function-views/function-parameters-grid';
|
|
9
8
|
import {ModelCatalogView} from './model-catalog-view';
|
|
@@ -19,34 +18,6 @@ export function test() {
|
|
|
19
18
|
grok.shell.info(_package.webRoot);
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
//name: manualOutlierDetectionDialog
|
|
23
|
-
//input: dataframe inputData
|
|
24
|
-
//output: dataframe augmentedInput
|
|
25
|
-
//output: dataframe editedInput
|
|
26
|
-
export async function manualOutlierSelectionDialog(inputData: DG.DataFrame) {
|
|
27
|
-
const call = grok.functions.getCurrentCall();
|
|
28
|
-
|
|
29
|
-
const IS_OUTLIER_COL_LABEL = 'isOutlier';
|
|
30
|
-
const OUTLIER_REASON_COL_LABEL = 'Rationale';
|
|
31
|
-
|
|
32
|
-
if (call.options['interactive']) {
|
|
33
|
-
const {augmentedInput, editedInput} = await selectOutliersManually(inputData);
|
|
34
|
-
return {augmentedInput, editedInput};
|
|
35
|
-
}
|
|
36
|
-
return new Promise<{augmentedInput: DG.DataFrame, editedInput: DG.DataFrame}>((resolve, reject) => {
|
|
37
|
-
if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
|
|
38
|
-
inputData.columns
|
|
39
|
-
.add(DG.Column.fromBitSet(IS_OUTLIER_COL_LABEL, DG.BitSet.create(inputData.rowCount, () => false)));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!inputData.columns.byName(OUTLIER_REASON_COL_LABEL)) {
|
|
43
|
-
inputData.columns
|
|
44
|
-
.add(DG.Column.fromStrings(OUTLIER_REASON_COL_LABEL, Array.from({length: inputData.rowCount}, () => '')));
|
|
45
|
-
}
|
|
46
|
-
resolve({augmentedInput: inputData, editedInput: inputData});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
21
|
//name: OutliersSelectionViewer
|
|
51
22
|
//description: Creates an outliers selection viewer
|
|
52
23
|
//tags: viewer
|
|
@@ -55,7 +26,7 @@ export function OutliersSelection() {
|
|
|
55
26
|
return new OutliersSelectionViewer();
|
|
56
27
|
}
|
|
57
28
|
|
|
58
|
-
//name:
|
|
29
|
+
//name: Export to Excel
|
|
59
30
|
//input: funccall call
|
|
60
31
|
//tags: export
|
|
61
32
|
export function exportToExcel(call: DG.FuncCall) {
|
|
@@ -71,16 +42,16 @@ export function functionEditor() {
|
|
|
71
42
|
#language: python
|
|
72
43
|
#sample: chem/smiles_coordinates.csv
|
|
73
44
|
#tags: demo, chem, rdkit
|
|
74
|
-
#input: dataframe t1 {columns:numerical} [first input data table]
|
|
75
|
-
#input: dataframe t2 {columns:numerical} [second input data table]
|
|
76
|
-
#input: column x {type:numerical; table:t1} [x axis column name]
|
|
77
|
-
#input: column y {type:numerical} [y axis column name]
|
|
78
|
-
#input: column date {type:datetime; format:mm/dd/yyyy} [date column name]
|
|
79
|
-
#input: column_list numdata {type:numerical; table:t1} [numerical columns names]
|
|
80
|
-
#input: int numcomp = 2 {
|
|
45
|
+
#input: dataframe t1 {columns: numerical; category: test} [first input data table]
|
|
46
|
+
#input: dataframe t2 {columns: numerical} [second input data table]
|
|
47
|
+
#input: column x {type: numerical; table: t1} [x axis column name]
|
|
48
|
+
#input: column y {type: numerical} [y axis column name]
|
|
49
|
+
#input: column date {type: datetime; format: mm/dd/yyyy} [date column name]
|
|
50
|
+
#input: column_list numdata {type :numerical; table:t1} [numerical columns names]
|
|
51
|
+
#input: int numcomp = 2 {min: 2; max: 7; units: mm} [number of components]
|
|
81
52
|
#input: bool center = true [number of components]
|
|
82
53
|
#input: string type = high {choices: ["high", "low"]} [type of filter]
|
|
83
|
-
#output: dataframe result {action:join(t1)} [pca components]
|
|
54
|
+
#output: dataframe result {action: join(t1)} [pca components]
|
|
84
55
|
#output: graphics scatter [scatter plot]
|
|
85
56
|
|
|
86
57
|
import numba
|
package/scripts/pMax.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
//name: Pmax
|
|
2
|
-
//description: pMax Filtration Model
|
|
3
|
-
//language: javascript
|
|
4
|
-
//tags: model, filtration
|
|
5
|
-
//input: dataframe inputTable {caption: Input table; viewer: Grid(block: 50)} [Should contain columns Time (min), Vol (mL), P1 (psi), P2 (psi)]
|
|
6
|
-
//input: dataframe reportingParameters {caption: Reporting parameters; viewer: Grid(block: 50)}
|
|
7
|
-
//input: double batchVolume = 100 {caption: Batch volume; units: L} [Batch volume]
|
|
8
|
-
//input: double batchTime = 2 {caption: Batch time; units: hours} [Batch time]
|
|
9
|
-
//input: double targetPressure = 20 {caption: Target pressure; units: psi} [Target pressure]
|
|
10
|
-
//input: double aMinFilter1Guessed = 0.153 {units: m²; caption:A_guessed filter 1} [A_guessed filter 1]
|
|
11
|
-
//input: double aMinFilter2Guessed = 0.153 {units: m²; caption:A_guessed filter 2} [A_guessed filter 2]
|
|
12
|
-
//input: double filterArea1 = 23 {units: m²; caption: A_trial filter 1} [A_trial filter 1]
|
|
13
|
-
//input: double filterArea2 = 23 {units: m²; caption: A_trial filter 2} [A_trial filter 2]
|
|
14
|
-
//input: double sf = 1.5 {caption: Safety factor}
|
|
15
|
-
//output: dataframe Filter1 {caption: Primary filter; viewer: Scatter Plot(block: 50, showDataframeFormulaLines: "true"); category: OUTPUT}
|
|
16
|
-
//output: dataframe Guessed1 {caption: Guessed primary filter; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
|
|
17
|
-
//output: dataframe t1 {caption: Primary filter results; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
|
|
18
|
-
//output: dataframe Filter2 {caption: Secondary filter; viewer: Scatter Plot(block: 50, showDataframeFormulaLines: "true"); category: OUTPUT}
|
|
19
|
-
//output: dataframe Guessed2 {caption: Guessed secondary filter; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
|
|
20
|
-
//output: dataframe t2 {caption: Secondary filter results; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
|
|
21
|
-
|
|
22
|
-
function gaussianElimination(input, orderOfPolynomialRegression) {
|
|
23
|
-
const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
|
|
24
|
-
for (let i = 0; i < n; i++) {
|
|
25
|
-
let maxrow = i;
|
|
26
|
-
for (let j = i + 1; j < n; j++)
|
|
27
|
-
if (Math.abs(input[i][j]) > Math.abs(input[i][maxrow]))
|
|
28
|
-
maxrow = j;
|
|
29
|
-
for (let k = i; k < n + 1; k++) {
|
|
30
|
-
const tmp = input[k][i];
|
|
31
|
-
input[k][i] = input[k][maxrow];
|
|
32
|
-
input[k][maxrow] = tmp;
|
|
33
|
-
}
|
|
34
|
-
for (let j = i + 1; j < n; j++)
|
|
35
|
-
for (let k = n; k >= i; k--)
|
|
36
|
-
input[k][j] -= (input[k][i] * input[i][j]) / input[i][i];
|
|
37
|
-
}
|
|
38
|
-
for (let j = n - 1; j >= 0; j--) {
|
|
39
|
-
let total = 0;
|
|
40
|
-
for (let k = j + 1; k < n; k++)
|
|
41
|
-
total += input[k][j] * coefficients[k];
|
|
42
|
-
coefficients[j] = (input[n][j] - total) / input[j][j];
|
|
43
|
-
}
|
|
44
|
-
return coefficients;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression) {
|
|
48
|
-
const lhs = [], rhs = [], len = xCol.length, k = orderOfPolynomialRegression + 1;
|
|
49
|
-
let a = 0, b = 0;
|
|
50
|
-
for (let i = 0; i < k; i++) {
|
|
51
|
-
for (let l = 0; l < len; l++)
|
|
52
|
-
a += (xCol.get(l) ** i) * yCol.get(l);
|
|
53
|
-
lhs.push(a);
|
|
54
|
-
a = 0;
|
|
55
|
-
const c = [];
|
|
56
|
-
for (let j = 0; j < k; j++) {
|
|
57
|
-
for (let l = 0; l < len; l++)
|
|
58
|
-
b += xCol.get(l) ** (i + j);
|
|
59
|
-
c.push(b);
|
|
60
|
-
b = 0;
|
|
61
|
-
}
|
|
62
|
-
rhs.push(c);
|
|
63
|
-
}
|
|
64
|
-
rhs.push(lhs);
|
|
65
|
-
return gaussianElimination(rhs, k);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function predictPolynomialRegression(coefficients, x) {
|
|
69
|
-
let y = coefficients[0];
|
|
70
|
-
for (let i = coefficients.length - 1; i > 0; i--)
|
|
71
|
-
y += coefficients[i] * Math.pow(x, i);
|
|
72
|
-
return y;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function equationString(xColName, yColName, coefficients) {
|
|
76
|
-
let s = '';
|
|
77
|
-
for (let [index, coefficient] of coefficients.slice(1).reverse().entries()) {
|
|
78
|
-
s += String(coefficient);
|
|
79
|
-
for (let i = 0; i < coefficients.length - index - 1; i++)
|
|
80
|
-
s += " * ${" + String(xColName) + "}";
|
|
81
|
-
s += " + ";
|
|
82
|
-
}
|
|
83
|
-
return "${" + yColName + "} = " + s + String(coefficients[0]);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const orderOfPolynomialRegression = 3;
|
|
87
|
-
const lengthOfSecondTable = 2985;
|
|
88
|
-
const colNames1 = {
|
|
89
|
-
'time': 'Time (min)',
|
|
90
|
-
'volume': 'Vol (mL)',
|
|
91
|
-
'pressure1': 'P1 (psi)',
|
|
92
|
-
'pressure2': 'P2 (psi)',
|
|
93
|
-
'tp1': 'TP 1 (L/m2)', 'flux1': 'Flux 1 (LMH)', 'res1': 'Res. 1 (psi/LMH)',
|
|
94
|
-
'tp2': 'TP 2 (L/m2)', 'flux2': 'Flux 2 (LMH)', 'res2': 'Res. 2 (psi/LMH)',
|
|
95
|
-
'deltaP': 'Delta P (psi)'
|
|
96
|
-
};
|
|
97
|
-
const colNames2 = {
|
|
98
|
-
'area': 'Guess Area (m2)',
|
|
99
|
-
'javg': 'Javg (LMH)',
|
|
100
|
-
'R': 'R calc (psi/LMH)',
|
|
101
|
-
'Y1': 'Y1', 'd1': 'Delta1',
|
|
102
|
-
'Y2': 'Y2', 'd2': 'Delta2'
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const t = inputTable.col(colNames1['time']);
|
|
106
|
-
const v = inputTable.col(colNames1['volume']);
|
|
107
|
-
const p1 = inputTable.col(colNames1['pressure1']);
|
|
108
|
-
const p2 = inputTable.col(colNames1['pressure2']);
|
|
109
|
-
const df1 = DG.DataFrame.fromColumns([t, v, p1, p2]);
|
|
110
|
-
df1.columns.addNewFloat(colNames1['tp1']).init((i) => (i > 0) ? 10 * v.get(i) / filterArea1 : 0);
|
|
111
|
-
df1.columns.addNewFloat(colNames1['tp2']).init((i) => (i > 0) ? 10 * v.get(i) / filterArea2 : 0);
|
|
112
|
-
df1.columns.addNewFloat(colNames1['flux1']).init((i) => (i > 0) ? 600 * (v.get(i) - v.get(i-1)) / (t.get(i) - t.get(i-1)) / filterArea1 : 0);
|
|
113
|
-
df1.columns.addNewFloat(colNames1['flux2']).init((i) => (i > 0) ? 600 * (v.get(i) - v.get(i-1)) / (t.get(i) - t.get(i-1)) / filterArea2 : 0);
|
|
114
|
-
df1.columns.addNewFloat(colNames1['deltaP']).init((i) => p1.get(i) - p2.get(i));
|
|
115
|
-
const deltaP = df1.col(colNames1['deltaP']), flux1 = df1.col(colNames1['flux1']), flux2 = df1.col(colNames1['flux2']);
|
|
116
|
-
df1.columns.addNewFloat(colNames1['res1']).init((i) => (i > 0) ? deltaP.get(i) / flux1.get(i) : 0);
|
|
117
|
-
df1.columns.addNewFloat(colNames1['res2']).init((i) => (i > 0) ? p2.get(i) / flux2.get(i) : 0);
|
|
118
|
-
Filter1 = DG.DataFrame.fromColumns([df1.col(colNames1['tp1']), df1.col(colNames1['res1'])]);
|
|
119
|
-
Filter2 = DG.DataFrame.fromColumns([df1.col(colNames1['tp2']), df1.col(colNames1['res2'])]);
|
|
120
|
-
const coefficients1 = polynomialRegressionCoefficients(df1.col(colNames1['tp1']), df1.col(colNames1['res1']), orderOfPolynomialRegression);
|
|
121
|
-
const coefficients2 = polynomialRegressionCoefficients(df1.col(colNames1['tp2']), df1.col(colNames1['res2']), orderOfPolynomialRegression);
|
|
122
|
-
|
|
123
|
-
Filter1.meta.addFormulaLine({
|
|
124
|
-
title: 'Third-order polynomial regression',
|
|
125
|
-
equation: equationString(colNames1['tp1'], colNames1['res1'], coefficients1),
|
|
126
|
-
zindex: -30,
|
|
127
|
-
color: '#ff0000',
|
|
128
|
-
width: 3
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
Filter2.meta.addFormulaLine({
|
|
132
|
-
title: 'Third-order polynomial regression',
|
|
133
|
-
equation: equationString(colNames1['tp2'], colNames1['res2'], coefficients2),
|
|
134
|
-
zindex: -30,
|
|
135
|
-
color: '#ff0000',
|
|
136
|
-
width: 3
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
const df2 = DG.DataFrame.create(lengthOfSecondTable);
|
|
140
|
-
df2.columns.addNewFloat(colNames2['area']).init((i) => (i > 0) ? batchVolume / i : 0);
|
|
141
|
-
const area = df2.col(colNames2['area']);
|
|
142
|
-
df2.columns.addNewFloat(colNames2['javg']).init((i) => (i > 0) ? batchVolume / area.get(i) / batchTime : 0);
|
|
143
|
-
const javg = df2.col(colNames2['javg']);
|
|
144
|
-
df2.columns.addNewFloat(colNames2['R']).init((i) => (i > 0) ? targetPressure / javg.get(i) : 0);
|
|
145
|
-
df2.columns.addNewFloat(colNames2['Y1']).init((i) => predictPolynomialRegression(coefficients1, i));
|
|
146
|
-
df2.columns.addNewFloat(colNames2['Y2']).init((i) => predictPolynomialRegression(coefficients2, i));
|
|
147
|
-
const rCalc = df2.col(colNames2['R']), y1 = df2.col(colNames2['Y1']), y2 = df2.col(colNames2['Y2']);
|
|
148
|
-
df2.columns.addNewFloat(colNames2['d1']).init((i) => Math.abs(rCalc.get(i) - y1.get(i)));
|
|
149
|
-
df2.columns.addNewFloat(colNames2['d2']).init((i) => Math.abs(rCalc.get(i) - y2.get(i)));
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
amin1 = df2.col(colNames2['area']).get(df2.col(colNames2['d1']).toList().indexOf(df2.col(colNames2['d1']).min));
|
|
153
|
-
amin2 = df2.col(colNames2['area']).get(df2.col(colNames2['d2']).toList().indexOf(df2.col(colNames2['d2']).min));
|
|
154
|
-
processFlow1 = batchVolume / batchTime, processFlow2 = batchVolume / batchTime;
|
|
155
|
-
processFlux1 = processFlow1 / amin1, processFlux2 = processFlow2 / amin2;
|
|
156
|
-
trialFlux1 = 600 * v.max / t.max / filterArea1, trialFlux2 = 600 * v.max / t.max / filterArea2;
|
|
157
|
-
aminSF1 = sf * amin1, aminSF2 = sf * amin2;
|
|
158
|
-
trialLoading1 = df1.col(colNames1['tp1']).max, trialLoading2 = df1.col(colNames1['tp2']).max;
|
|
159
|
-
processLoading1 = batchVolume / amin1, processLoading2 = batchVolume / amin2;
|
|
160
|
-
maxP1 = predictPolynomialRegression(coefficients1, processLoading1) * processFlux1;
|
|
161
|
-
maxP2 = predictPolynomialRegression(coefficients2, processLoading2) * processFlux2;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
guessedAmin1 = aMinFilter1Guessed, guessedAmin2 = aMinFilter2Guessed;
|
|
165
|
-
guessedProcessLoading1 = batchVolume / aMinFilter1Guessed, guessedProcessLoading2 = batchVolume / aMinFilter2Guessed;
|
|
166
|
-
guessedMaxP1 = predictPolynomialRegression(coefficients1, processLoading1) * processFlux1;
|
|
167
|
-
guessedMaxP2 = predictPolynomialRegression(coefficients2, processLoading2) * processFlux2;
|
|
168
|
-
guessedProcessFlux1 = processFlow1 / aMinFilter1Guessed, guessedProcessFlux2 = processFlow2 / aMinFilter2Guessed;
|
|
169
|
-
|
|
170
|
-
const names = ['Amin (m²)', 'Amin w SF (m²)', 'Trial Loading (L/m²)', 'Process Loading (L/m²)', 'Max P (psi)', 'Trial Flux (LMH)', 'Process Flux (LMH)', 'Process Flow (L/hr)'];
|
|
171
|
-
const guessedNames = ['Amin (m²)', 'Process Loading (L/m²)', 'Max P (psi)', 'Process Flux (LMH)'];
|
|
172
|
-
|
|
173
|
-
t1 = DG.DataFrame.fromColumns([
|
|
174
|
-
DG.Column.fromStrings('Name', names),
|
|
175
|
-
DG.Column.fromFloat32Array('Value', [amin1, aminSF1, trialLoading1, processLoading1, maxP1, trialFlux1, processFlux1, processFlow1])
|
|
176
|
-
]);
|
|
177
|
-
|
|
178
|
-
t2 = DG.DataFrame.fromColumns([
|
|
179
|
-
DG.Column.fromStrings('Name', names),
|
|
180
|
-
DG.Column.fromFloat32Array('Value', [amin2, aminSF2, trialLoading2, processLoading2, maxP2, trialFlux2, processFlux2, processFlow2])
|
|
181
|
-
]);
|
|
182
|
-
|
|
183
|
-
Guessed1 = DG.DataFrame.fromColumns([
|
|
184
|
-
DG.Column.fromStrings('Name', guessedNames),
|
|
185
|
-
DG.Column.fromFloat32Array('Value', [guessedAmin1, guessedProcessLoading1, guessedMaxP1, guessedProcessFlux1])
|
|
186
|
-
]);
|
|
187
|
-
|
|
188
|
-
Guessed2 = DG.DataFrame.fromColumns([
|
|
189
|
-
DG.Column.fromStrings('Name', guessedNames),
|
|
190
|
-
DG.Column.fromFloat32Array('Value', [guessedAmin2, guessedProcessLoading2, guessedMaxP2, guessedProcessFlux2])
|
|
191
|
-
]);
|
package/scripts/vMaxJS.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
//name: Vmax
|
|
2
|
-
//description: Predict the minimum filter size required for the separation of effluent from bioreactors, given the constraints of batch size and total batch time based on a training dataset of time vs filtrate volume for a given filter type, filter area and pressure
|
|
3
|
-
//language: javascript
|
|
4
|
-
//tags: model, filtration
|
|
5
|
-
//input: dataframe inputTable {caption: Input table; viewer: OutliersSelectionViewer(block: 25) | Scatter Plot(block: 75, filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true")}
|
|
6
|
-
//input: dataframe reportingParameters {caption: Reporting parameters; viewer: Grid()}
|
|
7
|
-
//input: double testFilterArea = 3.5 {caption: Test filter area; units: cm²} [Test filter area]
|
|
8
|
-
//input: double desiredVolumeOfBatch = 25 {caption: Desired batch volume; units: L} [Desired batch volume]
|
|
9
|
-
//input: double desiredProcessTime = 0.5 {caption: Desired process time; units: hr} [Desired process time]
|
|
10
|
-
//input: double sf = 1.5 {caption: Safety factor} [Safety factor]
|
|
11
|
-
//help-url: https://github.com/datagrok-ai/public/blob/master/packages/Compute/src/help.md
|
|
12
|
-
//output: dataframe regressionTable {caption: Regression table; viewer: Scatter Plot(block: 75, filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true"); category: OUTPUT}
|
|
13
|
-
//output: dataframe trialData {caption: Trial data; viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); category: OUTPUT}
|
|
14
|
-
//output: dataframe fluxDecayDf {caption: Flux decay experimental results; viewer: Scatter Plot(description: "Absolute flux decay", y: "J (LMH)", block: 50, filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195) | Scatter Plot(description: "Relative flux decay", y: "J/Jo", block: 50, filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195); category: OUTPUT}
|
|
15
|
-
//output: dataframe experimentalResultsSummary {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Experimental results summary; category: OUTPUT}
|
|
16
|
-
//output: dataframe recommendations {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Recommendations; category: OUTPUT}
|
|
17
|
-
//output: dataframe sampleCharacteristics {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Sample characteristics; category: OUTPUT}
|
|
18
|
-
//output: dataframe filter {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Filter; category: OUTPUT}
|
|
19
|
-
|
|
20
|
-
// inputTable = grok.shell.tables[0];
|
|
21
|
-
// reportingParameters = grok.shell.tables[1];
|
|
22
|
-
// testFilterArea = 3.5;
|
|
23
|
-
// desiredVolumeOfBatch = 25;
|
|
24
|
-
// desiredProcessTime = 0.5;
|
|
25
|
-
// sf = 1.5;
|
|
26
|
-
|
|
27
|
-
const expectedInputColNames = {
|
|
28
|
-
"time": "time (min)",
|
|
29
|
-
"volume": "filtrate volume (mL)",
|
|
30
|
-
"isOutlier": "isOutlier"
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const expectedReportParamsNames = {
|
|
34
|
-
1: "Filter family",
|
|
35
|
-
2: "Filter name",
|
|
36
|
-
3: "Pore rating (μm)",
|
|
37
|
-
4: "Effective membr. area (cm^2)",
|
|
38
|
-
5: "Membr material",
|
|
39
|
-
6: "Catalog nr",
|
|
40
|
-
7: "Date",
|
|
41
|
-
8: "Prior step",
|
|
42
|
-
9: "Prot conc. (mg/mL)",
|
|
43
|
-
10: "Density (g/L)",
|
|
44
|
-
11: "Turbidity (NTU)",
|
|
45
|
-
12: "Installed device",
|
|
46
|
-
13: "Project name",
|
|
47
|
-
14: "Filtration stage",
|
|
48
|
-
15: "ELN reference",
|
|
49
|
-
16: "Bioreactor ID",
|
|
50
|
-
17: "Bioreactor PCV (%)",
|
|
51
|
-
18: "Bioreactor turbidity (NTU)",
|
|
52
|
-
19: "Filter feed turbidity (NTU)",
|
|
53
|
-
20: "Filter feed PCV (%)",
|
|
54
|
-
21: "Filter feed pH",
|
|
55
|
-
22: "Filter feed LDH (U/L)",
|
|
56
|
-
23: "Filter feed conductivity (mS/cm)"
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
function gaussianElimination(input, orderOfPolynomialRegression) {
|
|
60
|
-
const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
|
|
61
|
-
for (let i = 0; i < n; i++) {
|
|
62
|
-
let maxrow = i;
|
|
63
|
-
for (let j = i + 1; j < n; j++)
|
|
64
|
-
if (Math.abs(input[i][j]) > Math.abs(input[i][maxrow]))
|
|
65
|
-
maxrow = j;
|
|
66
|
-
for (let k = i; k < n + 1; k++) {
|
|
67
|
-
const tmp = input[k][i];
|
|
68
|
-
input[k][i] = input[k][maxrow];
|
|
69
|
-
input[k][maxrow] = tmp;
|
|
70
|
-
}
|
|
71
|
-
for (let j = i + 1; j < n; j++)
|
|
72
|
-
for (let k = n; k >= i; k--)
|
|
73
|
-
input[k][j] -= (input[k][i] * input[i][j]) / input[i][i];
|
|
74
|
-
}
|
|
75
|
-
for (let j = n - 1; j >= 0; j--) {
|
|
76
|
-
let total = 0;
|
|
77
|
-
for (let k = j + 1; k < n; k++)
|
|
78
|
-
total += input[k][j] * coefficients[k];
|
|
79
|
-
coefficients[j] = (input[n][j] - total) / input[j][j];
|
|
80
|
-
}
|
|
81
|
-
return coefficients;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression) {
|
|
85
|
-
const lhs = [], rhs = [], len = xCol.length, k = orderOfPolynomialRegression + 1;
|
|
86
|
-
let a = 0, b = 0;
|
|
87
|
-
for (let i = 0; i < k; i++) {
|
|
88
|
-
for (let l = 0; l < len; l++)
|
|
89
|
-
a += (xCol.get(l) ** i) * yCol.get(l);
|
|
90
|
-
lhs.push(a);
|
|
91
|
-
a = 0;
|
|
92
|
-
const c = [];
|
|
93
|
-
for (let j = 0; j < k; j++) {
|
|
94
|
-
for (let l = 0; l < len; l++)
|
|
95
|
-
b += xCol.get(l) ** (i + j);
|
|
96
|
-
c.push(b);
|
|
97
|
-
b = 0;
|
|
98
|
-
}
|
|
99
|
-
rhs.push(c);
|
|
100
|
-
}
|
|
101
|
-
rhs.push(lhs);
|
|
102
|
-
return gaussianElimination(rhs, k);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const orderOfPolynomialRegression = 2;
|
|
106
|
-
const area = 0.00035;
|
|
107
|
-
const timeInMinutesCol = inputTable.col(expectedInputColNames['time']);
|
|
108
|
-
const volumeInMillilitersCol = inputTable.col(expectedInputColNames['volume']);
|
|
109
|
-
const isOutlierCol = inputTable.col(expectedInputColNames["isOutlier"]);
|
|
110
|
-
|
|
111
|
-
let df = DG.DataFrame.fromColumns([timeInMinutesCol, volumeInMillilitersCol, isOutlierCol]);
|
|
112
|
-
df.columns.addNewFloat('time (hr)').init((i) => timeInMinutesCol.get(i) / 60);
|
|
113
|
-
const timeInHours = df.col('time (hr)');
|
|
114
|
-
df.columns.addNewFloat('V (L/m2)').init((i) => 10 * volumeInMillilitersCol.get(i) / testFilterArea);
|
|
115
|
-
const newVolume = df.col('V (L/m2)');
|
|
116
|
-
df.columns.addNewFloat('t/V (hr/(L/m2))').init((i) => 100 * timeInHours.get(i) / newVolume.get(i));
|
|
117
|
-
df.columns.addNewFloat('Time (s)').init((i) => 60 * timeInMinutesCol.get(i));
|
|
118
|
-
df.columns.addNewFloat('V (L)').init((i) => volumeInMillilitersCol.get(i) / 1000);
|
|
119
|
-
const volumeInLiters = df.col('V (L)');
|
|
120
|
-
const timeInSeconds = df.col('Time (s)');
|
|
121
|
-
df.columns.addNewFloat('V/A (L/m2)').init((i) => volumeInLiters.get(i) / area);
|
|
122
|
-
const va = df.col('V/A (L/m2)');
|
|
123
|
-
|
|
124
|
-
const slopes = [], intercepts = [];
|
|
125
|
-
const windowLength = 3;
|
|
126
|
-
for (let i = 0; i < inputTable.rowCount - windowLength; i++) {
|
|
127
|
-
const xCol = DG.Column.fromFloat32Array('name', timeInSeconds.toList().slice(i, i + windowLength));
|
|
128
|
-
const yCol = DG.Column.fromFloat32Array('name', va.toList().slice(i, i + windowLength));
|
|
129
|
-
const coefficients = polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression);
|
|
130
|
-
slopes.push(coefficients[orderOfPolynomialRegression]);
|
|
131
|
-
intercepts.push(coefficients[orderOfPolynomialRegression - 1]);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
let newDf = DG.DataFrame.create(inputTable.rowCount - windowLength);
|
|
135
|
-
newDf.columns.addNewFloat('a2').init((i) => (i > 0) ? 3600 * (2 * slopes[i] * timeInSeconds.get(i) + intercepts[i]) : 0);
|
|
136
|
-
newDf.columns.addNewFloat('a1').init((i) => (i > 0) ? 3600 * (2 * slopes[i] * timeInSeconds.get(i) + intercepts[i]) : 0);
|
|
137
|
-
newDf.columns.addNewFloat('J (LMH)').init((i) => (i > 0) ? 3600 * (2 * slopes[i] * timeInSeconds.get(i) + intercepts[i]) : 0);
|
|
138
|
-
const j = newDf.col('J (LMH)');
|
|
139
|
-
newDf.columns.addNewFloat('J/Jo').init((i) => (i > 0) ? j.get(i) / (3600 * area) : 0);
|
|
140
|
-
let jj0 = newDf.col('J/Jo');
|
|
141
|
-
jj0 = DG.Column.fromFloat32Array('J/Jo', jj0.toList().map((e) => 100 * e / jj0.max));
|
|
142
|
-
fluxDecayDf = DG.DataFrame.fromColumns([
|
|
143
|
-
DG.Column.fromStrings('Run', Array(jj0.length - 1).fill('1')),
|
|
144
|
-
DG.Column.fromFloat32Array(va.name, va.toList().slice(1, inputTable.rowCount - windowLength)),
|
|
145
|
-
DG.Column.fromFloat32Array(j.name, j.toList().slice(1, j.length)),
|
|
146
|
-
DG.Column.fromFloat32Array(jj0.name, jj0.toList().slice(1, jj0.length)),
|
|
147
|
-
DG.Column.fromList('bool', isOutlierCol.name, isOutlierCol.toList().slice(1, isOutlierCol.length - windowLength))
|
|
148
|
-
]);
|
|
149
|
-
|
|
150
|
-
regressionTable = DG.DataFrame.fromColumns([
|
|
151
|
-
timeInMinutesCol,
|
|
152
|
-
volumeInMillilitersCol,
|
|
153
|
-
inputTable.col('t/V (hr/(L/m²))'),
|
|
154
|
-
isOutlierCol
|
|
155
|
-
]);
|
|
156
|
-
|
|
157
|
-
const timeMin = [], vol = [], isOutlier = [];
|
|
158
|
-
const isOutlierColList = isOutlierCol.toList();
|
|
159
|
-
for (let i = 0; i < inputTable.rowCount - windowLength; i++) {
|
|
160
|
-
if (isOutlierCol.get(i) == false) {
|
|
161
|
-
timeMin.push(timeInMinutesCol.get(i));
|
|
162
|
-
vol.push(volumeInMillilitersCol.get(i));
|
|
163
|
-
isOutlier.push(true in isOutlierColList.slice(i, i + windowLength));
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
coefficients = polynomialRegressionCoefficients(DG.Column.fromFloat32Array("time (min)", timeMin), DG.Column.fromFloat32Array("t/V (hr/(L/m2))", vol), 1);
|
|
168
|
-
const initialFlowRate = coefficients[0];
|
|
169
|
-
const trialThroughput = Math.round(1000 * va.max) / 1000;
|
|
170
|
-
const flux = initialFlowRate / testFilterArea;
|
|
171
|
-
const initialFlux = Math.round(1000 * j.get(1)) / 1000;
|
|
172
|
-
const ff0 = flux / initialFlux;
|
|
173
|
-
const meanFlux = Math.round(1000 * j.stats.avg) / 1000;
|
|
174
|
-
const vmax = Math.round(1000 * coefficients[1]) / 1000;
|
|
175
|
-
const v90 = Math.round(1000 * (vmax * 0.68)) / 1000;
|
|
176
|
-
const instantaneousFlux = j.get(j.length - 1);
|
|
177
|
-
const fluxDecay = Math.round(1000 * (1 - instantaneousFlux / initialFlux) * 100) / 1000;
|
|
178
|
-
const names = reportingParameters.col('Parameter name').toList();
|
|
179
|
-
const values = reportingParameters.col('Parameter value').toList();
|
|
180
|
-
const q0 = 1 / coefficients[0];
|
|
181
|
-
const amin = Math.round(1000 * (desiredVolumeOfBatch / vmax) + (desiredVolumeOfBatch / desiredProcessTime / q0)) / 1000;
|
|
182
|
-
const installedArea = Math.round(1000 * sf * amin) / 1000;
|
|
183
|
-
const processLoading = Math.round(1000 * volumeInLiters.get(volumeInLiters.length - 1) / installedArea) / 1000;
|
|
184
|
-
|
|
185
|
-
experimentalResultsSummary = DG.DataFrame.fromColumns([
|
|
186
|
-
DG.Column.fromStrings('Name', ['Run', 'Filter', 'Trial Throughput (L/m²)', 'Flux0 (LMH)', 'Mean Flux (LMH)', 'Vmax (L/m²)', 'Flux Decay (%)']),
|
|
187
|
-
DG.Column.fromStrings('Value', ['1', values[names.indexOf(expectedReportParamsNames[1])], String(trialThroughput), String(initialFlux), String(meanFlux), String(vmax), String(fluxDecay)])
|
|
188
|
-
]);
|
|
189
|
-
|
|
190
|
-
recommendations = DG.DataFrame.fromColumns([
|
|
191
|
-
DG.Column.fromStrings('Name', ['Volume (L)', 'Time (h)', 'Amin (m²)', 'Safety Factor', 'Installed Area', 'Process Loading (L/m²)', expectedReportParamsNames[1], expectedReportParamsNames[12]]),
|
|
192
|
-
DG.Column.fromStrings('Value', [String(desiredVolumeOfBatch), String(desiredProcessTime), String(amin), String(sf), String(installedArea), String(processLoading), values[names.indexOf(expectedReportParamsNames[1])], values[names.indexOf(expectedReportParamsNames[12])]])
|
|
193
|
-
]);
|
|
194
|
-
|
|
195
|
-
trialData = DG.DataFrame.fromColumns([
|
|
196
|
-
DG.Column.fromStrings('Name', ['Test Filter Area (m²)', 'Initial Flow Rate (L/h)', 'Vmax (m²)', 'V90 (m²)']),
|
|
197
|
-
DG.Column.fromStrings('Value', [String(Math.round(1000 * testFilterArea) / 1000), String(Math.round(1000 * initialFlowRate) / 1000), String(vmax), String(v90)])
|
|
198
|
-
]);
|
|
199
|
-
|
|
200
|
-
filter = DG.DataFrame.fromColumns([
|
|
201
|
-
DG.Column.fromStrings('Name', [expectedReportParamsNames[1], expectedReportParamsNames[2], expectedReportParamsNames[3], expectedReportParamsNames[4], expectedReportParamsNames[5], expectedReportParamsNames[6]]),
|
|
202
|
-
DG.Column.fromStrings('Value', [values[names.indexOf(expectedReportParamsNames[1])], values[names.indexOf(expectedReportParamsNames[2])], values[names.indexOf(expectedReportParamsNames[3])], values[names.indexOf(expectedReportParamsNames[4])], values[names.indexOf(expectedReportParamsNames[5])], values[names.indexOf(expectedReportParamsNames[6])]])
|
|
203
|
-
]);
|
|
204
|
-
|
|
205
|
-
sampleCharacteristics = DG.DataFrame.fromColumns([
|
|
206
|
-
DG.Column.fromStrings('Name', [expectedReportParamsNames[7], expectedReportParamsNames[8], expectedReportParamsNames[9], expectedReportParamsNames[10], expectedReportParamsNames[11]]),
|
|
207
|
-
DG.Column.fromStrings('Value', [values[names.indexOf(expectedReportParamsNames[7])].slice(0, 10), values[names.indexOf(expectedReportParamsNames[8])], values[names.indexOf(expectedReportParamsNames[9])], values[names.indexOf(expectedReportParamsNames[10])], values[names.indexOf(expectedReportParamsNames[11])]])
|
|
208
|
-
]);
|