Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

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

Removed deprecated functions. Will write new ones.

parent 5e00d819
...@@ -6,7 +6,6 @@ TODO: Move pandas dependancy elsewhere. ...@@ -6,7 +6,6 @@ TODO: Move pandas dependancy elsewhere.
""" """
import datetime as dt import datetime as dt
import numpy as np
def read_wdc_ae(wdc_filename): def read_wdc_ae(wdc_filename):
...@@ -147,60 +146,6 @@ def read_wdc_asy_sym(wdc_filename): ...@@ -147,60 +146,6 @@ def read_wdc_asy_sym(wdc_filename):
return return_data return return_data
def read_omni_csv(filename, filtering=False, **kwargs):
"""Take an OMNI csv file from cdaweb.sci.gsfc.nasa.gov
and turn it into a pandas.DataFrame.
Args:
fnames (dict): dict with filenames from omni .lst files.
The keys must be: density, temperature,
magnetic_field, velocity
filtering (bool): default=False Remove points where the value
is >sigma (default: sigma=3) from mean.
**kwargs:
coarseness (int): default=3, Number of standard deviations
above which to remove if filtering=True.
clean (bool): default=True, Clean the omni data of bad data points
Returns:
pandas.DataFrame: object with solar wind data
Make sure to download the csv files with cdaweb.sci.gsfc.nasa.gov
the header seperated into a json file for safety.
This only tested with OMNI data specifically.
"""
# TODO: This needs a lot of work
import pandas as pd
# Read the csv files and set the index to dates
colnames = ['Time', 'Bx [nT]', 'By [nT]', 'Bz [nT]',
'Vx [km/s]', 'Vy [km/s]', 'Vz [km/s]',
'Rho [n/cc]', 'T [K]']
with open(filename, 'r') as datafile:
data = pd.read_csv(datafile, names=colnames, skiprows=1)
data.set_index(pd.to_datetime(data[data.columns[0]]), inplace=True)
data.drop(columns=data.columns[0], inplace=True)
data.index.name = "Time [UT]"
# clean bad data
if kwargs.get('clean', True):
data["By [nT]"] = data["By [nT]"][data["By [nT]"].abs() < 80.]
data["Bx [nT]"] = data["Bx [nT]"][data["Bx [nT]"].abs() < 80.]
data["Bz [nT]"] = data["Bz [nT]"][data["Bz [nT]"].abs() < 80.]
data["Rho [n/cc]"] = data["Rho [n/cc]"][data["Rho [n/cc]"] < 500.]
data["Vx [km/s]"] = data["Vx [km/s]"][data["Vx [km/s]"].abs() < 2000.]
data["Vz [km/s]"] = data["Vz [km/s]"][data["Vz [km/s]"].abs() < 1000.]
data["Vy [km/s]"] = data["Vy [km/s]"][data["Vy [km/s]"].abs() < 1000.]
data["T [K]"] = data["T [K]"][data["T [K]"] < 1.e7]
if filtering:
_coarse_filtering(data, kwargs.get('coarseness', 3))
return data.interpolate().bfill().ffill()
def _coarse_filtering(data, coarseness=3): def _coarse_filtering(data, coarseness=3):
"""Applies coarse filtering to a pandas.DataFrame""" """Applies coarse filtering to a pandas.DataFrame"""
for column in data.columns: for column in data.columns:
...@@ -209,74 +154,6 @@ def _coarse_filtering(data, coarseness=3): ...@@ -209,74 +154,6 @@ def _coarse_filtering(data, coarseness=3):
data[column] = data[data[column].abs() < mean+coarseness*sigma][column] data[column] = data[data[column].abs() < mean+coarseness*sigma][column]
def write_imf_input(data, outfilename="IMF.dat", enable_rb=True, **kwargs):
"""Writes the pandas.DataFrame into an input file
that SWMF can read as input IMF (IMF.dat).
Args:
data: pandas.DataFrame object with solar wind data
outfilename: The output file name for ballistic solar wind data.
(default: "IMF.dat")
enable_rb: Enables solar wind input for the radiation belt model.
(default: True)
**kwargs:
gse (bool): (default: False) Use GSE coordinates instead of GSM.
Other paramaters:
gse: (default=False)
Use GSE coordinate system for the file instead of GSM default.
"""
# Generate BATS-R-US solar wind input file
with open(outfilename, 'w') as outfile:
outfile.write("CSV files downloaded from ")
outfile.write("https://cdaweb.gsfc.nasa.gov/\n")
if kwargs.get('gse', False):
outfile.write("#COOR\nGSE\n")
outfile.write("yr mn dy hr min sec msec bx by bz vx vy vz dens temp\n")
outfile.write("#START\n")
for index, rows in data.iterrows():
outfile.write(index.strftime("%Y %m %d %H %M %S") + ' ')
outfile.write(index.strftime("%f")[:3] + ' ')
outfile.write(str(rows['Bx [nT]'])[:7] + ' ')
outfile.write(str(rows['By [nT]'])[:7] + ' ')
outfile.write(str(rows['Bz [nT]'])[:7] + ' ')
outfile.write(str(rows['Vx [km/s]'])[:7] + ' ')
outfile.write(str(rows['Vy [km/s]'])[:7] + ' ')
outfile.write(str(rows['Vz [km/s]'])[:7] + ' ')
outfile.write(str(rows['Rho [n/cc]'])[:7] + ' ')
outfile.write(str(rows['T [K]'])[:7] + ' ')
outfile.write('\n')
# Generate RBE model solar wind input file
if enable_rb:
with open("RB.SWIMF", 'w') as rbfile:
# Choose first element as t=0 header (unsure if this is safe)
rbfile.write(data.index[0].strftime("%Y, %j, %H ")
+ "! iyear, iday, ihour corresponding to t=0\n")
swlag_time = None
if swlag_time in kwargs:
rbfile.write(str(kwargs["swlag_time"]) + " "
+ "! swlag time in seconds "
+ "for sw travel to subsolar\n")
# Unsure what 11902 means but following example file
rbfile.write("11902 data "
+ "P+ NP NONLIN P+ V (MOM)\n")
# Quantity header
rbfile.write("dd mm yyyy hh mm ss.ms "
+ "#/cc km/s\n")
for index, rows in data.iterrows():
rbfile.write(index.strftime("%d %m %Y %H %M %S.%f")
+ " "
+ str(rows['Rho [n/cc]'])[:8]
+ " "
# Speed magnitude
+ str(np.sqrt(rows['Vx [km/s]']**2
+ rows['Vy [km/s]']**2
+ rows['Vz [km/s]']**2))[:8]
+ '\n')
def read_gm_log(filename, colnames=None, dtypes=None, index_time=True): def read_gm_log(filename, colnames=None, dtypes=None, index_time=True):
"""Make a dictionary out of the indeces outputted """Make a dictionary out of the indeces outputted
from the GM model log. from the GM model log.
......
Markdown is supported
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