def test_tableinfo(self): """Test table info.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) self.assertTrue(tableexists("ttable.py_tmp.tab1")) self.assertTrue(tableiswritable("ttable.py_tmp.tab1")) self.assertEqual(t.nrows(), 0) self.assertEqual(t.ncols(), 6) self.assertTrue(compare(t.colnames(), ['cols', 'colc', 'coli', 'cold', 'colb', 'colarr'])) self.assertEqual(tableinfo("ttable.py_tmp.tab1"), {'readme': '', 'subType': '', 'type': ''}) t.addreadmeline("test table run") t.putinfo({'type': 'test', 'subType': 'test1'}) self.assertEqual(t.info()['readme'], 'test table run\n') self.assertEqual(t.info()['subType'], 'test1') self.assertEqual(t.info()['type'], 'test') self.assertEqual(len(t), 0) print(str(t)) self.assertEqual(t.endianformat(), 'little') t.close() tabledelete("ttable.py_tmp.tab1")
def test_tableinfo(self): """Test table info.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) self.assertTrue(tableexists("ttable.py_tmp.tab1")) self.assertTrue(tableiswritable("ttable.py_tmp.tab1")) self.assertEqual(t.nrows(), 0) self.assertEqual(t.ncols(), 6) self.assertTrue( compare(t.colnames(), ['cols', 'colc', 'coli', 'cold', 'colb', 'colarr'])) self.assertEqual(tableinfo("ttable.py_tmp.tab1"), { 'readme': '', 'subType': '', 'type': '' }) t.addreadmeline("test table run") t.putinfo({'type': 'test', 'subType': 'test1'}) self.assertEqual(t.info()['readme'], 'test table run\n') self.assertEqual(t.info()['subType'], 'test1') self.assertEqual(t.info()['type'], 'test') self.assertEqual(len(t), 0) print(str(t)) self.assertEqual(t.endianformat(), 'little') t.close() tabledelete("ttable.py_tmp.tab1")
def test_hypercolumn(self): """Test hypercolumns.""" scd1 = makescacoldesc("col2", "aa") scd2 = makescacoldesc("col1", 1, "IncrementalStMan") scd3 = makescacoldesc("colrec1", {}) acd1 = makearrcoldesc("arr1", 1, 0, [2, 3, 4]) acd2 = makearrcoldesc("arr2", 0. + 0j) td = maketabdesc([scd1, scd2, scd3, acd1, acd2]) tabledefinehypercolumn(td, "TiledArray", 4, ["arr1"]) tab = table("mytable", tabledesc=td, nrow=100) tab.done() tabledelete("mytable")
def test_numpy_unicode(self): table_path = join(self.workdir, 'blah.ms') col1 = makescacoldesc('mycol1', 'test', valuetype='string') col2 = makescacoldesc('mycol2', 'test', valuetype='string') t = table(table_path, maketabdesc([col1, col2]), ack=False) t.addrows(2) t.putcol('mycol1', np.array([unicode_string, unicode_string])) t.putcol('mycol2', [unicode_string, unicode_string]) t.close() t = table(table_path) self.assertEqual(t.getcol('mycol1'), t.getcol('mycol2'))
def test_deletecols(self): """Delete some columns.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) a = ['colarr', 'cols', 'colb', 'colc'] t.removecols(a) self.assertNotIn(a, t.colnames()) t.close() tabledelete("ttable.py_tmp.tab1")
def test_subtables(self): """Testing subtables.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) sub = table("sub", maketabdesc((c1, c2, c3))) t.putkeyword("subtablename", sub, makesubrecord=True) print(t.getsubtables()) t.close() tabledelete("ttable.py_tmp.tab1")
def test_iter(self): """Testing tableiter.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) t.addrows(2) for iter_ in t.iter('coli', sort=False): print(iter_.getcol('coli'), iter_.rownumbers(t)) iter_.close() t.close() tabledelete("ttable.py_tmp.tab1")
def test_adddata(self): """Add some more data.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) t.addrows(22) for i in range(2, 22): t.putcell('coli', i, i / 2) print(t[10]) t.close() tabledelete("ttable.py_tmp.tab1")
def test_taqlcalc(self): """Some TaQL calculations.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) t.addrows(2) np.testing.assert_array_almost_equal( t.calc("(1 km)cm"), np.array([100000.])) np.testing.assert_array_equal(t.calc("coli+1"), np.array([1, 1])) t.close() tabledelete("ttable.py_tmp.tab1")
def test_taqlcalc(self): """Some TaQL calculations.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) t.addrows(2) np.testing.assert_array_almost_equal(t.calc("(1 km)cm"), np.array([100000.])) np.testing.assert_array_equal(t.calc("coli+1"), np.array([1, 1])) t.close() tabledelete("ttable.py_tmp.tab1")
def test_check_datatypes(self): """Checking datatypes.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) self.assertEqual(t.coldatatype("coli"), 'int') self.assertEqual(t.coldatatype("cold"), 'double') self.assertEqual(t.coldatatype("cols"), 'string') self.assertEqual(t.coldatatype("colb"), 'boolean') self.assertEqual(t.coldatatype("colc"), 'dcomplex') self.assertEqual(t.coldatatype("colarr"), 'double') t.close() tabledelete("ttable.py_tmp.tab1")
def test_subset(self): """Create a subset.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) t1 = t.query('coli >0', sortlist='coli desc', columns='coli,cold') querycols = t1.colnames() t1 = taql('select coli,cold from $t where coli>0 order by coli desc') taqlcol = t1.colnames() self.assertEqual(querycols, taqlcol) t1.close() t.close() tabledelete("ttable.py_tmp.tab1")
def test_tablecolumn(self): """Table column.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) t.addrows(20) with tablecolumn(t, 'coli') as tc: tc[6] += 20 self.assertEqual(tc[6], 20) self.assertIn(20, tc[18:4:-2]) self.assertEqual(tc[0:][6], 20) self.assertEqual(tc.datatype(), 'int') self.assertEqual(tc.name(), 'coli') print(tc.table()) self.assertTrue(tc.isscalar()) self.assertFalse(tc.isvar()) self.assertEqual(tc.nrows(), 20) self.assertTrue(tc.iscelldefined(2)) self.assertEqual(tc.getcell(3), 0) print(tc._) self.assertEqual(tc.getcol(2, 15)[4], 20) tc.putkeyword('key1', "keyval") self.assertIn('key1', tc.keywordnames()) self.assertIn('key1', tc.fieldnames()) self.assertEqual(tc.getdesc()['dataManagerType'], 'StandardStMan') self.assertEqual(tc.getdminfo()['TYPE'], 'StandardStMan') for iter_ in tc.iter(sort=False): print(iter_[0]['coli']) self.assertEqual(len(tc), 20) self.assertEqual(tc.getkeywords()['key1'], 'keyval') np.testing.assert_equal(tc.getvarcol()['r1'], 0) tc.putcell(2, 55) self.assertEqual(tc[2], 55) iter_.close() t.close() tabledelete("ttable.py_tmp.tab1")
def test_addcolumns(self): """Add columns.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) t.addrows(2) cd1 = makecoldesc("col2", t.getcoldesc('coli')) t.addcols(cd1) self.assertEqual(t.ncols(), 7) self.assertIn('col2', t.colnames()) t.renamecol("col2", "ncol2") self.assertNotIn('col2', t.colnames()) self.assertIn('ncol2', t.colnames()) t.close() tabledelete("ttable.py_tmp.tab1")
def test_keywords(self): """Do keyword handling.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) t.addrows(2) t.putkeyword('key1', "keyval") t.putkeyword('keyrec', {'skey1': 1, 'skey2': 3.}) self.assertTrue(t._["keyrec"]['skey1'], 1) self.assertEqual(t.getkeyword('key1'), 'keyval') self.assertIn('key1', t.keywordnames()) self.assertIn('keyrec', t.keywordnames()) key1 = t.keywordnames() key2 = t.fieldnames() self.assertEqual(key1, key2) self.assertIn('skey1', t.fieldnames('keyrec')) self.assertIn('skey2', t.fieldnames('keyrec')) t.putcolkeyword('coli', 'keycoli', {'colskey': 1, 'colskey2': 3.}) self.assertEqual(t.getcolkeywords('coli')['keycoli']['colskey2'], 3) # getattr tc = t.coli self.assertEqual(tc[0], 0) self.assertEqual(t.key1, 'keyval') self.assertRaises(AttributeError, lambda: t.key2) t.removekeyword('key1') self.assertNotIn('key1', t.getcolkeywords('coli')) # Print table row # tr = t.row(['coli', 'cold') # self.assertEqual(tr[0]['coli'], 0) # # Update a few fields in the row # tr[0] = {'coli': 10, 'cold': 14} # self.assertEqual(tr[0]['coli'], 10) t.close() tabledelete("ttable.py_tmp.tab1")
def test_tableascii(self): """Testing ASCII table.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5)), ack=False) tcol = t.colnames() t.addrows(5) t.toascii('asciitemp1', columnnames=tcol) tablefromascii(tablename='tablefromascii', asciifile='asciitemp1') ta = table("tablefromascii", readonly=False) tacol = ta.colnames() self.assertEqual(tcol, tacol) ta.close() t.close() tabledelete('tablefromascii') tabledelete("ttable.py_tmp.tab1")
def test_copyandrename(self): """Copy and rename tables.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) t_copy = tablecopy("ttable.py_tmp.tab1", "ttabel.tab1") self.assertEqual(t.name().split('/')[-1], 'ttable.py_tmp.tab1') self.assertEqual(t_copy.name().split('/')[-1], 'ttabel.tab1') numofrows = t.nrows() numofcols = t.ncols() self.assertEqual(t_copy.nrows(), numofrows) self.assertEqual(t_copy.ncols(), numofcols) tablerename("ttabel.tab1", "renamedttabel.tab1") self.assertEqual(t_copy.name().split('/')[-1], 'renamedttabel.tab1') t_copy.done() tabledelete("renamedttabel.tab1") t.close() tabledelete("ttable.py_tmp.tab1")
def test_check_putdata(self): """Add rows and put data.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) t.addrows(2) self.assertEqual(t.nrows(), 2) np.testing.assert_array_equal(t.getcol('coli'), np.array([0, 0])) t.putcol("coli", (1, 2)) np.testing.assert_array_equal(t.getcol('coli'), np.array([1, 2])) np.testing.assert_array_equal(t.getcol('cold'), np.array([0., 0.])) t.putcol("cold", t.getcol('coli') + 3) np.testing.assert_array_equal(t.getcol('cold'), np.array([4., 5.])) t.removerows(1) self.assertEqual(t.nrows(), 1) t.close() tabledelete("ttable.py_tmp.tab1")
def test_check_putdata(self): """Add rows and put data.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) t.addrows(2) self.assertEqual(t.nrows(), 2) np.testing.assert_array_equal(t.getcol('coli'), np.array([0, 0])) t.putcol("coli", (1, 2)) np.testing.assert_array_equal(t.getcol('coli'), np.array([1, 2])) np.testing.assert_array_equal( t.getcol('cold'), np.array([0., 0.])) t.putcol("cold", t.getcol('coli') + 3) np.testing.assert_array_equal( t.getcol('cold'), np.array([4., 5.])) t.removerows(1) self.assertEqual(t.nrows(), 1) t.close() tabledelete("ttable.py_tmp.tab1")
def test_adddmcolumns(self): """Add some columns.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) # A scalar with the IncrementalStMan storage manager t.addcols(maketabdesc(makescacoldesc("coli2", 0)), dminfo={ 'TYPE': "IncrementalStMan", 'NAME': "ism1", 'SPEC': {} }) self.assertIn("coli2", t.colnames()) # An array with the StandardStMan t.addcols(maketabdesc(makearrcoldesc("colarrssm", ""))) self.assertIn("colarrssm", t.colnames()) # An array with the TiledShapeStMan t.addcols(maketabdesc(makearrcoldesc("colarrtsm", 0. + 0j, ndim=2)), dminfo={ 'TYPE': "TiledShapeStMan", 'NAME': "tsm1", 'SPEC': {} }) self.assertIn("colarrtsm", t.colnames()) print(t.getdminfo()) coldmi = t.getdminfo('colarrtsm') print(t.getcoldesc('colarrtsm')) coldmi["NAME"] = 'tsm2' t.addcols(maketabdesc(makearrcoldesc("colarrtsm2", 0., ndim=2)), coldmi) self.assertEqual(t.getdminfo('colarrtsm2')["NAME"], 'tsm2') t.removecols('colarrtsm2') # Write some data. t.addrows(22) t.putcell('colarrtsm', 0, np.array([[1, 2, 3], [4, 5, 6]])) t.putcell('colarrtsm', 1, t.getcell('colarrtsm', 0) + 10) self.assertEqual(t.getcell('colarrtsm', 0)[1, 2], 6) print(t.getvarcol('colarrtsm')) np.testing.assert_array_equal( t.getcellslice('colarrtsm', 0, [1, 1], [1, 2]), np.array([[5. + 0.j, 6. + 0.j]])) print(t.getvarcol('colarrtsm')) t.close() tabledelete("ttable.py_tmp.tab1")
def test_adddmcolumns(self): """Add some columns.""" c1 = makescacoldesc("coli", 0) c2 = makescacoldesc("cold", 0.) c3 = makescacoldesc("cols", "") c4 = makescacoldesc("colb", True) c5 = makescacoldesc("colc", 0. + 0j) c6 = makearrcoldesc("colarr", 0.) t = table("ttable.py_tmp.tab1", maketabdesc((c1, c2, c3, c4, c5, c6)), ack=False) # A scalar with the IncrementalStMan storage manager t.addcols(maketabdesc(makescacoldesc("coli2", 0)), dminfo={'TYPE': "IncrementalStMan", 'NAME': "ism1", 'SPEC': {}}) self.assertIn("coli2", t.colnames()) # An array with the StandardStMan t.addcols(maketabdesc(makearrcoldesc("colarrssm", ""))) self.assertIn("colarrssm", t.colnames()) # An array with the TiledShapeStMan t.addcols(maketabdesc(makearrcoldesc("colarrtsm", 0. + 0j, ndim=2)), dminfo={'TYPE': "TiledShapeStMan", 'NAME': "tsm1", 'SPEC': {}}) self.assertIn("colarrtsm", t.colnames()) print(t.getdminfo()) coldmi = t.getdminfo('colarrtsm') print(t.getcoldesc('colarrtsm')) coldmi["NAME"] = 'tsm2' t.addcols(maketabdesc(makearrcoldesc( "colarrtsm2", 0., ndim=2)), coldmi) self.assertEqual(t.getdminfo('colarrtsm2')["NAME"], 'tsm2') t.removecols('colarrtsm2') # Write some data. t.addrows(22) t.putcell('colarrtsm', 0, np.array([[1, 2, 3], [4, 5, 6]])) t.putcell('colarrtsm', 1, t.getcell('colarrtsm', 0) + 10) self.assertEqual(t.getcell('colarrtsm', 0)[1, 2], 6) print(t.getvarcol('colarrtsm')) np.testing.assert_array_equal(t.getcellslice('colarrtsm', 0, [1, 1], [1, 2]), np.array([[5. + 0.j, 6. + 0.j]])) print(t.getvarcol('colarrtsm')) t.close() tabledelete("ttable.py_tmp.tab1")
def makePOINTING2(tablename,direction,time,nbeam=1,texp=0.2): # modules import casacore.tables as tb # params direction_rad = direction/180.*np.pi n_direction = direction.shape[0] time_end = time.max() # make table colnames = ['DIRECTION', 'ANTENNA_ID', 'INTERVAL', 'NAME', 'NUM_POLY', 'TARGET', 'TIME', 'TIME_ORIGIN', 'TRACKING'] colkeywords = [{'MEASINFO': {'Ref': 'J2000', 'type': 'direction'},'QuantumUnits': np.array(['rad', 'rad'],dtype='|S4')}, {}, {'QuantumUnits': np.array(['s'],dtype='|S2')}, {},{}, {'MEASINFO': {'Ref': 'J2000', 'type': 'direction'},'QuantumUnits': np.array(['rad', 'rad'],dtype='|S4')}, {'MEASINFO': {'Ref': 'UTC', 'type': 'epoch'}, 'QuantumUnits': np.array(['s'],dtype='|S2')}, {'MEASINFO': {'Ref': 'UTC', 'type': 'epoch'}, 'QuantumUnits': np.array(['s'],dtype='|S2')}, {} ] #ndims = [2,1,1,1,1,2,1,1,1] #isarrays = [True,False,False,False,False,True,False,False,False] valuetypes = ['double','int','double','string','int','double','double','double','bool'] ndims = [2,1,1,1,1,-1,1,1,1] descs = [] for colname,colkeyword,valuetype,ndim in zip(colnames,colkeywords,valuetypes,ndims): if (colname=='DIRECTION' or colname=='TARGET'): descs.append(tb.makearrcoldesc(colname,0.0,datamanagertype='StandardStMan',datamanagergroup='StandardStMan',ndim=ndim,keywords=colkeyword,valuetype=valuetype,options=0)) else: descs.append(tb.makescacoldesc(colname,0.0,datamanagertype='StandardStMan',datamanagergroup='StandardStMan',keywords=colkeyword,valuetype=valuetype)) td = tb.maketabdesc(descs=descs) returned_table = tb.table(tablename,tabledesc=td,nrow=n_direction,readonly=False) value = np.zeros([n_direction,1,2],dtype='float64') value[:,0] = direction_rad.copy() returned_table.putcol('DIRECTION',value) value = np.zeros([n_direction],dtype='int32') returned_table.putcol('ANTENNA_ID',value) returned_table.putcol('NUM_POLY',value) value = np.zeros([n_direction],dtype='float64') returned_table.putcol('TIME_ORIGIN',value) value = np.zeros([n_direction],dtype='bool') returned_table.putcol('TRACKING',value) value = np.full([n_direction],texp,dtype='float64') returned_table.putcol('INTERVAL',value) value = time returned_table.putcol('TIME',value) returned_table.flush() returned_table.close()
def makeMAIN2(tablename,specdata,time,state_id,texp=0.2,tBW=2.5e9): # modules import casacore.tables as tb # params nrow = specdata.shape[0] nspw = specdata.shape[1] npol = specdata.shape[2] nchan = specdata.shape[3] weight = tBW/float(nchan) * texp sigma = (tBW/float(nchan) * texp)**-0.5 ind_spw = (np.linspace(0,2*nrow-1,2*nrow,dtype='int32') % 2) # tables colnames = ['UVW', 'FLAG', 'FLAG_CATEGORY', 'WEIGHT', 'SIGMA', 'ANTENNA1', 'ANTENNA2', 'ARRAY_ID', 'DATA_DESC_ID', 'EXPOSURE', 'FEED1', 'FEED2', 'FIELD_ID', 'FLAG_ROW', 'INTERVAL', 'OBSERVATION_ID', 'PROCESSOR_ID', 'SCAN_NUMBER', 'STATE_ID', 'TIME', 'TIME_CENTROID', 'FLOAT_DATA' ] colkeywords = [ {'MEASINFO': {'Ref': 'ITRF', 'type': 'uvw'},'QuantumUnits': np.array(['m', 'm', 'm'],dtype='|S2')}, {}, {'CATEGORY': np.array([],dtype='|S1')}, {},{},{},{},{},{}, {'QuantumUnits': np.array(['s'],dtype='|S2')}, {},{},{},{}, {'QuantumUnits': np.array(['s'],dtype='|S2')}, {},{},{},{}, {'MEASINFO': {'Ref': 'UTC', 'type': 'epoch'}, 'QuantumUnits': np.array(['s'],dtype='|S2')}, {'MEASINFO': {'Ref': 'UTC', 'type': 'epoch'}, 'QuantumUnits': np.array(['s'],dtype='|S2')}, {'UNIT': 'K'} ] ndims = [1,2,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2] isarrays = [True,True,True,True,True,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,True] valuetypes = ['double','bool','bool','float','float','int','int','int','int','double','int','int','int','bool','double','int','int','int','int','double','double','float'] descs = [] for colname,colkeyword,ndim,valuetype,isarray in zip(colnames,colkeywords,ndims,valuetypes,isarrays): if colname=='UVW': descs.append(tb.makearrcoldesc(colname,0.0,datamanagertype='StandardStMan',datamanagergroup='StandardStMan',ndim=ndim,keywords=colkeyword,valuetype=valuetype,options=5,shape=np.array([3], dtype='int32'))) elif isarray: descs.append(tb.makearrcoldesc(colname,0.0,datamanagertype='StandardStMan',datamanagergroup='StandardStMan',ndim=ndim,keywords=colkeyword,valuetype=valuetype)) else: descs.append(tb.makescacoldesc(colname,0.0,datamanagertype='StandardStMan',datamanagergroup='StandardStMan',keywords=colkeyword,valuetype=valuetype)) td = tb.maketabdesc(descs=descs) returned_table = tb.table(tablename,tabledesc=td,nrow=2*nrow,readonly=False) # put values value = np.zeros([2*nrow,3],dtype='float64') returned_table.putcol('UVW',value) value = np.full([2*nrow,2],sigma) returned_table.putcol('SIGMA',value) value = np.full([2*nrow,2],weight) returned_table.putcol('WEIGHT',value) value = np.zeros([2*nrow],dtype='int32') returned_table.putcol('ANTENNA1',value) returned_table.putcol('ANTENNA2',value) returned_table.putcol('ARRAY_ID',value) returned_table.putcol('FEED1',value) returned_table.putcol('FEED2',value) returned_table.putcol('FIELD_ID',value) returned_table.putcol('OBSERVATION_ID',value) returned_table.putcol('PROCESSOR_ID',value) value = np.zeros([2*nrow],dtype='bool') returned_table.putcol('FLAG_ROW',value) value = np.full([2*nrow],texp,dtype='float64') returned_table.putcol('EXPOSURE',value) returned_table.putcol('INTERVAL',value) value = np.zeros_like(np.concatenate([specdata[:,0],specdata[:,1]],axis=0),dtype='bool') value = value.transpose(0,2,1) returned_table.putcol('FLAG',value) value = np.zeros_like(np.concatenate([specdata[:,0],specdata[:,1]],axis=0),dtype='float64') for i in range(2): value[ind_spw==i] = specdata[:,i].copy() value = value.transpose(0,2,1) returned_table.putcol('FLOAT_DATA',value) value = np.zeros(2*nrow,dtype='int32') for i in range(2): value[ind_spw==i] = state_id value = np.zeros(2*nrow,dtype='int32') for i in range(2): value[ind_spw==i] = i returned_table.putcol('DATA_DESC_ID',value) value = np.zeros(2*nrow,dtype='int32') for i in range(2): value[ind_spw==i] = state_id returned_table.putcol('STATE_ID',value) value = np.zeros(2*nrow,dtype='int32') for i in range(2): value[ind_spw==i] = np.linspace(0,nrow-1,nrow,dtype='int32') returned_table.putcol('SCAN_NUMBER',value) value = np.zeros(2*nrow,dtype='float64') for i in range(2): value[ind_spw==i] = time.copy() returned_table.putcol('TIME',value) returned_table.putcol('TIME_CENTROID',value) returned_table.flush() returned_table.close()
def main(): parser = argparse.ArgumentParser() parser.add_argument('-o', '--output', help='The table to write', default='my_table') parser.add_argument('-t', '--column-type', help='The type of the column to write', default='float') parser.add_argument('-c', '--column-name', help='The name of the column to write', default=None) parser.add_argument( '-e', '--even', action='store_true', help='Write only from even ranks (to check sub-communicator writing)', default=False) parser.add_argument('-n', '--nrows', type=int, help='Number of rows to write per rank', default=100) parser.add_argument('-A', '--no-adios', action='store_true', help='Do not use ADIOS2', default=False) opts = parser.parse_args() colname = opts.column_name or 'MY_%s_COLUMN' % opts.column_type.upper() ref_val = None if opts.column_type == 'float': ref_val = 0. elif opts.column_type == 'int': ref_val = 0 elif opts.column_type == 'bool': ref_val = False else: parser.error( 'Only float, int and bool are supported column type names') from mpi4py import MPI comm = MPI.COMM_WORLD size = comm.Get_size() rank = comm.Get_rank() if opts.even: size = (size + 1) // 2 kwargs = {'datamanagertype': 'Adios2StMan'} if not opts.no_adios else {} scd = tables.makescacoldesc(colname, ref_val, **kwargs) td = tables.maketabdesc([scd]) t = tables.table(opts.output, td, nrow=opts.nrows * size) with t: if opts.even and rank % 2 != 0: return tc = tables.tablecolumn(t, colname) start = opts.nrows * rank if opts.even: start //= 2 tc[start:start + opts.nrows] = list(range(opts.nrows))
def test_getcol(self): c1 = makescacoldesc(unicode_string, 0) t = table(join(self.workdir, 'ascii'), maketabdesc([c1]), ack=False) t.getcol(unicode_string)