Skip to content
Snippets Groups Projects
Commit 94b5e779 authored by Ben Hein's avatar Ben Hein
Browse files

update readout script for toxicity analysis

parent 9467d19f
Branches
Tags
No related merge requests found
...@@ -3,80 +3,58 @@ import numpy as np ...@@ -3,80 +3,58 @@ import numpy as np
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import math import math
def label(quantity):
if quantity == 'E':
return 'Extinction Coefficient (1/m)'
if quantity == 'FED_In':
return 'FED Incapacitation'
#todo:
#"CO2 concentration (ppm)","CO concentration (ppm)",
#"HCN concentration (ppm)", "HCl concentration (ppm)", "FED Heat Dose",
#"FEC Smoke", "FIC Impairment", "FIC Incapacitation"
########## change here ##########
#number of agents
N = 50 #todo: parse from traj.xml
# possible quantities are: 'E','c_CO2','c_CO','c_HCl','c_HCN','FED_In','FEC_Smoke','FED_Heat','FIC_Im','FED_In'
quantity_select = 'E'
#################################
### traj XML readin ### traj XML readin
tree = ET.parse('toxicity_output_jpsfire.xml') tree = ET.parse('toxicity_output_jpsfire.xml')
root = tree.getroot() root = tree.getroot()
### empty arrays
t = E = co2 = co = hcn = hcl = fed_in = fec_smoke = fed_heat = fic_im = fic_in = np.array([])
### readout ### readout
data = []
for frame in root.iter('frame'): for frame in root.iter('frame'):
frame_id = int(frame.get('ID')) frame_id = int(frame.get('ID'))
for agent in frame.iter('agent'): for agent in frame.iter('agent'):
agent_id = int(agent.get('ID')) # todo: is it necessary to plot agent specifically agent_id = int(agent.get('ID'))
t = np.append(t, float(agent.get('t'))) t = float(agent.get('t'))
E = np.append(E, float(agent.get('E'))) quantity = float(agent.get('%s' % quantity_select))
co2 = np.append(co2, float(agent.get('c_CO2'))) data += [agent_id, t, quantity]
co = np.append(co, float(agent.get('c_CO'))) data = np.array(data).reshape((-1, 3))
hcl = np.append(hcl, float(agent.get('c_HCl')))
hcn = np.append(hcn, float(agent.get('c_HCN'))) for i in range(1,N+1):
fed_in = np.append(fed_in, float(agent.get('FED_In')))
fec_smoke = np.append(fec_smoke, float(agent.get('FEC_Smoke'))) ids_all = data[:,0]
fed_heat = np.append(fed_heat, float(agent.get('FED_Heat'))) time_all = data[:,1]
fic_im = np.append(fic_im, float(agent.get('FIC_Im'))) quantity_all = data[:,2]
fic_in = np.append(fic_in, float(agent.get('FED_In')))
time_max = np.max(time_all)
### prepare for plotting quantity_max = np.max(quantity_all)
values = [E, co2, co, hcn, hcl, fed_in, fed_heat, fec_smoke, fic_im, fic_in]
labels = ["Extinction Coefficient (1/m)", "CO2 concentration (ppm)","CO concentration (ppm)", if i == 1:
"HCN concentration (ppm)", "HCl concentration (ppm)", "FED Incapacitation", "FED Heat Dose", plt.plot(time_all[ids_all==1], quantity_all[ids_all==1], 'b', lw=2, label = 'agent time series')
"FEC Smoke", "FIC Impairment", "FIC Incapacitation"] plt.plot(time_all[ids_all==i], quantity_all[ids_all==i], 'b', lw=2, zorder=1)
units = ["1/m", "ppm", "ppm", "ppm", "ppm", "","","",""] #plt.plot([0,time_max], [1, 1], "r--", lw=2.5, label='%s threshold' %quantity_select) #threshold
plt.plot([0,time_max], [quantity_max, quantity_max], "k--", lw=2.5, label=r'%s max.' %quantity_select)
max_values = [] plt.xlabel("time [s]")
plt.ylabel("%s" % label(quantity_select))
for i in values: plt.xlim(50) # mean premovement time
max_values.append(max(i)) plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
i[i==0] = float('nan') plt.ylim()
plt.legend(loc=0)
### extinction plot plt.savefig('toxicity_output_plot_%s.png' % quantity_select, dpi=400)
plt.show()
plt.plot(t, E, 'bx') \ No newline at end of file
plt.plot([0,max(t)], [max_values[0], max_values[0]], 'r-', label='max = %.2f %s' % (max_values[0], units[0]))
plt.xlabel("Time")
plt.ylabel(labels[0])
plt.ylim(0)
plt.legend()
plt.savefig('toxicity_output_plot_0_extinction.png')
plt.close()
### concentration plot
plt.figure(figsize=(12,9))
for i in range(1,5):
plt.subplot(2,2,i)
plt.plot(t, values[i], 'bx')
plt.plot([0,max(t)], [max_values[i], max_values[i]], 'r-', label='max = %.2f %s' % (max_values[i], units[i]))
plt.xlabel("Time")
plt.ylabel(labels[i])
plt.ylim(0)
plt.legend()
plt.savefig('toxicity_output_plot_1_concentrations.png')
plt.close()
plt.figure(figsize=(12,9))
values2 = [fed_in, fec_smoke, fed_heat, fic_im, fic_in]
for j in range(5,9):
plt.subplot(2,2,j-4)
plt.plot(t, values[j], 'bx')
plt.plot([0,max(t)], [max_values[j], max_values[j]], 'r-', label='max = %.3f %s' % (max_values[j], units[j]))
plt.xlabel("Time")
plt.ylabel(labels[j])
plt.ylim(0)
plt.legend()
plt.savefig('toxicity_output_plot_2_FED_FEC_FIC.png')
plt.close()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment