@datagrok/compute 0.6.2 → 0.6.6

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.
@@ -63,6 +63,7 @@ export class OutliersSelectionViewer extends DG.JsViewer {
63
63
 
64
64
  const groupsListGrid = DG.Viewer.grid(clearTable());
65
65
  groupsListGrid.root.style.width = '100%';
66
+ groupsListGrid.root.style.minWidth = '230px';
66
67
  groupsListGrid.columns.setVisible([OUTLIER_RATIONALE_COL_LABEL, OUTLIER_COUNT_COL_LABEL, 'Actions']);
67
68
 
68
69
  groupsListGrid.onCellPrepare((gc) => {
@@ -178,85 +179,22 @@ export class OutliersSelectionViewer extends DG.JsViewer {
178
179
  }
179
180
  });
180
181
 
181
- const resetSelectedBtn = ui.button(
182
- 'RESET SELECTED',
183
- () => {
184
- inputData.selection.getSelectedIndexes().forEach((selectedIndex: number) => {
185
- inputData.set(IS_OUTLIER_COL_LABEL, selectedIndex, false);
186
- inputData.set(OUTLIER_RATIONALE_COL_LABEL, selectedIndex, '');
187
- });
188
- inputData.selection.setAll(false);
189
- },
190
- 'Remove the selected points from oultiers list',
191
- );
192
-
193
- const resetAllBtn = ui.button(
194
- 'RESET ALL',
195
- () => {
196
- (inputData.columns as DG.ColumnList).byName(IS_OUTLIER_COL_LABEL).init(
197
- (index) => initialData.get(IS_OUTLIER_COL_LABEL, index),
198
- );
199
- (inputData.columns as DG.ColumnList).byName(OUTLIER_RATIONALE_COL_LABEL).init(
200
- (index) => initialData.get(OUTLIER_RATIONALE_COL_LABEL, index),
201
- );
202
- },
203
- 'Cancel all changes',
204
- );
205
-
206
- const autoOutlierGroupBtn = ui.button(
207
- 'AUTO DETECT...',
208
- () => {
209
- const intInput = ui.intInput('N', 3);
210
- const columnInput = ui.columnInput('Column', inputData, null);
211
- ui.dialog('Detect outliers automatically')
212
- .add(columnInput.root)
213
- .add(intInput.root)
214
- .onOK(()=>{
215
- const meanValue = (columnInput.value as DG.Column).stats.avg;
216
- const stddev = (columnInput.value as DG.Column).stats.stdev;
217
- inputData.selection.init((index)=>
218
- Math.abs(meanValue - (columnInput.value as DG.Column).get(index)) > stddev*intInput.value,
219
- );
220
- inputData.selection.getSelectedIndexes().forEach((selectedIndex: number) => {
221
- inputData.set(IS_OUTLIER_COL_LABEL, selectedIndex, true);
222
- inputData.set(OUTLIER_RATIONALE_COL_LABEL, selectedIndex, `${intInput.value}x stddev rule`);
223
- });
224
- inputData.selection.setAll(false);
225
- })
226
- .show();
227
- },
228
- 'Detect outliers automatically',
229
- );
230
-
231
182
  inputData.selection.setAll(false);
232
183
 
233
- inputData.onSelectionChanged.subscribe(() => {
234
- if (inputData.selection.trueCount === 0) {
235
- resetSelectedBtn.classList.add('disabled');
236
- } else {
237
- resetSelectedBtn.classList.remove('disabled');
238
- }
239
- });
240
-
241
184
  updateGroupsTable();
242
- resetSelectedBtn.classList.add('disabled');
243
185
 
244
- const info = ui.info(
245
- ui.div([
246
- ui.p('Hold the “SHIFT” key and start to draw a freehand selection on the plot area'),
247
- ], {style: {'white-space': 'pre-wrap'}}),
248
- );
249
- info.style.marginBottom = '0px';
186
+ // const info = ui.info(
187
+ // ui.div([
188
+ // ui.p('Hold the “SHIFT” key and start to draw a freehand selection on the plot area'),
189
+ // ], {style: {'white-space': 'pre-wrap'}}),
190
+ // );
191
+ // info.style.marginBottom = '0px';
250
192
 
251
193
  this.root.replaceWith(
252
194
  ui.divV([
253
- info,
254
195
  ui.divV([
255
- ui.divH([
256
- resetSelectedBtn, resetAllBtn, autoOutlierGroupBtn,
257
- ], {style: {'text-align': 'center', 'justify-content': 'center'}}),
258
196
  groupsListGrid.root,
259
197
  ], {style: {'height': '75%'}}),
260
- ], {style: {'height': '100%', 'min-width': '230px'}}));
198
+ ], {style: {'height': '100%'}}));
261
199
  }
