@datagrok/compute 0.1.1 → 0.2.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.
- package/README.md +11 -234
- package/files/model-templates.json +27 -0
- package/package.json +9 -6
- package/scripts/Fab Arm Exchange.py +3 -1
- package/scripts/Heat Exchange.js +3 -1
- package/scripts/IntervalsFromECG.py +24 -0
- package/scripts/{Logistic map.js → Logistic Map.js } +3 -2
- package/scripts/{Lorenz attractor.js → Lorenz Attractor.js } +3 -2
- package/scripts/{Lotka-Volterra Model.js → Lotka-Volterra.js} +3 -2
- package/scripts/Maximal Volume.R +36 -20
- package/scripts/pMax.js +163 -0
- package/scripts/pkpd.R +1 -0
- package/scripts/popPK.R +10 -6
- package/scripts/trig.js +1 -0
- package/scripts/vMaxJS.js +115 -0
- package/src/export-funccall.ts +46 -1
- package/src/help.md +3 -0
- package/src/model-catalog-view.ts +9 -12
- package/src/model-handler.ts +22 -7
- package/src/onboard-model.ts +54 -4
- package/src/outliers-selection.ts +7 -2
- package/src/package.ts +112 -14
- package/webpack.config.js +1 -0
- package/help/ui-auto-generation.png +0 -0
- package/scripts/AT-COE.py +0 -8
- package/scripts/Chemometric.py +0 -16
- package/scripts/Heat Transfer Cooling.py +0 -8
- package/scripts/High-titer field.py +0 -8
- package/scripts/pMax.py +0 -8
package/README.md
CHANGED
|
@@ -1,236 +1,13 @@
|
|
|
1
1
|
# Compute
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
3. [Web-based UI](#user-interface) that could be [autogenerated](#autogenerated-ui),
|
|
15
|
-
[customized](#custom-ui), and [templates]
|
|
16
|
-
4. [One-touch deployment]
|
|
17
|
-
1. [Model versioning]
|
|
18
|
-
5. [Data sources]
|
|
19
|
-
6. [Metadata]
|
|
20
|
-
7. [Integration]: [API], [embedding]
|
|
21
|
-
8. [Logging, audit, and traceability]
|
|
22
|
-
9. [Leveraging the platform]
|
|
23
|
-
1. [Privileges and visibility]
|
|
24
|
-
2. [Usage analysis]
|
|
25
|
-
3. [Exploratory data analysis]
|
|
26
|
-
10. [Roadmap]
|
|
27
|
-
1. [Repository of curated scientific methods]
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* Composable (an output of one function becomes an input to the other)
|
|
31
|
-
* Could be connected to any data source (db, web service, file, etc)
|
|
32
|
-
* Logging, audit, traceability
|
|
33
|
-
* Privileges and visibility
|
|
34
|
-
|
|
35
|
-
`Compute` package:
|
|
36
|
-
|
|
37
|
-
* Enables a full lifecycle of models: create, tune, share, use, validate
|
|
38
|
-
* Provides for easy to use and highly automated evaluation and computation environment
|
|
39
|
-
* Enables contextual process for the Design of Experiment (sensitivity analysis and more)
|
|
40
|
-
|
|
41
|
-
In addition, Datagrok platform supports a UI layout markup, so that the model function becomes
|
|
42
|
-
a GUI-rich application with no manual coding.
|
|
43
|
-
|
|
44
|
-
Project planning board: [link](https://github.com/datagrok-ai/public/projects/8).
|
|
45
|
-
|
|
46
|
-
## Cross-language support
|
|
47
|
-
|
|
48
|
-
The basic unit of execution is a [function](https://datagrok.ai/help/overview/functions/function),
|
|
49
|
-
which could be written in [any language that Datagrok supports](https://datagrok.ai/help/develop/scripting)
|
|
50
|
-
, such as `Python`, `R`,
|
|
51
|
-
`Julia`, `Matlab/Octave`, `JavaScript`, and others. No matter which language is used,
|
|
52
|
-
each function has the following properties:
|
|
53
|
-
* Advanced support for input and output parameters
|
|
54
|
-
* Typed (cross-language support for scalars, vectors, dataframes, images)
|
|
55
|
-
* Intraspectable
|
|
56
|
-
* Metadata-annotated
|
|
57
|
-
* Dynamic discovery
|
|
58
|
-
* Polymorphic execution (platform doesn't care which language the function is implemented in)
|
|
59
|
-
* Function-level [metadata]
|
|
60
|
-
|
|
61
|
-
These properties unlock plenty
|
|
62
|
-
of interesting features covered below, such as
|
|
63
|
-
[scalable computations](#scalable-computations),
|
|
64
|
-
[reproducibility],
|
|
65
|
-
[automatic UI generation](#autogenerated-ui),
|
|
66
|
-
[audit],
|
|
67
|
-
[sensitivity analysis],
|
|
68
|
-
[optimization], and others.
|
|
69
|
-
|
|
70
|
-
## Scalable computations
|
|
71
|
-
|
|
72
|
-
Depending on the underlying language, a function could be executed on the client side,
|
|
73
|
-
server side, both, or either.
|
|
74
|
-
|
|
75
|
-
`JavaScript` and `C++` (compiled to [WebAssembly](https://webassembly.org/)) could be executed
|
|
76
|
-
right in the browser. The upside to that is unmatched responsiveness, data locality, and
|
|
77
|
-
computation locality. The downside is that many of the popular statistical and modeling
|
|
78
|
-
methods are not currently available in these languages yet. Note that while the computations are
|
|
79
|
-
performed locally, the proper audit and traceability still works (both input and output
|
|
80
|
-
parameters could be sent to the server for historic reasons).
|
|
81
|
-
|
|
82
|
-
`R`, `Python`, `Julia`, `Matlab`, and `Octave` are powerful languages with the mature
|
|
83
|
-
ecosystem of scientific libraries, and existing models implemented previously inside the
|
|
84
|
-
organization. They could only be executed on a server, and as such
|
|
85
|
-
the question of scalable computation arises. Datagrok takes care of that by using the
|
|
86
|
-
`message queue` architecture. When each server-based function is invoked, its parameters
|
|
87
|
-
are saved to a queue; one of the worker processes then picks a task (such as running a Python
|
|
88
|
-
function), executes it, and puts the results back. This architecture guarantees the following:
|
|
89
|
-
|
|
90
|
-
* The platform won't get overloaded by trying to execute too many tasks at once
|
|
91
|
-
* Scaling is as simple as adding more workers (which could be hosted externally if necessary)
|
|
92
|
-
* A queue serves as a basis for [audit] and [traceability]
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
## One-touch deployment
|
|
96
|
-
|
|
97
|
-
## User interface
|
|
98
|
-
|
|
99
|
-
Our goal is not computations for the sake of it, but
|
|
100
|
-
rather helping **users** derive actionable insights, and support the decision-making process.
|
|
101
|
-
The UI should be as easy to use as possible, tailored to the user needs, and
|
|
102
|
-
be specific for the tasks. On the other hand, it should be clean, universal, and easy enough
|
|
103
|
-
to be developed by a scientist without a deep understanding of the Datagrok platform.
|
|
104
|
-
To satisfy these seemingly contradictory requirements, we developed a hybrid approach to
|
|
105
|
-
building the UI, where the model author has full control over choosing how custom the UI
|
|
106
|
-
for the speficic model should be. In the most standard case, there is no need to write
|
|
107
|
-
a single line of code, as the UI is
|
|
108
|
-
[automatically generated](#autogenerated-ui) based on the function signature.
|
|
109
|
-
On the other end of the spectrum, you have the possibility to take everything in your own
|
|
110
|
-
hands and develop a completely [custom UI](#custom-ui). Anything in between is also possible.
|
|
111
|
-
|
|
112
|
-
### Autogenerated UI
|
|
113
|
-
|
|
114
|
-
Very often, a UI for the model is nothing more than the input fields for the
|
|
115
|
-
corresponding function's parameters. When this is the case, Datagrok generates the UI automatically
|
|
116
|
-
by constructing the corresponding input fields and output area with graphics and results,
|
|
117
|
-
and bringing it to life by making it interactive. Additional parameters' metadata, such
|
|
118
|
-
as units, category, description, input type (slider/combo box/etc), and others
|
|
119
|
-
are also taken into account.
|
|
120
|
-
|
|
121
|
-
The following picture demonstrates a working PK/PD model implemented in R
|
|
122
|
-
with the autogenerated UI (look at the script header area for details). While it looks
|
|
123
|
-
very similar to the traditional Shiny app, the R script does not have to deal with
|
|
124
|
-
the UI at all, which not only simplifies the development and maintenance, but also
|
|
125
|
-
provides for the uniform experience.
|
|
126
|
-
|
|
127
|
-
A visual tool for annotating function parameters is
|
|
128
|
-
[currently in the development](#https://github.com/datagrok-ai/public/issues/184).
|
|
129
|
-
|
|
130
|
-

|
|
131
|
-
|
|
132
|
-
Learn more: [function parameters](https://datagrok.ai/help/overview/functions/func-params-enhancement)
|
|
133
|
-
|
|
134
|
-
### Custom UI
|
|
135
|
-
|
|
136
|
-
On the other side of the spectrum, if necessary the UI could be developed
|
|
137
|
-
from scratch without any limitations, using either vanilla JavaScript,
|
|
138
|
-
a framework of your choice such as React, or
|
|
139
|
-
[Datagrok UI toolkit](../../help/develop/js-api.md#ui). No matter what
|
|
140
|
-
you choose, Datagrok [JS API](https://datagrok.ai/help/develop/develop) could always be used.
|
|
141
|
-
|
|
142
|
-
## One-touch deployment
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
## Analytical blocks
|
|
147
|
-
|
|
148
|
-
No matter which domain you are working with, which language your program in,
|
|
149
|
-
or what type of model you build, quite often you need the same set of tools (including visual tools) to
|
|
150
|
-
efficiently work with data. Naturally, it makes sense to implement these algorithms
|
|
151
|
-
just once, and then use them everywhere. Here are some examples:
|
|
152
|
-
|
|
153
|
-
1. Imputation of missing values
|
|
154
|
-
2. Outlier detection
|
|
155
|
-
3. Time series analysis
|
|
156
|
-
4. Validators
|
|
157
|
-
|
|
158
|
-
The fact that the typical analysis is an introspectable workflow consisting of functions
|
|
159
|
-
passing the data helps us deal with that in a declarative manner.
|
|
160
|
-
|
|
161
|
-
## Privileges and visibility
|
|
162
|
-
|
|
163
|
-
Datagrok has the built-in [role-based privileges system](https://datagrok.ai/help/govern/authorization)
|
|
164
|
-
that is used to define who can see, execute, or edit models.
|
|
165
|
-
|
|
166
|
-
## Roadmap
|
|
167
|
-
|
|
168
|
-
1. **UI markup**
|
|
169
|
-
|
|
170
|
-
Annotate function inputs and outputs to produce highly interactive, visually reach GUI:
|
|
171
|
-
|
|
172
|
-
* arrange inputs and outputs in blocks and tabs
|
|
173
|
-
* add captions, units of measure and other information to inputs and outputs
|
|
174
|
-
* automatically produce additional plots with Datagrok
|
|
175
|
-
[viewers](https://datagrok.ai/help/visualize/viewers)
|
|
176
|
-
|
|
177
|
-
2. **Input providers**
|
|
178
|
-
|
|
179
|
-
Produce inputs to functions in-place as outputs of other functions (aka input providers),
|
|
180
|
-
including:
|
|
181
|
-
|
|
182
|
-
* queries to databases
|
|
183
|
-
* dialog-based functions (outlier detection, data annotation)
|
|
184
|
-
* queries to OpenAPI and REST endpoints
|
|
185
|
-
* other computing functions with or without GUI
|
|
186
|
-
|
|
187
|
-
These may include UI parts as well. The input provider is specified as part of the Universal UI
|
|
188
|
-
markup.
|
|
189
|
-
|
|
190
|
-
3. **Persistent, sharable historical runs**
|
|
191
|
-
|
|
192
|
-
It is already possible to provide a link to a function (with specified input parameters in
|
|
193
|
-
the URI), which will open a function view and run it.
|
|
194
|
-
|
|
195
|
-
Once a certain version of a specific function is run with specific inputs, the result should
|
|
196
|
-
be stored in the immutable database log along with the inputs. Later it will be used to verify
|
|
197
|
-
the grounds for decisions made from these calculations.
|
|
198
|
-
|
|
199
|
-
4. **Sensitivity analysis**
|
|
200
|
-
|
|
201
|
-
* Sample inputs:
|
|
202
|
-
* by specified number of samples
|
|
203
|
-
* by a specified distribution or within a range
|
|
204
|
-
* for a specified set of scalar inputs and/or columns of the matrix input
|
|
205
|
-
* Produce variability analysis for outputs based on the sampled inputs
|
|
206
|
-
* Visualize the results of analysis with Datagrok viewers
|
|
207
|
-
|
|
208
|
-
5. **Modeling input parameters**
|
|
209
|
-
|
|
210
|
-
Solve an inversion problem: identify input conditions leading to specified output constraints.
|
|
211
|
-
|
|
212
|
-
6. **Outlier detection and annotation**
|
|
213
|
-
|
|
214
|
-
* Automatic outliers detection
|
|
215
|
-
* Manual outliers markup and annotation
|
|
216
|
-
* Used as an input provider in other functions
|
|
217
|
-
|
|
218
|
-
7. **Model Repository and discoverability**
|
|
219
|
-
|
|
220
|
-
8. **Scaling on demand**
|
|
221
|
-
|
|
222
|
-
9. **Asynchronous computation**
|
|
223
|
-
|
|
224
|
-
10. **Export and reporting**
|
|
225
|
-
|
|
226
|
-
11. **REST endpoints**
|
|
227
|
-
|
|
228
|
-
12. **Data annotation**
|
|
229
|
-
|
|
230
|
-
13. **Test data for functions**
|
|
231
|
-
|
|
232
|
-
14. **Functions versioning**
|
|
233
|
-
|
|
234
|
-
15. **Audit**
|
|
235
|
-
|
|
236
|
-
Most of the features are implemented in this package, some of them are part of the platform.
|
|
3
|
+
Provides additional analytical and UI blocks for
|
|
4
|
+
[Datagrok scientific computing](../../help/compute/compute.md)
|
|
5
|
+
|
|
6
|
+
* Model browser
|
|
7
|
+
* Outlier selector tool
|
|
8
|
+
* Universal export tool
|
|
9
|
+
* Step-by-step wizard for onboarding new models
|
|
10
|
+
* Model renderers
|
|
11
|
+
* Function views
|
|
12
|
+
* Function parameter grid
|
|
13
|
+
* A set of examples
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "Bioreactor simulation",
|
|
4
|
+
"props": [
|
|
5
|
+
{
|
|
6
|
+
"name": "reactorType",
|
|
7
|
+
"type": "string",
|
|
8
|
+
"choices": ["Experimental", "Production"]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "department",
|
|
12
|
+
"type": "string",
|
|
13
|
+
"choices": ["", "Production"]
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "Biosensors",
|
|
19
|
+
"props": [
|
|
20
|
+
{
|
|
21
|
+
"name": "sensor",
|
|
22
|
+
"type": "string",
|
|
23
|
+
"choices": ["Accelerometer", "GSR", "EEG", "ECG", "Eye Tracker"]
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
]
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/compute",
|
|
3
3
|
"friendlyName": "Compute",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.6",
|
|
5
5
|
"description": "",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"cash-dom": "latest",
|
|
8
|
-
"datagrok-api": "
|
|
8
|
+
"datagrok-api": ">=0.95.8",
|
|
9
9
|
"dayjs": "latest",
|
|
10
10
|
"exceljs": "^4.3.0",
|
|
11
11
|
"file-saver": "^2.0.5",
|
|
12
12
|
"ts-loader": "latest",
|
|
13
|
-
"typescript": "latest"
|
|
13
|
+
"typescript": "latest",
|
|
14
|
+
"wu": "latest"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
17
|
+
"@types/wu": "latest",
|
|
16
18
|
"@types/file-saver": "^2.0.3",
|
|
17
19
|
"@typescript-eslint/eslint-plugin": "^5.1.0",
|
|
18
20
|
"@typescript-eslint/parser": "^5.1.0",
|
|
@@ -22,12 +24,13 @@
|
|
|
22
24
|
"webpack-cli": "latest"
|
|
23
25
|
},
|
|
24
26
|
"scripts": {
|
|
25
|
-
"
|
|
27
|
+
"link-api": "npm link datagrok-api",
|
|
28
|
+
"debug-compute": "webpack & grok publish dev --release",
|
|
26
29
|
"release-compute": "grok publish --rebuild --release",
|
|
27
30
|
"build-compute": "webpack",
|
|
28
31
|
"build": "webpack",
|
|
29
|
-
"debug-compute-dev": "grok publish dev --rebuild",
|
|
30
|
-
"release-compute-dev": "grok publish dev --
|
|
32
|
+
"debug-compute-dev": "webpack && grok publish dev --rebuild",
|
|
33
|
+
"release-compute-dev": "grok publish dev --release",
|
|
31
34
|
"debug-compute-local": "grok publish local --rebuild",
|
|
32
35
|
"release-compute-local": "grok publish local --rebuild --release",
|
|
33
36
|
"debug-compute-localhost": "grok publish localhost --rebuild",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#name: Fab Arm Exchange
|
|
2
2
|
#language: python
|
|
3
|
-
#tags: model
|
|
3
|
+
#tags: model, simulation
|
|
4
|
+
#meta.modality: Antibody
|
|
5
|
+
#meta.domain: Manufacturing
|
|
4
6
|
#input: double meaConcentration = 60 {category:FAE Reaction Parameters; units:mM; caption:2-MEA Concentration} [2-MEA Concentration]
|
|
5
7
|
#input: double phOfFaeReaction = 7.5 {category:FAE Reaction Parameters; caption:pH of FAE Reaction} [pH of FAE Reaction]
|
|
6
8
|
#input: double faeReactionTime = 3 {category:FAE Reaction Parameters; units:hr; caption:FAE Reaction Time} [FAE Reaction Time]
|
package/scripts/Heat Exchange.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
//name: Heat Exchange
|
|
2
2
|
//language: javascript
|
|
3
|
-
//tags: model
|
|
3
|
+
//tags: model, simulation
|
|
4
|
+
//meta.modality: Small molecule
|
|
4
5
|
//input: int len = 1000
|
|
5
6
|
//input: double k = 1.2
|
|
6
7
|
//output: dataframe simulation {viewer: Line Chart(multiAxis: "true")}
|
|
7
8
|
//output: double finalTemperature
|
|
8
9
|
//output: double finalSaturation
|
|
9
10
|
//output: double finalConcentration
|
|
11
|
+
//meta.domain: Manufacturing
|
|
10
12
|
|
|
11
13
|
function sigmoid(z) {
|
|
12
14
|
return 1 / (1 + Math.exp(-z));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#name: IntervalsFromECG
|
|
2
|
+
#description: Identify the beats in an ECG signal and compute the IBIs
|
|
3
|
+
#language: python
|
|
4
|
+
#tags: model
|
|
5
|
+
#input: double samplingFrequency = 2048
|
|
6
|
+
#input: int bpmMax = 120 [Maximal expected heart rate (in beats per minute): (1 < bpm_max <= 400)]
|
|
7
|
+
#input: double delta = 0 [Threshold for the peak detection. By default it is computed from the signal (adaptive thresholding)]
|
|
8
|
+
#input: double k = 0.7 [Ratio at which the signal range is multiplied (when delta = 0), (0 < k < 1)]
|
|
9
|
+
#output: graphics Intervals
|
|
10
|
+
|
|
11
|
+
import pyphysio as ph
|
|
12
|
+
import matplotlib.pyplot as plt
|
|
13
|
+
from pyphysio.tests import TestData
|
|
14
|
+
|
|
15
|
+
ecg_data = TestData.ecg()
|
|
16
|
+
|
|
17
|
+
ecg = ph.EvenlySignal(values=ecg_data, sampling_freq=samplingFrequency, signal_type = 'ecg')
|
|
18
|
+
|
|
19
|
+
extracted = ph.BeatFromECG(bpm_max=bpmMax, delta=delta, k=k)(ecg)
|
|
20
|
+
|
|
21
|
+
Intervals = plt.plot(extracted)
|
|
22
|
+
plt.title('RR intervals')
|
|
23
|
+
plt.xlabel('Interval index')
|
|
24
|
+
plt.ylabel('Seconds')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//name: Logistic
|
|
2
|
-
//tags: model,
|
|
1
|
+
//name: Logistic Map
|
|
2
|
+
//tags: model, simulation
|
|
3
3
|
//description: Archetypal example of how complex, chaotic behaviour can arise from very simple non-linear dynamical equations.
|
|
4
4
|
//language: javascript
|
|
5
5
|
//input: int iterations = 1000 [Number of iterations per point]
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
//input: double spacing = 0.001 [Spacing between points on domain (r-axis)]
|
|
8
8
|
//input: double res = 8 [Largest n-cycle visible]
|
|
9
9
|
//output: dataframe df {viewer: Scatter plot(title: "Logistic map")}
|
|
10
|
+
//meta.domain: Nonlinear dynamics
|
|
10
11
|
|
|
11
12
|
function getRandomNumberInRange(min, max) {
|
|
12
13
|
return Math.random() * (max - min) + min;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
//name: Lorenz
|
|
2
|
-
//tags: model,
|
|
1
|
+
//name: Lorenz Attractor
|
|
2
|
+
//tags: model, simulation
|
|
3
|
+
//meta.domain: Nonlinear dynamics
|
|
3
4
|
//description: Set of chaotic solutions of the system for weather prediction. It illustrates the phenomenon known as the Butterfly effect or (more technically) sensitive dependence on initial conditions
|
|
4
5
|
//language: javascript
|
|
5
6
|
//input: int iterations = 1000
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
//name: Lotka-Volterra
|
|
2
|
-
//tags: model,
|
|
1
|
+
//name: Lotka-Volterra
|
|
2
|
+
//tags: model, simulation
|
|
3
|
+
//meta.domain: Nonlinear dynamics
|
|
3
4
|
//description: Model describes the dynamics of biological systems in which two species interact, one as a predator and the other as prey.
|
|
4
5
|
//language: javascript
|
|
5
6
|
//input: double x0 = 0.5 [Initial conditions for prey population]
|
package/scripts/Maximal Volume.R
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
#name:
|
|
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
|
|
2
3
|
#language: r
|
|
3
4
|
#tags: model
|
|
4
5
|
#input: dataframe test_data {editor: Compute:manualOutlierSelectionDialog; editor-button: Outliers...}
|
|
5
|
-
#input: double test_area =
|
|
6
|
-
#input: double
|
|
7
|
-
#input: double
|
|
8
|
-
#input: double
|
|
6
|
+
#input: double test_area = 3.5 {caption: Filter Area; units: cm²} [Filter area]
|
|
7
|
+
#input: double vbatch = 25 {caption: VBatch; units: L} [Desired batch size to process]
|
|
8
|
+
#input: double tbatch = 0.5 {caption: TBatch; units: hr} [Desired process time]
|
|
9
|
+
#input: double sf = 1.5 {caption: Safety Factor} [Safety Factor]
|
|
10
|
+
#output: dataframe processedData {viewer: Scatter Plot(x: "time (hr)", y: "t/V (hr/(L/m2))", showRegressionLine: "true"); category: Raw Plot}
|
|
9
11
|
#output: double vmax { category: Lin Reg Param }
|
|
10
12
|
#output: double q0 { category: Lin Reg Param }
|
|
11
13
|
#output: double slope_est { category: Lin Reg Param }
|
|
@@ -19,19 +21,33 @@
|
|
|
19
21
|
#output: double resid_ss { category: Lin Reg Param }
|
|
20
22
|
#output: double expl_ss { category: Lin Reg Param }
|
|
21
23
|
#output: double ss_tot { category: Lin Reg Param }
|
|
22
|
-
#output: double amin { category:
|
|
24
|
+
#output: double amin { category: Recommendation }
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
a <- as.data.frame(test_data)
|
|
27
|
+
a <- a[!a$isOutlier=='true',]
|
|
28
|
+
processedData <- a
|
|
29
|
+
processedData$time..min. <- processedData$time..min. / 60
|
|
30
|
+
names(processedData)[names(processedData) == "time..min."] <- "time (hr)"
|
|
31
|
+
processedData$filtrate.volume..mL. <- (processedData$filtrate.volume..mL./1000)/(test_area/10000)
|
|
32
|
+
names(processedData)[names(processedData) == "filtrate.volume..mL."] <- "V (L/m2)"
|
|
33
|
+
processedData["t/V (hr/(L/m2))"] <- processedData$`time (hr)` / processedData$`V (L/m2)`
|
|
34
|
+
|
|
35
|
+
lin_mod <- lm(`t/V (hr/(L/m2))` ~ `time (hr)`, data=processedData)
|
|
36
|
+
lin_mod_sum <- summary(lin_mod)
|
|
37
|
+
coeff <- lin_mod_sum$coefficients
|
|
38
|
+
slope_est <- coeff["`time (hr)`", "Estimate"]
|
|
39
|
+
slope_err <- coeff["`time (hr)`", "Std. Error"]
|
|
40
|
+
icept_est <- coeff["(Intercept)", "Estimate"]
|
|
41
|
+
icept_err <- coeff["(Intercept)", "Std. Error"]
|
|
42
|
+
rsq <- lin_mod_sum$r.squared
|
|
43
|
+
ad_rsq <- lin_mod_sum$adj.r.squared
|
|
44
|
+
f_stat <- lin_mod_sum$fstatistic[1]
|
|
45
|
+
df <- lin_mod_sum$df[2]
|
|
46
|
+
sigma <- lin_mod_sum$sigma
|
|
47
|
+
resid_ss <- sum(lin_mod_sum$residuals^2)
|
|
48
|
+
expl_ss <- sum((fitted(lin_mod) - mean(processedData$`t/V (hr/(L/m2))`))^2)
|
|
49
|
+
vmax <- round(1 / slope_est)
|
|
50
|
+
q0 <- round(1 / icept_est)
|
|
51
|
+
amin <- (vbatch / vmax) + (vbatch / tbatch / q0)
|
|
52
|
+
amin <- round(amin, digits = 1)
|
|
53
|
+
ss_tot <- resid_ss + expl_ss
|
package/scripts/pMax.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
//name: PmaxScript
|
|
2
|
+
//description: pMax Filtration Model
|
|
3
|
+
//language: javascript
|
|
4
|
+
//tags: model
|
|
5
|
+
//input: dataframe inputTable [Should contain columns Time (min), Vol (mL), P1 (psi), P2 (psi)]
|
|
6
|
+
//input: double batchVolume = 100 {units: L} [Batch Volume]
|
|
7
|
+
//input: double batchTime = 2 {units: hours} [Batch Time]
|
|
8
|
+
//input: double targetPressure = 20 {units: psi} [Target Pressure]
|
|
9
|
+
//input: double aMinFilter1Guessed = 0.153 {units: m²; caption:Amin Filter 1 guessed} [Amin Filter 1 guessed]
|
|
10
|
+
//input: double aMinFilter2Guessed = 0.153 {units: m²; caption:Amin Filter 2 guessed} [Amin Filter 2 guessed]
|
|
11
|
+
//input: double filterArea1 = 23 {units: m²} [Filter Area 1]
|
|
12
|
+
//input: double filterArea2 = 23 {units: m²} [Filter Area 2]
|
|
13
|
+
//input: double sf1 = 1.5 {caption: SF1}
|
|
14
|
+
//input: double sf2 = 1.5 {caption: SF2}
|
|
15
|
+
//input: int orderOfPolynomialRegression = 3 {caption: Order Of Polynomial Regression} [Order Of Polynomial Regression]
|
|
16
|
+
//output: dataframe Filter1 {viewer: Scatter Plot(x: "TP 1 (L/m2)", y: "Res. 1 (psi/LMH)", showRegressionLine: "true"); category: PRIMARY FILTER}
|
|
17
|
+
//output: dataframe Filter2 {viewer: Scatter Plot(x: "TP 2 (L/m2)", y: "Res. 2 (psi/LMH)", showRegressionLine: "true"); category: SECONDARY FILTER}
|
|
18
|
+
//output: double amin1 {units: m²; caption: Amin; category: PRIMARY FILTER}
|
|
19
|
+
//output: double amin2 {units: m²; caption: Amin; category: SECONDARY FILTER}
|
|
20
|
+
//output: double aminSF1 {units: m²; caption: Amin SF; category: PRIMARY FILTER}
|
|
21
|
+
//output: double aminSF2 {units: m²; caption: Amin SF; category: SECONDARY FILTER}
|
|
22
|
+
//output: double trialLoading1 {units: L/m²; caption: Trial Loading; category: PRIMARY FILTER}
|
|
23
|
+
//output: double trialLoading2 {units: L/m²; caption: Trial Loading; category: SECONDARY FILTER}
|
|
24
|
+
//output: double processLoading1 {units: L/m²; caption: Process Loading; category: PRIMARY FILTER}
|
|
25
|
+
//output: double processLoading2 {units: L/m²; caption: Process Loading; category: SECONDARY FILTER}
|
|
26
|
+
//output: double maxP1 {units: psi; caption: Max P; category: PRIMARY FILTER}
|
|
27
|
+
//output: double maxP2 {units: psi; caption: Max P; category: SECONDARY FILTER}
|
|
28
|
+
//output: double trialFlux1 {units: LMH; caption: Trial Flux; category: PRIMARY FILTER}
|
|
29
|
+
//output: double trialFlux2 {units: LMH; caption: Trial Flux; category: SECONDARY FILTER}
|
|
30
|
+
//output: double processFlux1 {units: LMH; caption: Process Flux; category: PRIMARY FILTER}
|
|
31
|
+
//output: double processFlux2 {units: LMH; caption: Process Flux; category: SECONDARY FILTER}
|
|
32
|
+
//output: double processFlow1 {units: L/hr; caption: Process Flow; category: PRIMARY FILTER}
|
|
33
|
+
//output: double processFlow2 {units: L/hr; caption: Process Flow; category: SECONDARY FILTER}
|
|
34
|
+
//output: double guessedAmin1 {units: m²; caption: Guessed Amin; category: PRIMARY FILTER}
|
|
35
|
+
//output: double guessedAmin2 {units: m²; caption: Guessed Amin; category: SECONDARY FILTER}
|
|
36
|
+
//output: double guessedProcessLoading1 {units: L/m²; caption: Guessed Process Loading; category: PRIMARY FILTER}
|
|
37
|
+
//output: double guessedProcessLoading2 {units: L/m²; caption: Guessed Process Loading; category: SECONDARY FILTER}
|
|
38
|
+
//output: double guessedMaxP1 {units: psi; caption: Guessed Max P; category: PRIMARY FILTER}
|
|
39
|
+
//output: double guessedMaxP2 {units: psi; caption: Guessed Max P; category: SECONDARY FILTER}
|
|
40
|
+
//output: double guessedProcessFlux1 {units: LMH; caption: Guessed Process Flux; category: PRIMARY FILTER}
|
|
41
|
+
//output: double guessedProcessFlux2 {units: LMH; caption: Guessed Process Flux; category: SECONDARY FILTER}
|
|
42
|
+
|
|
43
|
+
function gaussianElimination(input, orderOfPolynomialRegression) {
|
|
44
|
+
const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
|
|
45
|
+
for (let i = 0; i < n; i++) {
|
|
46
|
+
let maxrow = i;
|
|
47
|
+
for (let j = i + 1; j < n; j++)
|
|
48
|
+
if (Math.abs(input[i][j]) > Math.abs(input[i][maxrow]))
|
|
49
|
+
maxrow = j;
|
|
50
|
+
for (let k = i; k < n + 1; k++) {
|
|
51
|
+
const tmp = input[k][i];
|
|
52
|
+
input[k][i] = input[k][maxrow];
|
|
53
|
+
input[k][maxrow] = tmp;
|
|
54
|
+
}
|
|
55
|
+
for (let j = i + 1; j < n; j++)
|
|
56
|
+
for (let k = n; k >= i; k--)
|
|
57
|
+
input[k][j] -= (input[k][i] * input[i][j]) / input[i][i];
|
|
58
|
+
}
|
|
59
|
+
for (let j = n - 1; j >= 0; j--) {
|
|
60
|
+
let total = 0;
|
|
61
|
+
for (let k = j + 1; k < n; k++)
|
|
62
|
+
total += input[k][j] * coefficients[k];
|
|
63
|
+
coefficients[j] = (input[n][j] - total) / input[j][j];
|
|
64
|
+
}
|
|
65
|
+
return coefficients;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression) {
|
|
69
|
+
const lhs = [], rhs = [], len = xCol.length, k = orderOfPolynomialRegression + 1;
|
|
70
|
+
let a = 0, b = 0;
|
|
71
|
+
for (let i = 0; i < k; i++) {
|
|
72
|
+
for (let l = 0; l < len; l++)
|
|
73
|
+
a += (xCol.get(l) ** i) * yCol.get(l);
|
|
74
|
+
lhs.push(a);
|
|
75
|
+
a = 0;
|
|
76
|
+
const c = [];
|
|
77
|
+
for (let j = 0; j < k; j++) {
|
|
78
|
+
for (let l = 0; l < len; l++)
|
|
79
|
+
b += xCol.get(l) ** (i + j);
|
|
80
|
+
c.push(b);
|
|
81
|
+
b = 0;
|
|
82
|
+
}
|
|
83
|
+
rhs.push(c);
|
|
84
|
+
}
|
|
85
|
+
rhs.push(lhs);
|
|
86
|
+
return gaussianElimination(rhs, k);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function predictPolynomialRegression(coefficients, x) {
|
|
90
|
+
let result = coefficients[0];
|
|
91
|
+
for (let i = coefficients.length - 1; i > 0; i--)
|
|
92
|
+
result += coefficients[i] * Math.pow(x, i);
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const lengthOfSecondTable = 2985;
|
|
97
|
+
const colNames1 = {
|
|
98
|
+
'time': 'Time (min)',
|
|
99
|
+
'volume': 'Vol (mL)',
|
|
100
|
+
'pressure1': 'P1 (psi)',
|
|
101
|
+
'pressure2': 'P2 (psi)',
|
|
102
|
+
'tp1': 'TP 1 (L/m2)', 'flux1': 'Flux 1 (LMH)', 'res1': 'Res. 1 (psi/LMH)',
|
|
103
|
+
'tp2': 'TP 2 (L/m2)', 'flux2': 'Flux 2 (LMH)', 'res2': 'Res. 2 (psi/LMH)',
|
|
104
|
+
'deltaP': 'Delta P (psi)'
|
|
105
|
+
};
|
|
106
|
+
const colNames2 = {
|
|
107
|
+
'area': 'Guess Area (m2)',
|
|
108
|
+
'javg': 'Javg (LMH)',
|
|
109
|
+
'R': 'R calc (psi/LMH)',
|
|
110
|
+
'Y1': 'Y1', 'd1': 'Delta1',
|
|
111
|
+
'Y2': 'Y2', 'd2': 'Delta2'
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const t = inputTable.col(colNames1['time']);
|
|
115
|
+
const v = inputTable.col(colNames1['volume']);
|
|
116
|
+
const p1 = inputTable.col(colNames1['pressure1']);
|
|
117
|
+
const p2 = inputTable.col(colNames1['pressure2']);
|
|
118
|
+
const df1 = DG.DataFrame.fromColumns([t, v, p1, p2]);
|
|
119
|
+
df1.columns.addNewFloat(colNames1['tp1']).init((i) => (i > 0) ? 10 * v.get(i) / filterArea1 : 0);
|
|
120
|
+
df1.columns.addNewFloat(colNames1['tp2']).init((i) => (i > 0) ? 10 * v.get(i) / filterArea2 : 0);
|
|
121
|
+
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);
|
|
122
|
+
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);
|
|
123
|
+
df1.columns.addNewFloat(colNames1['deltaP']).init((i) => p1.get(i) - p2.get(i));
|
|
124
|
+
const deltaP = df1.col(colNames1['deltaP']), flux1 = df1.col(colNames1['flux1']), flux2 = df1.col(colNames1['flux2']);
|
|
125
|
+
df1.columns.addNewFloat(colNames1['res1']).init((i) => (i > 0) ? deltaP.get(i) / flux1.get(i) : 0);
|
|
126
|
+
df1.columns.addNewFloat(colNames1['res2']).init((i) => (i > 0) ? p2.get(i) / flux2.get(i) : 0);
|
|
127
|
+
Filter1 = DG.DataFrame.fromColumns([df1.col(colNames1['tp1']), df1.col(colNames1['res1'])]);
|
|
128
|
+
Filter2 = DG.DataFrame.fromColumns([df1.col(colNames1['tp2']), df1.col(colNames1['res2'])]);
|
|
129
|
+
const coefficients1 = polynomialRegressionCoefficients(df1.col(colNames1['tp1']), df1.col(colNames1['res1']), orderOfPolynomialRegression);
|
|
130
|
+
const coefficients2 = polynomialRegressionCoefficients(df1.col(colNames1['tp2']), df1.col(colNames1['res2']), orderOfPolynomialRegression);
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
const df2 = DG.DataFrame.create(lengthOfSecondTable);
|
|
134
|
+
df2.columns.addNewFloat(colNames2['area']).init((i) => (i > 0) ? batchVolume / i : 0);
|
|
135
|
+
const area = df2.col(colNames2['area']);
|
|
136
|
+
df2.columns.addNewFloat(colNames2['javg']).init((i) => (i > 0) ? batchVolume / area.get(i) / batchTime : 0);
|
|
137
|
+
const javg = df2.col(colNames2['javg']);
|
|
138
|
+
df2.columns.addNewFloat(colNames2['R']).init((i) => (i > 0) ? targetPressure / javg.get(i) : 0);
|
|
139
|
+
df2.columns.addNewFloat(colNames2['Y1']).init((i) => predictPolynomialRegression(coefficients1, i));
|
|
140
|
+
df2.columns.addNewFloat(colNames2['Y2']).init((i) => predictPolynomialRegression(coefficients2, i));
|
|
141
|
+
const rCalc = df2.col(colNames2['R']), y1 = df2.col(colNames2['Y1']), y2 = df2.col(colNames2['Y2']);
|
|
142
|
+
df2.columns.addNewFloat(colNames2['d1']).init((i) => Math.abs(rCalc.get(i) - y1.get(i)));
|
|
143
|
+
df2.columns.addNewFloat(colNames2['d2']).init((i) => Math.abs(rCalc.get(i) - y2.get(i)));
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
amin1 = df2.col(colNames2['area']).get(df2.col(colNames2['d1']).toList().indexOf(df2.col(colNames2['d1']).min));
|
|
147
|
+
amin2 = df2.col(colNames2['area']).get(df2.col(colNames2['d2']).toList().indexOf(df2.col(colNames2['d2']).min));
|
|
148
|
+
processFlow1 = batchVolume / batchTime, processFlow2 = batchVolume / batchTime;
|
|
149
|
+
processFlux1 = processFlow1 / amin1, processFlux2 = processFlow2 / amin2;
|
|
150
|
+
trialFlux1 = 600 * v.max / t.max / filterArea1, trialFlux2 = 600 * v.max / t.max / filterArea2;
|
|
151
|
+
aminSF1 = sf1 * amin1, aminSF2 = sf2 * amin2;
|
|
152
|
+
trialLoading1 = df1.col(colNames1['tp1']).max, trialLoading2 = df1.col(colNames1['tp2']).max;
|
|
153
|
+
processLoading1 = batchVolume / amin1, processLoading2 = batchVolume / amin2;
|
|
154
|
+
maxP1 = predictPolynomialRegression(coefficients1, processLoading1) * processFlux1;
|
|
155
|
+
maxP2 = predictPolynomialRegression(coefficients2, processLoading2) * processFlux2;
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
guessedAmin1 = aMinFilter1Guessed, guessedAmin2 = aMinFilter2Guessed;
|
|
159
|
+
guessedProcessLoading1 = batchVolume / aMinFilter1Guessed, guessedProcessLoading2 = batchVolume / aMinFilter2Guessed;
|
|
160
|
+
guessedMaxP1 = predictPolynomialRegression(coefficients1, processLoading1) * processFlux1;
|
|
161
|
+
guessedMaxP2 = predictPolynomialRegression(coefficients2, processLoading2) * processFlux2;
|
|
162
|
+
guessedProcessFlux1 = processFlow1 / aMinFilter1Guessed, guessedProcessFlux2 = processFlow2 / aMinFilter2Guessed;
|
|
163
|
+
|