-
Notifications
You must be signed in to change notification settings - Fork 1
/
predict_indices.py
77 lines (56 loc) · 2.28 KB
/
predict_indices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Do it for one index or for all indices?
import os
import argparse # parse command line arguments
import pandas as pd
import xarray as xr
from PCRR import PCRR # Custom model class
# 1. Train the model on the training observations
# 2. Make predictions
class data_class(object):
"""Class to hold all necessary data
with methods to clean up the data"""
def __init__(self, args):
try:
self.df = pd.read_csv(args.y_train)
except:
print('Provide path to valid .csv file with indices')
try:
self.nc = xr.open_dataset(args.x_train)
except:
print('Provide path to valid .nc file with pressure anomalies')
def cleanup_df(self):
time = pd.date_range(start='1950-01', end='2017-09', freq='MS')
# Drop year and month columns, replace with a datetime index
# So that it corresponds with the time dimension in the .nc file with input data
self.df = df.drop(['yyyy', 'mm'], axis=1).set_index(time)
self.df[self.df == -99.90] = np.nan # Set NaNs
self.df = self.df.drop(['Expl.Var.'], axis=1) # Drop columns that we don't need
def get_y_train(self, coi='NAO'):
pass
def get_x_train(self):
pass
def train_model(args):
pass
def main():
parser = argparse.ArgumentParser(
description='Predict COIs with PCA-RR based on historical training data')
parser.add_argument('x_train', type=str,
help='Path. Input data: .nc file with pressure anomalies')
parser.add_argument('y_train', type=str,
help='Path. Input data: .csv file with observed indices')
parser.add_argument('x_test', type=str,
help='Path. .nc file with inputs to make predictions')
parser.add_argument('coi', type=str, default='NAO',
help='Index to predict')
parser.add_argument('-nc', '--n_comp', type=int, default=20,
help='Number of principal components to use')
args = parser.parse_args()
print('Reading in the training data')
data = data_class(args)
x_train = data.get_x_train()
y_train = data.get_y_train()
x_test = data.get_x_test()
print('Training the model...')
model =
if __name__ == "__main__":
main()