262
200
  }
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: export To Excel
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 {range:2-7} [number of components]
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,204 +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()} [Should contain columns Time (min), Vol (mL), P1 (psi), P2 (psi)]
6
- //input: dataframe reportingParameters {caption: Reporting Parameters; viewer: Grid()}
7
- //input: double batchVolume = 100 {units: L} [Batch Volume]
8
- //input: double batchTime = 2 {units: hours} [Batch Time]
9
- //input: double targetPressure = 20 {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(showDataframeFormulaLines: "true"); category: OUTPUT}
16
- //output: dataframe t1 {caption: Primary Filter Results; category: OUTPUT}
17
- //output: dataframe Guessed1 {caption: Guessed Primary Filter; category: OUTPUT}
18
- //output: dataframe Filter2 {caption: Secondary Filter; viewer: Scatter Plot(showDataframeFormulaLines: "true"); category: OUTPUT}
19
- //output: dataframe t2 {caption: Secondary Filter Results; category: OUTPUT}
20
- //output: dataframe Guessed2 {caption: Guessed Secondary Filter; 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
- t1 = DG.DataFrame.fromColumns([
171
- DG.Column.fromFloat32Array('Amin (m²)', [amin1]),
172
- DG.Column.fromFloat32Array('Amin w SF (m²)', [aminSF1]),
173
- DG.Column.fromFloat32Array('Trial Loading (L/m²)', [trialLoading1]),
174
- DG.Column.fromFloat32Array('Process Loading (L/m²)', [processLoading1]),
175
- DG.Column.fromFloat32Array('Max P (psi)', [maxP1]),
176
- DG.Column.fromFloat32Array('Trial Flux (LMH)', [trialFlux1]),
177
- DG.Column.fromFloat32Array('Process Flux (LMH)', [processFlux1]),
178
- DG.Column.fromFloat32Array('Process Flow (L/hr)', [processFlow1])
179
- ]);
180
-
181
- t2 = DG.DataFrame.fromColumns([
182
- DG.Column.fromFloat32Array('Amin (m²)', [amin2]),
183
- DG.Column.fromFloat32Array('Amin w SF (m²)', [aminSF2]),
184
- DG.Column.fromFloat32Array('Trial Loading (L/m²)', [trialLoading2]),
185
- DG.Column.fromFloat32Array('Process Loading (L/m²)', [processLoading2]),
186
- DG.Column.fromFloat32Array('Max P (psi)', [maxP2]),
187
- DG.Column.fromFloat32Array('Trial Flux (LMH)', [trialFlux2]),
188
- DG.Column.fromFloat32Array('Process Flux (LMH)', [processFlux2]),
189
- DG.Column.fromFloat32Array('Process Flow (L/hr)', [processFlow2])
190
- ]);
191
-
192
- Guessed1 = DG.DataFrame.fromColumns([
193
- DG.Column.fromFloat32Array('Amin (m²)', [guessedAmin1]),
194
- DG.Column.fromFloat32Array('Process Loading (L/m²)', [guessedProcessLoading1]),
195
- DG.Column.fromFloat32Array('Max P (psi)', [guessedMaxP1]),
196
- DG.Column.fromFloat32Array('Process Flux (LMH)', [guessedProcessFlux1]),
197
- ]);
198
-
199
- Guessed2 = DG.DataFrame.fromColumns([
200
- DG.Column.fromFloat32Array('Amin (m²)', [guessedAmin2]),
201
- DG.Column.fromFloat32Array('Process Loading (L/m²)', [guessedProcessLoading2]),
202
- DG.Column.fromFloat32Array('Max P (psi)', [guessedMaxP2]),
203
- DG.Column.fromFloat32Array('Process Flux (LMH)', [guessedProcessFlux2]),
204
- ]);
package/scripts/vMaxJS.js DELETED
@@ -1,187 +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() | Scatter Plot(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(filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true"); category: OUTPUT}
13
- //output: dataframe trialData {caption: Trial Data; category: OUTPUT}
14
- //output: dataframe fluxDecayDf {caption: Flux Decay Experimental Results; viewer: Scatter Plot(filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195) | Grid(); category: OUTPUT}
15
- //output: dataframe experimentalResultsSummary {caption: Experimental Results Summary; category: OUTPUT}
16
- //output: dataframe recommendations {caption: Recommendations; category: OUTPUT}
17
- //output: dataframe sampleCharacteristics {caption: Sample Characteristics; category: OUTPUT}
18
- //output: dataframe filter {caption: Filter; category: OUTPUT}
19
-
20
- function gaussianElimination(input, orderOfPolynomialRegression) {
21
- const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
22
- for (let i = 0; i < n; i++) {
23
- let maxrow = i;
24
- for (let j = i + 1; j < n; j++)
25
- if (Math.abs(input[i][j]) > Math.abs(input[i][maxrow]))
26
- maxrow = j;
27
- for (let k = i; k < n + 1; k++) {
28
- const tmp = input[k][i];
29
- input[k][i] = input[k][maxrow];
30
- input[k][maxrow] = tmp;
31
- }
32
- for (let j = i + 1; j < n; j++)
33
- for (let k = n; k >= i; k--)
34
- input[k][j] -= (input[k][i] * input[i][j]) / input[i][i];
35
- }
36
- for (let j = n - 1; j >= 0; j--) {
37
- let total = 0;
38
- for (let k = j + 1; k < n; k++)
39
- total += input[k][j] * coefficients[k];
40
- coefficients[j] = (input[n][j] - total) / input[j][j];
41
- }
42
- return coefficients;
43
- }
44
-
45
- function polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression) {
46
- const lhs = [], rhs = [], len = xCol.length, k = orderOfPolynomialRegression + 1;
47
- let a = 0, b = 0;
48
- for (let i = 0; i < k; i++) {
49
- for (let l = 0; l < len; l++)
50
- a += (xCol.get(l) ** i) * yCol.get(l);
51
- lhs.push(a);
52
- a = 0;
53
- const c = [];
54
- for (let j = 0; j < k; j++) {
55
- for (let l = 0; l < len; l++)
56
- b += xCol.get(l) ** (i + j);
57
- c.push(b);
58
- b = 0;
59
- }
60
- rhs.push(c);
61
- }
62
- rhs.push(lhs);
63
- return gaussianElimination(rhs, k);
64
- }
65
-
66
- const orderOfPolynomialRegression = 2;
67
- const area = 0.00035;
68
- const isOutlierCol = inputTable.col('isOutlier');
69
- const timeMin = [];
70
- const vol = [];
71
- for (let i = 0; i < isOutlierCol.length; i++) {
72
- if (isOutlierCol.get(i) == false) {
73
- timeMin.push(inputTable.col('time (min)').get(i));
74
- vol.push(inputTable.col('filtrate volume (mL)').get(i));
75
- }
76
- }
77
- dfWithoutOutliers = inputTable;
78
- // DG.DataFrame.fromColumns([
79
- // DG.Column.fromList('double', 'time (min)', timeMin),
80
- // DG.Column.fromList('double', 'filtrate volume (mL)', vol),
81
- // ]);
82
- const timeInMinutes = dfWithoutOutliers.col('time (min)');
83
- const volumeInMilliliters = dfWithoutOutliers.col('filtrate volume (mL)');
84
- dfWithoutOutliers.columns.addNewFloat('time (hr)').init((i) => timeInMinutes.get(i) / 60);
85
- const timeInHours = dfWithoutOutliers.col('time (hr)');
86
-
87
- dfWithoutOutliers.columns.addNewFloat('V (L/m2)').init((i) => 10 * volumeInMilliliters.get(i) / testFilterArea);
88
- const newVolume = dfWithoutOutliers.col('V (L/m2)');
89
-
90
- dfWithoutOutliers.columns.addNewFloat('t/V (hr/(L/m2))').init((i) => 100 * timeInHours.get(i) / newVolume.get(i));
91
-
92
- dfWithoutOutliers.columns.addNewFloat('Time (s)').init((i) => 60 * timeInMinutes.get(i));
93
- dfWithoutOutliers.columns.addNewFloat('V (L)').init((i) => volumeInMilliliters.get(i) / 1000);
94
- const volumeInLiters = dfWithoutOutliers.col('V (L)');
95
- const timeInSeconds = dfWithoutOutliers.col('Time (s)');
96
- dfWithoutOutliers.columns.addNewFloat('V/A (L/m2)').init((i) => volumeInLiters.get(i) / area);
97
- const va = dfWithoutOutliers.col('V/A (L/m2)');
98
- // const va = inputTable.
99
- const ca = [], cb = [];
100
- const windowLength = 3;
101
- for (let i = 0; i < va.length - windowLength; i++) {
102
- const xCol = DG.Column.fromList('double', 'name', timeInSeconds.toList().slice(i, i + windowLength));
103
- const yCol = DG.Column.fromList('double', 'name', va.toList().slice(i, i + windowLength));
104
- const coefficients = polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression);
105
- ca.push(coefficients[orderOfPolynomialRegression]);
106
- cb.push(coefficients[orderOfPolynomialRegression - 1]);
107
- }
108
- let newDf = DG.DataFrame.create(dfWithoutOutliers.rowCount - windowLength);
109
- newDf.columns.addNewFloat('a2').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
110
- newDf.columns.addNewFloat('a1').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
111
- newDf.columns.addNewFloat('J (LMH)').init((i) => (i > 0) ? 3600 * (2 * ca[i] * timeInSeconds.get(i) + cb[i]) : 0);
112
- const j = newDf.col('J (LMH)');
113
- newDf.columns.addNewFloat('J/Jo').init((i) => (i > 0) ? j.get(i) / (3600 * area) : 0);
114
- const jj0 = newDf.col('J/Jo');
115
- fluxDecayDf = DG.DataFrame.fromColumns([
116
- DG.Column.fromStrings('Run', Array(jj0.length - 1).fill('1')),
117
- DG.Column.fromFloat32Array(va.name, va.toList().slice(1, va.length - windowLength)),
118
- DG.Column.fromFloat32Array(j.name, j.toList().slice(1, j.length)),
119
- DG.Column.fromFloat32Array(jj0.name, jj0.toList().slice(1, jj0.length)),
120
- DG.Column.fromList('bool', isOutlierCol.name, isOutlierCol.toList().slice(1, isOutlierCol.length - windowLength))
121
- ]);
122
-
123
- regressionTable = DG.DataFrame.fromColumns([
124
- inputTable.col('time (min)'),
125
- inputTable.col('filtrate volume (mL)'),
126
- dfWithoutOutliers.col('t/V (hr/(L/m2))'),
127
- isOutlierCol
128
- ]);
129
- coefficients = [1.8, 4.32];//[4.32, 1.8];//polynomialRegressionCoefficients(inputTable.col("time (min)"), dfWithoutOutliers.col("t/V (hr/(L/m2))"), 1);
130
- const trialThroughput = va.max;
131
- const flux = 9372.11;
132
- const ff0 = flux / j.get(1);
133
- const meanFlux = j.stats.avg;
134
- const vmax = 0.28;//Math.round(1 / coefficients[1]);
135
- const instantaneousFlux = j.get(j.length - 1);
136
- const initialFlux = j.get(1);
137
- const fluxDecay = (1 - instantaneousFlux / initialFlux) * 100;
138
- const names = reportingParameters.col('Parameter').toList();
139
- const values = reportingParameters.col('Value').toList();
140
- experimentalResultsSummary = DG.DataFrame.fromColumns([
141
- DG.Column.fromStrings('Run', ['1']),
142
- DG.Column.fromStrings('Filter', [values[names.indexOf('Filter Name')]]),
143
- DG.Column.fromFloat32Array('Trial Throughput (L/m²)', [trialThroughput]),
144
- DG.Column.fromFloat32Array('Flux0 (LMH)', [j.get(1)]),
145
- DG.Column.fromFloat32Array('Mean Flux (LMH)', [meanFlux]),
146
- DG.Column.fromFloat32Array('Vmax (L/m²)', [vmax]),
147
- DG.Column.fromFloat32Array('Flux Decay (%)', [fluxDecay]),
148
- ]);
149
- const q0 = Math.round(1 / coefficients[0]);
150
- const amin = (desiredVolumeOfBatch / vmax) + (desiredVolumeOfBatch / desiredProcessTime / q0);
151
- const installedArea = sf * amin;
152
- const processLoading = volumeInLiters.get(volumeInLiters.length - 1) / installedArea;
153
- recommendations = DG.DataFrame.fromColumns([
154
- DG.Column.fromFloat32Array('Volume (L)', [desiredVolumeOfBatch]),
155
- DG.Column.fromFloat32Array('Time (h)', [desiredProcessTime]),
156
- DG.Column.fromFloat32Array('Amin (m²)', [amin]),
157
- DG.Column.fromFloat32Array('Safety Factor', [sf]),
158
- DG.Column.fromFloat32Array('Installed Area', [installedArea]),
159
- DG.Column.fromFloat32Array('Process Loading (L/m²)', [processLoading]),
160
- DG.Column.fromStrings('Filter', [values[names.indexOf('Filter Name')]]),
161
- DG.Column.fromStrings('Installed Device', [values[names.indexOf('Installed Device')]]),
162
- ]);
163
-
164
- const v90 = vmax * 0.68;
165
- const initialFlowRate = coefficients[0];
166
- trialData = DG.DataFrame.fromColumns([
167
- DG.Column.fromFloat32Array('Test Filter Area (m²)', [testFilterArea]),
168
- DG.Column.fromFloat32Array('Initial Flow Rate (L/h)', [initialFlowRate]),
169
- DG.Column.fromFloat32Array('Vmax (m²)', [vmax]),
170
- DG.Column.fromFloat32Array('V90 (m²)', [v90]),
171
- ]);
172
-
173
- filter = DG.DataFrame.fromColumns([
174
- DG.Column.fromStrings('Filter Family', [values[names.indexOf('Filter Family')]]),
175
- DG.Column.fromStrings('Filter Name', [values[names.indexOf('Filter Name')]]),
176
- DG.Column.fromStrings('Pore Rating (μm)', [values[names.indexOf('Pore rating (μm)')]]),
177
- DG.Column.fromStrings('Effective Membr. Area (cm^2)', [values[names.indexOf('Effective Membr. Area (cm^2)')]]),
178
- DG.Column.fromStrings('Membr material', [values[names.indexOf('Membr material')]]),
179
- DG.Column.fromStrings('Catalog Nr', [values[names.indexOf('Catalog Nr')]]),
180
- ]);
181
- sampleCharacteristics = DG.DataFrame.fromColumns([
182
- DG.Column.fromStrings('Date', [values[names.indexOf('date ')]]),
183
- DG.Column.fromStrings('Prior Step', [values[names.indexOf('Prior Step')]]),
184
- DG.Column.fromStrings('Prot conc. (mg/mL)', [values[names.indexOf('Prot conc. (mg/mL)')]]),
185
- DG.Column.fromStrings('Density (g/L)', [values[names.indexOf('Density (g/L)')]]),
186
- DG.Column.fromStrings('Turbidity (NTU)', [values[names.indexOf('Turbidity (NTU)')]]),
187
- ]);