OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
MDN.utils Namespace Reference

Classes

class  CustomUnpickler
 

Functions

def ignore_warnings (func)
 
def find_wavelength (k, waves, validate=True, tol=5)
 
def closest_wavelength (k, waves, validate=True, tol=5)
 
def safe_int (v)
 
def get_wvl (nc_data, key)
 
def line_messages (messages, nbars=1)
 
def get_labels (wavelengths, slices, n_out=None)
 
def compress (path, overwrite=False)
 
def uncompress (path, overwrite=False)
 
def store_pkl (filename, output)
 
def read_pkl (filename)
 
def cache (filename, recache=False)
 
def using_feature (args, flag)
 
def split_data (x_data, other_data=[], n_train=0.5, n_valid=0, seed=None, shuffle=True)
 
def mask_land (data, bands, threshold=0.1, verbose=False)
 
def get_tile_data (filenames, sensor, allow_neg=True, rhos=False, anc=False, **kwargs)
 
def generate_config (args, create=True, verbose=True)
 
def get_data (args)
 

Function Documentation

◆ cache()

def MDN.utils.cache (   filename,
  recache = False 
)
Decorator for caching function outputs 

Definition at line 145 of file utils.py.

◆ closest_wavelength()

def MDN.utils.closest_wavelength (   k,
  waves,
  validate = True,
  tol = 5 
)
Value of closest wavelength 

Definition at line 35 of file utils.py.

◆ compress()

def MDN.utils.compress (   path,
  overwrite = False 
)
Compress a folder into a .zip archive 

Definition at line 95 of file utils.py.

◆ find_wavelength()

def MDN.utils.find_wavelength (   k,
  waves,
  validate = True,
  tol = 5 
)
Index of closest wavelength 

Definition at line 26 of file utils.py.

◆ generate_config()

def MDN.utils.generate_config (   args,
  create = True,
  verbose = True 
)
Create a config file for the current settings, and store in
a folder location determined by certain parameters: 
    MDN/model_loc/sensor/model_lbl/model_uid/config
"model_uid" is computed within this function, but a value can 
also be passed in manually via args.model_uid in order to allow
previous MDN versions to run.


Definition at line 293 of file utils.py.

◆ get_data()

def MDN.utils.get_data (   args)
Main function for gathering datasets 

Definition at line 616 of file utils.py.

◆ get_labels()

def MDN.utils.get_labels (   wavelengths,
  slices,
  n_out = None 
)
Helper to get label for each target output. Assumes 
that any variable in <slices> which has more than a 
single slice index, will have an associated wavelength
label. 

Usage:
    wavelengths = [443, 483, 561, 655]
    slices = {'bbp':slice(0,4), 'chl':slice(4,5), 'tss':slice(5,6)}
    n_out  = 5
    labels = get_labels(wavelengths, slices, n_out) 
        # labels -> ['bbp443', 'bbp483', 'bbp561', 'bbp655', 'chl']


Definition at line 76 of file utils.py.

◆ get_tile_data()

def MDN.utils.get_tile_data (   filenames,
  sensor,
  allow_neg = True,
  rhos = False,
  anc = False,
**  kwargs 
)
Gather the correct Rrs/rhos bands from a given scene, as well as ancillary features if necessary 

Definition at line 243 of file utils.py.

◆ get_wvl()

def MDN.utils.get_wvl (   nc_data,
  key 
)
Get all wavelengths associated with the given key, available within the netcdf 

Definition at line 47 of file utils.py.

◆ ignore_warnings()

def MDN.utils.ignore_warnings (   func)
Decorator to silence all warnings (Runtime, User, Deprecation, etc.) 

Definition at line 16 of file utils.py.

◆ line_messages()

def MDN.utils.line_messages (   messages,
  nbars = 1 
)
Allow multiline message updates via tqdm. 
Need to call print() after the tqdm loop, 
equal to the number of messages which were
printed via this function (to reset cursor).

nbars is the number of tqdm bars the line
messages come after.

Usage:
    nbars = 2
    for i in trange(5):
        for j in trange(5, leave=False):
            messages = [i, i/2, i*2]
            line_messages(messages, nbars)
    for _ in range(len(messages) + nbars - 1): print()


Definition at line 53 of file utils.py.

◆ mask_land()

def MDN.utils.mask_land (   data,
  bands,
  threshold = 0.1,
  verbose = False 
)
Modified Normalized Difference Water Index, or NDVI if 1500nm+ is not available 

Definition at line 211 of file utils.py.

◆ read_pkl()

def MDN.utils.read_pkl (   filename)
Helper to read pickle file 

Definition at line 140 of file utils.py.

◆ safe_int()

def MDN.utils.safe_int (   v)
Parse int if possible, and return None otherwise 

Definition at line 41 of file utils.py.

◆ split_data()

def MDN.utils.split_data (   x_data,
  other_data = [],
  n_train = 0.5,
  n_valid = 0,
  seed = None,
  shuffle = True 
)
Split the given data into training, validation, and testing 
subsets, randomly shuffling the original data order.


Definition at line 176 of file utils.py.

◆ store_pkl()

def MDN.utils.store_pkl (   filename,
  output 
)
Helper to write pickle file 

Definition at line 134 of file utils.py.

◆ uncompress()

def MDN.utils.uncompress (   path,
  overwrite = False 
)
Uncompress a .zip archive 

Definition at line 103 of file utils.py.

◆ using_feature()

def MDN.utils.using_feature (   args,
  flag 
)
Certain hyperparameter flags have a yet undecided default value,
which means there are two possible names: using the feature, or 
not using it. This method simply combines both into a single 
boolean signal, which indicates whether to add the feature. 
For example:
    use_flag = hasattr(args, 'use_ratio') and args.use_ratio
    no_flag  = hasattr(args, 'no_ratio') and not args.no_ratio 
    signal   = use_flag or no_flag  # if true, we add ratios
becomes
    signal = using_feature(args, 'ratio') # if true, we add ratios  


Definition at line 158 of file utils.py.