In [2]:
from chxanalys.chx_libs import (np, roi, time, datetime, os, getpass, db, get_images,LogNorm, plt,ManualMask)
from chxanalys.chx_generic_functions import (get_detector, get_fields, get_sid_filenames,load_data, RemoveHot, show_img,get_avg_img, reverse_updown,create_cross_mask )
from skimage.draw import line_aa, line, polygon, circle
%matplotlib notebook
In [3]:
CYCLE= '2017_1'
In [4]:
path = '/XF11ID/analysis/%s/masks/'%CYCLE
print ("The analysis results will be saved in : %s"%path)
In [6]:
uid = '129ecb'
In [7]:
detector = get_detector( db[uid ] )
print ('Detector is: %s'%detector )
sud = get_sid_filenames(db[uid])
print ('scan_id, full-uid, data path are: %s--%s--%s'%(sud[0], sud[1], sud[2][0] ))
In [8]:
#imgs = load_data( uid, detector, reverse= True )
imgs = load_data( uid, detector, reverse= False )
md = imgs.md
Nimg=len(imgs)
In [9]:
imgs
Out[9]:
In [10]:
md
Out[10]:
In [12]:
pixel_mask = 1- np.int_( np.array( md['pixel_mask'], dtype= bool) )
In [14]:
show_img( imgs[0]*pixel_mask , vmin=.0001, vmax=1000, logs=True, image_name ='uid=%s'%uid )
In [15]:
show_img(pixel_mask, vmin=0, vmax=1, image_name ='pixel_mask--uid=%s'%uid )
In [16]:
avg_img = get_avg_img( imgs, sampling = 1000, plot_ = False, uid =uid)
In [19]:
show_img(avg_img*pixel_mask,vmin=0.01,vmax=5, logs=True, image_name= 'uid= %s with pixel mask'%uid)
In [20]:
mask_rh = RemoveHot( avg_img, 5E8, plot_=True)
In [21]:
#md['beam_center_x']=1437;md['beam_center_y']=824
md['beam_center_x'],2167-md['beam_center_y']
Out[21]:
In [22]:
#creat the left part mask
partial_mask = create_cross_mask( avg_img, center=[ 1413, 1350],
wy_left=0, wy_right= 16,
wx_up= 0, wx_down= 0,center_radius= 0 )
In [23]:
#creat the right part mask
partial_mask *= create_cross_mask( avg_img, center=[ 1436.0, 1348.0],
wy_left=12, wy_right= 12,
wx_up= 12, wx_down= 12,center_radius= 0 )
#partial_mask2[1285:1350,1430:1440,] = False
In [24]:
#creat the up part mask
partial_mask *= create_cross_mask( avg_img, center=[ 1440, 1351],
wy_left=0, wy_right= 0,
wx_up= 0, wx_down= 0,center_radius= 0 )
In [25]:
#creat the down part mask
partial_mask *= create_cross_mask( avg_img, center=[ 1444, 1351],
wy_left=0, wy_right= 0,
wx_up= 0, wx_down= 0,center_radius= 0 )
In [26]:
full_mask = partial_mask
In [27]:
show_img( full_mask )
In [28]:
mask = np.array ( full_mask * pixel_mask*mask_rh , dtype = bool )
In [29]:
fig, ax = plt.subplots()
#new_mask =
im=ax.imshow( (~mask) * avg_img,origin='lower' ,
norm= LogNorm( vmin=0.1, vmax= 1e1 ), cmap='viridis')
#im = ax.imshow(avg_img, cmap='viridis',origin='lower', norm= LogNorm( vmin=0.001, vmax=100 ) )
plt.show()
In [30]:
fig, ax = plt.subplots()
im = ax.imshow((mask)*avg_img, cmap='viridis',origin='lower', norm= LogNorm( vmin=.1, vmax=3 ) )
plt.show()
In [31]:
#mask = np.array ( ~new_mask* ~plgon_mask * md['pixel_mask']*mask_rh, dtype = bool )
fig, ax = plt.subplots()
im=ax.imshow(mask, origin='lower' ,vmin=0, vmax=1,cmap='viridis')
fig.colorbar(im)
plt.show()
In [32]:
np.save( path + uid +"_mask", mask)
In [33]:
path + uid +"_mask"
Out[33]:
In [35]:
meaningful_name = 'Dec3_4M_SAXS2' +"_mask"
In [ ]:
np.save( path + meaningful_name, mask)