def test_update_swapped(self): """ same dimension, swapped rows """ self.assertTrue(ap.conf.has(self.h5filename)) ormdata_dst = ap.OrmData(ap.conf.filename(self.h5filename)) ormdata_src = ap.OrmData(ap.conf.filename(self.h5filename)) nrow, ncol = len(ormdata_src.bpm), len(ormdata_src.trim) # reset data for i in range(nrow): for j in range(ncol): ormdata_src.m[i,j] = 0.0 # rotate the rows down by 2 import collections rbpm = collections.deque(ormdata_src.bpm) rbpm.rotate(2) ormdata_src.bpm = [b for b in rbpm] for itrial in range(10): idx = [] for i in range(nrow*ncol//4): k = random.randint(0, nrow*ncol-1) idx.append(divmod(k, ncol)) ormdata_src._mask[idx[-1][0]][idx[-1][1]] = 0 ormdata_dst.update(ormdata_src) for i,j in idx: i0, j0 = (i-2+nrow) % nrow, (j + ncol) % ncol self.assertEqual(ormdata_dst.m[i0,j0], 0.0)
def test_update(self): """ same data different mask """ bpmlst = [e.name for e in ap.getElements('BPM')] trimlst = ['ch1g6c15b', 'cl2g6c14b', 'cm1g4c26a'] trimlst1 = trimlst[0:1] trimlst2 = trimlst[1:2] #trimx = ['CXH1G6C15B'] trims = ap.getElements(trimlst) for t in trims: t.x = 0 t.y = 0 nametag = time.strftime("%Y%m%d_%H%M.hdf5") fname1 = "orm_update_1_" + nametag fname2 = "orm_update_2_" + nametag orm1 = ap.measOrbitRm(bpmlst, trimlst1, fname1, verbose=2) orm2 = ap.measOrbitRm(bpmlst, trimlst2, fname2, verbose=2) ormdata_dst = ap.OrmData(fname1) ormdata_src = ap.OrmData(fname2) ormdata_dst.update(ormdata_src) self.assertIn(trimlst2[0], ormdata_dst.getTrimNames())
def test_update_submatrix(self): """ same dimension, swapped rows """ self.assertTrue(ap.conf.has(self.h5filename)) ormdata = ap.OrmData(ap.conf.filename(self.h5filename)) nrow, ncol = len(ormdata.bpm), len(ormdata.trim) # prepare for subset for itrial1 in range(10): idx = [] bpms, trims = set([]), set([]) planes = [set([]), set([])] for itrial2 in range(nrow*ncol//4): k = random.randint(0, nrow*ncol-1) i,j = divmod(k, ncol) idx.append([i, j]) bpms.add(ormdata.bpm[i][0]) planes[0].add(ormdata.bpm[i][1]) trims.add(ormdata.trim[j][0]) planes[1].add(ormdata.trim[j][1]) m = ormdata.getSubMatrix(bpm, trim, planes, full=False) for i,j in idx: self.assertEqual(ormdata_dst.m[i0,j0], 0.0)
def test_trim_bpm(self): self.assertTrue(ap.conf.has(self.h5filename)) ormdata = ap.OrmData(ap.conf.filename(self.h5filename)) trimx = ['fxl2g1c07a', 'cxh1g6c15b'] for trim in trimx: self.assertTrue(ormdata.hasTrim(trim)) bpmx = ap.getGroupMembers(['BPM', 'C0[2-4]'], op='intersection') self.assertEqual(len(bpmx), 18) for bpm in bpmx: self.assertTrue(ormdata.hasBpm(bpm.name))
def test_update(self): """ same data different mask """ self.assertTrue(ap.conf.has(self.h5filename)) ormdata_dst = ap.OrmData(ap.conf.filename(self.h5filename)) ormdata_src = ap.OrmData(ap.conf.filename(self.h5filename)) nrow, ncol = len(ormdata_src.bpm), len(ormdata_src.trim) # reset data for i in range(nrow): for j in range(ncol): ormdata_src.m[i,j] = 0.0 for itrial in range(3): idx = [] for i in range(nrow*ncol//4): k = random.randint(0, nrow*ncol-1) idx.append(divmod(k, ncol)) ormdata_src._mask[idx[-1][0]][idx[-1][1]] = 0 ormdata_dst.update(ormdata_src) for i,j in idx: self.assertEqual(ormdata_dst.m[i,j], 0.0)