Commit 5c2fec8a authored by Clément Haëck's avatar Clément Haëck
Browse files

Fix HF_inv data

parent e63e44b1
......@@ -10,6 +10,7 @@ import tol_colors as tc
import lib
import lib.data.HF_TS
import lib.data.hists
import lib.data.HF_inv
# plt.switch_backend('agg')
......@@ -41,7 +42,7 @@ def add_args(parser):
parser.add_argument('-plot', action='store_true')
args = lib.get_args(['region', 'year', 'fixes', 'grid_file'],
args = lib.get_args(['region', 'year', 'fixes', 'grid_file', 'season'],
add_args=add_args)
args['fixes']['Y'] = args['year']
PLOT = args['plot']
......@@ -126,9 +127,8 @@ for idx in hf.idx.values:
dpi=150)
ofile = path.join(lib.root_data, args['region'], 'HF',
args['grid_file'] + '_inversion_times_{:d}.txt'.format(
args['year']))
args['Y'] = args['year']
ofile = lib.data.HF_inv.get_filename(args)
with open(ofile, 'w') as f:
for t in inv_times:
print(*t, file=f)
......@@ -8,12 +8,13 @@ import lib.data
ARGS_DIR = {'region', 'season'}
defaults = {'season': 'spring'}
pregex = ("%(grid_file:rgx=.*)_inversion_times_%(Y).txt")
def get_root(args=None, **kwargs):
args = lib.data.process_args(ARGS_DIR, args, replace_defaults=defaults,
**kwargs,)
root = path.join(lib.root_data, args['region'], 'HF', 'inversion',
root = path.join(lib.root_data, args['region'], 'HF', 'Inversion',
args['season'])
return root
......@@ -23,7 +24,7 @@ auto_attr = lib.data.create_data(__name__, pregex, get_root, ARGS_DIR,
def get_data(args=None, to_datetime=False, **kwargs):
finder = get_finder(args, **kwargs)
finder = auto_attr['get_finder'](args, **kwargs)
inv_times = {}
for file in finder.get_files():
with open(file, 'r') as f:
......@@ -32,3 +33,7 @@ def get_data(args=None, to_datetime=False, **kwargs):
year = int(date[:4])
if to_datetime:
date = datetime.strptime(date, '%Y-%m-%d')
if year not in inv_times:
inv_times[year] = {}
inv_times[year][idx] = date
return inv_times
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