|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import numpy as np |
| 4 | +import re |
| 5 | +from datetime import datetime |
| 6 | +import matplotlib.pyplot as plt |
| 7 | + |
| 8 | +#----------------------------------------------------------------------------- |
| 9 | +# Read in the EUV CSV file. Get out: |
| 10 | +# - short and long wavelengths |
| 11 | +# - EUV parameters |
| 12 | +# - Absorption cross sections for N2, O2, and O |
| 13 | +#----------------------------------------------------------------------------- |
| 14 | + |
| 15 | +def read_euv_csv_file(file): |
| 16 | + |
| 17 | + fpin = open(file, 'r') |
| 18 | + |
| 19 | + iColStart = 5 |
| 20 | + iColEnd = -1 |
| 21 | + |
| 22 | + for line in fpin: |
| 23 | + cols = line.split(',') |
| 24 | + if (cols[0] == 'Short'): |
| 25 | + short = np.asarray(cols[iColStart:iColEnd], dtype = float) |
| 26 | + if (cols[0] == 'Long'): |
| 27 | + long = np.asarray(cols[iColStart:iColEnd], dtype = float) |
| 28 | + if (cols[0] == 'F74113'): |
| 29 | + f74113 = np.asarray(cols[iColStart:iColEnd], dtype = float) |
| 30 | + if (cols[0] == 'AFAC'): |
| 31 | + afac = np.asarray(cols[iColStart:iColEnd], dtype = float) |
| 32 | + if (cols[0] == 'N2' and cols[2] == 'abs'): |
| 33 | + n2cs = np.asarray(cols[iColStart:iColEnd], dtype = float) |
| 34 | + if (cols[0] == 'O2' and cols[2] == 'abs'): |
| 35 | + o2cs = np.asarray(cols[iColStart:iColEnd], dtype = float) |
| 36 | + if (cols[0] == 'O' and cols[2] == 'abs'): |
| 37 | + ocs = np.asarray(cols[iColStart:iColEnd], dtype = float) |
| 38 | + |
| 39 | + fpin.close() |
| 40 | + |
| 41 | + data = {'short': short * 1e-10, |
| 42 | + 'long': long * 1e-10, |
| 43 | + 'f74113': f74113 * 1e9 * 1e4, # /cm2 to /m2 |
| 44 | + 'afac': afac, |
| 45 | + 'ocross': ocs * 1e-22, |
| 46 | + 'o2cross': o2cs * 1e-22, |
| 47 | + 'n2cross': n2cs * 1e-22} |
| 48 | + |
| 49 | + return data |
| 50 | + |
| 51 | +#----------------------------------------------------------------------------- |
| 52 | +# Plot out spectrum to a file |
| 53 | +#----------------------------------------------------------------------------- |
| 54 | + |
| 55 | +def plot_spectrum(wavelengths_in_m, intensities, filename): |
| 56 | + |
| 57 | + fig = plt.figure(figsize = (10,5)) |
| 58 | + ax = fig.add_subplot(111) |
| 59 | + |
| 60 | + ax.scatter(wavelengths_in_m * 1e10, intensities) |
| 61 | + ax.set_xlabel('Wavelength (A)') |
| 62 | + ax.set_ylabel('Intensity (photons/m2/s)') |
| 63 | + |
| 64 | + fig.savefig(filename) |
| 65 | + plt.close() |
| 66 | + |
| 67 | +#----------------------------------------------------------------------------- |
| 68 | +# Plot var as a function of altitutde |
| 69 | +#----------------------------------------------------------------------------- |
| 70 | + |
| 71 | +def plot_value_vs_alt(alts, values, filename, var_name, is_log = False): |
| 72 | + |
| 73 | + fig = plt.figure(figsize = (5,10)) |
| 74 | + ax = fig.add_subplot(111) |
| 75 | + |
| 76 | + ax.plot(values, alts) |
| 77 | + ax.set_xlabel(var_name) |
| 78 | + ax.set_ylabel('Altitude (km)') |
| 79 | + if (is_log): |
| 80 | + ax.set_xscale('log') |
| 81 | + |
| 82 | + fig.savefig(filename) |
| 83 | + plt.close() |
| 84 | + |
0 commit comments