Exemple #1
0
def test_various():
    a = 'a'
    args = argparse.Namespace(a='def_test', unittesting='')
    x = cm_utils.query_default(a, args)
    assert x == 'def_test'
    args = argparse.Namespace(a='def_test', unittesting='none')
    x = cm_utils.query_default(a, args)
    assert x is None
    args = argparse.Namespace(a='def_test', unittesting='false')
    x = cm_utils.query_default(a, args)
    assert not x
    args = argparse.Namespace(a='def_test', unittesting='true')
    x = cm_utils.query_default(a, args)
    assert x
    args = argparse.Namespace(a='def_test', unittesting='unittest')
    x = cm_utils.query_default(a, args)
    assert x == 'unittest'
    spk = cm_utils.make_part_key(None, None)
    assert spk == cm_utils.system_wide_key
    a, b, c = cm_utils.split_part_key('a:b:c')
    assert c == 'c'
    is_active = cm_utils.is_active(None, None, None)
    assert is_active
    t_tst = cm_utils.get_astropytime('now')
    out = cm_utils.get_stopdate(t_tst)
    assert out == t_tst
    d = cm_utils.get_time_for_display(None)
    assert d == 'None'
    c = cm_utils.put_keys_in_order(['1:A:Z', '2:B:X'], 'RPN')
    assert c[0] == '1:A:Z'
Exemple #2
0
def add_entry_to_parts(session, args):
    # NotNull
    hpn = args.station_name
    rev = 'A'
    dt = cm_utils.get_astropytime(args.date, args.time)
    data = [[hpn, rev, 'hpn', hpn], [hpn, rev, 'hpn_rev', rev],
            [hpn, rev, 'hptype', 'station'],
            [hpn, rev, 'manufacturer_number', args.sernum],
            [hpn, rev, 'start_gpstime', dt.gps]]
    cm_partconnect.update_part(session, data)
Exemple #3
0
def test_datetime():
    from astropy.time import Time
    sys.argv = ['test']
    p = argparse.ArgumentParser()
    cm_utils.add_date_time_args(p)
    args = p.parse_args()
    assert args.date == 'now'
    assert args.time == 0.0
    import datetime
    tout = cm_utils.get_astropytime(datetime.datetime.now())
    assert type(tout) == Time
    tout = cm_utils.get_astropytime(2400001.0)
    assert type(tout) == Time
    pytest.raises(ValueError, cm_utils.get_astropytime, 0.0)
    tout = cm_utils.get_astropytime('none')
    assert tout is None
    tout = cm_utils.get_astropytime('2018/1/1', '0.0')
    assert type(tout) == Time
    pytest.raises(ValueError, cm_utils.get_astropytime, '18/1/1')
    tout = cm_utils.get_astropytime('2018/1/1', '12:30:00')
    assert type(tout) == Time
    pytest.raises(ValueError, cm_utils.get_astropytime, '2018/1/1', '0:0:0:0')
    pytest.raises(ValueError, cm_utils.get_astropytime, '2018/1/1', 'x')
Exemple #4
0
def add_entry_to_geo_location(session, args):
    # NotNull
    sname = args.station_name
    dt = cm_utils.get_astropytime(args.date, args.time)
    data = [[sname, 'station_name', sname],
            [sname, 'station_type_name', args.station_type_name],
            [sname, 'created_gpstime', dt.gps]]
    # Other
    if args.datum:
        data.append([sname, 'datum', args.datum])
    if args.tile:
        data.append([sname, 'tile', args.tile])
    if args.northing:
        data.append([sname, 'northing', args.northing])
    if args.easting:
        data.append([sname, 'easting', args.easting])
    if args.elevation:
        data.append([sname, 'elevation', args.elevation])
    geo_location.update(session, data, args.add_new_geo)
Exemple #5
0
                        '--query',
                        help="Set flag if wished to be queried",
                        action='store_true')
    cm_utils.add_date_time_args(parser)
    parser.add_argument('--date2',
                        help="Stop date (if not None)",
                        default=None)
    parser.add_argument('--time2',
                        help="Stop time (if not None)",
                        default=None)
    parser.add_argument('--verbose',
                        help="Turn verbose mode on.",
                        action='store_true')
    args = parser.parse_args()

    if args.query:
        args = query_args(args)

    # Pre-process some args
    start_date = cm_utils.get_astropytime(args.date, args.time)
    stop_date = cm_utils.get_astropytime(args.date2, args.time2)

    db = mc.connect_to_mc_db(args)
    session = db.sessionmaker()

    # Check for part
    if args.verbose:
        print("Adding part_rosetta {}: - {}".format(args.hpn, args.syspn))
    cm_partconnect.update_part_rosetta(args.hpn, args.syspn, start_date,
                                       stop_date, session)
