Skip to content

Commit

Permalink
Merge pull request #73 from MingjieJian/develop
Browse files Browse the repository at this point in the history
Merge Develop to master
  • Loading branch information
MingjieJian authored Apr 22, 2024
2 parents a2ce89e + f15338a commit 36dd7f3
Show file tree
Hide file tree
Showing 59 changed files with 3,412 additions and 2,214 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: pypi-publish

on: push
on:
push:
branches: [master]


jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.vscode/
__pycache__/
docs/_build/
build/
build/**
*.pyc
node_modeules/
2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023, Mingjie Jian
Copyright (c) 2024, Mingjie Jian

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7582434.svg)](https://doi.org/10.5281/zenodo.7582434) [![Documentation Status](https://readthedocs.org/projects/pymoog/badge/?version=latest)](https://pymoog.readthedocs.io/en/latest/?badge=latest)

## News

pymoog is now 1.0.0! The main drivers are all availalbe (binary, doflux, synpop and abpop newly added), with many bugs fixed.
Note that there are some breaking changes compared to the previous versions, and the description will be availabe in the [documentation](https://pymoog.readthedocs.io/en/latest/) soon.

Thanks the very useful synpop and abpop example provided by Charli Sakari.

-------------------------------------

`pymoog` is a python3 wrapper for running the LTE spectrum synthesis part of the code [MOOG](https://www.as.utexas.edu/~chris/moog.html) written by Chris Sneden.
It wraps up the (a bit) teidous steps for generating a synthetic spectra into four python commands, while retaining the functions provided by MOOG.
Besides, it also provides some other functions for analysing the MOOG result, mainly contribution function and fitting stellar parameters.
Expand Down
4 changes: 4 additions & 0 deletions build/lib/pymoog/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from . import synth
from . import doflux
from . import line_data
from . import line_analysis
from . import contri_func
from . import abfind
from . import blends
Expand All @@ -8,5 +10,7 @@
from . import binary
from . import internal
from . import mpfit
from . import synpop
from . import abpop

__version__ = '0.1.3'
115 changes: 7 additions & 108 deletions build/lib/pymoog/abfind.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/usr/bin/python
from . import moog_structure
from . import private
from . import line_data
from . import model
from . import rundir_num
import subprocess

MOOG_path = '{}/.pymoog/moog_nosm/moog_nosm_NOV2019/'.format(private.os.environ['HOME'])
# self.rundir_path = '{}/.pymoog/rundir/'.format(private.os.environ['HOME'])
MOOG_file_path = '{}/.pymoog/files/'.format(private.os.environ['HOME'])

class abfind(rundir_num.rundir_num):
def __init__(self, teff, logg, m_h, vmicro=2, mass=1, line_list='ges', prefix=''):
class abfind(moog_structure.moog_structure):
def __init__(self, teff, logg, m_h, vmicro=2, mass=1, line_list='ges', prefix='', vmicro_mode='flexible'):
'''
Initiate a abfind Instance and read the parameters.
Expand All @@ -27,109 +24,14 @@ def __init__(self, teff, logg, m_h, vmicro=2, mass=1, line_list='ges', prefix=''
prefix : str, default ''.
The prefix to be added to the name of rundir. Convenient when you want to find a specified rundir if there are many.
'''
super(abfind, self).__init__('{}/.pymoog/'.format(private.os.environ['HOME']), 'abfind', prefix=prefix)
super(abfind, self).__init__('abfind', prefix=prefix)
self.teff = teff
self.logg = logg
self.m_h = m_h
self.vmicro = vmicro
self.mass = mass
self.line_list = line_list

def prepare_file(self, model_file=None, model_format='moog', abun_change=None, atmosphere=1, lines=1, molecules=1, molecules_include=None, model_type='marcs', model_chem='st', model_geo='auto'):
'''
Prepare the model, linelist and control files for MOOG.
Can either provide stellar parameters and wavelengths or provide file names.
If fine name(s) provided, the files will be copied to working directory for calculation.
Parameters
----------
model_file : str, optional
The name of the model file. If not specified, the code will use internal model.
model_format : str, optional
The type of the INPUT model file. Default is "moog" (then no conversion of format will be done); can be "moog", "kurucz-atlas9", "kurucz-atlas12" or "marcs". Should left as it is when not providing the input model file.
abun_change : dict of pairs {int:float, ...}
Abundance change, have to be a dict of pairs of atomic number and [X/Fe] values.
atmosphere : int, default 1
The atmosphere value described in MOOG documention, section III.
lines : int, default 1
The lines value described in MOOG documention, section III.
molecules : int, default 1
The molecules value described in MOOG documention, section III.
molecules_include : list, default None
Molecules to be included to molecular calculation. Follows the MOOG notation.
model_type : str, default marcs
The type of internal atmosphere model. Must be kurucz or marcs.
model_chem : str, default st
The chemical composition of marcs model. Only valid when model_type is marcs.
model_geo : str, default auto
The geometry of MARCS model, either 's' for spherical, 'p' for plane-parallel or 'auto'.
'''

if model_file == None:
# Model file is not specified, will download Kurucz model according to stellar parameters.
model.interpolate_model(self.teff, self.logg, self.m_h, vmicro=self.vmicro, mass=self.mass, abun_change=abun_change, molecules_include=molecules_include, save_name=self.rundir_path + 'model.mod', model_type=model_type, chem=model_chem, geo=model_geo)
self.model_file = 'model.mod'
else:
# Model file is specified; record model file name and copy to working directory.
if model_format == 'moog':
private.subprocess.run(['cp', model_file, self.rundir_path], encoding='UTF-8', stdout=private.subprocess.PIPE)
self.model_file = model_file.split('/')[-1]
elif model_format[:6] == 'kurucz':
model.kurucz2moog(model_path=model_file, abun_change=abun_change, model_format=model_format[7:], molecules_include=molecules_include, converted_model_path=self.rundir_path + 'model.mod')
self.model_file = 'model.mod'
elif model_format == 'marcs':
marcs_model = model.read_marcs_model(model_file)
model.marcs2moog(marcs_model, self.rundir_path + 'model.mod', abun_change=abun_change, molecules_include=molecules_include)
self.model_file = 'model.mod'
else:
raise ValueError("The input model_type is not supported. Have to be either 'moog', 'kurucz' or 'marcs.")


# Create line list.
if isinstance(self.line_list, str):
# Linelist file have to be specified; record linelist file name and copy to working directory.
subprocess.run(['cp', self.line_list, self.rundir_path], encoding='UTF-8', stdout=subprocess.PIPE)
self.line_list = self.line_list.split('/')[-1]
elif isinstance(self.line_list, private.pd.DataFrame):
line_data.save_linelist(self.line_list.sort_values('id'), self.rundir_path + 'line.list')
self.line_list = 'line.list'
else:
raise TypeError('Type of input linelist have to be either str or pandas.DataFrame.')

# Create parameter file.
self.create_para_file(atmosphere=atmosphere, lines=lines)

def create_para_file(self, atmosphere=1, lines=1, molecules=1):
'''
Function for creating the parameter file of batch.par for abfind.
Parameters
----------
atmosphere : int, default 1
The atmosphere value described in MOOG documention, section III.
lines : int, default 1
The lines value described in MOOG documention, section III.
molecules : int, default 1
The molecules value described in MOOG documention, section III.
'''
MOOG_para_file = open(self.rundir_path + '/batch.par', 'w')
# Parameter list of MOOG: standard output file (1), summary output file (2), smoothed output file (3),
# begin wavelength, end wavelength, wavelength step;
# smoothing function, Gaussian FWHM, vsini, limb darkening coefficient,
# Macrotrubulent FWHM, Lorentzian FWHM
#MOOG_para_file = open('batch.par', 'w')
MOOG_contant = ["abfind\n",
"standard_out '{}'\n".format('MOOG.out1'),
"summary_out '{}'\n".format('MOOG.out2'),
"model_in '{}'\n".format(self.model_file),
"lines_in '{}'\n".format(self.line_list),
"atmosphere {}\n".format(atmosphere),
"lines {}\n".format(lines),
"molecules {}\n".format(molecules),
"terminal 'x11'\n",
]
MOOG_para_file.writelines(MOOG_contant)
MOOG_para_file.close()
self.line_list_in = line_list
self.vmicro_mode = vmicro_mode

def run_moog(self, output=False):
'''
Expand All @@ -146,9 +48,6 @@ def run_moog(self, output=False):
'''

MOOG_run = private.subprocess.run([MOOG_path + '/MOOGSILENT'], stdout=private.subprocess.PIPE, cwd=self.rundir_path)

# if unlock:
# self.unlock()

MOOG_run = str(MOOG_run.stdout, encoding = "utf-8").split('\n')
MOOG_output = []
Expand Down Expand Up @@ -205,6 +104,6 @@ def read_output(self, remove=True):
abfind_dict[ele_index] = abfind_s_df

if remove:
self.remove()
self.remove_rundir()

self.abfind_res = abfind_dict
Loading

0 comments on commit 36dd7f3

Please sign in to comment.