David Saylor commited on
Commit ·
820bf6e
1
Parent(s): 93fc118
tidying things up
Browse files- exposure_module/exposure.py +35 -42
- functions.py +57 -18
exposure_module/exposure.py
CHANGED
|
@@ -1,46 +1,43 @@
|
|
| 1 |
import numpy as np
|
| 2 |
-
from flask import
|
| 3 |
-
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
| 4 |
-
import matplotlib
|
| 5 |
-
matplotlib.use('Agg')
|
| 6 |
-
import matplotlib.pyplot as plt
|
| 7 |
-
import io
|
| 8 |
-
import base64
|
| 9 |
from functions import *
|
| 10 |
from . import blueprint
|
| 11 |
|
| 12 |
# Named polymer matrices and category numbers
|
| 13 |
nPoly = 20
|
| 14 |
-
PolyData = np.zeros((nPoly,), dtype=[('name', 'a75'), ('
|
| 15 |
-
PolyData[0] = ('Silicone',
|
| 16 |
-
PolyData[1] = ('Polyethylene (density <= 0.94 g/cm3)',
|
| 17 |
-
PolyData[2] = ('Polyethylene (density > 0.94 g/cm3)', 2)
|
| 18 |
-
PolyData[3] = ('Polyethylene terephthalate',
|
| 19 |
-
PolyData[4] = ('Polyurethane (polyether)',
|
| 20 |
-
PolyData[5] = ('Polycarbonate',
|
| 21 |
-
PolyData[6] = ('Polyoxymethylene', 2)
|
| 22 |
PolyData[7] = ('Poly(methyl methacrylate)', 3)
|
| 23 |
-
PolyData[8] = ('Acrylonitrile butadiene styrene', 2)
|
| 24 |
-
PolyData[9] = ('Polyether block amide',
|
| 25 |
-
PolyData[10] = ('Polyamide',
|
| 26 |
-
PolyData[11] = ('Polystyrene',
|
| 27 |
-
PolyData[12] = ('Polyvinyl chloride (plasticized)',
|
| 28 |
-
PolyData[13] = ('Polytetrafluoroethylene', 2)
|
| 29 |
-
PolyData[14] = ('Polyvinyl acetate',
|
| 30 |
-
PolyData[15] = ('Polypropylene', 2)
|
| 31 |
-
PolyData[16] = ('Polybutylene terephthalate',
|
| 32 |
-
PolyData[17] = ('Polyetheretherketone',
|
| 33 |
-
PolyData[18] = ('Fluorinated ethylene propylene', 2)
|
| 34 |
-
PolyData[19] = ('Other polymer',
|
| 35 |
|
|
|
|
| 36 |
polymers = np.zeros(nPoly, dtype='object')
|
| 37 |
for i in range(nPoly):
|
| 38 |
polymers[i] = PolyData[i][0].decode('UTF-8')
|
| 39 |
|
|
|
|
| 40 |
@blueprint.route('/exposure', methods=['GET'])
|
| 41 |
def exposure():
|
| 42 |
return render_template('exposure_index.html', polymers=polymers)
|
| 43 |
|
|
|
|
| 44 |
@blueprint.route('/exposure', methods=['POST'])
|
| 45 |
def exp_post():
|
| 46 |
amount = float(request.form["amount"])
|
|
@@ -68,10 +65,15 @@ def exp_post():
|
|
| 68 |
assume3 = request.form.get("assume3") is not None
|
| 69 |
assume4 = request.form.get("assume4") is not None
|
| 70 |
assume5 = request.form.get("assume5") is not None
|
| 71 |
-
|
| 72 |
assume = np.array((assume1, assume2, assume3, assume4, assume5))
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
MOS = TTC / release
|
| 77 |
|
|
@@ -79,19 +81,10 @@ def exp_post():
|
|
| 79 |
MOS = sigfigs(MOS, 2)
|
| 80 |
diff = sigfigs(diff, 2)
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
ax.plot(tarray,rates,'o')
|
| 87 |
-
ax.set(
|
| 88 |
-
xlabel='time (days)',
|
| 89 |
-
ylabel='release rate (mg/day)',
|
| 90 |
-
)
|
| 91 |
-
pngImage = io.BytesIO()
|
| 92 |
-
FigureCanvas(fig).print_png(pngImage)
|
| 93 |
-
pngImageB64String = "data:image/png;base64,"
|
| 94 |
-
pngImageB64String += base64.b64encode(pngImage.getvalue()).decode('utf8')
|
| 95 |
|
| 96 |
return render_template('exposure_report.html', polymers=polymers, pIndex=pIndex, release=release,
|
| 97 |
assume=assume, area=area, vol=vol, amount=amount, diff=diff, time=time, exposure=exposure, TTC=TTC,
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
+
from flask import render_template, request
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from functions import *
|
| 4 |
from . import blueprint
|
| 5 |
|
| 6 |
# Named polymer matrices and category numbers
|
| 7 |
nPoly = 20
|
| 8 |
+
PolyData = np.zeros((nPoly,), dtype=[('name', 'a75'), ('Ap', 'f')])
|
| 9 |
+
PolyData[0] = ('Silicone', 16.9)
|
| 10 |
+
PolyData[1] = ('Polyethylene (density <= 0.94 g/cm3)', 11.7)
|
| 11 |
+
PolyData[2] = ('Polyethylene (density > 0.94 g/cm3)', 8.2)
|
| 12 |
+
PolyData[3] = ('Polyethylene terephthalate', 2.6)
|
| 13 |
+
PolyData[4] = ('Polyurethane (polyether)', 11.7)
|
| 14 |
+
PolyData[5] = ('Polycarbonate', 2.6)
|
| 15 |
+
PolyData[6] = ('Polyoxymethylene', 8.2)
|
| 16 |
PolyData[7] = ('Poly(methyl methacrylate)', 3)
|
| 17 |
+
PolyData[8] = ('Acrylonitrile butadiene styrene', 8.2)
|
| 18 |
+
PolyData[9] = ('Polyether block amide', 11.7)
|
| 19 |
+
PolyData[10] = ('Polyamide', 2.6)
|
| 20 |
+
PolyData[11] = ('Polystyrene', 2.6)
|
| 21 |
+
PolyData[12] = ('Polyvinyl chloride (plasticized)', 16.9)
|
| 22 |
+
PolyData[13] = ('Polytetrafluoroethylene', 8.2)
|
| 23 |
+
PolyData[14] = ('Polyvinyl acetate', 11.7)
|
| 24 |
+
PolyData[15] = ('Polypropylene', 8.2)
|
| 25 |
+
PolyData[16] = ('Polybutylene terephthalate', 2.6)
|
| 26 |
+
PolyData[17] = ('Polyetheretherketone', 2.6)
|
| 27 |
+
PolyData[18] = ('Fluorinated ethylene propylene', 8.2)
|
| 28 |
+
PolyData[19] = ('Other polymer', None)
|
| 29 |
|
| 30 |
+
# Convert the list to a format the html likes
|
| 31 |
polymers = np.zeros(nPoly, dtype='object')
|
| 32 |
for i in range(nPoly):
|
| 33 |
polymers[i] = PolyData[i][0].decode('UTF-8')
|
| 34 |
|
| 35 |
+
# load the index page for the exposure module
|
| 36 |
@blueprint.route('/exposure', methods=['GET'])
|
| 37 |
def exposure():
|
| 38 |
return render_template('exposure_index.html', polymers=polymers)
|
| 39 |
|
| 40 |
+
# build the report page for the exposure module
|
| 41 |
@blueprint.route('/exposure', methods=['POST'])
|
| 42 |
def exp_post():
|
| 43 |
amount = float(request.form["amount"])
|
|
|
|
| 65 |
assume3 = request.form.get("assume3") is not None
|
| 66 |
assume4 = request.form.get("assume4") is not None
|
| 67 |
assume5 = request.form.get("assume5") is not None
|
|
|
|
| 68 |
assume = np.array((assume1, assume2, assume3, assume4, assume5))
|
| 69 |
|
| 70 |
+
Ap = PolyData[pIndex][1]
|
| 71 |
+
if not np.isnan(Ap):
|
| 72 |
+
diff = piringer(MW, Ap)
|
| 73 |
+
else:
|
| 74 |
+
diff = wilkechang(MW)
|
| 75 |
+
|
| 76 |
+
release = SheetRelease(amount, vol, area, time, diff)
|
| 77 |
|
| 78 |
MOS = TTC / release
|
| 79 |
|
|
|
|
| 81 |
MOS = sigfigs(MOS, 2)
|
| 82 |
diff = sigfigs(diff, 2)
|
| 83 |
|
| 84 |
+
# Generate the rate plot using matplotlib
|
| 85 |
+
tarray = np.arange(1., 31., 1.)
|
| 86 |
+
rates = SheetRates(amount, vol, area, tarray, diff)
|
| 87 |
+
pngImageB64String = RatePlot(tarray, rates)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
return render_template('exposure_report.html', polymers=polymers, pIndex=pIndex, release=release,
|
| 90 |
assume=assume, area=area, vol=vol, amount=amount, diff=diff, time=time, exposure=exposure, TTC=TTC,
|
functions.py
CHANGED
|
@@ -1,18 +1,28 @@
|
|
| 1 |
import math
|
| 2 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def sigfigs(number, n):
|
|
|
|
| 5 |
return round(number, n - int(math.floor(math.log10(math.fabs(number)))) - 1)
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
D = D * 3600.
|
| 17 |
tau = D * time / L ** 2.
|
| 18 |
if tau <= 0.5:
|
|
@@ -20,17 +30,12 @@ def calcexposure(MW, amount, vol, area, time, pIndex, PolyData):
|
|
| 20 |
else:
|
| 21 |
release = amount * (1. - (8. / (np.pi ** 2.)) * np.exp(-tau * np.pi ** 2. / 4.))
|
| 22 |
|
| 23 |
-
return release
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
def calcrates(MW, amount, vol, area, time, pIndex, PolyData):
|
| 26 |
-
Ap = np.array((16.9, 11.7, 8.2, 2.6))
|
| 27 |
-
L = vol / area
|
| 28 |
-
if PolyData[pIndex][1] < 4:
|
| 29 |
-
D = 1e4 * np.exp(Ap[PolyData[pIndex][1]] - 0.1351 * MW ** (2. / 3.) + 0.003 * MW - 10454. / 310.)
|
| 30 |
-
else:
|
| 31 |
-
Va = 4.76 + 1.32 * MW
|
| 32 |
-
D = 7.4e-8 * (18. * 2.6) ** 0.5 * 310. / 0.6913 / Va ** 0.6
|
| 33 |
D = D * 86400.
|
|
|
|
| 34 |
|
| 35 |
rates = np.zeros(len(time))
|
| 36 |
tau = D * time[0] / L ** 2.
|
|
@@ -46,4 +51,38 @@ def calcrates(MW, amount, vol, area, time, pIndex, PolyData):
|
|
| 46 |
else:
|
| 47 |
rates[i] = amount * (1. - (8. / (np.pi ** 2.)) * np.exp(-tau * np.pi ** 2. / 4.)) - np.sum(rates[:i])
|
| 48 |
|
| 49 |
-
return rates
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import math
|
| 2 |
import numpy as np
|
| 3 |
+
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
| 4 |
+
import matplotlib
|
| 5 |
+
matplotlib.use('Agg')
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
import io
|
| 8 |
+
import base64
|
| 9 |
|
| 10 |
def sigfigs(number, n):
|
| 11 |
+
|
| 12 |
return round(number, n - int(math.floor(math.log10(math.fabs(number)))) - 1)
|
| 13 |
|
| 14 |
+
def piringer(Mw, Ap):
|
| 15 |
+
|
| 16 |
+
return 1e4 * np.exp(Ap - 0.1351 * Mw ** (2. / 3.) + 0.003 * Mw - 10454. / 310.)
|
| 17 |
+
|
| 18 |
+
def wilkechang(Mw):
|
| 19 |
+
|
| 20 |
+
Va = 4.76 + 1.32 * Mw
|
| 21 |
+
return 7.4e-8 * (18. * 2.6) ** 0.5 * 310. / 0.6913 / Va ** 0.6
|
| 22 |
|
| 23 |
+
def SheetRelease(amount, vol, area, time, D):
|
| 24 |
+
|
| 25 |
+
L = vol / area
|
| 26 |
D = D * 3600.
|
| 27 |
tau = D * time / L ** 2.
|
| 28 |
if tau <= 0.5:
|
|
|
|
| 30 |
else:
|
| 31 |
release = amount * (1. - (8. / (np.pi ** 2.)) * np.exp(-tau * np.pi ** 2. / 4.))
|
| 32 |
|
| 33 |
+
return release
|
| 34 |
+
|
| 35 |
+
def SheetRates(amount, vol, area, time, D):
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
D = D * 86400.
|
| 38 |
+
L = vol / area
|
| 39 |
|
| 40 |
rates = np.zeros(len(time))
|
| 41 |
tau = D * time[0] / L ** 2.
|
|
|
|
| 51 |
else:
|
| 52 |
rates[i] = amount * (1. - (8. / (np.pi ** 2.)) * np.exp(-tau * np.pi ** 2. / 4.)) - np.sum(rates[:i])
|
| 53 |
|
| 54 |
+
return rates
|
| 55 |
+
|
| 56 |
+
def RatePlot(tarray, rates):
|
| 57 |
+
|
| 58 |
+
fig, ax = plt.subplots(figsize=(6, 4))
|
| 59 |
+
plt.subplots_adjust(left=0.15, bottom=0.15, right=0.95, top=0.95, wspace=0.0, hspace=0.0)
|
| 60 |
+
ax.plot(tarray, rates, 'o')
|
| 61 |
+
ax.set(
|
| 62 |
+
xlabel='time (days)',
|
| 63 |
+
ylabel='release rate (mg/day)',
|
| 64 |
+
)
|
| 65 |
+
pngImage = io.BytesIO()
|
| 66 |
+
FigureCanvas(fig).print_png(pngImage)
|
| 67 |
+
pngImageB64String = "data:image/png;base64,"
|
| 68 |
+
pngImageB64String += base64.b64encode(pngImage.getvalue()).decode('utf8')
|
| 69 |
+
|
| 70 |
+
return pngImageB64String
|
| 71 |
+
|
| 72 |
+
def calcexposure(MW, amount, vol, area, time, pIndex, PolyData):
|
| 73 |
+
Ap = np.array((16.9, 11.7, 8.2, 2.6))
|
| 74 |
+
L = vol / area
|
| 75 |
+
if PolyData[pIndex][1] < 4:
|
| 76 |
+
D = 1e4 * np.exp(Ap[PolyData[pIndex][1]] - 0.1351 * MW ** (2. / 3.) + 0.003 * MW - 10454. / 310.)
|
| 77 |
+
else:
|
| 78 |
+
Va = 4.76 + 1.32 * MW
|
| 79 |
+
D = 7.4e-8 * (18. * 2.6) ** 0.5 * 310. / 0.6913 / Va ** 0.6
|
| 80 |
+
|
| 81 |
+
D = D * 3600.
|
| 82 |
+
tau = D * time / L ** 2.
|
| 83 |
+
if tau <= 0.5:
|
| 84 |
+
release = 2. * amount * np.sqrt(tau / np.pi)
|
| 85 |
+
else:
|
| 86 |
+
release = amount * (1. - (8. / (np.pi ** 2.)) * np.exp(-tau * np.pi ** 2. / 4.))
|
| 87 |
+
|
| 88 |
+
return release, D
|