Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_impv.py: 90%

39 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-01 07:19 +0000

1import sys 

2 

3from casatools import image 

4from casatasks import casalog 

5from .ialib import write_image_history 

6 

7def impv( 

8 imagename, outfile, mode, start, end, center, length, pa, width, 

9 unit, overwrite, region, chans, stokes, mask, stretch 

10): 

11 casalog.origin('impv') 

12 try: 

13 if len(outfile) == 0: 

14 raise Exception("outfile must be specified.") 

15 mymode = mode.lower() 

16 if mymode.startswith('c'): 

17 if len(start) == 0 or len(end) == 0: 

18 raise ValueError("When mode='coords', start and end must both be specified.") 

19 center = "" 

20 length = "" 

21 pa = "" 

22 elif mymode.startswith('l'): 

23 if ( 

24 len(center) == 0 

25 or ( 

26 not isinstance(length, (int, float)) 

27 and len(length) == 0 

28 ) 

29 or len(pa) == 0 

30 ): 

31 raise ValueError("When mode='length', center, length, and pa must all be specified.") 

32 start = "" 

33 end = "" 

34 else: 

35 raise ValueError("Unsupported value for mode.") 

36 myia = image() 

37 outia = None 

38 myia.dohistory(False) 

39 if (not myia.open(imagename)): 

40 raise RuntimeError("Cannot create image analysis tool using %s" % imagename) 

41 outia = myia.pv( 

42 outfile=outfile, start=start, end=end, center=center, 

43 length=length, pa=pa, width=width, unit=unit, 

44 overwrite=overwrite, region=region, chans=chans, 

45 stokes=stokes, mask=mask, stretch=stretch, wantreturn=True 

46 ) 

47 

48 try: 

49 param_names = impv.__code__.co_varnames[:impv.__code__.co_argcount] 

50 vars = locals( ) 

51 param_vals = [vars[p] for p in param_names] 

52 

53 write_image_history( 

54 outia, sys._getframe().f_code.co_name, 

55 param_names, param_vals, casalog 

56 ) 

57 except Exception as instance: 

58 casalog.post("*** Error \'%s\' updating HISTORY" % (instance), 'WARN') 

59 

60 finally: 

61 if (myia): 

62 myia.done() 

63 if (outia): 

64 outia.done()