Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_partition.py: 24%
46 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 19:53 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-31 19:53 +0000
1import os
2import shutil
3import string
4import copy
5import math
7from casatasks import casalog
8from casatools import ms, mstransformer
9from .parallel.parallel_data_helper import ParallelDataHelper
10from . import flaghelper as fh
11from .mstools import write_history
13def partition(vis,
14 outputvis,
15 createmms,
16 separationaxis,
17 numsubms,
18 flagbackup, # only for MMS
19 datacolumn,
20 field,
21 spw,
22 scan,
23 antenna,
24 correlation,
25 timerange,
26 intent,
27 array,
28 uvrange,
29 observation,
30 feed,
31 disableparallel, # HIDDEN parameter to create an MMS in sequential
32 ddistart, # HIDDEN parameter to be used when merging sub-tables
33 taql # HIDDEN parameter to be used for balanced partition schema
35 ):
36 """Create a multi visibility set from an existing visibility set:
38 Keyword arguments:
39 vis -- Name of input visibility file (MS)
40 default: none; example: vis='ngc5921.ms'
41 outputvis -- Name of output visibility file (MS)
42 default: none; example: outputvis='ngc5921_src.ms'
43 createmms -- Boolean flag if we're creating Multi MS
44 default: True
45 separationaxis -- what axis do we intend to split on.
46 default = 'auto'
47 Options: 'scan','spw','auto'
48 numsubms -- Number of sub-MSs to create.
49 default: 'auto'
50 flagbackup -- Backup the FLAG column of the output MMS
51 default: True
53 datacolumn -- Which data column to use to create the output
54 default='data'; example: datacolumn='data'
55 Options: 'data', 'corrected', 'model', 'all',
56 'float_data', 'lag_data', 'float_data,data', and
57 'lag_data,data'.
58 note: 'all' = whichever of the above that are present.
59 field -- Field name
60 default: field = '' means use all sources
61 field = 1 # will get field_id=1 (if you give it an
62 integer, it will retrieve the source with that index)
63 field = '1328+307' specifies source '1328+307'.
64 Minimum match can be used, egs field = '13*' will
65 retrieve '1328+307' if it is unique or exists.
66 Source names with imbedded blanks cannot be included.
67 spw -- Spectral window index identifier
68 default=-1 (all); example: spw=1
69 antenna -- antenna names
70 default '' (all),
71 antenna = '3 & 7' gives one baseline with antennaid = 3,7.
72 timerange -- Time range
73 default='' means all times. examples:
74 timerange = 'YYYY/MM/DD/hh:mm:ss~YYYY/MM/DD/hh:mm:ss'
75 timerange='< YYYY/MM/DD/HH:MM:SS.sss'
76 timerange='> YYYY/MM/DD/HH:MM:SS.sss'
77 timerange='< ddd/HH:MM:SS.sss'
78 timerange='> ddd/HH:MM:SS.sss'
79 scan -- Scan numbers to select.
80 default '' (all).
81 intent -- Select based on the scan intent.
82 default '' (all)
83 array -- (Sub)array IDs to select.
84 default '' (all).
85 uvrange -- uv distance range to select.
86 default '' (all).
87 observation -- observation ID(s) to select.
88 default '' (all).
89 """
91 casalog.origin('partition')
93 # Initiate the helper class
94 pdh = ParallelDataHelper('partition', locals())
96 # Validate input and output parameters
97 pdh.setupIO()
99 if createmms:
101 if disableparallel:
102 pdh.bypassParallelProcessing(1)
103 else:
104 pdh.bypassParallelProcessing(0)
106 # Get a cluster
107 pdh.setupCluster(thistask='partition')
109 # Execute the jobs using cluster
110 pdh.go()
111 pdh.bypassParallelProcessing(0)
113 # Create a backup of the flags that are in the MMS
114 casalog.origin('partition')
115 if flagbackup and os.path.exists(outputvis):
116 casalog.post('Create a backup of the flags that are in the MMS')
117 fh.backupFlags(aflocal=None, msfile=outputvis, prename='partition')
119 # Write history to output MS, not the input ms.
120 try:
121 param_names = partition.__code__.co_varnames[:partition.__code__.co_argcount]
122 local_vars = locals( )
123 param_vals = [local_vars[p] for p in param_names]
125 casalog.post('Updating the history in the output', 'DEBUG1')
126 write_history(ms(), outputvis, 'partition', param_names,
127 param_vals, casalog)
128 except Exception as instance:
129 casalog.post("*** Error \'%s\' updating HISTORY" % (instance),
130 'WARN')
132 return
135 try:
136 mtlocal = mstransformer()
138 # Gather all the parameters in a dictionary.
139 config = {}
140 config = pdh.setupParameters(inputms=vis, outputms=outputvis, field=field,
141 spw=spw, array=array, scan=scan, antenna=antenna, correlation=correlation,
142 uvrange=uvrange,timerange=timerange, intent=intent, observation=str(observation),
143 feed=feed,taql=taql)
145 # ddistart will be used in the tool when re-indexing the spw table
146 config['ddistart'] = ddistart
148 config['datacolumn'] = datacolumn
150 # Configure the tool and all the parameters
152 casalog.post('%s'%config, 'DEBUG1')
153 mtlocal.config(config)
155 # Open the MS, select the data and configure the output
156 mtlocal.open()
158 # Run the tool
159 casalog.post('Run the tool to partition the MS')
160 mtlocal.run()
162 finally:
163 mtlocal.done()