Skip to content

Commit

Permalink
Experiment import update
Browse files Browse the repository at this point in the history
Updated experimental conditions import to work for old Tranter style experiment files
  • Loading branch information
tsikes committed Aug 23, 2021
1 parent 016ea7c commit cba7b9e
Showing 1 changed file with 68 additions and 20 deletions.
88 changes: 68 additions & 20 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,22 +343,46 @@ def __init__(self, parent):
self.parent = parent
self.path = parent.path
self.convert_units = parent.convert_units
self.load_style = 'new_tranter'
# self.load_full_series_box = parent.load_full_series_box
# self.set_load_full_set()
# self.load_full_series_box.stateChanged.connect(lambda: self.set_load_full_set())


def parameters(self, file_path):
def parameters(self, file_path):
with open(file_path) as f:
lines = f.read().splitlines()

if lines[0] == '[Date]': # new Tranter style
self.load_style = 'new_tranter'
parameters = self.read_tranter_exp_new(lines)
elif lines[0] == '"[Expt Parameters]"': # old Tranter style
self.load_style = 'old_tranter'
parameters = self.read_tranter_exp_old(lines)
else:
self.load_style = 'new_tranter'
parameters = self.read_tranter_exp_new(lines)

# Units are assumed to be: T1 [°C], P1 [Torr], u1 [mm/μs], P4 [psi]
parameters['T1'] = self.convert_units(parameters['T1'], '°C', '2ct')
parameters['P1'] = self.convert_units(parameters['P1'], 'Torr', '2ct')
parameters['u1'] = self.convert_units(parameters['u1'], 'mm/μs', '2ct')
parameters['P4'] = self.convert_units(parameters['P4'], 'psi', '2ct')
parameters['Sample_Rate'] *= 1E-6 # Hz to MHz ?

return parameters

def read_tranter_exp_new(self, lines):
def get_config(section, key):
val = self.config[section][key]
for delimiter in ['"', "'"]: # remove delimiters
val = val.strip(delimiter)

return val

self.config = configparser.RawConfigParser()
self.config.read(file_path)
self.config.read_string('\n'.join(lines))

# Get mixture composition
mix = {}
for key in [item[0] for item in self.config.items('Mixture')]: # search all keys in section
Expand Down Expand Up @@ -393,23 +417,42 @@ def get_config(section, key):
'P4': float(get_config('Expt Params', 'P4')),
'exp_mix': deepcopy(mix), 'thermo_mix': deepcopy(mix),
'Sample_Rate': float(get_config('Expt Params', 'SampRate'))}

# Convert to cantera units
# parameters['T1'] += 273.15 # Celcius to Kelvin
# parameters['P1'] *= 101325/760 # Torr to Pa
# parameters['u1'] *= 1000 # mm/μs to m/s
# parameters['P4'] *= 4.4482216152605/0.00064516 # Psi to Pa
# parameters['Sample_Rate'] *= 1E-6 # Hz to MHz ?

# Units are assumed to be: T1 [°C], P1 [Torr], u1 [mm/μs], P4 [psi]
parameters['T1'] = self.convert_units(parameters['T1'], '°C', '2ct')
parameters['P1'] = self.convert_units(parameters['P1'], 'Torr', '2ct')
parameters['u1'] = self.convert_units(parameters['u1'], 'mm/μs', '2ct')
parameters['P4'] = self.convert_units(parameters['P4'], 'psi', '2ct')
parameters['Sample_Rate'] *= 1E-6 # Hz to MHz ?


return parameters


def read_tranter_exp_old(self, lines):
parameters = {'T1': None, 'P1': None, 'u1': None, 'exp_mix': {}, 'thermo_mix': {}}

key = None
processed = {'exp_mix': [], 'shock_conditions': []}
for line in lines:
if line == '"[Thermochemistry]"':
key = 'exp_mix'
continue
elif line == '"[Start Conditions]"' or line == '"[Expt Times]"':
key = 'shock_conditions'
continue
elif line.isspace() or len(line) == 0:
key = None
continue

if key is not None:
processed[key].append(line)

parameters['P1'] = float(processed['shock_conditions'][1])
parameters['T1'] = float(processed['shock_conditions'][2])
parameters['u1'] = 120.0/float(processed['shock_conditions'][-1])
parameters['P4'] = 1.0

for line in processed['exp_mix']:
species, mol_frac = line[1:].split(';')[:2]
parameters['exp_mix'][species] = float(mol_frac)

parameters['thermo_mix'] = parameters['exp_mix']
parameters['Sample_Rate'] = 50000000.0

return parameters

def csv(self, file):
def is_numeric(strings):
for str in strings: # test for all strings
Expand Down Expand Up @@ -447,6 +490,11 @@ def is_numeric(strings):

def exp_data(self, file_path):
exp_data, nonnumeric = self.csv(file_path)

if self.load_style == 'old_tranter':
exp_data = np.array(exp_data)
exp_data = exp_data[:,[0,2]]
exp_data = exp_data[:-1,:]

return exp_data

Expand Down

0 comments on commit cba7b9e

Please sign in to comment.