Exemple #6
0
                        choices=['name', 'num', 'ser', 'none'],
                        default='num',
                        help="Label by station_name (name), ant_num (num) "
                        "serial_num (ser) or none (none) (num)")
    parser.add_argument('--hookup-type',
                        dest='hookup_type',
                        help="Hookup type to use for active antennas.",
                        default=None)
    args = parser.parse_args()
    if len(args.fg_action) > 1:
        position = cm_utils.listify(args.fg_action[1])
    args.fg_action = args.fg_action[0].lower()
    args.background = args.background.lower()
    args.station_types = args.station_types.lower()
    args.label = args.label.lower()
    at_date = cm_utils.get_astropytime(args.date, args.time)
    if args.station_types not in ['default', 'all']:
        args.station_types = cm_utils.listify(args.station_types)
    if args.label == 'false' or args.label == 'none':
        args.label = False
    xgraph = args.xgraph.upper()
    ygraph = args.ygraph.upper()
    if args.fg_action.startswith('s'):
        cutoff = at_date
        at_date = cm_utils.get_astropytime('now')

    # start session and instances
    db = mc.connect_to_mc_db(args)
    session = db.sessionmaker()
    G = geo_handling.Handling(session)
Exemple #7
0
"""
from astropy.time import Time
import warnings

from hera_mc import mc, cm_utils

if __name__ == '__main__':
    parser = mc.get_mc_argument_parser()
    parser.add_argument('-g',
                        '--gps',
                        help="Convert from gps seconds to time.",
                        default=None)
    cm_utils.add_date_time_args(parser)
    args = parser.parse_args()

warn_msg = "mc_gps.py is deprecated in favor of mc_clock.py "\
           "- mc_gps.py will be retained until January 2021"
warnings.warn(warn_msg, DeprecationWarning)

if args.gps is None:
    Time_object = cm_utils.get_astropytime(args.date, args.time)
    print("\n\tThe supplied date was  {}".format(str(Time_object)))
    print("\t...corresponding gps is  {}\n".format(Time_object.gps))
    print("\tThe Julian Date is {}\n".format(Time_object.jd))
else:
    Time_object = Time(int(args.gps), format='gps')
    print("\n\tThe supplied gps second was {}".format(args.gps))
    print("\t...corresponding Time is {}".format(str(Time_object.isot)))
    print("\tThe Julian Date is {}\n".format(Time_object.jd))
Exemple #8
0
def test_datetime(parts):
    dt = cm_utils.get_astropytime('2017-01-01', 0.0)
    gps_direct = int(Time('2017-01-01 00:00:00', scale='utc').gps)
    assert int(dt.gps) == gps_direct
    parser.add_argument('-l',
                        '--last-period',
                        dest='last_period',
                        default=None,
                        help="Time period from present for data (in minutes). "
                        "If present ignores start/stop.")

    args = parser.parse_args()

    if args.last_period:
        stop_time = Time.now()
        start_time = (
            stop_time -
            TimeDelta(float(args.last_period) / (60.0 * 24.0), format='jd'))
    else:
        start_time = cm_utils.get_astropytime(args.start_date, args.start_time)
        stop_time = cm_utils.get_astropytime(args.stop_date, args.stop_time)

    db = mc.connect_to_mc_db(args)
    session = db.sessionmaker()

    relevant_arg_name = valid_tables[args.table]['arg_name']
    for arg in list_of_filter_args:
        if getattr(args, arg) is not None and arg != relevant_arg_name:
            print('{arg} is specified but does not apply to table {table}, '
                  'so it will be ignored.'.format(arg=arg, table=args.table))

    method_kwargs = {
        'starttime':
        start_time,
        'stoptime':
Exemple #10
0
                    action='store_true')
parser.add_argument('--ports', help="Include only these ports, csv list",
                    default=None)
cm_utils.add_verbosity_args(parser)
cm_utils.add_date_time_args(parser)
parser.add_argument('--notes-start-date', dest='notes_start_date',
                    help="<For notes> start_date for notes [<]",
                    default='<')
parser.add_argument('--notes-start-time', dest='notes_start_time',
                    help="<For notes> start_time for notes",
                    default=0.0)
args = parser.parse_args()

args.verbosity = cm_utils.parse_verbosity(args.verbosity)
view = all_views[args.view[0].lower()]
date_query = cm_utils.get_astropytime(args.date, args.time)
notes_start_date = cm_utils.get_astropytime(args.notes_start_date,
                                            args.notes_start_time)

# Start session
db = mc.connect_to_mc_db(args)
session = db.sessionmaker()

if args.list_columns:
    if view == 'revisions':
        from hera_mc import cm_revisions
        print("Use 'present'/'all' or any/all of:")
        print(','.join(cm_revisions.ordered_columns))
    else:
        from hera_mc import cm_dossier
        blank = cm_dossier.PartEntry(None, None)