Skip to content

Commit

Permalink
update data analysis & export
Browse files Browse the repository at this point in the history
  • Loading branch information
XPD Operator committed Mar 7, 2024
1 parent 966468e commit c77b32c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 40 deletions.
2 changes: 1 addition & 1 deletion scripts/_data_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def t_unit_converter(t0 = 'min', t1 = 'min'):
return t_frame.loc[t0, t1]


def rate_uncit_converter(r0 = 'ul/min', r1 = 'ul/min'):
def rate_unit_converter(r0 = 'ul/min', r1 = 'ul/min'):

v0 = r0.split('/')[0]
t0 = r0.split('/')[1]
Expand Down
16 changes: 10 additions & 6 deletions scripts/_data_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import pandas as pd
import os
import _data_analysis as da
from _data_analysis import *



Expand Down Expand Up @@ -36,13 +36,16 @@ def _auto_name_sample(infuse_rates, prefix=None):
prefix_list = [f'Pre{i:02d}' for i in range(infuse_rates.shape[1])]
else:
prefix_list = prefix

# prefix_array = np.asarray(prefix_list)

sample = []
for i in range(infuse_rates.shape[0]):
name = ''
for j in range(infuse_rates.shape[1]):
# for j in range(infuse_rates.shape[1]):
for j in range(len(prefix_list)):
int_rate = int(round(float(infuse_rates[i][j]), 0))
name += f'{prefix_list[j]}_{int_rate:04d}_'
name += f'{prefix_list[j]}_{int_rate:03d}_'
sample.append(name[:-1])

return sample
Expand All @@ -60,7 +63,7 @@ def _auto_name_sample2(pump_list, prefix=None):

get_rate = [pump.read_infuse_rate.get() for pump in pump_list]
get_unit = [pump.read_infuse_rate_unit.get() for pump in pump_list]
ruc_list = [da.rate_unit_converter(r0 = unit, r1 = 'ul/min') for unit in get_unit]
ruc_list = [rate_unit_converter(r0 = unit, r1 = 'ul/min') for unit in get_unit]
get_status = [pump.status.get() for pump in pump_list]

is_infusing = []
Expand All @@ -83,9 +86,10 @@ def _auto_name_sample2(pump_list, prefix=None):
sample = []
for i in range(infuse_rates.shape[0]):
name = ''
for j in range(infuse_rates.shape[1]):
# for j in range(infuse_rates.shape[1]):
for j in range(len(prefix_list)):
int_rate = int(round(float(infuse_rates[i][j]), 0))
name += f'{prefix_list[j]}_{int_rate:04d}_'
name += f'{prefix_list[j]}_{int_rate:03d}_'
sample.append(name[:-1])

return sample
Expand Down
40 changes: 20 additions & 20 deletions scripts/_synthesis_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def synthesis_queue(
):

if name_by_prefix:
sample = _auto_name_sample(rate_list, prefix=prefix)
sample = de._auto_name_sample(rate_list, prefix=prefix)

