In [1]:
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)
%matplotlib notebook
In [4]:
path = '/XF11ID/analysis/2016_3/masks/'
print ("The analysis results will be saved in : %s"%path)
In [6]:
uid = '05e27b' #count : 1 ['05e27b'] (scan num: 2968) (Measurement: CoralPor 1kHz 5k frames )
uid = 'eaed19' #count : 1 ['eaed19'] (scan num: 3929) (Measurement: coralpor 750Hz 5k )
uid = '6b07666f'
uid ='e368d5' #count : 1 ['e368d5'] (scan num: 4323) (Measurement: empty cell image for mask )
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
In [9]:
imgs
Out[9]:
In [10]:
Nimg=len(imgs)
In [11]:
md
Out[11]:
In [12]:
#%matplotlib inline
In [ ]:
In [13]:
pixel_mask = 1- np.int_( np.array( md['pixel_mask'], dtype= bool) )
In [14]:
#%run /XF11ID/analysis/Analysis_Pipelines/Develop/chxanalys/chxanalys/Create_Report.py
#%run /XF11ID/analysis/Analysis_Pipelines/Develop/chxanalys/chxanalys/chx_generic_functions.py
In [ ]:
In [15]:
show_img( imgs[0] , vmin=.0001, vmax=1000, logs=True, image_name ='uid=%s'%uid )
In [ ]:
In [16]:
show_img(pixel_mask, vmin=0, vmax=1, image_name ='pixel_mask--uid=%s'%uid )
In [17]:
imgs.shape
Out[17]:
In [18]:
avg_img = get_avg_img( imgs, sampling = 1000, plot_ = True, uid =uid)
In [124]:
#show_img( avg_img*md['pixel_mask'], vmin= .01, vmax= 100,
# logs= True, aspect=1.,image_name ='img*pixel_mask--uid=%s'%uid )
In [125]:
#show_img( avg_img*md['pixel_mask'], vmin= 1, vmax= 1000, aspect=1.,
#
# logs= True, image_name ='img*pixel_mask--uid=%s'%uid )
In [126]:
#show_img( avg_img*md['pixel_mask'], vmin= 1, vmax= 1000, xlim=[1000, 2070], ylim=[1000, 1500], aspect=1.,
#
# logs= True, image_name ='img*pixel_mask--uid=%s'%uid )
In [19]:
avg_img.shape
Out[19]:
In [20]:
2167-784
Out[20]:
In [21]:
mask_rh = RemoveHot( avg_img, 5E4, plot_=True)
In [22]:
fig, ax = plt.subplots()
m = ManualMask(ax, avg_img* md['pixel_mask']*mask_rh,
cmap='viridis',origin='lower',
vmin=.01, vmax=1.50)
plt.show()
In [ ]:
In [23]:
new_mask = m.mask
manu_mask = new_mask.copy()
fig, ax = plt.subplots()
im=ax.imshow(new_mask,origin='lower' ,vmin=0, vmax=1,cmap='viridis')
fig.colorbar(im)
plt.show()
In [24]:
manu_mask = new_mask.copy()
In [25]:
from skimage.draw import line_aa, line, polygon, circle
In [26]:
def create_cross_mask( image, center, wy_left=4, wy_right=4, wx_up=4, wx_down=4,
center_circle = True, center_radius=10
):
'''
Give image and the beam center to create a cross-shaped mask
wy_left: the width of left h-line
wy_right: the width of rigth h-line
wx_up: the width of up v-line
wx_down: the width of down v-line
center_circle: if True, create a circle with center and center_radius
Return:
the cross mask
'''
imy, imx = image.shape
cx,cy = center
bst_mask = np.zeros_like( image , dtype = bool)
###
#for right part
wy = wy_right
x = np.array( [ cx, imx, imx, cx ])
y = np.array( [ cy-wy, cy-wy, cy + wy, cy + wy])
rr, cc = polygon( y,x)
bst_mask[rr,cc] =1
###
#for left part
wy = wy_left
x = np.array( [0, cx, cx,0 ])
y = np.array( [ cy-wy, cy-wy, cy + wy, cy + wy])
rr, cc = polygon( y,x)
bst_mask[rr,cc] =1
###
#for up part
wx = wx_up
x = np.array( [ cx-wx, cx + wx, cx+wx, cx-wx ])
y = np.array( [ cy, cy, imy, imy])
rr, cc = polygon( y,x)
bst_mask[rr,cc] =1
###
#for low part
wx = wx_down
x = np.array( [ cx-wx, cx + wx, cx+wx, cx-wx ])
y = np.array( [ 0,0, cy, cy])
rr, cc = polygon( y,x)
bst_mask[rr,cc] =1
rr, cc = circle( cy, cx, center_radius)
bst_mask[rr,cc] =1
full_mask= ~bst_mask
return full_mask
In [28]:
md
Out[28]:
In [27]:
show_img( imgs[0] , vmin=.0001, vmax=1000, logs=True, image_name ='uid=%s'%uid )
In [29]:
avg_img.shape
Out[29]:
In [30]:
2167-786
Out[30]:
In [ ]:
In [46]:
full_mask = create_cross_mask( avg_img, center=[ 1471, 1381],
wy_left=0, wy_right=20,
wx_up= 14, wx_down= 10,center_radius= 54 )
In [47]:
show_img( full_mask )
In [ ]:
In [33]:
if False:#center of beam stop
bst_mask = np.zeros_like( avg_img , dtype = bool)
beam_center = [1381, 1471]
##h
cx= 1750
cy = 1380
wx= 2070- cx
wy = 20
x = np.array( [ cx-wx, cx+wx, cx+wx, cx - wx, ])
y = np.array( [ cy-wy, cy-wy, cy + wy, cy + wy])
rr, cc = polygon( y,x)
bst_mask[rr,cc] =1
##h
cx= 1750
cy = 1380
wx= 2070- cx
wy = 20
x = np.array( [ cx-wx, cx+wx, cx+wx, cx - wx, ])
y = np.array( [ cy-wy, cy-wy, cy + wy, cy + wy])
rr, cc = polygon( y,x)
bst_mask[rr,cc] =1
#c=1381
#w=5
#bst_mask2 = np.zeros_like( avg_img , dtype = bool)
#x = np.array( [ 0, 1340, 1340, 0])
#y = np.array( [ c-w, c-w, c+w, c+w])
#rr, cc = polygon( y,x)
#bst_mask2[rr,cc] =1
full_mask= ~bst_mask #* ~bst_mask2 *~bst_mask3 *~bst_mask4
In [138]:
#show_img(full_mask)
In [48]:
mask = np.array ( full_mask * pixel_mask*mask_rh , dtype = bool )
In [49]:
fig, ax = plt.subplots()
#new_mask =
im=ax.imshow( (~mask) * avg_img,origin='lower' ,
norm= LogNorm( vmin=0.1, vmax= 1e2 ), cmap='viridis')
#im = ax.imshow(avg_img, cmap='viridis',origin='lower', norm= LogNorm( vmin=0.001, vmax=100 ) )
plt.show()
In [50]:
fig, ax = plt.subplots()
#new_mask =
#im=ax.imshow( (Mask) * avg_img,origin='lower' ,
# norm= LogNorm( vmin=0.001, vmax=30 ), cmap='viridis')
#im = ax.imshow((mask)*avg_img, cmap='viridis',origin='lower', norm= LogNorm( vmin=0.001, vmax=100 ) )
im = ax.imshow((mask)*avg_img, cmap='viridis',origin='lower', norm= LogNorm( vmin=1, vmax=1000 ) )
plt.show()
In [51]:
#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 [52]:
np.save( path + uid +"_mask", mask)
In [245]:
#np.save( path + 'July3' +"_mask", mask)
In [53]:
path + uid +"_mask"
Out[53]:
In [55]:
#np.save( path + 'Nov3_4M' +"_mask", mask)
In [147]:
#path + 'Octo28_4M' +"_mask"
In [40]:
#np.save( path + 'Octo21_1M_pixel' +"_mask", md['pixel_mask'])
In [ ]:
In [ ]: