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

38 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-10-31 17:39 +0000

1import os 

2from casatools import ms, mstransformer 

3from casatasks import casalog 

4from .mstools import write_history 

5 

6 

7def uvcontsub(vis=None, outputvis=None, field=None, spw=None, 

8 scan=None, intent=None, array=None, observation=None, 

9 datacolumn=None, fitspec=None, fitmethod=None, fitorder=None, 

10 writemodel=None): 

11 

12 """Continuum subtraction in the uv plane""" 

13 

14 casalog.origin('uvcontsub') 

15 

16 casalog.post('The task uvcontsub has been updated. It does not yet support combining ' 

17 'spws for fitting. If you need this functionality please use ' 

18 'uvcontsub_old.') 

19 

20 result = {} 

21 mtlocal = mstransformer() 

22 

23 try: 

24 if not outputvis: 

25 raise ValueError('parameter outputvis: a name is required for the output MS') 

26 elif os.path.exists(outputvis): 

27 raise ValueError('Output MS ({}) already exists, refusing to overwrite it'. 

28 format(outputvis)) 

29 

30 # Set up the mstransformer config from task parameters 

31 config = {'uvcontsub': True, 

32 'inputms': vis, 

33 'outputms': outputvis, 

34 'field': field, 

35 'spw': spw, 

36 'array': array, 

37 'scan': scan, 

38 'intent': intent, 

39 'observation': observation, 

40 'datacolumn': datacolumn, 

41 'reindex': False 

42 } 

43 # Add uvcontsub-TVI config options 

44 if fitmethod == 'gsl': 

45 denoising_lib = True 

46 elif fitmethod == 'casacore': 

47 denoising_lib = False 

48 else: 

49 raise ValueError(f'Unrecognized fit method: {fitmethod}') 

50 uvcont_cfg = {'fitspec': fitspec, 

51 'denoising_lib': denoising_lib, 

52 'niter': 1, 

53 'fitorder': fitorder, 

54 'writemodel': writemodel, 

55 'want_cont': False, 

56 'nthreads': None 

57 } 

58 config['uvcontsublib'] = uvcont_cfg 

59 

60 # Configure the mstransformer tool 

61 casalog.post('mstransfom config: {}'.format(config), 'DEBUG') 

62 mtlocal.config(config) 

63 

64 # Open the MS, select the data and configure the output 

65 mtlocal.open() 

66 

67 # Run the tool 

68 casalog.post('Running continnum subtraction') 

69 mt_result = mtlocal.run() 

70 

71 finally: 

72 mtlocal.done() 

73 

74 # Write history to output MS only. Input MS is read only 

75 try: 

76 mslocal = ms() 

77 param_names = uvcontsub.__code__.co_varnames[:uvcontsub.__code__.co_argcount] 

78 loc_vars = locals() 

79 param_vals = [loc_vars[p] for p in param_names] 

80 write_history(mslocal, outputvis, 'uvcontsub', param_names, 

81 param_vals, casalog) 

82 except Exception as instance: 

83 casalog.post("*** Error \'{}\' updating HISTORY".format(instance), 'WARN') 

84 finally: 

85 mslocal.done() 

86 

87 return mt_result['uvcontsub']