00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 """
00011 :py:class:`PSCalib.GlobalUtils` - contains a set of utilities
00012
00013 Usage::
00014
00015 # Import
00016 import PSCalib.GlobalUtils as gu
00017
00018 # Methods
00019 #resp = gu.<method(pars)>
00020
00021 dettype = gu.det_type_from_source(source)
00022 detname = gu.string_from_source(source)
00023
00024 mmask = gu.merge_masks(mask1=None, mask2=None, dtype=np.uint8)
00025 mask = gu.mask_neighbors(mask_in, allnbrs=True, dtype=np.uint8)
00026
00027 arr2d = gu.reshape_nda_to_2d(nda)
00028 arr3d = gu.reshape_nda_to_3d(nda)
00029
00030 # Get string with time stamp, ex: 2016-01-26T10:40:53
00031 ts = gu.str_tstamp(fmt='%Y-%m-%dT%H:%M:%S', time_sec=None)
00032
00033 usr = gu.get_enviroment(env='USER')
00034 usr = gu.get_login()
00035 host = gu.get_hostname()
00036 cwd = gu.get_cwd()
00037
00038 gu.save_textfile(text, path, mode='w') # mode: 'w'-write, 'a'-append
00039
00040 @see other interface methods in :py:class:`PSCalib.CalibPars`, :py:class:`PSCalib.CalibParsStore`
00041
00042 This software was developed for the SIT project.
00043 If you use all or part of it, please give an appropriate acknowledgment.
00044
00045 @version $Id: 2013-03-08$
00046
00047 @author Mikhail S. Dubrovin
00048 """
00049
00050
00051 __version__ = "$Revision: 13028 $"
00052
00053
00054
00055 import os
00056 import getpass
00057 import socket
00058 import numpy as np
00059 from time import localtime, strftime
00060
00061
00062
00063
00064
00065
00066
00067
00068 PEDESTALS = 0
00069 PIXEL_STATUS = 1
00070 PIXEL_RMS = 2
00071 PIXEL_GAIN = 3
00072 PIXEL_MASK = 4
00073 PIXEL_BKGD = 5
00074 COMMON_MODE = 6
00075 GEOMETRY = 7
00076
00077 calib_types = ( PEDESTALS, PIXEL_STATUS, PIXEL_RMS, PIXEL_GAIN, PIXEL_MASK, PIXEL_BKGD, COMMON_MODE, GEOMETRY)
00078 calib_names = ('pedestals', 'pixel_status', 'pixel_rms', 'pixel_gain', 'pixel_mask', 'pixel_bkgd', 'common_mode', 'geometry')
00079 calib_dtypes = ( np.float32, np.uint16, np.float32, np.float32, np.uint8, np.float32, np.double, str)
00080
00081 dic_calib_type_to_name = dict(zip(calib_types, calib_names))
00082 dic_calib_name_to_type = dict(zip(calib_names, calib_types))
00083 dic_calib_type_to_dtype = dict(zip(calib_types, calib_dtypes))
00084
00085 LOADED = 1
00086 DEFAULT = 2
00087 UNREADABLE = 3
00088 UNDEFINED = 4
00089 WRONGSIZE = 5
00090 NONFOUND = 6
00091 DCSTORE = 7
00092
00093 calib_statvalues = ( LOADED, DEFAULT, UNREADABLE, UNDEFINED, WRONGSIZE, NONFOUND, DCSTORE)
00094 calib_statnames = ('LOADED', 'DEFAULT', 'UNREADABLE', 'UNDEFINED', 'WRONGSIZE', 'NONFOUND', 'DCSTORE')
00095
00096 dic_calib_status_value_to_name = dict(zip(calib_statvalues, calib_statnames))
00097 dic_calib_status_name_to_value = dict(zip(calib_statnames, calib_statvalues))
00098
00099
00100
00101
00102
00103
00104 UNDEFINED = 0
00105 CSPAD = 1
00106 CSPAD2X2 = 2
00107 PRINCETON = 3
00108 PNCCD = 4
00109 TM6740 = 5
00110 OPAL1000 = 6
00111 OPAL2000 = 7
00112 OPAL4000 = 8
00113 OPAL8000 = 9
00114 ORCAFL40 = 10
00115 EPIX = 11
00116 EPIX10K = 12
00117 EPIX100A = 13
00118 FCCD960 = 14
00119 ANDOR = 15
00120 ACQIRIS = 16
00121 IMP = 17
00122 QUARTZ4A150 = 18
00123 RAYONIX = 19
00124 EVR = 20
00125 FCCD = 21
00126 TIMEPIX = 22
00127 FLI = 23
00128 PIMAX = 24
00129 ANDOR3D = 25
00130 JUNGFRAU = 26
00131
00132
00133
00134
00135
00136
00137
00138 """ Enumetated detector types"""
00139
00140 list_of_det_type = (UNDEFINED, CSPAD, CSPAD2X2, PRINCETON, PNCCD, TM6740, \
00141 OPAL1000, OPAL2000, OPAL4000, OPAL8000, \
00142 ORCAFL40, EPIX, EPIX10K, EPIX100A, FCCD960, ANDOR, ACQIRIS, IMP, QUARTZ4A150, RAYONIX,
00143 EVR, FCCD, TIMEPIX, FLI, PIMAX, ANDOR3D, JUNGFRAU)
00144 """ List of enumetated detector types"""
00145
00146 list_of_det_names = ('UNDEFINED', 'Cspad', 'Cspad2x2', 'Princeton', 'pnCCD', 'Tm6740', \
00147 'Opal1000', 'Opal2000', 'Opal4000', 'Opal8000', \
00148 'OrcaFl40', 'Epix', 'Epix10k', 'Epix100a', 'Fccd960', 'Andor', 'Acqiris', 'Imp', 'Quartz4A150', 'Rayonix',\
00149 'Evr', 'Fccd', 'Timepix', 'Fli', 'Pimax', 'Andor3d', 'Jungfrau')
00150 """ List of enumetated detector names"""
00151
00152 list_of_calib_groups = ('UNDEFINED',
00153 'CsPad::CalibV1',
00154 'CsPad2x2::CalibV1',
00155 'Princeton::CalibV1',
00156 'PNCCD::CalibV1',
00157 'Camera::CalibV1',
00158 'Camera::CalibV1',
00159 'Camera::CalibV1',
00160 'Camera::CalibV1',
00161 'Camera::CalibV1',
00162 'Camera::CalibV1',
00163 'Epix::CalibV1',
00164 'Epix10k::CalibV1',
00165 'Epix100a::CalibV1',
00166 'Camera::CalibV1',
00167 'Andor::CalibV1',
00168 'Acqiris::CalibV1',
00169 'Imp::CalibV1',
00170 'Camera::CalibV1',
00171 'Camera::CalibV1',
00172 'EvrData::CalibV1',
00173 'Camera::CalibV1',
00174 'Timepix::CalibV1',
00175 'Fli::CalibV1',
00176 'Pimax::CalibV1',
00177 'Andor3d::CalibV1',
00178 'Jungfrau::CalibV1'
00179 )
00180 """ List of enumetated detector calibration groups"""
00181
00182 dic_det_type_to_name = dict(zip(list_of_det_type, list_of_det_names))
00183 """ Dictionary for detector type : name"""
00184
00185 dic_det_type_to_calib_group = dict(zip(list_of_det_type, list_of_calib_groups))
00186 """ Dictionary for detector type : group"""
00187
00188
00189 bld_names = \
00190 ['EBeam',
00191 'PhaseCavity',
00192 'FEEGasDetEnergy',
00193 'Nh2Sb1Ipm01',
00194 'HxxUm6Imb01',
00195 'HxxUm6Imb02',
00196 'HfxDg2Imb01',
00197 'HfxDg2Imb02',
00198 'XcsDg3Imb03',
00199 'XcsDg3Imb04',
00200 'HfxDg3Imb01',
00201 'HfxDg3Imb02',
00202 'HxxDg1Cam',
00203 'HfxDg2Cam',
00204 'HfxDg3Cam',
00205 'XcsDg3Cam',
00206 'HfxMonCam',
00207 'HfxMonImb01',
00208 'HfxMonImb02',
00209 'HfxMonImb03',
00210 'MecLasEm01',
00211 'MecTctrPip01',
00212 'MecTcTrDio01',
00213 'MecXt2Ipm02',
00214 'MecXt2Ipm03',
00215 'MecHxmIpm01',
00216 'GMD',
00217 'CxiDg1Imb01',
00218 'CxiDg2Imb01',
00219 'CxiDg2Imb02',
00220 'CxiDg4Imb01',
00221 'CxiDg1Pim',
00222 'CxiDg2Pim',
00223 'CxiDg4Pim',
00224 'XppMonPim0',
00225 'XppMonPim1',
00226 'XppSb2Ipm',
00227 'XppSb3Ipm',
00228 'XppSb3Pim',
00229 'XppSb4Pim',
00230 'XppEndstation0',
00231 'XppEndstation1',
00232 'MecXt2Pim02',
00233 'MecXt2Pim03',
00234 'CxiDg3Spec',
00235 'Nh2Sb1Ipm02',
00236 'FeeSpec0',
00237 'SxrSpec0',
00238 'XppSpec0',
00239 'XcsUsrIpm01',
00240 'XcsUsrIpm02',
00241 'XcsUsrIpm03',
00242 'XcsUsrIpm04',
00243 'XcsSb1Ipm01',
00244 'XcsSb1Ipm02',
00245 'XcsSb2Ipm01',
00246 'XcsSb2Ipm02',
00247 'XcsGonIpm01',
00248 'XcsLamIpm01',
00249 'XppAin01',
00250 'XcsAin01',
00251 'AmoAin01']
00252
00253
00254
00255
00256 def det_type_from_source(source) :
00257 """ Returns enumerated detector type for string source
00258 """
00259 str_src = str(source)
00260 if ':Cspad.' in str_src : return CSPAD
00261 elif ':Cspad2x2.' in str_src : return CSPAD2X2
00262 elif ':pnCCD.' in str_src : return PNCCD
00263 elif ':Princeton.' in str_src : return PRINCETON
00264 elif ':Andor.' in str_src : return ANDOR
00265 elif ':Epix100a.' in str_src : return EPIX100A
00266 elif ':Epix10k.' in str_src : return EPIX10K
00267 elif ':Epix.' in str_src : return EPIX
00268 elif ':Opal1000.' in str_src : return OPAL1000
00269 elif ':Opal2000.' in str_src : return OPAL2000
00270 elif ':Opal4000.' in str_src : return OPAL4000
00271 elif ':Opal8000.' in str_src : return OPAL8000
00272 elif ':Tm6740.' in str_src : return TM6740
00273 elif ':OrcaFl40.' in str_src : return ORCAFL40
00274 elif ':Fccd960.' in str_src : return FCCD960
00275 elif ':Acqiris.' in str_src : return ACQIRIS
00276 elif ':Imp.' in str_src : return IMP
00277 elif ':Quartz4A150.' in str_src : return QUARTZ4A150
00278 elif ':Rayonix.' in str_src : return RAYONIX
00279 elif ':Evr.' in str_src : return EVR
00280 elif ':Fccd.' in str_src : return FCCD
00281 elif ':Timepix.' in str_src : return TIMEPIX
00282 elif ':Fli.' in str_src : return FLI
00283 elif ':Pimax.' in str_src : return PIMAX
00284 elif ':DualAndor.' in str_src : return ANDOR3D
00285 elif ':Jungfrau.' in str_src : return JUNGFRAU
00286 else : return UNDEFINED
00287
00288
00289
00290
00291
00292 def string_from_source(source) :
00293 """Returns string like "CxiDs2.0:Cspad.0" from "Source('DetInfo(CxiDs2.0:Cspad.0)')" or "Source('DsaCsPad')"
00294 """
00295 str_in_quots = str(source).split('"')[1]
00296 str_split = str_in_quots.split('(')
00297 return str_split[1].rstrip(')') if len(str_split)>1 else str_in_quots
00298
00299
00300
00301 def shape_nda_to_2d(arr) :
00302 """Return shape of np.array to reshape to 2-d
00303 """
00304 sh = arr.shape
00305 if len(sh)<3 : return sh
00306 return (arr.size/sh[-1], sh[-1])
00307
00308
00309
00310 def shape_nda_to_3d(arr) :
00311 """Return shape of np.array to reshape to 3-d
00312 """
00313 sh = arr.shape
00314 if len(sh)<4 : return sh
00315 return (arr.size/sh[-1]/sh[-2], sh[-2], sh[-1])
00316
00317
00318
00319 def reshape_nda_to_2d(arr) :
00320 """Reshape np.array to 2-d
00321 """
00322 sh = arr.shape
00323 if len(sh)<3 : return arr
00324 arr.shape = (arr.size/sh[-1], sh[-1])
00325 return arr
00326
00327
00328
00329 def reshape_nda_to_3d(arr) :
00330 """Reshape np.array to 3-d
00331 """
00332 sh = arr.shape
00333 if len(sh)<4 : return arr
00334 arr.shape = (arr.size/sh[-1]/sh[-2], sh[-2], sh[-1])
00335 return arr
00336
00337
00338
00339 def merge_masks(mask1=None, mask2=None, dtype=np.uint8) :
00340 """Merging masks using np.logical_and rule: (0,1,0,1)^(0,0,1,1) = (0,0,0,1)
00341 """
00342 if mask1 is None : return mask2
00343 if mask2 is None : return mask1
00344
00345 shape1 = mask1.shape
00346 shape2 = mask2.shape
00347
00348 if shape1 != shape2 :
00349 if len(shape1) > len(shape2) : mask2.shape = shape1
00350 else : mask1.shape = shape2
00351
00352 mask = np.logical_and(mask1, mask2)
00353 return mask if dtype==np.bool else np.asarray(mask, dtype)
00354
00355
00356
00357 def mask_neighbors(mask, allnbrs=True, dtype=np.uint8) :
00358 """Return mask with masked eight neighbor pixels around each 0-bad pixel in input mask.
00359
00360 mask : int - n-dimensional (n>1) array with input mask
00361 allnbrs : bool - False/True - masks 4/8 neighbor pixels.
00362 """
00363 shape_in = mask.shape
00364 if len(shape_in) < 2 :
00365 raise ValueError('Input mask has less then 2-d, shape = %s' % str(shape_in))
00366
00367 mask_out = np.asarray(mask, dtype)
00368
00369 if len(shape_in) == 2 :
00370
00371 mask_out[0:-1,:] = np.logical_and(mask_out[0:-1,:], mask[1:, :])
00372 mask_out[1:, :] = np.logical_and(mask_out[1:, :], mask[0:-1,:])
00373 mask_out[:,0:-1] = np.logical_and(mask_out[:,0:-1], mask[:,1: ])
00374 mask_out[:,1: ] = np.logical_and(mask_out[:,1: ], mask[:,0:-1])
00375 if allnbrs :
00376
00377 mask_out[0:-1,0:-1] = np.logical_and(mask_out[0:-1,0:-1], mask[1: ,1: ])
00378 mask_out[1: ,0:-1] = np.logical_and(mask_out[1: ,0:-1], mask[0:-1,1: ])
00379 mask_out[0:-1,1: ] = np.logical_and(mask_out[0:-1,1: ], mask[1: ,0:-1])
00380 mask_out[1: ,1: ] = np.logical_and(mask_out[1: ,1: ], mask[0:-1,0:-1])
00381
00382 else :
00383
00384 mask_out.shape = mask.shape = shape_nda_to_3d(mask)
00385
00386
00387 mask_out[:, 0:-1,:] = np.logical_and(mask_out[:, 0:-1,:], mask[:, 1:, :])
00388 mask_out[:, 1:, :] = np.logical_and(mask_out[:, 1:, :], mask[:, 0:-1,:])
00389 mask_out[:, :,0:-1] = np.logical_and(mask_out[:, :,0:-1], mask[:, :,1: ])
00390 mask_out[:, :,1: ] = np.logical_and(mask_out[:, :,1: ], mask[:, :,0:-1])
00391 if allnbrs :
00392
00393 mask_out[:, 0:-1,0:-1] = np.logical_and(mask_out[:, 0:-1,0:-1], mask[:, 1: ,1: ])
00394 mask_out[:, 1: ,0:-1] = np.logical_and(mask_out[:, 1: ,0:-1], mask[:, 0:-1,1: ])
00395 mask_out[:, 0:-1,1: ] = np.logical_and(mask_out[:, 0:-1,1: ], mask[:, 1: ,0:-1])
00396 mask_out[:, 1: ,1: ] = np.logical_and(mask_out[:, 1: ,1: ], mask[:, 0:-1,0:-1])
00397
00398 mask_out.shape = mask.shape = shape_in
00399
00400 return mask_out
00401
00402
00403
00404 def mask_edges(mask, mrows=1, mcols=1, dtype=np.uint8) :
00405 """Return mask with a requested number of row and column pixels masked - set to 0.
00406 mask : int - n-dimensional (n>1) array with input mask
00407 mrows : int - number of edge rows to mask
00408 mcols : int - number of edge columns to mask
00409 """
00410 sh = mask.shape
00411 if len(sh) < 2 :
00412 raise ValueError('Input mask has less then 2-d, shape = %s' % str(sh))
00413
00414 mask_out = np.asarray(mask, dtype)
00415
00416
00417
00418 if len(sh) == 2 :
00419 rows, cols = sh
00420
00421 if mrows > rows :
00422 raise ValueError('Requested number of edge rows=%d to mask exceeds 2-d, shape=%s' % (mrows, str(sh)))
00423
00424 if mcols > cols :
00425 raise ValueError('Requested number of edge columns=%d to mask exceeds 2-d, shape=%s' % (mcols, str(sh)))
00426
00427 if mrows>0 :
00428
00429 mask_rows = np.zeros((mrows,cols), dtype=mask.dtype)
00430 mask_out[:mrows ,:] = mask_rows
00431 mask_out[-mrows:,:] = mask_rows
00432
00433 if mcols>0 :
00434
00435 mask_cols = np.zeros((rows,mcols), dtype=mask.dtype)
00436 mask_out[:,:mcols ] = mask_cols
00437 mask_out[:,-mcols:] = mask_cols
00438
00439 else :
00440 mask_out.shape = shape_nda_to_3d(mask)
00441
00442 segs, rows, cols = mask_out.shape
00443
00444 if mrows > rows :
00445 raise ValueError('Requested number of edge rows=%d to mask exceeds 2-d, shape=%s' % (mrows, str(sh)))
00446
00447 if mcols > cols :
00448 raise ValueError('Requested number of edge columns=%d to mask exceeds 2-d, shape=%s' % (mcols, str(sh)))
00449
00450 if mrows>0 :
00451
00452 mask_rows = np.zeros((segs,mrows,cols), dtype=mask.dtype)
00453 mask_out[:, :mrows ,:] = mask_rows
00454 mask_out[:, -mrows:,:] = mask_rows
00455
00456 if mcols>0 :
00457
00458 mask_cols = np.zeros((segs,rows,mcols), dtype=mask.dtype)
00459 mask_out[:, :,:mcols ] = mask_cols
00460 mask_out[:, :,-mcols:] = mask_cols
00461
00462 mask_out.shape = sh
00463
00464 return mask_out
00465
00466
00467
00468 def str_tstamp(fmt='%Y-%m-%dT%H:%M:%S', time_sec=None) :
00469 """Returns string timestamp for specified format and time in sec or current time by default
00470 """
00471 return strftime(fmt, localtime(time_sec))
00472
00473
00474
00475 def get_enviroment(env='USER') :
00476 """Returns the value of specified by string name environment variable
00477 """
00478 return os.environ[env]
00479
00480
00481
00482 def get_login() :
00483 """Returns login name
00484 """
00485
00486 return getpass.getuser()
00487
00488
00489
00490 def get_hostname() :
00491 """Returns login name
00492 """
00493
00494 return socket.gethostname()
00495
00496
00497
00498 def get_cwd() :
00499 """Returns current working directory
00500 """
00501 return os.getcwd()
00502
00503
00504
00505 def create_directory(dir, verb=False) :
00506 if os.path.exists(dir) :
00507 if verb : print 'Directory exists: %s' % dir
00508 else :
00509 os.makedirs(dir)
00510 if verb : print 'Directory created: %s' % dir
00511
00512
00513
00514 def save_textfile(text, path, mode='w') :
00515 """Saves text in file specified by path. mode: 'w'-write, 'a'-append
00516 """
00517 f=open(path, mode)
00518 f.write(text)
00519 f.close()
00520
00521
00522
00523 def load_textfile(path) :
00524 """Returns text file as a str object
00525 """
00526 f=open(path, 'r')
00527 recs = f.read()
00528 f.close()
00529 return recs
00530
00531
00532
00533 def calib_dir(env) :
00534 cdir = env.calibDir()
00535
00536
00537 if os.path.exists(cdir) :
00538 return cdir
00539
00540
00541
00542 def exp_name(env) :
00543 exp = env.experiment()
00544 if exp=='' : return None
00545 return exp
00546
00547
00548
00549 def alias_for_src_name(env) :
00550 ckeys = env.configStore().keys()
00551 srcs = [k.src() for k in ckeys]
00552 alias = [k.alias() for k in ckeys]
00553 d = dict(zip(srcs, alias))
00554 for s,a in d.items() : print 'src: %40s alias: %s' % (s, a)
00555
00556
00557
00558
00559
00560
00561
00562 def test_mask_neighbors_2d(allnbrs=True) :
00563 from pyimgalgos.NDArrGenerators import random_exponential
00564 import pyimgalgos.Graphics as gr
00565
00566 randexp = random_exponential(shape=(40,60), a0=1)
00567 fig = gr.figure(figsize=(16,6), title='Random 2-d mask')
00568 axim1 = gr.add_axes(fig, axwin=(0.05, 0.05, 0.40, 0.91))
00569 axcb1 = gr.add_axes(fig, axwin=(0.452, 0.05, 0.01, 0.91))
00570
00571 axim2 = gr.add_axes(fig, axwin=(0.55, 0.05, 0.40, 0.91))
00572 axcb2 = gr.add_axes(fig, axwin=(0.952, 0.05, 0.01, 0.91))
00573
00574 mask = np.select((randexp>6,), (0,), default=1)
00575 mask_nbrs = mask_neighbors(mask, allnbrs)
00576 img1 = mask
00577 img2 = mask_nbrs
00578
00579 imsh1, cbar1 = gr.imshow_cbar(fig, axim1, axcb1, img1, amin=0, amax=10, orientation='vertical')
00580 imsh2, cbar2 = gr.imshow_cbar(fig, axim2, axcb2, img2, amin=0, amax=10, orientation='vertical')
00581 gr.show(mode=None)
00582
00583
00584
00585 def test_mask_neighbors_3d(allnbrs=True) :
00586 from pyimgalgos.NDArrGenerators import random_exponential
00587 import pyimgalgos.Graphics as gr
00588
00589
00590 randexp = random_exponential(shape=(2,30,80), a0=1)
00591
00592 fig = gr.figure(figsize=(16,6), title='Random > 2-d mask')
00593 axim1 = gr.add_axes(fig, axwin=(0.05, 0.05, 0.40, 0.91))
00594 axcb1 = gr.add_axes(fig, axwin=(0.452, 0.05, 0.01, 0.91))
00595
00596 axim2 = gr.add_axes(fig, axwin=(0.55, 0.05, 0.40, 0.91))
00597 axcb2 = gr.add_axes(fig, axwin=(0.952, 0.05, 0.01, 0.91))
00598
00599 mask = np.select((randexp>6,), (0,), default=1)
00600 mask_nbrs = mask_neighbors(mask, allnbrs)
00601
00602 img1 = reshape_nda_to_2d(mask)
00603 img2 = reshape_nda_to_2d(mask_nbrs)
00604
00605 imsh1, cbar1 = gr.imshow_cbar(fig, axim1, axcb1, img1, amin=0, amax=10, orientation='vertical')
00606 imsh2, cbar2 = gr.imshow_cbar(fig, axim2, axcb2, img2, amin=0, amax=10, orientation='vertical')
00607 gr.show(mode=None)
00608
00609
00610
00611 def test_mask_edges_2d(mrows=1, mcols=1) :
00612 from pyimgalgos.NDArrGenerators import random_exponential
00613 import pyimgalgos.Graphics as gr
00614
00615 fig = gr.figure(figsize=(8,6), title='Mask edges 2-d')
00616 axim1 = gr.add_axes(fig, axwin=(0.05, 0.05, 0.87, 0.91))
00617 axcb1 = gr.add_axes(fig, axwin=(0.922, 0.05, 0.01, 0.91))
00618
00619 mask = np.ones((20,30))
00620 mask_out = mask_edges(mask, mrows, mcols)
00621
00622 img1 = mask_out
00623 imsh1, cbar1 = gr.imshow_cbar(fig, axim1, axcb1, img1, amin=0, amax=10, orientation='vertical')
00624 gr.show(mode=None)
00625
00626
00627
00628 def test_mask_edges_3d(mrows=1, mcols=1) :
00629 from pyimgalgos.NDArrGenerators import random_exponential
00630 import pyimgalgos.Graphics as gr
00631
00632 fig = gr.figure(figsize=(8,6), title='Mask edges 2-d')
00633 axim1 = gr.add_axes(fig, axwin=(0.05, 0.05, 0.87, 0.91))
00634 axcb1 = gr.add_axes(fig, axwin=(0.922, 0.05, 0.01, 0.91))
00635
00636
00637 mask = np.ones((2,20,30))
00638 mask_out = mask_edges(mask, mrows, mcols)
00639
00640 img1 = reshape_nda_to_2d(mask_out)
00641 imsh1, cbar1 = gr.imshow_cbar(fig, axim1, axcb1, img1, amin=0, amax=10, orientation='vertical')
00642 gr.show(mode=None)
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658 def do_test() :
00659
00660 print 'get_enviroment(USER) : %s' % get_enviroment()
00661 print 'get_login() : %s' % get_login()
00662 print 'get_hostname() : %s' % get_hostname()
00663 print 'get_cwd() : %s' % get_cwd()
00664
00665
00666 if len(sys.argv) > 1 :
00667
00668 if sys.argv[1] == '1' : test_mask_neighbors_2d(allnbrs = False)
00669 if sys.argv[1] == '2' : test_mask_neighbors_2d(allnbrs = True)
00670 if sys.argv[1] == '3' : test_mask_neighbors_3d(allnbrs = False)
00671 if sys.argv[1] == '4' : test_mask_neighbors_3d(allnbrs = True)
00672 if sys.argv[1] == '5' : test_mask_edges_2d(mrows=5, mcols=1)
00673 if sys.argv[1] == '6' : test_mask_edges_2d(mrows=0, mcols=5)
00674 if sys.argv[1] == '7' : test_mask_edges_3d(mrows=1, mcols=2)
00675 if sys.argv[1] == '8' : test_mask_edges_3d(mrows=5, mcols=0)
00676
00677
00678
00679 if __name__ == "__main__" :
00680 do_test()
00681
00682