Page History
...
In order to interactively communicate between the Mask Editor and other application(s) Marcin Sikorski requested to introduce the file exchange mechanism for image and mask. It is assumed that external event processing application periodically supplies averaged image, Mask Editor can load it and use for interactive ROI mask correction, and submit in response the mask, which will be used by the external application. This asynchronous data exchange mechanism was implemented in CorAna.ArrFileExchange class. Data exchange is implemented for This algorithm uses numpy arrays using with np.save(fname,arr)
and arr=np.load(fname)
methods. In order to get rid of collisions between reader and writer the "ring-buffer" (a.k.a. "round-robin") exchange mechanism is implemented. Data producer writes files with names numerated enumerated in the ring buffer. During writing data is saved in the file with temporary name. When the file is written, it is renamed to indexed name. This eliminates probability of the read/write collision. Data consumer checks availability of the new data and loads numpy array from the latest file if necessary.
Interface for class CorAna.ArrFileExchange
Code Block |
---|
#----------------------- # code in array producer #----------------------- afe = ArrFileExchange(prefix='./my-numpy-arr') # one call per object arr = ... # supply array here afe.save_arr(arr) # as many times as you need #----------------------- # code in array consumer #----------------------- afe = ArrFileExchange(prefix='./my-numpy-arr') # one call per object arr = afe.get_arr_latest() # as many times as you need # optional methodsmethod: status = afe.is_new_arr_available() # returns True/False if the new array IS/IS NOT available # since last call to arr = afe.get_arr_latest() |
...
med -f -i work/my-roi-img -m work/my-roi-mask,
assuming that path to the file directory work/
already exists. Options in this example brings new provide functionality as follows;
...
External application may communicate with launched med through the code pattern shown below
Code Block |
---|
from CorAna.ArrFileExchange import * ... # create reader/writer objects with file name prefixes # exactly like in the med command line for opposite party: afe_rd = ArrFileExchange(prefix='work/my-roi-mask') afe_wr = ArrFileExchange(prefix='work/my-roi-img') ... # image writer image = np.array(...) # supply numpy array for image afe_wr.save_arr(image) # image writer ... # mask reader if afe_rd.is_new_arr_available() : # check that the new data is available mask = afe_rd.get_arr_latest() # mask reader |
...