Blame view

radiation_fields.py 6.28 KB
bb489272   Jalabert   initial commit
1
2
3
4
5
6
7
8
9
10
11
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 23 09:55:18 2022

@author: frede
"""
import numpy as np
from astropy.table import Table

'''

eb0979a8   Jalabert   delete useless sp...
12
This program calculates the scaling factor of the radiation field G0 relative
bb489272   Jalabert   initial commit
13
14
to the data of an object or a set of objects radiating for given distances
A file containing my G0 values with the associated distance will then be created
eb0979a8   Jalabert   delete useless sp...
15
16

We take the standard Habing value for the interstellar medium 5.6x10^-14 ergs cm-3
bb489272   Jalabert   initial commit
17
18
between 91.2 and 240nm as normalization factor of G0

eb0979a8   Jalabert   delete useless sp...
19
20
The file to be used must contain in column 1 the wavelength in nm,
and in column 2 the intensity per wavelength per sr (in erg cm-2 s-1 nm-1 sr-1).
bb489272   Jalabert   initial commit
21
22
23
24
Each column should not have a name

Example of execution of the program for the star of 10 solar radius HD200775,
for a distance to the star at 20pc :
eb0979a8   Jalabert   delete useless sp...
25

bb489272   Jalabert   initial commit
26
27
28
radiation_field(filename='HD200775_RF.txt', star_radius=10, parsec=20)

If I want to generate a hundred values of G0 :
eb0979a8   Jalabert   delete useless sp...
29

bb489272   Jalabert   initial commit
30
31
32
33
34
radiation_field('HD200775_RF.txt', 10, 20, ISRF=False, RF_list=True)

The program will tell me that for 20pc my first value of G0 is not of the order of 1e6,
and will make me enter a new value of distance (in pc) until finding G0 of the order of 1e6

eb0979a8   Jalabert   delete useless sp...
35
36
If I want to calculate G0 for the interstellar medium
with an approach described by Habing (1968),
bb489272   Jalabert   initial commit
37
38
39
40
41
(using Habing file with datas of wavelength and intensity per wavelength per sr) :

radiation_field('habing1968.txt', 1, 1, ISRF=True)

For the interstellar medium, the parameters star_radius, parsec and RF_list
eb0979a8   Jalabert   delete useless sp...
42
are no longer important;
bb489272   Jalabert   initial commit
43
44
45
46
47
48
49
50
51
52
53
54
the part of the program executed will be independent of them

'''

''' Constants '''
h = 6.62607015e-34 #Planck constant in J s
c = 299792458 #Light speed in m s-1

''' Conversions '''
ev = 1.602176634e-19 # 1 ev = 1.602176634e-19 J and value of electron charge

def radiation_field(filename, star_radius , parsec, ISRF=False, RF_list=False):
eb0979a8   Jalabert   delete useless sp...
55

bb489272   Jalabert   initial commit
56
    """
eb0979a8   Jalabert   delete useless sp...
57

bb489272   Jalabert   initial commit
58
    ----------
eb0979a8   Jalabert   delete useless sp...
59
    filename : str,
bb489272   Jalabert   initial commit
60
61
62
63
64
        name of the .txt containing intensity and wavelength data
    parsec : float,
        distance in parsec from the star
    star_radius : float,
        star radius, in unit of solar radius
eb0979a8   Jalabert   delete useless sp...
65
    ISRF : bool,
bb489272   Jalabert   initial commit
66
67
68
69
        Interstellar Radiation Field; if true, then the filename is a file for ISRF
        if false, the radiation field of a star is studied
    RF_list: bool,
        If false, the calculation of G0 is done for a given distance,
eb0979a8   Jalabert   delete useless sp...
70
71
72
73
74
        if true, it is done for a hundred distances whose input distance
        will correspond to a G0 of the order of 1e6

    returns the value of G0 for a given distance, the distance,
    wavelengths from 91.2nm (13.6ev) to 2 microns, the corresponding intensity
bb489272   Jalabert   initial commit
75
    at a distance d_0, the energy intensity, the energy, the values of ISRF and RF_list
eb0979a8   Jalabert   delete useless sp...
76

bb489272   Jalabert   initial commit
77
    -------
eb0979a8   Jalabert   delete useless sp...
78

