-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenSensorArray.py
executable file
·128 lines (111 loc) · 5.41 KB
/
screenSensorArray.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
############################################################################
#
# Imperial College London, United Kingdom
# Multifunctional Nanomaterials Laboratory
#
# Project: ERASE
# Year: 2020
# Python: Python 3.7
# Authors: Ashwin Kumar Rajagopalan (AK)
#
# Purpose:
# Generates hypothetical sorbents using latin hypercube sampling. The
# sorbents are assumed to exhibit Langmuirian behavior.
#
# Last modified:
# - 2021-02-11, AK: Minor fixes
# - 2021-02-11, AK: Fix for parallel computing
# - 2020-10-29, AK: Add 3 sorbent sensor
# - 2020-10-28, AK: Add auxiliary functions as a module
# - 2020-10-22, AK: Initial creation
#
# Input arguments:
#
#
# Output arguments:
#
#
############################################################################
import numpy as np
from numpy import savez
import auxiliaryFunctions
import multiprocessing # For parallel processing
from joblib import Parallel, delayed # For parallel processing
from tqdm import tqdm # To track progress of the loop
from estimateConcentration import estimateConcentration
import os
# Number of sensors in the array
numSensors = 1
# Get the commit ID of the current repository
gitCommitID = auxiliaryFunctions.getCommitID()
# Find out the total number of cores available for parallel processing
num_cores = multiprocessing.cpu_count()
# Total number of sensor elements/gases simulated and generated using
# generateHypotheticalAdsorbents.py function
numberOfAdsorbents = 20
numberOfGases = 2
# "True" gas composition that is exposed to the sensor array (0-4)
# Check generateTrueSensorResponse.py for the actual concentrations
moleFracID = 1
# Check for number of sensors in the array
if numSensors == 1:
##### FOR 1 SORBENT SENSOR ARRAY #####
# Get the current date and time for saving purposes
simulationDT = auxiliaryFunctions.getCurrentDateTime()
# Loop over all the sorbents for a single material sensor
# Using parallel processing to loop through all the materials
arrayConcentration = np.zeros(numberOfAdsorbents)
arrayConcentration = Parallel(n_jobs=num_cores)(delayed(estimateConcentration)
(numberOfAdsorbents,numberOfGases,moleFracID,[ii])
for ii in tqdm(range(numberOfAdsorbents)))
# Convert the output list to a matrix
arrayConcentration = np.array(arrayConcentration)
elif numSensors == 2:
##### FOR 2 SORBENT SENSOR ARRAY #####
# Get the current date and time for saving purposes
simulationDT = auxiliaryFunctions.getCurrentDateTime()
# Loop over all the sorbents for a single material sensor
# Using parallel processing to loop through all the materials
arrayConcentration = np.zeros(numberOfAdsorbents)
for jj in range(numberOfAdsorbents-1):
arrayConcentrationTemp = Parallel(n_jobs=num_cores)(delayed(estimateConcentration)
(numberOfAdsorbents,numberOfGases,moleFracID,[ii,jj])
for ii in tqdm(range(jj+1,numberOfAdsorbents)))
# Convert the output list to a matrix
arrayConcentrationTemp = np.array(arrayConcentrationTemp)
if jj == 0:
arrayConcentration = arrayConcentrationTemp
else:
arrayConcentration = np.append(arrayConcentration,arrayConcentrationTemp, axis=0)
elif numSensors == 3:
##### FOR 3 SORBENT SENSOR ARRAY #####
# Get the current date and time for saving purposes
simulationDT = auxiliaryFunctions.getCurrentDateTime()
# Loop over all the sorbents for a single material sensor
# Using parallel processing to loop through all the materials
arrayConcentration = np.zeros(numberOfAdsorbents)
for kk in range(numberOfAdsorbents-1):
for jj in range(kk+1,numberOfAdsorbents-1):
arrayConcentrationTemp = Parallel(n_jobs=num_cores)(delayed(estimateConcentration)
(numberOfAdsorbents,numberOfGases,moleFracID,[ii,jj,kk])
for ii in tqdm(range(jj+1,numberOfAdsorbents)))
# Convert the output list to a matrix
arrayConcentrationTemp = np.array(arrayConcentrationTemp)
if kk == 0 and jj == 1:
arrayConcentration = arrayConcentrationTemp
else:
arrayConcentration = np.append(arrayConcentration,arrayConcentrationTemp, axis=0)
# Save the array concentration into a native numpy file
# The .npy file is saved in a folder called simulationResults (hardcoded)
filePrefix = "arrayConcentration"
saveFileName = filePrefix + "_" + simulationDT + "_" + gitCommitID;
savePath = os.path.join('simulationResults',saveFileName)
# Check if inputResources directory exists or not. If not, create the folder
if not os.path.exists('simulationResults'):
os.mkdir('simulationResults')
# Save the array ceoncentration obtained from estimateConcentration
savez (savePath, arrayConcentration = arrayConcentration, # Estimated Concentration
numberOfAdsorbents = numberOfAdsorbents, # Estimated response
numberOfGases = numberOfGases, # Flag to gases to be sensed
numSensors = numSensors, # Number of sensors in the array
moleFracID = moleFracID) # Mole fraction