Пример #1
0
    def __init__(self, dsname):
	"""Create and return an open CTF dataset object. You may open many
	CTF datasets at once by creating many instances of this class."""

	self.dsData = None      # set this now so __del__ won't complain

	if dsname[-1] == '/':
	    dsname = dsname[:-1]
	b = os.path.basename(dsname)
	if b[-3:] != '.ds':
	    raise Exception, "%s is not a dataset name" % dsname
	self.dsname = dsname
	self.setname = b[:-3]

	# Open files. We allow the .meg4 file to be absent.

	res4name = self.getDsFileNameExt('.res4')
	self.r = ctf.readRes4(res4name)
	try:
	    meg4name = self.getDsFileNameExt('.meg4')
	    self.dsData = dsData(self.r, meg4name)  # handle to open .meg4 file
	except:
	    pass

	# A mapping from channel name to number, backwards compatible name.

	self.channel = self.r.chanIndex

	# Get the marks, if any.

	self.marks = markers(dsname)

	# Get the dewar coordinates of the head from the .hc file, if any.

	hc = self.getDsFileNameExt('.hc')
	try:
	    n, l, r = getHC(hc, 'dewar')
	    self.dewar = n, l, r

	    # compute the transform into the head frame
	    self.dewar_to_head = fid.fid(n, l, r)

	    # compute the head coordinates in the head frame
	    self.head = [fid.fid_transform(self.dewar_to_head, x) for x in self.dewar]
	except:
	    pass
Пример #2
0
def dsopen(dsname):
	if dsname[-1] == '/':
		dsname = dsname[:-1]
	s = os.path.splitext(dsname)
	if s[1] != '.ds':
		raise Exception, "%s is not a dataset name" % dsname

	# get the SWIG wrapper for MEGH and change its class

	ds = ctf.dsopen(dsname)
	ds.__class__ = dsWrap

	# create a mapping from channel name to number

	d = {}
	for m in range(ds.getNumberOfChannels()):
	    n = ds.getChannelName(m).split('-')[0]
	    d[n] = m
	ds.channel = d

	# get the marks, if any
	ds.marks = markers(dsname)

	# get the dewar coordinates of the head from the hc file, if any
	hc = ds.dsname + '/' + ds.setname + '.hc'
	try:
		n, l, r = getHC(hc, 'dewar')
		ds.dewar = n, l, r

		# compute the transform into the head frame
		ds.dewar_to_head = fid.fid(n, l, r)

		# compute the head coordinates in the head frame
		ds.head = [fid.fid_transform(ds.dewar_to_head, x) for x in ds.dewar]
	except:
		pass
	return ds