def Iso_Dev(self): wl = WinstonLutz(self.direct_name, use_filenames=True) g_iso = wl.gantry_iso_size coll_iso = wl.collimator_iso_size couch_iso = wl.couch_iso_size epid_rms = wl.cax2epid_distance() return (g_iso, coll_iso, couch_iso, epid_rms)
def test_load_from_file_object(self): path = osp.join(TEST_DIR, 'noisy_WL_30x5.zip') ref_w = WinstonLutz.from_zip(path) ref_w.analyze() with open(path, 'rb') as f: w = WinstonLutz.from_zip(f) w.analyze() self.assertIsInstance(w, WinstonLutz) self.assertEqual(w.gantry_iso_size, ref_w.gantry_iso_size)
def setUpClass(cls): filename = cls.get_filename() if cls.zip: cls.wl = WinstonLutz.from_zip(filename, use_filenames=cls.use_filenames) else: cls.wl = WinstonLutz(filename, use_filenames=cls.use_filenames) if cls.print_results: print(cls.wl.results()) print(cls.wl.bb_shift_vector)
def test_load_from_stream(self): path = osp.join(TEST_DIR, 'noisy_WL_30x5.zip') ref_w = WinstonLutz.from_zip(path) ref_w.analyze() with open(path, 'rb') as f: s = io.BytesIO(f.read()) w = WinstonLutz.from_zip(s) w.analyze() self.assertIsInstance(w, WinstonLutz) self.assertEqual(w.gantry_iso_size, ref_w.gantry_iso_size)
def OpenCOne(self): directory = QFileDialog.getExistingDirectory( self, 'Select backup directory') win_directory = QtCore.QDir.toNativeSeparators(directory) wl = WinstonLutz(win_directory) d.getCountImages = len(wl.images) d.pathDir = win_directory wl.images[0].plot() self.ui.pushButton.setEnabled(False) self.ui.pushButton__Summary.setEnabled(False) self.ui.pushButton__IzoSize.setEnabled(False) file = open("file.txt", "w") file.write(str(wl.result_cone())) file.close()
def getIzoSize(self): wl = WinstonLutz(d.pathDir) self.ui.label_CouchZize.setText( str('{0:.2f}'.format(wl.couch_iso_size))) self.ui.label_GentrySize.setText(str(wl.collimator_iso_size)) self.ui.label_GentryIZOSIZE.setText( str('{0:.2f}'.format(wl.gantry_iso_size)))
def changeImages(self): num = int(self.ui.spinBox.text()) direct_tory = d.pathDir wl = WinstonLutz(direct_tory) if num < d.getCountImages: wl.images[num].plot() else: self.showdialog()
def run_wl(path): """Function to pass to the process pool executor to process picket fence images.""" try: my_wl = WinstonLutz.from_zip(path) if my_wl.gantry_iso_size > 3: raise ValueError return 'Success' except Exception as e: return 'Failure: {} @ {}'.format(e, path)
def test_not_yet_analyzed(self): wl = WinstonLutz.from_demo_images() with self.assertRaises(ValueError): wl.results() # not yet analyzed with self.assertRaises(ValueError): wl.plot_images() with self.assertRaises(ValueError): wl.plot_summary()
def test_invalid_dir(self): with self.assertRaises(ValueError): WinstonLutz(r'nonexistant/dir')
def test_loading_1_image_fails(self): with self.assertRaises(ValueError): WinstonLutz(osp.join(TEST_DIR, 'lutz', '1_image'))
def setUpClass(cls): cls.wl = WinstonLutz(cls.image_dir)
def QA_Report(self): # app.config['MONGO_URI'] = "mongodb://localhost:27017/WinstonLutzTest" # mongo = PyMongo(app) client = MongoClient('localhost', 27017) db = client.QA fs = gridfs.GridFS(db) init_dir = os.getcwd() os.chdir(self.direct_name) fnames = glob.glob('*.dcm') position = [ 'Gantry270Couch0.dcm', 'Gantry0Couch0.dcm', 'Gantry90Couch0.dcm', 'Gantry180Couch0.dcm', 'Gantry0Couch90.dcm', 'Gantry0Couch45.dcm', 'Gantry0Couch315.dcm', 'Gantry0Couch270.dcm' ] for i, fname in enumerate(fnames): name = position[i] shutil.move(fname, name) wl = WinstonLutz(self.direct_name, use_filenames=True) # wl.plot_summary() wl.save_summary('summary.png') plt.close() r = wl.results() rr = r.split('\n') wltreportname = 'WLT' + datetime.now().strftime('%d%m%Y') + '.pdf' # c = canvas.Canvas('WLT'+ datetime.now().strftime('%d%m%Y') + '.pdf') c = canvas.Canvas(wltreportname) c.setLineWidth(0.3) c.drawImage(init_dir + "\\images\\qmh_logo.png", 50, 750, 90, 80) c.drawString(150, 780, 'Department of Clinical Oncology Medical Physics Unit') c.drawString(50, 700, 'Date: ' + datetime.now().strftime('%d-%m-%Y')) c.drawString(50, 685, 'LINAC: ' + self.LINAC) y = 670 for line in rr: c.drawString(50, y, line) y -= 15 c.drawImage('summary.png', 30, 20, 7 * inch, 5 * inch) c.save() fileID = fs.put(open(wltreportname, 'rb')) db.WLTest.insert_one({ 'LINAC': self.LINAC, 'QA Date': datetime.now().strftime('%d-%m-%Y'), 'Gantry Isocenter Size': str(('%.4f' % wl.gantry_iso_size)), 'Couch Isocenter Size': str(('%.4f' % wl.couch_iso_size)), 'PV Isocenter Size': str(('%.4f' % wl.collimator_iso_size)), 'reportpdf': wltreportname }) return wltreportname
def getEpidSag(self): wl = WinstonLutz(d.pathDir) wl.plot_epid_sag()
def setUp(self): self.wl = WinstonLutz.from_demo_images()
def setUpClass(cls): cls.wl = WinstonLutz.from_demo_images()
def test_loading_demo_files(self): wl = WinstonLutz.from_demo_images() # shouldn't raise
def GentrySag(self): wl = WinstonLutz(d.pathDir) wl.plot_gantry_sag()
def sumary_Info(self): wl = WinstonLutz(d.pathDir) wl.plot_summary() wl.publish_pdf(d.pathDir + '//result.pdf')
def test_loading_1_image_fails(self): with self.assertRaises(ValueError): folder = get_folder_from_cloud_test_repo(['Winston-Lutz', 'lutz', '1_image']) WinstonLutz(folder)
def test_bb_too_far_away_fails(self): """BB is >20mm from CAX""" file = get_file_from_cloud_test_repo([TEST_DIR, 'bb_too_far_away.zip']) wl = WinstonLutz.from_zip(file) with self.assertRaises(ValueError): wl.analyze()
def test_bad_filenames(self): # tests_basic that using filenames with incorrect syntax will fail wl_dir = osp.join(TEST_FILES_DIR, 'Winston-Lutz', 'Bad Names.zip') with self.assertRaises(ValueError): wl = WinstonLutz.from_zip(wl_dir, use_filenames=True)
def test_run_demo(self): WinstonLutz.run_demo() # shouldn't raise
def test_plot_wo_all_axes(self): # test that analyzing images w/o gantry images doesn't fail wl_zip = osp.join(TEST_FILES_DIR, 'Winston-Lutz', 'Naming.zip') wl = WinstonLutz.from_zip(wl_zip, use_filenames=True) wl.plot_summary() # shouldn't raise
def setUpClass(cls): filename = cls.get_filename() if cls.zip: cls.wl = WinstonLutz.from_zip(filename) else: cls.wl = WinstonLutz(filename)
def summeryCone(self): wl = WinstonLutz(d.pathDir) wl.plot_coneSummery() wl.publishCone_pdf(d.pathDir + '//resultCone.pdf')