Skip to content

Commit

Permalink
fix(model.py): fix model header after interpolation
Browse files Browse the repository at this point in the history
The header now starts with "KURUCZ" and the next line include stellar parameters. When no
interpolation is needed the output is correct.
  • Loading branch information
MingjieJian committed Jul 24, 2020
1 parent 062b8e8 commit e075ca7
Show file tree
Hide file tree
Showing 31 changed files with 205,627 additions and 23 deletions.
Binary file modified pymoog/__pycache__/synth.cpython-38.pyc
Binary file not shown.
103,382 changes: 103,382 additions & 0 deletions pymoog/files/linelist/ges/ges_hfs_iso

Large diffs are not rendered by default.

102,092 changes: 102,092 additions & 0 deletions pymoog/files/linelist/ges/ges_nohfs_noiso

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pymoog/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ def combine_linelist()
vald.sort_values('wavelength', inplace=True)
vald.reset_index(drop=True, inplace=True)

line_data.save_linelist(vald, 'files/linelist/vald')
line_data.save_linelist(vald, 'files/linelist/vald')
16 changes: 6 additions & 10 deletions pymoog/line_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ def save_linelist(linelist_all, sub_ll_name, wav_start=None, wav_end=None, type=
with open(sub_ll_name, 'w') as file:
file.write('VALD linelist\n')
for i in range(len(sub_linelist)):
if np.isnan(sub_linelist.iloc[i].values[-1]):
file.write('{:10.4f}{:10.5f}{:10.4f}{:10.3f}{:10.3f}\n'.format(*sub_linelist.iloc[i].values[:-1]))
else:
file.write('{:10.4f}{:10.5f}{:10.4f}{:10.3f}{:10.3f}{:10.3f}\n'.format(*sub_linelist.iloc[i].values))
line = '{:10.4f}{:10.5f}{:10.4f}{:10.3f}{:10.3f}{:10.3f}{:10.3f}\n'.format(*sub_linelist.iloc[i].values).replace('nan', ' ')
file.write(line)

def read_linelist(linelist_path, loggf_cut=None):
'''
Expand All @@ -166,14 +164,13 @@ def read_linelist(linelist_path, loggf_cut=None):
Cut on loggf (only save for the lines with loggf > loggf_cut)
'''
linelist = pd.read_fwf(linelist_path,
colspecs=[(0,11), (11,21), (21,31), (31,41), (41,51), (51,61)],
names=['wavelength', 'id', 'EP', 'loggf', 'C6', 'D0'],
colspecs=[(0,11), (11,21), (21,31), (31,41), (41,51), (51,61), (61,71)],
names=['wavelength', 'id', 'EP', 'loggf', 'C6', 'D0', 'EW'],
skiprows=1)
# MOOG seems will crash if there is line with EP larger than 50eV, so they are removed.
# MOOG seems to crash if there is line with EP larger than 50eV, so they are removed.
linelist = linelist[(linelist['EP'] <= 50)]
if loggf_cut != None:
linelist = linelist[(linelist['loggf'] >= loggf_cut)]
print('fsdfadsf')
linelist.reset_index(drop=True, inplace=True)
return linelist

Expand Down Expand Up @@ -212,8 +209,7 @@ def vald2moog_format(init_linelist_name, out_linelist_name, head=None, loggf_cut

# subprocess.run(['sed', "s/'//g", init_linelist_name, '>', 'temp'])
# subprocess.run(['mv', "temp", init_linelist_name])
vald_init = pd.read_csv(init_linelist_name,skiprows=2, skipfooter=footer_index, usecols=range(9), engine = 'python' ,
names=['element', 'wavelength', 'EP', 'loggf', 'rad_damp', 'Stark_damp', 'Walls_damp', 'Lande_factor', 'Comment'])
vald_init = pd.read_csv(init_linelist_name,skiprows=2, skipfooter=footer_index, usecols=range(9), engine = 'python', names=['element', 'wavelength', 'EP', 'loggf', 'rad_damp', 'Stark_damp', 'Walls_damp', 'Lande_factor', 'Comment'])

if head != None:
vald_init = vald_init[:head]
Expand Down
125 changes: 125 additions & 0 deletions pymoog/linelist.ipynb

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions pymoog/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def save_interpo_model(teff, logg, m_h, abun, model_line, pradk, to_path):
else:
pass

content = ['Kurucz model: ' + 'TEFF {:.0f} GRAVITY {:.5f} LTE\n'.format(teff, logg)]
content = ['Kurucz model: ' + 'TEFF {:.1f} GRAVITY {:.5f} LTE\n'.format(teff, logg)]
content = content + ['TITLE SDSC GRID [{:+.1f}] VTURB 2.0 KM/S L/H 1.25\n'.format(m_h)]
content = content + [' OPACITY IFOP 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0\n']
content = content + [' CONVECTION ON 1.25 TURBULENCE OFF 0.00 0.00 0.00 0.00\n']
Expand Down Expand Up @@ -223,20 +223,20 @@ def KURUCZ_convert(model_path=None, vmicro=2.0, abun_change=None, converted_mode
# Convert the model files into MOOG format.

# Read and save the first two lines (except 'TITLE ') into header.
header = ['Kurucz model: ' + model_file.readline()]
header = header + [model_file.readline()]
try:
m_h = re.findall(r'\[(.*)\]', header[1])[0]
except IndexError:
m_h = 0
print(header)
header = model_file.readline() + model_file.readline()
teff, logg, m_h, vmicro_model, l_h = [float(s) for s in re.findall(r'[-+]?[0-9]*\.?[0-9]+', header)]
# try:
# m_h = re.findall(r'\[(.*)\]', header[1])[0]
# except IndexError:
# m_h = 0
# print(header)

# Read the abundance change as well as model lines.
temp = model_file.readline() + model_file.readline() + model_file.readline()

abun_list = ''
temp = model_file.readline()
while temp[:17] == ' ABUNDANCE CHANGE':
while 'ABUNDANCE CHANGE' in temp[:17]:
abun_list = abun_list + temp[17:]
temp = model_file.readline()
abun = np.array(abun_list.split(), dtype='f').reshape(int(len(abun_list.split())/2), 2)
Expand Down Expand Up @@ -272,8 +272,8 @@ def KURUCZ_convert(model_path=None, vmicro=2.0, abun_change=None, converted_mode
c_model_file = open(c_model_path, 'w')

# Header part
c_model_file.writelines(header[0])
c_model_file.writelines(header[1])
c_model_file.writelines('KURUCZ\n')
c_model_file.writelines('TEFF = {:.1f}, LOGG = {:.1f}, M/H = {:.1f}, VTURB = {:.1f}, L/H = {:.2f}\n'.format(teff, logg, m_h, vmicro_model, l_h))

# Model part
c_model_file.writelines('ntau= ' + str(model_linen) + '\n')
Expand Down
2 changes: 1 addition & 1 deletion pymoog/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def prepare_file(self, model_file=None, line_list=None, loggf_cut=None):

if line_list == None:
# Linelist file is not specified, will use built-in VALD linelist according to wavelength specification.
vald = line_data.read_linelist(MOOG_file_path + '/linelist/vald', loggf_cut=loggf_cut)
vald = line_data.read_linelist(MOOG_file_path + 'linelist/ges/ges_hfs_iso', loggf_cut=loggf_cut)
line_data.save_linelist(vald, MOOG_run_path + 'line.list', wav_start=self.start_wav, wav_end=self.end_wav)
self.line_list = 'line.list'
else:
Expand Down
9 changes: 9 additions & 0 deletions pymoog/temp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Kurucz model: EFF 4500. GRAVITY 3.00000 LTE
ITLE SDSC GRID [-2.0] VTURB 2.0 KM/S L/H 1.25
ntau= 3
ABUNDANCE CHANGE 9 -7.48 10 -3.95 11
ABUNDANCE CHANGE 15 -6.59 16 -4.83 17
ABUNDANCE CHANGE 21 -8.94 22 -7.05 23
2.0E00
NATOMS 0 -2.0
NMOL 0

0 comments on commit e075ca7

Please sign in to comment.