def prepare_topbase_xs(self, top, levels, top_levels, suffix="Mac", levmax = 1e50): '''write array of topbase class instances to file in macro atom format, with lower and upper levels specified''' lu = 1 # we assume ionization to ground state of +ion print len(top), len(levels), len(top_levels) count = 0 topnew = [] for i in range(len(top)): #print top_levels[i].z, top_levels[i].nnstring for j in range(len(levels)): #print top_levels[i].nnstring, "//" ,levels[j].nnstring if top_levels[i].nnstring == levels[j].nnstring and top_levels[i].z == levels[j].z and top_levels[i].ion == levels[j].ion: if levels[j].lvl<=levmax: ll = levels[j].lvl ion = levels[j].ion #print "match", ll, top_levels[i].z, levels[j].nnstring ## write the summary records n_p = top[i].np if n_p>100: n_p = 100 if n_p>0: topnew_class = cls.top_photo_mac ( top[i].Z, top[i].ion, ll, lu, top[i].E0, n_p, top[i].energy, top[i].XS) topnew.append ( topnew_class) count +=1 return np.array(topnew)
def read_top_macro(self, filename, mode="Mac"): ''' 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,ll,lu, 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) # create blank array to store topbase class instances top = np.ndarray( len(Z),dtype=np.object) nline = 0 for i in range(len(top)): n_p = int(num_records[i]) nmax = nline + n_p top[i] = cls.top_photo_mac (Z[i], int(ion[i]), int(ll[i]), int(lu[i]), E0[i], n_p, energy[nline:nmax], XS[nline:nmax]) nline = nmax # top is an array of class instances like the topbase_ptr in PYTHONRT return top
def read_xsections(level_class_array, fname="%s/PHIXS" % default_folder,outname="xs.out", z_select = None, write=True): ''' read_atom_model reads Stuart's photoionization data from the PHIXS file and converts it into an array of cls.top_photo_mac class instances to be written out to file. Arguments: level_class_array array-like array of level class instances linked to data to get thresholds ''' f = open(fname, "r") nxs = 0 data = [] for line in f: d = line.split() if len(d) == 6: nxs += 1 if len(d) > 0: data.append(d) f.close() print "WE HAVE READ %i XSECTIONS" % nxs i = 0 # create a blank array to store classes xs = [] # (l.z, l.ion, l.lvl, l.ionpot, l.E, l.g, l.rad_rate, l.nnstring)) while i < len(data) and i < MAX: if len(data[i]) == 6: # we have a summary record z = int(data[i][0]) lower_ion = int(data[i][1]) lower_level = int(data[i][2]) upper_ion = int(data[i][3]) upper_level = int(data[i][4]) entries = int(data[i][5]) if z == z_select or z_select == None: # find the threshold for this ion and level for ilev in range(len(level_class_array)): if level_class_array[ilev].z == z and level_class_array[ilev].ion == lower_ion: if level_class_array[ilev].lvl == lower_level: threshold = -level_class_array[ilev].ionpot XS = np.zeros(entries) energy = np.zeros(entries) for j in range(entries): i+=1 energy[j] = threshold + float(data[i][0]) XS[j] = float(data[i][1]) * MEGABARN #print i xs.append(cls.top_photo_mac(z, lower_ion, lower_level, upper_level, threshold, entries, energy, XS)) i+=1 # write out the file if write: sub.write_top_macro(xs, outname, suffix = "Mac", append = False, levmax = 100)