bb489272   Jalabert   initial commit
79
80
81
    """

    ''' association of file data '''
eb0979a8   Jalabert   delete useless sp...
82
    wave_intensity = Table.read(filename, format='ascii')
9b18e070   Jalabert   feat add and corr...
83
84
    wavelength = wave_intensity['col1'] #in nm
    wavelength_intensity = wave_intensity['col2'] #in erg cm-2 s-1 nm-1 sr-1
bb489272   Jalabert   initial commit
85
86
    #=> intensity per nm per sr

0917f1d1   Jalabert   feat add commenta...
87
    ''' useful parameters '''
bb489272   Jalabert   initial commit
88
89
90
91
92
93
    radiation_field = []
    distance = []
    energy = ( ( (h/ev) * (c*1e2) ) / (wavelength*1e-7) )[::-1] #in ev
    r = star_radius*7e10 #radius of the star in cm
    d_0 = 3.086e18*parsec #1pc = 3.086e18cm

eb0979a8   Jalabert   delete useless sp...
94
    ''' energy intensity in erg s-1 cm-2 sr-1 eV-1 '''
bb489272   Jalabert   initial commit
95
    energy_intensity = wavelength_intensity[::-1] * ( (h/ev) * (c*1e9) )/(energy**2)
eb0979a8   Jalabert   delete useless sp...
96

bb489272   Jalabert   initial commit
97
98
    ''' indentation '''
    i=0
eb0979a8   Jalabert   delete useless sp...
99

bb489272   Jalabert   initial commit
100
    if ISRF :
eb0979a8   Jalabert   delete useless sp...
101

bb489272   Jalabert   initial commit
102
103
104
105
106
107
108
        ''' Radiation Field '''
        intensity_range = (wavelength >= 91.2) & (wavelength <= 240)
        #far UV range, 91.2nm corresponding to 13.6ev
        g_0 = np.trapz( 2*np.pi * wavelength_intensity[intensity_range], wavelength[intensity_range])/(5.6e-14 * c*1e2)
        #g_0 dimensionless
        radiation_field.append(g_0)
        distance.append(0)
eb0979a8   Jalabert   delete useless sp...
109

bb489272   Jalabert   initial commit
110
    else:
eb0979a8   Jalabert   delete useless sp...
111

bb489272   Jalabert   initial commit
112
113
        if RF_list :
            while i < 100:
eb0979a8   Jalabert   delete useless sp...
114

bb489272   Jalabert   initial commit
115
116
117
118
119
                ''' distance '''
                if i == 0 :
                    d = d_0
                else:
                    d = 5*i * d_0
eb0979a8   Jalabert   delete useless sp...
120

bb489272   Jalabert   initial commit
121
122
                ''' initialization '''
                g_0 = 0
eb0979a8   Jalabert   delete useless sp...
123

bb489272   Jalabert   initial commit
124
125
126
                ''' geometrical dillution '''
                diluted_intensity = wavelength_intensity*(r/d)**2
                #intensity diluted and extincted in erg cm-2 s-1 nm-1 sr-1
eb0979a8   Jalabert   delete useless sp...
127

bb489272   Jalabert   initial commit
128
129
                '''energy intensity in erg s-1 cm-2 sr-1 eV-1'''
                energy_intensity = diluted_intensity[::-1] * ( (h/ev) * (c*1e9) )/(energy**2)
eb0979a8   Jalabert   delete useless sp...
130

bb489272   Jalabert   initial commit
131
132
133
134
135
                ''' Radiation Field '''
                intensity_range = (wavelength >= 91.2) & (wavelength <= 240)
                g_0 = np.trapz(2 * np.pi * diluted_intensity[intensity_range], wavelength[intensity_range])/(5.6e-14 * c * 1e2)
                distance.append(d)
                radiation_field.append(g_0)
eb0979a8   Jalabert   delete useless sp...
136

bb489272   Jalabert   initial commit
137
138
139
140
141
142
143
                if (radiation_field[0] >= 2e6 or radiation_field[0] < 1e6):
                    radiation_field = []
                    parsec = float(input('radiation_field[0] = {}, set a value of parsec such that radiation_field[0] is proportional to 1e6 : '.format(g_0),))
                    distance = []
                    d_0 = 3.086e18*parsec
                    i = 0
                else:
eb0979a8   Jalabert   delete useless sp...
144
                    i = i + 1
bb489272   Jalabert   initial commit
145
        else:
eb0979a8   Jalabert   delete useless sp...
146

bb489272   Jalabert   initial commit
147
148
149
            d = d_0
            ''' geometrical dillution '''
            diluted_intensity = wavelength_intensity*(r/d)**2
eb0979a8   Jalabert   delete useless sp...
150

bb489272   Jalabert   initial commit
151
152
            '''energy intensity in erg s-1 cm-2 sr-1 eV-1'''
            energy_intensity = diluted_intensity[::-1] * ( (h/ev) * (c*1e9) )/(energy**2)
eb0979a8   Jalabert   delete useless sp...
153

bb489272   Jalabert   initial commit
154
155
156
157
158
            ''' Radiation Field '''
            intensity_range = (wavelength >= 91.2) & (wavelength <= 240)
            g_0 = np.trapz(2 * np.pi * diluted_intensity[intensity_range], wavelength[intensity_range])/(5.6e-14 * c * 1e2)
            distance.append(d)
            radiation_field.append(g_0)
eb0979a8   Jalabert   delete useless sp...
159

0917f1d1   Jalabert   feat add commenta...
160
    ''' creation of data files '''
bb489272   Jalabert   initial commit
161
162
163
164
165
166
167
    document_1 = Table([wavelength , wavelength_intensity] , names =('col1','col2'))
    document_1.meta['comments'] = ['wavelength (nm)' , 'intensity (erg s-1 cm-2 nm-1 sr-1)']
    document_1.write('intensity_per_wavelength.txt', format = 'ascii', overwrite=True)

    document_2 = Table([distance , radiation_field], names =('col1', 'col2'))
    document_2.meta['comments'] = ['distance (cm)' , 'radiation field (dimensionless)']
    document_2.write('radiation_field_per_distance.txt', format = 'ascii', overwrite=True)
eb0979a8   Jalabert   delete useless sp...
168

bb489272   Jalabert   initial commit
169
    return radiation_field[0], distance[0], wavelength, wavelength_intensity, energy_intensity, energy, ISRF, RF_list