Skip to content

Commit

Permalink
add transform_bkg & do pdf fitting when washing loop
Browse files Browse the repository at this point in the history
  • Loading branch information
XPD Operator committed May 30, 2024
1 parent 2d1791b commit 5df88e4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
5 changes: 4 additions & 1 deletion scripts/_get_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,7 @@ def find_qmax(filename, ave_cutoff=8e-03, window_length=21):

pdfconfig.qmax=qmax
print(pdfconfig)
transform_bkg(pdfconfig, testfile, output_dir=output_dir, plot_setting={'marker':'.','color':'green'} )
transform_bkg(pdfconfig, testfile, output_dir=output_dir, plot_setting={'marker':'.','color':'green'} )



34 changes: 20 additions & 14 deletions scripts/_synthesis_queue_RM.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,14 @@ def synthesis_queue(
###### Kafka analyze data here. #######

## 7. Wash the loop and mixer
wash_tube_queue2(pump_list, wash_tube, rate_unit,
pos=[pos,pos,pos,pos,pos],
zmq_control_addr=zmq_control_addr,
zmq_info_addr=zmq_info_addr)
if wash_tube[0] == 0:
wash_tube_queue2(pump_list, wash_tube, rate_unit,
pos=[pos,pos,pos,pos,pos],
zmq_control_addr=zmq_control_addr,
zmq_info_addr=zmq_info_addr)
elif wash_tube[0] == 1:
inst1 = BInst("queue_stop")
RM.item_add(inst1, pos='front')


# 8. stop infuese for all pumps
Expand All @@ -188,6 +192,8 @@ def synthesis_queue(





def wash_tube_queue(pump_list, wash_tube, rate_unit,
pos=[0,1,2,3,4],
zmq_control_addr='tcp://localhost:60615',
Expand All @@ -201,27 +207,27 @@ def wash_tube_queue(pump_list, wash_tube, rate_unit,


### Set up washing tube/loop
flowplan = BPlan('set_group_infuse2', [wash_tube[0]], [wash_tube[1]],
rate_list=[wash_tube[2]],
flowplan = BPlan('set_group_infuse2', [wash_tube[1]], [wash_tube[2]],
rate_list=[wash_tube[3]],
target_vol_list=['30 ml'],
set_target_list=[False],
rate_unit=rate_unit)
RM.item_add(flowplan, pos=pos[1])


### Start washing tube/loop
flowplan = BPlan('start_group_infuse', [wash_tube[1]], [wash_tube[2]])
flowplan = BPlan('start_group_infuse', [wash_tube[2]], [wash_tube[3]])
RM.item_add(flowplan, pos=pos[2])


### Wash loop/tube for xxx seconds
restplan = BPlan('sleep_sec_q', wash_tube[3])
restplan = BPlan('sleep_sec_q', wash_tube[4])
RM.item_add(restplan, pos=pos[3])



### Stop washing
flowplan = BPlan('stop_group', [wash_tube[1]])
flowplan = BPlan('stop_group', [wash_tube[2]])
RM.item_add(flowplan, pos=pos[4])


Expand All @@ -240,27 +246,27 @@ def wash_tube_queue2(pump_list, wash_tube, rate_unit,


### Set up washing tube/loop
flowplan = BPlan('set_group_infuse2', [wash_tube[0], wash_tube[3]], [wash_tube[1], wash_tube[4]],
rate_list=[wash_tube[2], wash_tube[5]],
flowplan = BPlan('set_group_infuse2', [wash_tube[1], wash_tube[4]], [wash_tube[2], wash_tube[5]],
rate_list=[wash_tube[3], wash_tube[6]],
target_vol_list=['30 ml', '15 ml'],
set_target_list=[False, False],
rate_unit=rate_unit)
RM.item_add(flowplan, pos=pos[1])


### Start washing tube/loop
flowplan = BPlan('start_group_infuse', [wash_tube[1], wash_tube[4]], [wash_tube[2], wash_tube[5]])
flowplan = BPlan('start_group_infuse', [wash_tube[2], wash_tube[5]], [wash_tube[3], wash_tube[6]])
RM.item_add(flowplan, pos=pos[2])


### Wash loop/tube for xxx seconds
restplan = BPlan('sleep_sec_q', wash_tube[6])
restplan = BPlan('sleep_sec_q', wash_tube[7])
RM.item_add(restplan, pos=pos[3])



### Stop washing
flowplan = BPlan('stop_group', [wash_tube[1], wash_tube[4]])
flowplan = BPlan('stop_group', [wash_tube[2], wash_tube[5]])
RM.item_add(flowplan, pos=pos[4])


Expand Down
35 changes: 31 additions & 4 deletions scripts/kafka_consumer_iterate_RM.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import json
import glob
from tqdm import tqdm
from diffpy.pdfgetx import PDFConfig

import resource
resource.setrlimit(resource.RLIMIT_NOFILE, (65536, 65536))
Expand All @@ -21,6 +22,7 @@
from _plot_helper import plot_uvvis
import _data_analysis as da
import _pdf_calculator as pc
import _get_pdf as gp

# from bluesky_queueserver.manager.comms import zmq_single_request
from bluesky_queueserver_api.zmq import REManagerAPI
Expand Down Expand Up @@ -135,6 +137,12 @@
agent = build_agen2(peak_target=peak_target)


iq_to_gr = False
if iq_to_gr:
gr_path = '/home/xf28id2/Documents/ChengHung/pdfstream_test/'
cfg_fn = '/home/xf28id2/Documents/ChengHung/pdfstream_test/pdfgetx3.cfg'
bkg_fn = glob.glob(os.path.join(gr_path, '**bkg**.chi'))

fitting_pdf = False
if fitting_pdf:
pdf_cif_dir = '/home/xf28id2/Documents/ChengHung/pdffit2_example/CsPbBr3/'
Expand Down Expand Up @@ -226,8 +234,20 @@ def print_message(consumer, doctype, doc,
print(f"sample type: {message['sample_type']}")

if name == 'stop':
RM.queue_stop()
print('\n*** qsever stop for data export, identification, and fitting ***\n')
# stop queue for data analysis, used with quick processing, washing loop after analysis
if wash_tube[0] == 0:
RM.queue_stop()
print('\n*** qsever stop for data export, identification, and fitting ***\n')

## conduct data analysis, especially for pdf calculation, during washing loop
elif wash_tube[0] == 1:
wash_tube_queue2(pump_list, wash_tube, rate_unit,
zmq_control_addr=zmq_control_addr,
zmq_info_addr=zmq_info_addr
)
RM.queue_start()
print('\n*** Start data analysis, export, and pdf fitting during washing loop***\n')

print(f"{datetime.datetime.now().isoformat()} documents {name}\n"
f"contents: {pprint.pformat(message)}"
)
Expand All @@ -252,6 +272,13 @@ def print_message(consumer, doctype, doc,

## obtain phase fraction & particle size from g(r)
if 'scattering' in stream_list:
if iq_to_gr:
pdfconfig = PDFConfig()
pdfconfig.readConfig(cfg_fn)
pdfconfig.backgroundfiles = bkg_fn[-1]
sqfqgr_path = gp.transform_bkg(pdfconfig, testfile, output_dir=gr_path,
plot_setting={'marker':'.','color':'green'}, test=True)
gr_data = sqfqgr_path['gr']
if fitting_pdf:
phase_fraction, particel_size = pc._pdffit2_CsPbX3(gr_data, cif_list, qmax=20, qdamp=0.031, qbroad=0.032, fix_APD=False, toler=0.001)
pdf_property={'Br_ratio': phase_fraction[0], 'Br_size':particel_size[0]}
Expand Down Expand Up @@ -423,7 +450,7 @@ def print_message(consumer, doctype, doc,
print(f'\nReach the target, stop iteration, stop all pumps, and wash the loop.\n')

### Stop all infusing pumps and wash loop
wash_tube_queue(pump_list, wash_tube, rate_unit,
wash_tube_queue2(pump_list, wash_tube, rate_unit,
zmq_control_addr=zmq_control_addr,
zmq_info_addr=zmq_info_addr)

Expand Down Expand Up @@ -478,7 +505,7 @@ def print_message(consumer, doctype, doc,
print('*** qsever aborted due to too many bad scans, please check setup ***\n')

### Stop all infusing pumps and wash loop
wash_tube_queue(pump_list, wash_tube, rate_unit,
wash_tube_queue2(pump_list, wash_tube, rate_unit,
zmq_control_addr=zmq_control_addr,
zmq_info_addr=zmq_info_addr)

Expand Down

0 comments on commit 5df88e4

Please sign in to comment.