Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatasks/private/task_importvla.py: 13%
53 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
3from casatools import vlafiller, ms, agentflagger, table
4from casatasks import casalog
5from .mstools import write_history
7_ms = ms( )
8_filler = vlafiller( )
10def importvla(archivefiles,vis,bandname,frequencytol,project,starttime,
11 stoptime,applytsys,autocorr,antnamescheme,keepblanks,evlabands):
12 i=0
13 overwrite=True
14 ok = True
15 try:
16 casalog.origin('importvla')
17 if ((type(vis)!=str) | (vis=='') | (os.path.exists(vis))):
18 raise ValueError('Need valid visibility file name (bad name or already exists)')
19 if (os.path.exists(vis)):
20 raise ValueError('Visibility file already exists - remove or rename')
21 for archivefile in archivefiles:
22 if i>0: overwrite=False
23 if ((type(archivefile)==str) & (os.path.exists(archivefile))):
24 _filler.fill( msname=vis,inputfile=archivefile,overwrite=overwrite,
25 bandname=bandname,freqtol=frequencytol,project=project,
26 start=starttime,stop=stoptime,applytsys=applytsys,
27 keepautocorr=autocorr,antnamescheme=antnamescheme,
28 keepblanks=keepblanks,evlabands=evlabands )
29 i += 1
30 else:
31 raise ValueError('Archive file not found - please verify the name')
32 except Exception as exc:
33 msg = "*** Error importing %s to %s: %s" % (archivefiles, vis, exc)
34 raise RuntimeError(msg)
36 nrows = 0
37 try:
38 _tb = table()
39 ok &=_tb.open(vis)
40 nrows = _tb.nrows()
41 _tb.done()
42 except Exception:
43 msg = "*** Error checking size of visibility file %s: %s" % (vis,instance)
44 raise RuntimeError(msg)
46 if nrows == 0:
47 msg = "*** visibility file is empty: %s" % vis
48 raise Exception(msg)
50 # Write history
51 try:
52 param_names = importvla.__code__.co_varnames[:importvla.__code__.co_argcount]
53 vars = locals( )
54 param_vals = [vars[p] for p in param_names]
56 ok &= write_history(_ms, vis, 'importvla', param_names,param_vals, casalog)
57 except Exception as instance:
58 casalog.post("*** Error \'%s\' updating HISTORY" % instance, 'WARN')
60 # write initial flag version
61 if ok:
62 try:
63 _af = agentflagger()
64 ok &= _af.open(vis);
65 ok &= _af.saveflagversion('Original', comment='Original flags at import into CASA', merge='replace')
66 ok &= _af.done();
67 except Exception:
68 msg = "*** Error writing initial flag version of %s: %s" % (vis, instance)
69 raise RuntimeError(msg)