-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradmc3d_dustopac_setup.py
72 lines (49 loc) · 2.65 KB
/
radmc3d_dustopac_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import numpy as np
import os
import shutil
"""
Tyler Baines
March 29, 2019
This script generates the dust opacity input file that will be read by radmc.
Dust Opacity Library used contains DSharp opacities with mie scattering matrices
at various grain sizes. file name to be
"""
def dustopac_setup(logagrain):
# grain sizes used to make dust opac files in logaritmic space
# Fine gridding up to 4 coarse grid to 5
# this reason is because of time to make dust opac model bhmie code
available_logagrain_S1 = np.linspace(-2,5,1000) # orginal models to made
available_logagrain_S1 = available_logagrain_S1[available_logagrain_S1 < 4] # make correction here
available_logagrain_S2 = np.linspace(4,5,25) # coarse grid of large grains
available_logagrain_S2 = np.append(available_logagrain_S2, 4.033)
# combine both fine and coarse grids and round values to 4 to match dust opacity filename format
available_logagrain = np.round(np.concatenate([available_logagrain_S1, available_logagrain_S2]) ,4)
parentDIR = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
# loop through grain sizes that are in dust opacity library and copy them over
for agrain in logagrain:
# condition to find closest respectable value of grain size model file
agrain_close = available_logagrain[(np.abs(available_logagrain - agrain)).argmin()]
dust_file = f'dustkapscatmat_DSHARPmix_{agrain_close}_-1_5_500_181_0.05_20_5.0_True.inp'
source = os.path.join(parentDIR, 'DustKappaScatmat Library', dust_file)
destination = dust_file[:-34] + '.inp'
shutil.copy2(source, destination)
# end of loop
# get all dust species name that were copied to be written to file
dust_species = [i for i in os.listdir() if i.startswith('dustkapscatmat_DSHARPmix_')]
nspecies = len(dust_species)
with open('dustopac.inp', 'w+') as f:
# Write formating section
f.write('2\n') # iformat
f.write(f'{nspecies}\n') # number species to be used
f.write('-----------------------------\n') # Stellar information: centered
# Write species sections
for i, dopac in enumerate(dust_species):
f.write(f'inputstyle[{i}]\n')
f.write('iquantum[0]\n')
f.write(f'{dopac}\n')
f.write('-----------------------------\n')
return
#Testing purposes
#dustopac_setup(np.array([-2.01, 0.003]))
#dustopac_setup([-2.01])
#$dustopac_setup(-2.01, 0.003)