files_conversions.py
1.11 KB
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
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 28 10:22:25 2022
@author: frede
"""
from astropy.table import Table
import numpy as np
import matplotlib.pyplot as plt
filename = str(input('filename = ',))
test = Table.read(filename, format = 'ascii')
wavelength = test['col1'] #in nm
intensity = test['col2'] #in #photons s-1 cm-2 nm-1
''' constants '''
h = 6.62607015e-34*1e7 #in erg s
c = 299792458*1e9 #in nm s-1
converted_wavelength = wavelength
converted_intensity = intensity * (h*c)/(converted_wavelength)
#in erg s-1 cm-2 nm-1 sr-1
test_2 = Table([converted_wavelength , converted_intensity], names=('col1' , 'col2'))
test_2.meta['comments'] = ['wavelength (nm)' , 'intensity (erg s-1 cm-2 nm-1)']
test_2.write('draine1978.txt', format = 'ascii', overwrite = True)
plt.figure()
plt.plot(wavelength,intensity,'k')
plt.ylabel('Spectrum intensity (#photons s$^-1$ cm$^-2$ nm$^-1$)')
plt.xlabel('Wavelength (nm)')
plt.figure()
plt.semilogy(converted_wavelength,converted_intensity*1e-4,'k')
plt.ylabel('Spectrum intensity (W $m^{-2}$ $nm^{-1}$ sr$^-1$)')
plt.xlabel('Wavelength (nm)')
plt.axis([0 , 2100 , 1.8e-10 , 2e-10])