Skip to content

Commit

Permalink
v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cef committed May 24, 2016
1 parent 0fa9cf3 commit a553c4a
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 84 deletions.
21 changes: 7 additions & 14 deletions INSTRUCTIONS.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,27 @@ STEPS

1. Replace 'default_work_dir' with your appropriate baseline MESA directory.
The example here uses the 3M model input physics from Fields et al. 2016.
The 'rates_tables/rates_list.txt' MUST list the rate you wish to sample
The 'rates_tables/rates_list.txt' MUST list the rate(s) you wish to sample
and the text file containing your to be generated sampled rate.

2. Edit the 'reac_samp.py' file to adjust the rates you will include in
your sampling scheme. Nomenclature in example follows the MESA reaction
handles found in 'mesa/data/rates_data/reactions.list' and
'mesa/rates/private/rates_names.f90'. The example samples the 12C(a,g)16O
reaction.
2. Provide the raw STARLIB rate data for the rates in your scheme and place
in 'starlib_raw_rates' with naming following MESA nomenclature. Include a
'rates_list.txt' file using the format from 'mesa/data/rates_data/rates_tables'.

3. Provide the raw STARLIB rate data for the rates in your scheme and place
in 'starlib_raw_rates' with naming following MESA nomenclature. The
example includes the raw STARLIB rate data for the 12C(a,g)16O
reaction.

4. Execute reac_samp.make_dirs(n),reac_samp.make_var_rates(n) where 'n' is the
3. Execute reac_samp.make_dirs(n),reac_samp.make_var_rates(n) where 'n' is the
number of samples in your scheme.

OUTPUT

'rate_varitation_factors.txt' the random numbers used for the i'th sampled model.

- The first column is the number of the rate used in your scheme, 0->M for M sampled rates. In the example, only 12C(a,g)16O was sampled, so '0' corresponds to the 12C(a,g)16O.
- The first column is the number of the rate used in your scheme, 0->M for M sampled
rates.

- The second column is the random number that is used to generate the i'th sample for the M'th reaction.

'example_grid/' grid of monte carlo stellar models each with a set of 'rate_tables' containing sampled rates to be read by MESA for each individual run.

'reac_samp_example.pdf' a diagram generated once 'c12_ag_o16_example.py' is generated to show the sampled rates for 12C(a,g)16O compared to the median value in STARLIB.



Expand Down
Empty file modified README.txt
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion default_work_dir/rate_tables/rates_list.txt

This file was deleted.

40 changes: 40 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
### Imports
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import reac_samp

n = input('Please type the number of samples in your scheme: ');

reac_samp.make_dirs(n),reac_samp.make_var_rates(n)

'''
fig = plt.figure()
# median rate dsitrubtion from STARLIB
med_data = (np.loadtxt('starlib_raw_rates/r_c12_ag_o16.txt',dtype=float, usecols=(0, 1,2)))
t9=(med_data[:,0])
rr=(med_data[:,1])
fu=(med_data[:,2])
# plot median for comparison
lines = plt.plot(t9,rr,linewidth=3.0,marker='o',markeredgewidth=1.0,ms=2.0,zorder=10,color='k')
#plot sampled rate distributions for c12(a,g)o16
for i in range(1,n+1):
data=(np.loadtxt('example_grid/'+str(i)+'/rate_tables/r_c12_ag_o16.txt',dtype=float,skiprows=3))
t9=(data[:,0]/10.)
rr=(data[:,1])
plt.hold(True)
lines = plt.plot(t9,rr,linewidth=0.5,marker='o',markeredgewidth=1.0,ms=1.0)
plt.ylabel(r'$\rm{Reaction \ Rate}$',fontsize=24)
plt.xlabel(r'$T \ (\rm{GK})$',fontsize=24)
plt.annotate(r'$^{12}\rm{C}(\alpha,\gamma)^{16}O$',xy=(0.075, 0.8),xycoords='axes fraction',fontsize=20)
plt.tight_layout()
plt.savefig("reac_samp_example.pdf")
plt.show()
'''



2 changes: 2 additions & 0 deletions get_rate_labels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
awk '{print $1}' ./starlib_raw_rates/rates_list.txt > 'rate_labels.txt'
22 changes: 14 additions & 8 deletions reac_samp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,27 @@

### Imports
import numpy as np
import shutil,os,sys,re
import shutil,subprocess,os
from os import remove, close
from tempfile import mkstemp
from shutil import move
from shutil import copyfile


# EDIT THIS TO CHANGE WHICH RATES ARE IN YOUR SCHEME
# THIS EXAMPLE ONLY SAMPLES THE C12(A,G)O16 REACTION

'''
rates_list = [
'r_c12_ag_o16',\
]


'''

rates_list = []
subprocess.call(['./get_rate_labels.sh'])
with open("rate_labels.txt") as f:
rates_list = [line.rstrip() for line in f]
os.remove('rate_labels.txt')

"""
# SAMPLING SCHEME USED IN FIELDS ET AL. 2016, APJ - http://arxiv.org/abs/1603.06666
rates_list = [
Expand Down Expand Up @@ -89,6 +96,7 @@ def replace(file_path, pattern, subst):

# copy default directory and number it according to i'th variant
def make_dirs(N_var):
copyfile('./starlib_raw_rates/rates_list.txt','./default_work_dir/rate_tables/rates_list.txt' )
for i in range(1,N_var+1):
shutil.copytree('default_work_dir','example_grid/'+str(i))
return
Expand All @@ -111,7 +119,7 @@ def make_var_rates(N_var):
samp_ind = []
for i in range(1,N_var+1):
for j in range(len(rates_list)):
data=(np.loadtxt('starlib_raw_rates/'+str(rates_list[j])+'.txt',dtype=float, usecols=(0, 1,2)))
data=(np.loadtxt('starlib_raw_rates/'+str(rates_list[j])+'.txt',dtype=float, usecols=(0, 1,2),skiprows=1))
t9=(10.*data[:,0])
rr=(data[:,1])
fu=(data[:,2])
Expand All @@ -128,7 +136,5 @@ def make_var_rates(N_var):
np.savetxt('rate_varitation_factors.txt', np.column_stack([samp_ind, rec]),fmt=['%i',' %1.8f\t'])
return




make_dirs(50),make_var_rates(50)

Binary file modified reac_samp.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions starlib_raw_rates/.gitignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
61 changes: 0 additions & 61 deletions starlib_raw_rates/r_c12_ag_o16.txt

This file was deleted.

0 comments on commit a553c4a

Please sign in to comment.