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

Many changes to io for better parsing. WDC functions work better

parent 26a66ca6
......@@ -37,9 +37,8 @@ def read_wdc_ae(wdc_filename):
# Open and make sure it is correct file
with open(wdc_filename) as wdc_file:
header = wdc_file.readline()
assert header[:8] == 'AEALAOAU', ('Does not seem to be a WDC AE file.'
+ 'First 8 characters: ' + header[:8]
assert header[:8] == 'AEALAOAU', \
'Does not seem to be a WDC AE file. First 8 chars: ' + header[:8]
# Parse
for line in wdc_file:
......@@ -72,7 +71,7 @@ def read_wdc_asy_sym(wdc_filename):
and puts it into a dictionary.
wdc_filename (str): Relative filename to read.
wdc_filename (str): Relative filename (or file handle no.) to read.
dict: of values.
......@@ -123,6 +122,10 @@ def read_wdc_asy_sym(wdc_filename):
for line in wdc_file:
# Parse
year = int(line[12:14])
if year < 70: # Starts from 1970 but only gives 2 digits
year += 2000
year += 1900
month = int(line[14:16])
day = int(line[16:18])
hour = int(line[19:21])
......@@ -272,15 +275,17 @@ def write_imf_input(data, outfilename="IMF.dat", enable_rb=True, **kwargs):
+ '\n')
def read_gm_log(filename, colnames=None, index_time=True):
def read_gm_log(filename, colnames=None, dtypes=None, index_time=True):
"""Make a dictionary out of the indeces outputted
from the GM model log.
filename (str): The filename as a string.
filename (str): The relative filename as a string. (or file handle no.)
colnames ([str]): (default: None) Supply the name of the columns.
If None it will use second line
of log file.
dtypes ([types]): (default: None) Provide types for the columns, if
None then all will be float.
index_time (bool): (default: True) Make a column of dt.datetime objects
in dictionary key 'Time [UT]'.
......@@ -294,7 +299,7 @@ def read_gm_log(filename, colnames=None, index_time=True):
dst ='run/GM/IO2/log_e20140215-100500.log')
# Plot AL indeces
plt.plot(geo['Time [UT]', geo['AL'])
plt.plot(geo['times', geo['AL'])
......@@ -316,13 +321,17 @@ def read_gm_log(filename, colnames=None, index_time=True):
for line_num, line in enumerate(logfile):
if line_num > 2: # First two lines are usually metadata
for col, data in enumerate(line.split()):
if dtypes:
data = dtypes[col](data)
data = float(data)
# datetime index
if index_time:
return_data['Time [UT]'] = []
return_data['times'] = []
for row, year in enumerate(return_data[colnames[1]]):
return_data['Time [UT]'].append(
int(return_data[colnames[2]][row]), # month
int(return_data[colnames[3]][row]), # day
......@@ -97,7 +97,7 @@ def get_omni_data(time_from, time_to, **kwargs):
# Initialize return dict
return_data = {}
return_data['Time [UT]'] = []
return_data['times'] = []
for name in col_names:
return_data[name] = []
......@@ -118,14 +118,25 @@ def get_omni_data(time_from, time_to, **kwargs):
+ cols[3], # minute
'%Y %j %H %M')
if time >= time_from and time <= time_to:
return_data['Time [UT]'].append(time)
# Assign the data from after the time columns (0:3)
for num, value in enumerate(cols[4:len(col_names)+4]):
if _check_bad_omni_num(value):
return return_data # dictionary with omni values where index is the row
def _check_bad_omni_num(value_string):
"""Returns true if bad or false if not"""
for char in value_string:
if char != '9' and char != '.':
return False
return True
def download_magnetogram_adapt(time, map_type='fixed', **kwargs):
'''This routine downloads GONG ADAPT magnetograms.
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