David Saylor commited on
Commit
8083ddd
·
1 Parent(s): 62d7688

added 30 day exposure plot

Browse files
Files changed (2) hide show
  1. CHRISv1.py +49 -3
  2. templates/exposure_report.html +7 -0
CHRISv1.py CHANGED
@@ -1,7 +1,14 @@
1
- from flask import Flask, render_template, request
2
- import numpy as np
3
  import math
 
 
4
 
 
 
 
 
 
 
 
5
 
6
  def sigfigs(number, n):
7
  return round(number, n - int(math.floor(math.log10(math.fabs(number)))) - 1)
@@ -189,9 +196,23 @@ def exp_post():
189
  MOS = sigfigs(MOS, 2)
190
  diff = sigfigs(diff, 2)
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  return render_template('exposure_report.html', polymers=polymers, pIndex=pIndex, release=release,
193
  assume=assume, area=area, vol=vol, amount=amount, diff=diff, time=time, exposure=exposure, TTC=TTC,
194
- MOS=MOS, chemName=chemName)
195
 
196
 
197
  def calcexposure(MW, amount, vol, area, time, pIndex):
@@ -212,6 +233,31 @@ def calcexposure(MW, amount, vol, area, time, pIndex):
212
 
213
  return release, D
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
  if __name__ == '__main__':
217
  app.run()
 
 
 
1
  import math
2
+ import numpy as np
3
+ from flask import Flask, render_template, request, Response
4
 
5
+ from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
6
+ from matplotlib.figure import Figure
7
+ import matplotlib
8
+ matplotlib.use('Agg')
9
+ import matplotlib.pyplot as plt
10
+ import io
11
+ import base64
12
 
13
  def sigfigs(number, n):
14
  return round(number, n - int(math.floor(math.log10(math.fabs(number)))) - 1)
 
196
  MOS = sigfigs(MOS, 2)
197
  diff = sigfigs(diff, 2)
198
 
199
+ fig, ax = plt.subplots(figsize=(6, 4))
200
+ plt.subplots_adjust(left=0.15, bottom=0.15, right=0.95, top=0.95, wspace=0.0, hspace=0.0)
201
+ tarray = np.arange(1.,31.,1.)
202
+ rates = calcrates(MW, amount, vol, area, tarray, pIndex)
203
+ ax.plot(tarray,rates,'o')
204
+ ax.set(
205
+ xlabel='time (days)',
206
+ ylabel='release rate (mg/day)',
207
+ )
208
+ pngImage = io.BytesIO()
209
+ FigureCanvas(fig).print_png(pngImage)
210
+ pngImageB64String = "data:image/png;base64,"
211
+ pngImageB64String += base64.b64encode(pngImage.getvalue()).decode('utf8')
212
+
213
  return render_template('exposure_report.html', polymers=polymers, pIndex=pIndex, release=release,
214
  assume=assume, area=area, vol=vol, amount=amount, diff=diff, time=time, exposure=exposure, TTC=TTC,
215
+ MOS=MOS, chemName=chemName, image=pngImageB64String)
216
 
217
 
218
  def calcexposure(MW, amount, vol, area, time, pIndex):
 
233
 
234
  return release, D
235
 
236
+ def calcrates(MW, amount, vol, area, time, pIndex):
237
+ Ap = np.array((16.9, 11.7, 8.2, 2.6))
238
+ L = vol / area
239
+ if PolyData[pIndex][1] < 4:
240
+ D = 1e4 * np.exp(Ap[PolyData[pIndex][1]] - 0.1351 * MW ** (2. / 3.) + 0.003 * MW - 10454. / 310.)
241
+ else:
242
+ Va = 4.76 + 1.32 * MW
243
+ D = 7.4e-8 * (18. * 2.6) ** 0.5 * 310. / 0.6913 / Va ** 0.6
244
+ D = D * 86400.
245
+
246
+ rates = np.zeros(len(time))
247
+ tau = D * time[0] / L ** 2.
248
+ if tau < 0.5:
249
+ rates[0] = 2. * amount * np.sqrt(tau / np.pi)
250
+ else:
251
+ rates[0] = amount * (1. - (8. / (np.pi ** 2.)) * np.exp(-tau * np.pi ** 2. / 4.))
252
+
253
+ for i in range(1,len(time)):
254
+ tau = D * time[i] / L ** 2.
255
+ if tau < 0.5:
256
+ rates[i] = 2. * amount * np.sqrt(tau / np.pi) - np.sum(rates[:i])
257
+ else:
258
+ rates[i] = amount * (1. - (8. / (np.pi ** 2.)) * np.exp(-tau * np.pi ** 2. / 4.)) - np.sum(rates[:i])
259
+
260
+ return rates
261
 
262
  if __name__ == '__main__':
263
  app.run()
templates/exposure_report.html CHANGED
@@ -47,7 +47,14 @@ where \( \tau= D t A^2 / V^2 \) and \( A \) and \( V \) are the surface area and
47
  \( M_0 \) = {{amount}} mg <br>
48
  \( D \) = {{diff}} cm<sup>2</sup>/h <br>
49
  \( t \) = {{time}} h <br>
 
 
50
  <p>
 
 
 
 
 
51
 
52
  <h3> Assumptions </h3>
53
 
 
47
  \( M_0 \) = {{amount}} mg <br>
48
  \( D \) = {{diff}} cm<sup>2</sup>/h <br>
49
  \( t \) = {{time}} h <br>
50
+ </p>
51
+
52
  <p>
53
+ In addition to the maximum daily (day 1) release rate, it can be helpful to examine the decay in release rate over time predicted by the model,
54
+ which is illustrated for the first 30 days of exposure in the plot below:
55
+ </p>
56
+
57
+ <img src="{{ image }}"/>
58
 
59
  <h3> Assumptions </h3>
60