def _parse_pars(pars) -> Dict: """ Takes dictionary of parameters, converting values to required type and providing defaults for missing values. Args: pars: Parameters dictionary. Returns: Dictionary of converted (and optionally validated) parameters. """ # Fallback to default for missing values and perform conversion. for k in PARAM_CONVERSION: if pars.get(k) is None: pars[k] = PARAM_CONVERSION[k][1] # _logger.warning(f"No value found for parameter '{k}'. Using "f"default value {pars[k]}.") else: conversion_func = PARAM_CONVERSION[k][0] if conversion_func: try: pars[k] = conversion_func(pars[k]) except ValueError as e: _logger.error(f"Unable to convert '{k}': {pars[k]} to " f"expected type {conversion_func.__name__}.") raise e # Fallback to default for missing paths. for p in DEFAULT_TO_OBS_DIR: if pars.get(p) is None: pars[p] = pars[OBS_DIR] return pars
def find_min_mean(mean_sds, grid): """ Determine the ref pixel block with minimum mean value :param list mean_sds: List of mean standard deviations from each reference pixel grid :param list grid: List of ref pixel coordinates tuples :return: Tuple of (refy, refx) with minimum mean :rtype: tuple """ log.debug('Ranking ref pixel candidates based on mean values') try: refp_index = np.nanargmin(mean_sds) return grid[refp_index] except RefPixelError as v: log.error(v) return v