Beispiel #1
0
	def read_topbase(self, filename, mode="Top"):
		'''
		read in XS info from Topbase XS data in Python format

		:INPUT:
			filename 		string
							atomic data filename e.g. topbase_h1_phot.py
		:OUTPUT:
			top 			topbase class instance
							topbase class instance containing information 
							for this filename
		'''

		# read in summary records
		Z,ion,islp,l, E0, num_records = sum_records = np.loadtxt( filename, 
				dtype={'names': ('Z', 'ion', 'islp', 'l', 'E0', 'np'), 
				'formats': ('i4', 'i4', 'i4', 'i4', 'float', 'i4')}, 
	                        comments='Phot%s ' % mode , delimiter=None, converters=None, 
	                        skiprows=0, usecols=(1,2,3,4,5,6), unpack=True, ndmin=0)
		
		# then read the actual cross sections
		energy, XS = np.loadtxt(filename, dtype='float', 
	                        comments='Phot%sS' % mode, delimiter=None, converters=None, 
	                        skiprows=0, usecols=(1,2), unpack=True, ndmin=0)

		#ion = int(Z) - int(ne) +1

		# create blank array to store topbase class instances
		top = np.ndarray( len(Z),dtype=np.object)

		sr = np.transpose(sum_records)

		nline = 0
		
		for i in range(len(top)):

			n_p = int(num_records[i])
			nmax = nline + n_p

			#ion = int(Z[i]) - int(ne[i]) + 1

			
			top[i] = cls.top_photo(Z[i], int(ion[i]), int(islp[i]), int(l[i]), E0[i], n_p, energy[nline:nmax], XS[nline:nmax])

			#if ion[i] == 2 and int(islp[i]) / 100 != 2:
			#	print "Error, non doublet in He II! ion %i islp[i] %i" % (ion, int(islp[i]))
			#	print sr[i]
			#	print ne[i], ion[i] 

			nline = nmax
			
		# top is an array of class instances like the topbase_ptr in PYTHONRT
		return top
Beispiel #2
0
	def read_original_topbase_xs(self, filename, suffix="Mac"):

		'''this needs to be done manually, annoyingly, as format of
		topbase has no PhotTop or PhotMac string'''

		f = open(filename, "r")

		i = -1

		top = []

		for line in f:

			data = line.split()

			if len(data) == 2:
				top_dummy.energy[j] = float(data[0]) * RYDBERG
				top_dummy.XS[j] = 1e-18 * float(data[1])

				if j > top_dummy.np:
					print "error, j > top[i].np"

				j += 1

			elif len(data) == 7:
				i += 1 
				j = 0

				if i>0: top.append(top_dummy)


				Z = int(data[1])
				ion = Z - int(data[2]) + 1 
				islp = int(data[3])
				l = int(data[4])
				E = -1 * float(data[5]) * RYDBERG
				num = int(data[6])

				top_dummy = cls.top_photo (Z, ion, islp, l, E, num, np.ndarray( num, dtype=np.object), np.ndarray( num, dtype=np.object))

			elif data[0]!="#": 
				print "Didn't understand data, exiting"
				print line
				sys.exit()

		top = np.array(top)

		return top