Commit eb0979a8444970f54ebfbabd8840486cfaa0ccc5
1 parent
41c0408a
Exists in
master
delete useless spaces
Showing
1 changed file
with
40 additions
and
40 deletions
Show diff stats
radiation_fields.py
... | ... | @@ -9,37 +9,37 @@ from astropy.table import Table |
9 | 9 | |
10 | 10 | ''' |
11 | 11 | |
12 | -This program calculates the scaling factor of the radiation field G0 relative | |
12 | +This program calculates the scaling factor of the radiation field G0 relative | |
13 | 13 | to the data of an object or a set of objects radiating for given distances |
14 | 14 | A file containing my G0 values with the associated distance will then be created |
15 | - | |
16 | -We take the standard Habing value for the interstellar medium 5.6x10^-14 ergs cm-3 | |
15 | + | |
16 | +We take the standard Habing value for the interstellar medium 5.6x10^-14 ergs cm-3 | |
17 | 17 | between 91.2 and 240nm as normalization factor of G0 |
18 | 18 | |
19 | -The file to be used must contain in column 1 the wavelength in nm, | |
20 | -and in column 2 the intensity per wavelength per sr (in erg cm-2 s-1 nm-1 sr-1). | |
19 | +The file to be used must contain in column 1 the wavelength in nm, | |
20 | +and in column 2 the intensity per wavelength per sr (in erg cm-2 s-1 nm-1 sr-1). | |
21 | 21 | Each column should not have a name |
22 | 22 | |
23 | 23 | Example of execution of the program for the star of 10 solar radius HD200775, |
24 | 24 | for a distance to the star at 20pc : |
25 | - | |
25 | + | |
26 | 26 | radiation_field(filename='HD200775_RF.txt', star_radius=10, parsec=20) |
27 | 27 | |
28 | 28 | If I want to generate a hundred values of G0 : |
29 | - | |
29 | + | |
30 | 30 | radiation_field('HD200775_RF.txt', 10, 20, ISRF=False, RF_list=True) |
31 | 31 | |
32 | 32 | The program will tell me that for 20pc my first value of G0 is not of the order of 1e6, |
33 | 33 | and will make me enter a new value of distance (in pc) until finding G0 of the order of 1e6 |
34 | 34 | |
35 | -If I want to calculate G0 for the interstellar medium | |
36 | -with an approach described by Habing (1968), | |
35 | +If I want to calculate G0 for the interstellar medium | |
36 | +with an approach described by Habing (1968), | |
37 | 37 | (using Habing file with datas of wavelength and intensity per wavelength per sr) : |
38 | 38 | |
39 | 39 | radiation_field('habing1968.txt', 1, 1, ISRF=True) |
40 | 40 | |
41 | 41 | For the interstellar medium, the parameters star_radius, parsec and RF_list |
42 | -are no longer important; | |
42 | +are no longer important; | |
43 | 43 | the part of the program executed will be independent of them |
44 | 44 | |
45 | 45 | ''' |
... | ... | @@ -52,34 +52,34 @@ c = 299792458 #Light speed in m s-1 |
52 | 52 | ev = 1.602176634e-19 # 1 ev = 1.602176634e-19 J and value of electron charge |
53 | 53 | |
54 | 54 | def radiation_field(filename, star_radius , parsec, ISRF=False, RF_list=False): |
55 | - | |
55 | + | |
56 | 56 | """ |
57 | - | |
57 | + | |
58 | 58 | ---------- |
59 | - filename : str, | |
59 | + filename : str, | |
60 | 60 | name of the .txt containing intensity and wavelength data |
61 | 61 | parsec : float, |
62 | 62 | distance in parsec from the star |
63 | 63 | star_radius : float, |
64 | 64 | star radius, in unit of solar radius |
65 | - ISRF : bool, | |
65 | + ISRF : bool, | |
66 | 66 | Interstellar Radiation Field; if true, then the filename is a file for ISRF |
67 | 67 | if false, the radiation field of a star is studied |
68 | 68 | RF_list: bool, |
69 | 69 | If false, the calculation of G0 is done for a given distance, |
70 | - if true, it is done for a hundred distances whose input distance | |
71 | - will correspond to a G0 of the order of 1e6 | |
72 | - | |
73 | - returns the value of G0 for a given distance, the distance, | |
74 | - wavelengths from 91.2nm (13.6ev) to 2 microns, the corresponding intensity | |
70 | + if true, it is done for a hundred distances whose input distance | |
71 | + will correspond to a G0 of the order of 1e6 | |
72 | + | |
73 | + returns the value of G0 for a given distance, the distance, | |
74 | + wavelengths from 91.2nm (13.6ev) to 2 microns, the corresponding intensity | |
75 | 75 | at a distance d_0, the energy intensity, the energy, the values of ISRF and RF_list |
76 | - | |
76 | + | |
77 | 77 | ------- |
78 | - | |
78 | + | |
79 | 79 | """ |
80 | 80 | |
81 | 81 | ''' association of file data ''' |
82 | - wave_intensity = Table.read( filename, format='ascii' ) | |
82 | + wave_intensity = Table.read(filename, format='ascii') | |
83 | 83 | wavelength = wave_intensity['col1'] #in nm |
84 | 84 | wavelength_intensity = wave_intensity['col2'] #in erg cm-2 s-1 nm-1 sr-1 |
85 | 85 | #=> intensity per nm per sr |
... | ... | @@ -91,14 +91,14 @@ def radiation_field(filename, star_radius , parsec, ISRF=False, RF_list=False): |
91 | 91 | r = star_radius*7e10 #radius of the star in cm |
92 | 92 | d_0 = 3.086e18*parsec #1pc = 3.086e18cm |
93 | 93 | |
94 | - ''' energy intensity in erg s-1 cm-2 sr-1 eV-1 ''' | |
94 | + ''' energy intensity in erg s-1 cm-2 sr-1 eV-1 ''' | |
95 | 95 | energy_intensity = wavelength_intensity[::-1] * ( (h/ev) * (c*1e9) )/(energy**2) |
96 | - | |
96 | + | |
97 | 97 | ''' indentation ''' |
98 | 98 | i=0 |
99 | - | |
99 | + | |
100 | 100 | if ISRF : |
101 | - | |
101 | + | |
102 | 102 | ''' Radiation Field ''' |
103 | 103 | intensity_range = (wavelength >= 91.2) & (wavelength <= 240) |
104 | 104 | #far UV range, 91.2nm corresponding to 13.6ev |
... | ... | @@ -106,34 +106,34 @@ def radiation_field(filename, star_radius , parsec, ISRF=False, RF_list=False): |
106 | 106 | #g_0 dimensionless |
107 | 107 | radiation_field.append(g_0) |
108 | 108 | distance.append(0) |
109 | - | |
109 | + | |
110 | 110 | else: |
111 | - | |
111 | + | |
112 | 112 | if RF_list : |
113 | 113 | while i < 100: |
114 | - | |
114 | + | |
115 | 115 | ''' distance ''' |
116 | 116 | if i == 0 : |
117 | 117 | d = d_0 |
118 | 118 | else: |
119 | 119 | d = 5*i * d_0 |
120 | - | |
120 | + | |
121 | 121 | ''' initialization ''' |
122 | 122 | g_0 = 0 |
123 | - | |
123 | + | |
124 | 124 | ''' geometrical dillution ''' |
125 | 125 | diluted_intensity = wavelength_intensity*(r/d)**2 |
126 | 126 | #intensity diluted and extincted in erg cm-2 s-1 nm-1 sr-1 |
127 | - | |
127 | + | |
128 | 128 | '''energy intensity in erg s-1 cm-2 sr-1 eV-1''' |
129 | 129 | energy_intensity = diluted_intensity[::-1] * ( (h/ev) * (c*1e9) )/(energy**2) |
130 | - | |
130 | + | |
131 | 131 | ''' Radiation Field ''' |
132 | 132 | intensity_range = (wavelength >= 91.2) & (wavelength <= 240) |
133 | 133 | g_0 = np.trapz(2 * np.pi * diluted_intensity[intensity_range], wavelength[intensity_range])/(5.6e-14 * c * 1e2) |
134 | 134 | distance.append(d) |
135 | 135 | radiation_field.append(g_0) |
136 | - | |
136 | + | |
137 | 137 | if (radiation_field[0] >= 2e6 or radiation_field[0] < 1e6): |
138 | 138 | radiation_field = [] |
139 | 139 | parsec = float(input('radiation_field[0] = {}, set a value of parsec such that radiation_field[0] is proportional to 1e6 : '.format(g_0),)) |
... | ... | @@ -141,22 +141,22 @@ def radiation_field(filename, star_radius , parsec, ISRF=False, RF_list=False): |
141 | 141 | d_0 = 3.086e18*parsec |
142 | 142 | i = 0 |
143 | 143 | else: |
144 | - i = i + 1 | |
144 | + i = i + 1 | |
145 | 145 | else: |
146 | - | |
146 | + | |
147 | 147 | d = d_0 |
148 | 148 | ''' geometrical dillution ''' |
149 | 149 | diluted_intensity = wavelength_intensity*(r/d)**2 |
150 | - | |
150 | + | |
151 | 151 | '''energy intensity in erg s-1 cm-2 sr-1 eV-1''' |
152 | 152 | energy_intensity = diluted_intensity[::-1] * ( (h/ev) * (c*1e9) )/(energy**2) |
153 | - | |
153 | + | |
154 | 154 | ''' Radiation Field ''' |
155 | 155 | intensity_range = (wavelength >= 91.2) & (wavelength <= 240) |
156 | 156 | g_0 = np.trapz(2 * np.pi * diluted_intensity[intensity_range], wavelength[intensity_range])/(5.6e-14 * c * 1e2) |
157 | 157 | distance.append(d) |
158 | 158 | radiation_field.append(g_0) |
159 | - | |
159 | + | |
160 | 160 | ''' creation of data files ''' |
161 | 161 | document_1 = Table([wavelength , wavelength_intensity] , names =('col1','col2')) |
162 | 162 | document_1.meta['comments'] = ['wavelength (nm)' , 'intensity (erg s-1 cm-2 nm-1 sr-1)'] |
... | ... | @@ -165,5 +165,5 @@ def radiation_field(filename, star_radius , parsec, ISRF=False, RF_list=False): |
165 | 165 | document_2 = Table([distance , radiation_field], names =('col1', 'col2')) |
166 | 166 | document_2.meta['comments'] = ['distance (cm)' , 'radiation field (dimensionless)'] |
167 | 167 | document_2.write('radiation_field_per_distance.txt', format = 'ascii', overwrite=True) |
168 | - | |
168 | + | |
169 | 169 | return radiation_field[0], distance[0], wavelength, wavelength_intensity, energy_intensity, energy, ISRF, RF_list | ... | ... |