-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaddsubtable.py
More file actions
executable file
·50 lines (38 loc) · 1.71 KB
/
Copy pathaddsubtable.py
File metadata and controls
executable file
·50 lines (38 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import casacore.tables as pt
from os import path
import sys
from shutil import copytree
import argparse
def addsubtable(msfile, subtablefile, name=None, dry_run=False):
"""Adds an existing table as a subtable to another table
The subtable is copied into the MS if it is not a subdirectory already"""
subtablename = path.basename(subtablefile.rstrip("/"))
if path.commonpath([msfile, subtablefile]) != path.commonpath([msfile]):
print(f"Copying {subtablefile} into {path.join(msfile, subtablename)}")
if not dry_run:
copytree(subtablefile, path.join(msfile, subtablename))
subtablefile = path.join(msfile, subtablename)
t = pt.table(msfile, readonly=False, ack=False)
sub = pt.table(subtablefile, ack=False)
if not dry_run:
t.putkeyword(subtablename, sub, makesubrecord=True)
else:
print(f"Would make {subtablename} a subtable of {msfile}")
sub.close()
if name is not None:
if dry_run:
print(f"Would set TELESCOPE_NAME={name} in {msfile}::OBSERVATION")
else:
pt.taql(f"UPDATE $t::OBSERVATION SET TELESCOPE_NAME='{name}'")
t.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Copy an existing table (e.g. PHASED_ARRAY) to another table as a subtable"
)
parser.add_argument("ms", help="Master measurement set")
parser.add_argument("subtable", help="Subtable to add")
parser.add_argument("-n", "--dry-run", help="Dry run", action="store_true")
parser.add_argument("--name", help="Set telescope name", type=str)
args = parser.parse_args()
addsubtable(args.ms, args.subtable, dry_run=args.dry_run, name=args.name)