Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xatomic #1077

Merged
merged 4 commits into from
May 24, 2024
Merged

Xatomic #1077

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions py_progs/CheckAtomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
the number of photioniztion x-sections
or the number of collisional x-sections

The routine must b run from a directory
in which the variious files in the
master file are properly linked.


History:

Expand Down
72 changes: 60 additions & 12 deletions py_progs/Macro2Simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

Command line usage (if any):

usage: Macro2Simple.py filename
usage: Macro2Simple.py [-nlev xxx] ion1 ion2 ...

where:

-nlev xxx Resets the maxium number of levels to a specific value
ion1 ion2 .... etc names of ion in the format we are using

Description:

Expand All @@ -26,6 +31,7 @@
History:

240127 ksl Coding begun
240522 ksl Mods to make the program work with current versions of MakeMacro

'''

Expand All @@ -37,24 +43,32 @@


def write_simple_levels(ion="h_1", nlevels=10):
xtab=get_levels(ion,nlevels)

try:
xtab=get_levels(ion,nlevels)
except:
print('Could not get macro levels for ion %s %d' % (ion,nlevels))
print('Was MakeMacroRun for this ion?')
return ''

xtab['Dtype']='LevTop'
xtab['eqn']=-99.0

ztab=xtab['Dtype','Element','Ion','islp','ilv','ion_pot','ex','g','eqn','rad_rate','config']
outfile='%s_levels_simple.dat' % ion
outfile='Adata/%s_levels_simple.dat' % ion
ztab.write(outfile,format='ascii.fixed_width_two_line',overwrite=True)
return outfile



def write_simple_lines(ion="h_1"):
infile='%s_lines.dat' % ion
outfile='%s_lines_simple.dat' % ion
infile='Adata/%s_lines.dat' % ion
outfile='Adata/%s_lines_simple.dat' % ion
try:
x=ascii.read(infile)
except:
print('Error: write_simple_lines: Could not read %s' % infile)
print('Was MakeMacroRun for this ion?')
return []
x['Dtype']='Line'
x.write(outfile,format='ascii.fixed_width_two_line',overwrite=True)
Expand All @@ -65,29 +79,63 @@ def write_simple_lines(ion="h_1"):

def doit(ion='h_1',nlevels=10):
lev_file=write_simple_levels(ion,nlevels)
if len(lev_file)==0:
print('Failed for ion %s with levels %d' % (ion,nlevels))
return

print(lev_file)
line_file=write_simple_lines(ion)
print(line_file)
x = ch.ion(ion, temperature=1e5)
nelec = x.Z - x.Ion + 1
filename = "p%02d.%02d.dat" % (x.Z, nelec)
outfile = "%s_phot_simple.dat" % (ion)
filename = "Phot/p%02d.%02d.dat" % (x.Z,x.Ion)
outfile = "Adata/%s_phot_simple.dat" % (ion)
phot_tab,xtab=RedoPhot.extrap(filename,1e5)
if len(phot_tab)==0:
print('Error: Exiting because of previous problems')
return
RedoPhot.write_phot_tab(outfile,phot_tab,xtab)
print(outfile)
return


def steer(argv):
'''
Set up the various inputs, and call the actual routine
to convert an ion that exists to a simple ion
'''

i=1
ion=[]
nlevels=1000
while i<len(argv):
if argv[i][0:2]=='-h':
print(__doc__)
return
elif argv[i]=='-nlev':
i+=1
nlevels=int(argv[i])
else:
ion.append(argv[i])
i+=1

if len(ion)==0:
print('Error: No ins to convert: ',argv)
return

for one_ion in ion:
if one_ion.isdigit():
print('Improperly formatted command line:',argv)
print(__doc__)
return

for one_ion in ion:
doit(one_ion,nlevels)

# Next lines permit one to run the routine from the command line
if __name__ == "__main__":
import sys
if len(sys.argv)==3:
doit(sys.argv[1],int(sys.argv[2]))
elif len(sys.argv)==2:
doit(sys.argv[1],10)
if len(sys.argv)>1:
steer(sys.argv)
else:
print (__doc__)

Expand Down
8 changes: 7 additions & 1 deletion py_progs/MakeMacro.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ def get_levels(ion="h_1", nlevels=10):
Python can read the astropy table for levels directly,
so normally one would write this to a file
"""
x = ch.ion(ion, temperature=1e5)
print('get_levels: Getting levels for %s and nlevels %s' % (ion,nlevels))
try:
x = ch.ion(ion, temperature=1e5)
except:
print('Error: get_levels: failed for %s' % ion)
raise IOError
First_Ion_Pot = x.Ip

# Find the ionization potential of lower ionization
Expand Down Expand Up @@ -273,6 +278,7 @@ def get_levels(ion="h_1", nlevels=10):
xxtab["ilv"][i] = n
i += 1

print('The number of macro levels is %d' % (len(xxtab)))
return xxtab


Expand Down
5 changes: 3 additions & 2 deletions py_progs/RedoPhot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def read_phot(photfile='o_2_phot.dat'):
try:
f=open(photfile)
except:
print('Error: %s not found' % photfile)
print('Error: RedoPhot.read_phot: %s not found' % photfile)
return [],[]

rlines=f.readlines()
Expand Down Expand Up @@ -212,6 +212,7 @@ def write_phot_tab(out_name,xsum,xcross):
Note that this routine is not prevented from
writing data to an existing file.
'''
print('RedoPhot: Starting to write phot file to %s' % (out_name))

f=open(out_name,'w')
i=0
Expand Down Expand Up @@ -279,7 +280,7 @@ def steer(argv):
i+=1

if infile=='':
print('Error: not enught arguments: ',argv)
print('Error: not enough arguments: ',argv)
return

redo_one(infile,outroot)
Expand Down
Loading