-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_generator.py
More file actions
69 lines (54 loc) · 2.17 KB
/
Copy pathdata_generator.py
File metadata and controls
69 lines (54 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# PACKAGES
import os
import numpy as np
from modules.reaction_models import Model
from modules.arrhenius import rateConstant, conv2mass
import pandas as pd
import random
# convFlag = True if you are about to generate conversion data
# = False if not
convFlag = False
# DIRECTORIES
MAIN_DIR = os.getcwd() # current working directory
DATA = os.path.join(MAIN_DIR,'data') # data directory
# create DATA directory
if not os.path.exists(DATA):
os.makedirs(DATA)
# models names supported in this software
modelNames = ["A2","A3","A4","D1","D2","D3","D4","F0","F1","F2","F3","P2","P3","P4","R2","R3"]
# pick up a model
model = Model('A2')
# physical properties
enthalpy = 147.8e+3 # J mol-1
frequency = 1.75e+22
temperature = np.linspace(320.0,330.0,3)
# random number seed for generating data noise
random.seed(10)
# generate a kinetics (m,t) or (conversion,t) data set for each temperature
for T in temperature:
# determine an Arrhenius rate constant
k = rateConstant(frequency,enthalpy,T)
print(k)
# calculate the start end end time for the sample data
alpha = np.linspace(0.05,0.95,100)
startTime = model.g(alpha[0])/k
endTime = model.g(alpha[-1])/k
time = np.linspace(startTime,endTime,100)
# calculate the conversion based on the chosen model
# conversion = np.array([ model.alpha(t,k)+random.uniform(0.01, 0.03) for t in time])
conversion = np.array([ model.alpha(t,k) for t in time])
# assume initial and final mass
m0, minf = 10.0, 8.2
# convert converstion fraction to mass
mass = np.array([conv2mass(m0,minf,alpha) for alpha in conversion])
# data to dictionary
if convFlag:
data = {'mass': mass, 'mass units': 'mg', 'conversion': conversion, 'time': time, 'time units': 'min', 'temperature': T, 'temperature units' : 'Kelvin'}
else:
data = {'mass': mass, 'mass units': 'mg', 'time': time, 'time units': 'min', 'temperature': T, 'temperature units' : 'Kelvin'}
# dictionary to dataframe
df = pd.DataFrame(data)
# CSV filename
Csv = os.path.join(DATA,str(T)+'_Kelvin.csv')
# dataframe to csv
df.to_csv(Csv,index=False)