File: create_casacore_table.py

package info (click to toggle)
casacore-data-lines 0%2Bgit2016.11.26-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 72 kB
  • sloc: python: 61; sh: 31; makefile: 4
file content (72 lines) | stat: -rwxr-xr-x 2,559 bytes parent folder | download | duplicates (3)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3

import argparse
import datetime
import dateutil.parser
import json

from casacore import tables
 
default_version = "1.1"
default_date = "2016-11-26T13:26"

default_input = "lines.json"
default_path = "Lines"

parser = argparse.ArgumentParser(
    usage = 'casacore-update-lines [options]',
    description = 'Update casacore Observatory table from json input')
parser.add_argument('-i', '--input-file',
                    help='JSON oinput file (default: {})'
                    .format(default_input),
                    default=default_input)
parser.add_argument('-o', '--output-path',
                    help='output table path (default: {})'
                    .format(default_path),
                    default=default_path)
parser.add_argument('-v', '--version',
                    help='Set version number in table (default: {})'
                    .format(default_version),
                    default=default_version)
parser.add_argument('-d', '--date',
                    help='Set version date in database (default: {})'
                    .format(default_date),
                    default=default_date)
args = parser.parse_args()

with open(args.input_file) as f:
    linestable = json.load(f)

# Create data table
columns = [
    tables.makescacoldesc('MJD', 0., valuetype='double',
                          keywords={'UNIT':'d'}),
    tables.makescacoldesc('Name', '', valuetype='string'),
    tables.makescacoldesc('Type', '', valuetype='string'),
    tables.makescacoldesc('Freq', 0., valuetype='double',
                          keywords={'UNIT':'GHz'}),
    tables.makescacoldesc('Source', '', valuetype='string'),
    tables.makescacoldesc('Comment', '', valuetype='string'),
]

with tables.table('Lines', tables.tablecreatedesc(columns), len(linestable)) as tbl:
    tbl.putinfo({'type': 'IERS', 'subType': 'lines'})
    tbl.putkeywords({
        'MJD0': 0,
        'dMJD': 0.0,
        'VS_VERSION': '{:04d}.{:04d}'.format(*(int(i)
                                           for i in args.version.split('.'))),
        'VS_CREATE': dateutil.parser.parse(args.date).strftime('%Y/%m/%d/%H:%M'),
        'VS_DATE': dateutil.parser.parse(args.date).strftime('%Y/%m/%d/%H:%M'),
        'VS_TYPE': 'List of spectral line rest frequencies'
    })

    tablerows = tbl.row()
    for i, line in enumerate(linestable):
        tablerows.put(i, {
            'MJD': 0.0,
            'Name': line['name'],
            'Type': 'REST',
            'Freq': line['frequency'],
            'Source': 'WSRT'
        })