OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
parameters.py
Go to the documentation of this file.
1 import argparse
2 
3 parser = argparse.ArgumentParser(epilog="""
4  Passing a filename will estimate the desired parameter from the Rrs
5  contained in that file. Otherwise, a model will be trained (if not
6  already existing), and estimates will be made for the testing data.\n
7 """)
8 
9 parser.add_argument('--ifile', type=str, required=False)
10 parser.add_argument('--ofile', type=str, required=False)
11 
12 parser.add_argument("filename", nargs ="?", help="CSV file containing Rrs values to estimate from")
13 parser.add_argument("--model_loc", default="Weights", help="Location of trained model weights")
14 # parser.add_argument("--data_loc", default="/media/brandon/NASA/Data/Insitu", help="Location of in situ data")
15 # parser.add_argument("--sim_loc", default="/media/brandon/NASA/Data/Simulated", help="Location of simulated data")
16 parser.add_argument("--data_loc", default="D:/Data/Insitu", help="Location of in situ data")
17 parser.add_argument("--sim_loc", default="D:/Data/Simulated", help="Location of simulated data")
18 parser.add_argument("--n_redraws", default=50, type=int, help="Number of plot redraws during training (i.e. updates plot every n_iter / n_redraws iterations); only used with --plot_loss.")
19 parser.add_argument("--n_rounds", default=10, type=int, help="Number of models to fit, with median output as the final estimate")
20 
21 
22 ''' Flags '''
23 parser.add_argument("--threshold", default=None, type=float, help="Output the maximum prior estimate when the prior is above this threshold, and the weighted average estimate otherwise. Set to None, thresholding is not used")
24 parser.add_argument("--avg_est", action ="store_true", help="Use the prior probability weighted mean as the estimate; otherwise, use maximum prior")
25 parser.add_argument("--no_save", action ="store_true", help="Do not save the model after training")
26 parser.add_argument("--no_load", action ="store_true", help="Do load a saved model (and overwrite, if not no_save)")
27 parser.add_argument("--verbose", action ="store_true", help="Verbose output printing")
28 parser.add_argument("--silent", action ="store_true", help="Turn off all printing")
29 parser.add_argument("--plot_loss", action ="store_true", help="Plot the model loss while training")
30 parser.add_argument("--darktheme", action ="store_true", help="Use a dark color scheme in plots")
31 parser.add_argument("--animate", action ="store_true", help="Store the training progress as an animation (mp4)")
32 parser.add_argument("--save_data", action ="store_true", help="Save the data used for the given args")
33 parser.add_argument("--save_stats",action ="store_true", help="Store partial training statistics & estimates for later analysis")
34 parser.add_argument("--LOO_CV", action ="store_true", help="Leave-one-out cross validation")
35 
36 
37 ''' Flags which require model retrain if changed '''
38 update = parser.add_argument_group('Model Parameters', 'Parameters which require a new model to be trained if they are changed')
39 update.add_argument("--sat_bands", action ="store_true", help="Use bands specific to certain products when utilizing satellite retrieved spectra")
40 update.add_argument("--benchmark", action ="store_true", help="Train only on partial dataset, and use remaining to benchmark")
41 update.add_argument("--product", default="chl", help="Product to estimate")
42 update.add_argument("--sensor", default="OLI", help="Sensor to estimate from (See meta.py for available options)")
43 update.add_argument("--align", default=None, help="Comma-separated list of sensors to align data with; passing \"all\" uses all sensors (See meta.py for available options)")
44 update.add_argument("--model_lbl", default="", help="Label for a model")
45 update.add_argument("--seed", default=42, type=int, help="Random seed")
46 update.add_argument("--subset", default='', help="Comma-separated list of datasets to use when fetching data")
47 
48 
49 ''' Flags which have a yet undecided default value '''
50 flags = parser.add_argument_group('Model Flags', 'Flags which require a new model to be trained if they are changed')
51 
52 # flags.add_argument("--no_noise", action ="store_true", help="Do not add noise when training the model")
53 flags.add_argument("--use_noise", action ="store_true", help="Add noise when training the model")
54 
55 # flags.add_argument("--no_ratio", action ="store_true", help="Do not add band ratios as input features")
56 flags.add_argument("--use_ratio", action ="store_true", help="Add band ratios as input features")
57 
58 flags.add_argument("--use_auc", action ="store_true", help="Normalize input features using AUC")
59 
60 flags.add_argument("--use_tchlfix", action ="store_true", help="Correct chl for pheopigments")
61 # flags.add_argument("--no_tchlfix", action ="store_true", help="Do not correct chl for pheopigments")
62 
63 # flags.add_argument("--no_cache", action ="store_true", help="Do not use any cached data")
64 # flags.add_argument("--use_cache", action ="store_true", help="Use cached data, if available")
65 
66 flags.add_argument("--use_boosting", action ="store_true", help="Use boosting when training in multiple trials (no longer implemented)")
67 # flags.add_argument("--no_boosting",action ="store_true", help="Do not use boosting when training in multiple trials")
68 
69 flags.add_argument("--no_bagging", action ="store_true", help="Do not use bagging when training in multiple trials")
70 # flags.add_argument("--use_bagging", action ="store_true", help="Use bagging when training in multiple trials")
71 
72 flags.add_argument("--use_sim", action ="store_true", help="Use simulated training data")
73 
74 flags.add_argument("--use_excl_Rrs", action ="store_true", help="Drop raw Rrs features from the input when using ratio features")
75 flags.add_argument("--use_all_ratio", action ="store_true", help="Use exhaustive list of ratio features instead of only those found in literature (should be combined with --use_kbest)")
76 
77 flags.add_argument("--use_kbest", type=int, nargs='?', const=5, default=0, help="Select top K features to use as input, based on mutual information")
78 
79 
80 ''' Hyperparameters '''
81 hypers = parser.add_argument_group('Hyperparameters', 'Hyperparameters used in training the model (also requires model retrain if changed)')
82 hypers.add_argument("--n_iter", default=10000, type=int, help="Number of iterations to train the model")
83 hypers.add_argument("--n_mix", default=5, type=int, help="Number of gaussians to fit in the mixture model")
84 hypers.add_argument("--batch", default=128, type=int, help="Number of samples in a training batch")
85 hypers.add_argument("--n_hidden", default=100, type=int, help="Number of neurons per hidden layer")
86 hypers.add_argument("--n_layers", default=5, type=int, help="Number of hidden layers")
87 hypers.add_argument("--imputations", default=5, type=int, help="Number of samples used for imputation when handling NaNs in the target")
88 hypers.add_argument("--lr", default=1e-3, type=float, help="Learning rate")
89 hypers.add_argument("--l2", default=1e-3, type=float, help="L2 regularization")
90 hypers.add_argument("--epsilon", default=1e-3, type=float, help="Variance regularization (ensures covariance has a valid decomposition)")
91 
92 
93 dataset = parser.add_mutually_exclusive_group()
94 dataset.add_argument("--all_test", action="store_const", dest="dataset", const="all")
95 dataset.add_argument("--sentinel_paper", action="store_const", dest="dataset", const="sentinel_paper")
96 parser.set_defaults(dataset='all', use_sim=False)
97 
98 
99 
100 def get_args(kwargs={}, use_cmdline=True, **kwargs2):
101  kwargs2.update(kwargs)
102 
103  if use_cmdline: args = parser.parse_args()
104  else: args = parser.parse_args([])
105 
106  for k, v in kwargs2.items():
107  setattr(args, k, v)
108 
109  # use_all_ratio implies use_ratio
110  if getattr(args, 'use_all_ratio', False):
111  setattr(args, 'use_ratio', True)
112 
113  return args
def get_args(kwargs={}, use_cmdline=True, **kwargs2)
Definition: parameters.py:100