def get_times(msname, solint, startrow, nrow, qrest): query2 = 'SELECT DISTINCT INTERVAL FROM {} where {}'.format( msname, qrest) dts = tb.taql(query2).getcol('INTERVAL') # casalog.post("{}".format(dts), "DEBUG") [dt] = dts # equivalent to asserting that there is one element. nrow = int(solint / dt) q1 = 'SELECT DISTINCT TIME FROM ' + msname + ' where ' + qrest casalog.post("Query {}".format(q1), "DEBUG") times_t = tb.taql(q1) casalog.post("Distinct times {}".format(times_t.nrows()), "DEBUG") times = times_t.getcol('TIME', startrow=startrow, nrow=nrow) return times
def get_global_times(msname, qrest, solint, startrow=0): tb.open(msname) query2 = 'SELECT DISTINCT INTERVAL FROM {} WHERE {}'.format( msname, qrest) dts = tb.taql(query2).getcol('INTERVAL') # casalog.post("{}".format(dts), "DEBUG") [dt] = dts # equivalent to asserting that there is one element. nrow = int(solint / dt) q1 = 'SELECT DISTINCT TIME FROM {} WHERE {}'.format(msname, qrest) times_t = tb.taql(q1) casalog.post("Query {}".format(q1), "DEBUG") casalog.post("Distinct times {}".format(times_t.nrows()), "DEBUG") times = times_t.getcol('TIME', startrow=startrow, nrow=nrow) (n_times, ) = times.shape return times, n_times, nrow, dt
def another_min_max_time(msname, timeq): tb.open(msname) t = tb.taql( "select TIME as t0, TIME+INTERVAL as t1 from {} where {}".format( msname, timeq)) tmin = min(t.getcol('t0')) tmax = max(t.getcol('t1')) return tmin, tmax
def distinct_thing(msname, query, colname): tb.open(msname) q = "select distinct {} from {} where {}".format(colname, msname, query) r = list(tb.taql(q).getcol(colname)) try: assert len(r) == 1 except: raise AssertionError("Query {} gives non-unique result ({})".format( q, r)) return r[0]
def actual_antennas(msname, timeq): tb.open(msname) table2 = tb.taql("select TIME, ANTENNA1, ANTENNA2" " from {} where ".format(msname) + timeq) d = {} for a in table2.getcol('ANTENNA1'): d.__setitem__(a, d.get(a, 0) + 1) for a in table2.getcol('ANTENNA2'): d.__setitem__(a, d.get(a, 0) + 1) return d
def checkwithtaql(taqlstring): os.system('rm -rf mynewtable.tab') tb.create('mynewtable.tab') tb.open('mynewtable.tab', nomodify=False) rval = tb.taql(taqlstring) tb.close() therval = rval.nrows() tmpname = rval.name() rval.close() os.system('rm -rf mynewtable.tab') os.system('rm -rf ' + tmpname) print "Found ", therval, " rows in selection." return therval
def checkwithtaql(taqlstring): os.system('rm -rf mynewtable.tab') tb.create('mynewtable.tab') tb.open('mynewtable.tab',nomodify=False) rval = tb.taql(taqlstring) tb.close() therval = rval.nrows() tmpname = rval.name() rval.close() os.system('rm -rf mynewtable.tab') os.system('rm -rf '+tmpname) print "Found ", therval, " rows in selection." return therval
def actual_min_max_times(msname, timeq): tb.open(msname) table2 = tb.taql( "select TIME, TIME+INTERVAL as T1, ANTENNA1, ANTENNA2 from {} where {}" .format(msname, timeq)) ant_time_map = dict() for (t, a) in zip(table2.getcol('TIME'), table2.getcol('ANTENNA1')): ant_time_map.setdefault(a, set()).add(t) for (t, a) in zip(table2.getcol('TIME'), table2.getcol('ANTENNA2')): ant_time_map.setdefault(a, set()).add(t) casalog.post( "Antennas available {}".format( utils.list_of_numbers_to_s(ant_time_map.keys())), "INFO") times_for_all_antennas = reduce(operator.and_, ant_time_map.values()) return min(times_for_all_antennas), max(times_for_all_antennas)
def actual_timerangeq(msname, timeq): tb.open(msname) table2 = tb.taql("select TIME, ANTENNA1, ANTENNA2 from {} where {}".format( msname, timeq)) ant_time_map = dict() for (t, a) in zip(table2.getcol('TIME'), table2.getcol('ANTENNA1')): ant_time_map.setdefault(a, set()).add(t) for (t, a) in zip(table2.getcol('TIME'), table2.getcol('ANTENNA2')): ant_time_map.setdefault(a, set()).add(t) casalog.post( "Antennas available {}".format( utils.list_of_numbers_to_s(ant_time_map.keys())), "INFO") times_for_all_antennas = reduce(operator.and_, ant_time_map.values()) # casalog.post("[ffd.actual_timerangeq] Times: {} {}".format( # len(times_for_all_antennas), sorted(times_for_all_antennas)), "DEBUG") query = "TIME > {} and TIME < {}".format(min(times_for_all_antennas), max(times_for_all_antennas)) # print >>sys.stderr, "Adjusting time query from {} to {}".format(timeq, query) return query