rate_list = np.asarray(rate_list, dtype=np.float32)
if len(rate_list.shape) == 1:
Expand Down Expand Up @@ -306,26 +306,26 @@ def synthesis_queue(

## Auto generate sample name with given prefix and infuse_rate
## If prefix = None, 'Pre00', 'Pre01', 'Pre02', ... will be used.
def _auto_name_sample(infuse_rates, prefix=None):
infuse_rates = np.asarray(infuse_rates)

if len(infuse_rates.shape) == 1:
infuse_rates = infuse_rates.reshape(1, infuse_rates.shape[0])

if prefix == None:
prefix_list = [f'Pre{i:02d}' for i in range(infuse_rates.shape[1])]
else:
prefix_list = prefix

sample = []
for i in range(infuse_rates.shape[0]):
name = ''
for j in range(infuse_rates.shape[1]):
int_rate = int(round(float(infuse_rates[i][j]), 0))
name += f'{prefix_list[j]}_{int_rate:03d}_'
sample.append(name[:-1])
# def _auto_name_sample(infuse_rates, prefix=None):
# infuse_rates = np.asarray(infuse_rates)

# if len(infuse_rates.shape) == 1:
# infuse_rates = infuse_rates.reshape(1, infuse_rates.shape[0])

# if prefix == None:
# prefix_list = [f'Pre{i:02d}' for i in range(infuse_rates.shape[1])]
# else:
# prefix_list = prefix

# sample = []
# for i in range(infuse_rates.shape[0]):
# name = ''
# for j in range(infuse_rates.shape[1]):
# int_rate = int(round(float(infuse_rates[i][j]), 0))
# name += f'{prefix_list[j]}_{int_rate:03d}_'
# sample.append(name[:-1])

return sample
# return sample



Expand Down
20 changes: 11 additions & 9 deletions scripts/kafka_consumer_iterate_qserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@

# agent_data_path = '/home/xf28id2/data_ZnCl2'
# agent_data_path = '/home/xf28id2/data_ZnI2_60mM'
# agent_data_path = '/home/xf28id2/data_halide'
agent_data_path = '/home/xf28id2/data_dilute_halide'
agent_data_path = '/home/xf28id2/data_halide'
# agent_data_path = '/home/xf28id2/data_dilute_halide'

# dofs = [
# DOF(description="CsPb(oleate)3", name="infusion_rate_CsPb", units="uL/min", search_bounds=(5, 110)),
Expand All @@ -115,12 +115,12 @@
# ]

use_good_bad = True
USE_AGENT_iterate = False
peak_target = 590
USE_AGENT_iterate = True
peak_target = 580

write_agent_data = True
rate_label = ['infusion_rate_CsPb', 'infusion_rate_Br', 'infusion_rate_Cl', 'infusion_rate_I2']
# rate_label = ['infusion_rate_CsPb', 'infusion_rate_Br', 'infusion_rate_I2', 'infusion_rate_Cl']
# rate_label = ['infusion_rate_CsPb', 'infusion_rate_Br', 'infusion_rate_Cl', 'infusion_rate_I2']
rate_label = ['infusion_rate_CsPb', 'infusion_rate_Br', 'infusion_rate_I2', 'infusion_rate_Cl']

if USE_AGENT_iterate:

Expand Down Expand Up @@ -426,9 +426,11 @@ def print_message(consumer, doctype, doc,
# new_points = agent.ask("qem", n=1)
# agent.save_data(filepath="/home/xf28id2/data_halide/init_240122_01.h5")

peak_diff = peak_emission - peak_target
# peak_diff = peak_emission - peak_target
peak_diff = False

if (peak_diff <= 3) and (peak_diff >=-3):
# if (peak_diff <= 3) and (peak_diff >=-3):
if peak_diff:
print(f'\nTarget peak: {peak_target} nm vs. Current peak: {peak_emission} nm\n')
print(f'\nReach the target, stop iteration, stop all pumps, and wash the loop.\n')

Expand Down Expand Up @@ -613,7 +615,7 @@ def print_message(consumer, doctype, doc,
print(f'*** New points from agent: {new_points} ***\n')

set_target_list = [0 for i in range(new_points['points'].shape[1])]
sample = sq._auto_name_sample(new_points['points'], prefix=prefix)
sample = de._auto_name_sample(new_points['points'], prefix=prefix[1:])

sq.synthesis_queue(
syringe_list=syringe_list,
Expand Down
2 changes: 1 addition & 1 deletion scripts/kafka_consumer_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
# agent_data_path = '/home/xf28id2/data_halide'
agent_data_path = '/home/xf28id2/data_halide'

write_agent_data = False
write_agent_data = True
# rate_label = ['infusion_rate_CsPb', 'infusion_rate_Br', 'infusion_rate_Cl', 'infusion_rate_I2']
rate_label = ['infusion_rate_CsPb', 'infusion_rate_Br', 'infusion_rate_I2', 'infusion_rate_Cl']

Expand Down
14 changes: 11 additions & 3 deletions scripts/prepare_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ def build_agen(peak_target=660, peak_tolerance=5):
Cl_up_limit = 0


# dofs = [
# DOF(description="CsPb(oleate)3", name="infusion_rate_CsPb", units="uL/min", search_bounds=(8, 110)),
# DOF(description="TOABr", name="infusion_rate_Br", units="uL/min", search_bounds=(50, 200)),
# DOF(description="ZnCl2", name="infusion_rate_Cl", units="uL/min", search_bounds=(0, Cl_up_limit)),
# DOF(description="ZnI2", name="infusion_rate_I2", units="uL/min", search_bounds=(0, I_up_limit)),
# ]


dofs = [
DOF(description="CsPb(oleate)3", name="infusion_rate_CsPb", units="uL/min", search_bounds=(2, 110)),
DOF(description="CsPb(oleate)3", name="infusion_rate_CsPb", units="uL/min", search_bounds=(8, 110)),
DOF(description="TOABr", name="infusion_rate_Br", units="uL/min", search_bounds=(50, 200)),
DOF(description="ZnI2", name="infusion_rate_I2", units="uL/min", search_bounds=(0, I_up_limit)),
DOF(description="ZnCl2", name="infusion_rate_Cl", units="uL/min", search_bounds=(0, Cl_up_limit)),
DOF(description="ZnI2", name="infusion_rate_I2", units="uL/min", search_bounds=(0, I_up_limit)),
]
]


objectives = [
Expand Down

0 comments on commit c77b32c

Please sign in to comment.