Commit a2ce5349 authored by Qusai Al Shidi's avatar Qusai Al Shidi 💬
Browse files

Just have the python header.

parent f4c7b4fc
#!/usr/bin/env python3
"""
cleanomnidata.py
This script is to clean solar wind files to input into SWMF that has been retrieved from OMNIWeb.
"""
import sys
from omni2swmf import clean
from omni2swmf import read_data
USAGE_TEXT = "Usage:\n \
./cleanomnidata.py input.dat ouput.dat\n \
input.dat:\n\t \
Filename of input that has already been converted to SWMF solar wind file through omniweb2swmf.py.\n \
output.dat:\n\t \
Filename of output that will be cleaned."
def main():
"""
Program run.
"""
args = sys.argv
try:
data = read_data(args[1])
ifile = open(args[1], 'r')
except:
print("Please specify input file.")
print(USAGE_TEXT)
sys.exit(1)
try:
ofile = open(args[2], 'w')
except:
print("Please specify output file.")
print(USAGE_TEXT)
sys.exit(1)
b_x = clean(data['bx'])
b_y = clean(data['by'])
b_z = clean(data['bz'])
v_x = clean(data['vx'])
v_y = clean(data['vy'])
v_z = clean(data['vz'])
dens = clean(data['dens'])
temp = clean(data['temp'])
linenum = 0
for line in ifile:
if linenum < 3:
ofile.write(line)
else:
ofile.write(line[:22] + ' ' +
str(b_x[linenum-3])[:5] + ' ' +
str(b_y[linenum-3])[:5] + ' ' +
str(b_z[linenum-3])[:5] + ' ' +
str(v_x[linenum-3])[:7] + ' ' +
str(v_y[linenum-3])[:7] + ' ' +
str(v_z[linenum-3])[:7] + ' ' +
str(dens[linenum-3])[:7] + ' ' +
str(temp[linenum-3])[:7] + '\n')
linenum += 1
ifile.close()
ofile.close()
main()
#!/usr/bin/env python3
"""
Plot the cleaned omni data
"""
import sys
import numpy as np
import matplotlib.pyplot as plt
from omni2swmf import read_data
from omni2swmf import clean
START_DATE = 14
END_DATE = 18
def plotv():
""" Plot magnetic fields """
args = sys.argv
try:
data = read_data(args[1])
except:
print("Please provide the cleaned omni file as input.")
plt.subplot(3, 1, 1)
x_axis = np.linspace(START_DATE, END_DATE, np.size(data['bx']))
plt.plot(x_axis, clean(data['vx']))
plt.ylabel('$V_x$ [km s$^{-1}$]')
plt.subplot(3, 1, 2)
plt.plot(x_axis, clean(data['vy']))
plt.ylabel('$V_y$ [km s$^{-1}$]')
plt.subplot(3, 1, 3)
plt.plot(x_axis, clean(data['vz']))
plt.ylabel('$V_z$ [km s$^{-1}$]')
plt.xlabel('Date')
plt.tight_layout()
plt.show()
def plotb():
""" Plot magnetic fields """
args = sys.argv
try:
data = read_data(args[1])
except:
print("Please provide the cleaned omni file as input.")
plt.subplot(3, 1, 1)
x_axis = np.linspace(START_DATE, END_DATE, np.size(data['bx']))
plt.plot(x_axis, clean(data['bx']))
plt.ylabel('$B_x$ [nT]')
plt.subplot(3, 1, 2)
plt.plot(x_axis, clean(data['by']))
plt.ylabel('$B_y$ [nT]')
plt.subplot(3, 1, 3)
plt.plot(x_axis, clean(data['bz']))
plt.ylabel('$B_z$ [nT]')
plt.xlabel('Date')
plt.tight_layout()
plt.show()
def plotnt():
""" Plot magnetic fields """
args = sys.argv
try:
data = read_data(args[1])
except:
print("Please provide the cleaned omni file as input.")
plt.subplot(2, 1, 1)
x_axis = np.linspace(START_DATE, END_DATE, np.size(data['bx']))
plt.plot(x_axis, clean(data['dens']))
plt.ylabel('Density [$1/cm^{-3}$]')
plt.subplot(2, 1, 2)
plt.plot(x_axis, clean(data['temp']))
plt.ylabel('$T$ [K]')
plt.xlabel('Date')
plt.tight_layout()
plt.show()
plotnt()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment