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

Writing IMF files fixed, will not write nans anymore

parent 1a0466a7
......@@ -4,6 +4,7 @@ Here are tools to read and write files relating to SWMF.
"""
import datetime as dt
import numpy as np
from .tools import _make_line
......@@ -68,21 +69,27 @@ def write_imf_input(imf_data, filename='IMF.dat', **kwargs):
file_imf.write(_make_line(command)+'\n')
# write dat file
def justified(str_list, width=7):
'Returns justified'
return [s.rjust(width) for s in str_list]
file_imf.write('\n'+' '.join(justified(columns_dat)))
file_imf.write('\n'+' '.join(_justified(columns_dat)))
file_imf.write('\n#START\n')
lines = []
for index, _time in enumerate(imf_data[column_keys[0]]):
dirty = False # Don't write line if it has NaN
line = _time_repr(_time)
for key in column_keys[1:]:
line += [str(round(imf_data[key][index], 2))]
line = ' '.join(justified(line))
lines += line + '\n'
if np.isnan(imf_data[key][index]):
dirty = True
if not dirty:
line = ' '.join(_justified(line))
lines += line + '\n'
file_imf.writelines(lines)
def _justified(str_list, width=7):
'Returns justified list from string list'
return [s.rjust(width) for s in str_list]
def read_wdc_ae(wdc_filename):
"""Read an auroral electrojet (AE) indeces from Kyoto's World Data Center
text file into a dictionary of lists.
......
......@@ -9,7 +9,7 @@ __author__ = 'Qusai Al Shidi'
__email__ = 'qusai@umich.edu'
import datetime as dt
from ftplib import FTP, all_errors
import ftplib
import gzip
from operator import itemgetter
import shutil
......@@ -208,7 +208,7 @@ def get_omni_data(time_from, time_to, **kwargs):
# Assign the data from after the time columns
for col_name, value in zip(omni['cols'],
cols[omni['ntimecols']:]):
if _check_bad_omni_num(value):
if _bad_omni_num(value):
return_data[col_name] += [None]
else:
return_data[col_name] += [float(value)]
......@@ -228,7 +228,7 @@ def _urls_omni_hires(time_from, time_to):
dtstart=time_from,
until=dt.datetime(time_to.year,
time_to.month,
1)):
1)+dt.timedelta(32)):
suffix = 'omni_min'
suffix += str(date.year) + str(date.month).zfill(2)
suffix += '.asc'
......@@ -247,7 +247,7 @@ def _urls_omni_lores(time_from, time_to):
yield prefix+suffix
def _check_bad_omni_num(value_string):
def _bad_omni_num(value_string):
"""Returns true if bad or false if not. Bad numbers usually just have 9s
in omni.
"""
......
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