def open(self): """Open a PSF file and read its headers. Example: Trying to open a valid psf file >>> psf=PSFReader('./test/psf/srcSweep') >>> psf.open() """ if self.asc == None: self.asc = psfasc.is_psfasc(self.filename) if not self.asc: self.file = open(self.filename, "rb") if self.validate(): self.deSerializeFile(self.file) else: raise PSFInvalid("Invalid PSF file") else: newpsfobj = psfasc.parse("psfasc", open(self.filename).read()) self.header = newpsfobj.header self.types = newpsfobj.types self.sweeps = newpsfobj.sweeps self.traces = newpsfobj.traces self.values = newpsfobj.values self.lastid = newpsfobj.lastid self.verbose = newpsfobj.verbose
def create_psfreader(*args, **kwargs): """PSFReader factory that can use either libpsf or pure python""" use_libpsf = True if 'USELIBPSF' in os.environ: use_libpsf = bool(int(os.environ['USELIBPSF'])) ## Try to import libpsf if use_libpsf: try: import psflibpsf except ImportError: use_libpsf = False os.environ['USELIBPSF'] = '0' if use_libpsf and not psfasc.is_psfasc(args[0]): return psflibpsf.PSFReader(*args, **kwargs) else: return psf.PSFReader(*args, **kwargs)