def test_update(self): # Reduce elapsed time by a half elapsed_time = self.original_elapsed_time / 2. f = indexer.SharedFile(nativem4) f.set_node_attr('/conf', 'elapsed', elapsed_time) doc = filedata.MisuraDocument(proxy=f) doc.reloadData() doc.root = f.conf # # This will import only a half of the points # imp=filedata.OperationMisuraImport(filedata.ImportParamsMisura(filename=nativem4)) # imp.do(doc) nt = len(doc.data['0:t'].data) nh = len(doc.data['0:hsm/sample0/h'].data) lastt = doc.data['0:t'].data[-1] f.set_node_attr('/conf', 'elapsed', self.original_elapsed_time) r = doc.update() nt1 = len(doc.data['0:t'].data) nh1 = len(doc.data['0:hsm/sample0/h'].data) lastt1 = doc.data['0:t'].data[-1] self.assertEqual([nt1, nh1], [nt, nh]) # self.assertLess(abs(2*lastt-lastt1),doc.interval) # # Empty update r = doc.update() self.assertEqual(r, []) f.close()
def test_log_is_not_implemented(self): fpath = os.path.join(iutils_testing.data_dir, 'test_video.h5') fp = indexer.SharedFile(fpath) log = fileui.OfflineLog(fp) self.assertEqual('unimplemented', log.toPlainText())
def check_curve(self, op): """Check thermal cycle curve format""" fp = indexer.SharedFile(op) fp.load_conf() curve = fp.conf.kiln['curve'] self.assertGreater(len(curve), 1) self.assertEqual(len(curve[0]), 2) fp.close()
def test_log(self): fpath = os.path.join(iutils_testing.data_dir, 'test_video.h5') fp = indexer.SharedFile(fpath) log = fileui.OfflineLog(fp) txt = log.toPlainText() self.assertTrue( txt.startswith('Importing from'), msg='Wrong log: ' + txt)
def check_standard(self, op): """Perform a re-standard""" # TODO: create test files with Width variable! fp = indexer.SharedFile(op) fp.load_conf() self.assertNotIsInstance(fp.conf.hsm.sample0['Sintering']['time'], basestring) fp.run_scripts(fp.conf.hsm) end = fp.col('/kiln/T',-1) self.assertEqual(fp.conf.hsm.measure['end']['time'], end[0]) self.assertEqual(fp.conf.hsm.measure['end']['temp'], end[1]) fp.close()
def check_import(self, op, names=False): """Simulate a data import operation""" logging.debug('check_import', op) fp = indexer.SharedFile(op) fp.load_conf() rm = devtree.recursiveModel(fp.conf) fp.close() # Simulate an import imp = filedata.OperationMisuraImport( filedata.ImportParamsMisura(filename=op)) doc = filedata.MisuraDocument() imp.do(doc) # if names is not False: # self.assertEqual(set(imp.outdatasets), names) for ds in doc.data.itervalues(): self.assertFalse(np.isnan(ds.data).any()) return doc
def check_images(self, op, fmt='ImageM3', max_num = 10): """Check imported images""" print ' CHECK IMAGES' dec = filedata.DataDecoder() fp = indexer.SharedFile(op) dec.reset(proxy=fp, datapath='/hsm/sample0/frame') dec.ext = 'ImageM3' t, img = dec.get_data(0) self.assertEqual(img.width(), 640) self.assertEqual(img.height(), 480) ofmt = fp.get_node_attr('/hsm/sample0/frame', 'type') N = fp.len('/hsm/sample0/frame') t, last_img = dec.get_data(N - 1) dec.close() fp.close() # dec uses a copy of fp: must close both! self.assertTrue(img) self.assertEqual(fmt, ofmt) self.assertTrue(last_img)
def test_init(self): fpath = os.path.join(iutils_testing.data_dir, 'test_video.h5') # Simulate an import imp = filedata.OperationMisuraImport( filedata.ImportParamsMisura(filename=fpath)) doc = filedata.MisuraDocument() imp.do(doc) fp = indexer.SharedFile(fpath) decoder = filedata.DataDecoder() profile = '/hsm/sample0/profile' decoder.reset(fp, profile) self.sync(decoder) doc.decoders[fpath+':'+profile] = decoder mini = fileui.MiniImage(doc, '/hsm/sample0/profile') mini.saveDir = iutils_testing.data_dir mini.set_idx(0) self.saved_file = mini.save_frame() self.assertTrue(os.path.exists(self.saved_file))
def setUpClass(cls): f = indexer.SharedFile(nativem4) cls.doc = filedata.MisuraDocument(proxy=f) cls.doc.reloadData() f.close()
def tearDown(self): f = indexer.SharedFile(nativem4) f.set_node_attr('/conf', 'elapsed', self.original_elapsed_time) f.close()
def setUp(self): f = indexer.SharedFile(nativem4) self.original_elapsed_time = f.get_node_attr('/conf', 'elapsed') f.close()
def get_outpath(self, tcode=False, img=True, force=True, keep_img=True): # Open DB and import test data if not tcode: self.dbpath, tcode = self.dbpath.split('|') self.tcode = tcode conn, cursor = m3db.getConnectionCursor(self.dbpath) cursor.execute("select * from PROVE where IDProve = '%s'" % tcode) tests = cursor.fetchall() if len(tests) != 1: logging.debug('Wrong number of tests found', tests) conn.close() return False test = tests[0] self.test = test self.icode = m3db.getImageCode(tcode) cursor.execute( "select * from IMMAGINI where [IDProve] = '%s' order by Tempo" % self.icode) self.rows = cursor.fetchall() logging.debug('CONVERT GOT', len(self.rows)) if len(self.rows) < 1: logging.debug('No points', self.rows) conn.close() return False conn.close() # ## # Open Output File safeName = ''.join(c for c in self.test[m3db.fprv.Desc_Prova] if c in valid_chars) outpath = os.path.join(self.outdir, safeName + '_' + tcode + '.h5') # Manage overwriting options if os.path.exists(outpath): # Keep current images if keep_img: outFile = indexer.SharedFile(outpath, mode='a') found = outFile.has_node('/hsm/sample0/frame') # If no images: create new file if not found: outFile.close() del outFile os.remove(outpath) outFile = indexer.SharedFile(outpath, mode='w') # Else, wipe out data points and configuration, but keep images else: # but keep images! img = False # If I am forcing overwriting and not caring about current images, # create new file elif force: os.remove(outpath) outFile = indexer.SharedFile(outpath, mode='w') # If I am not forcing neither keeping images, return the current file else: logging.debug('Already exported path:', outpath) return outpath # If it does not exist, create! else: outFile = indexer.SharedFile(outpath, mode='w') self.outpath = outpath self.outFile = outFile self.img = img self.keep_img = keep_img self.force = force return self.outpath