Page MenuHomec4science

parameter_map.py
No OneTemporary

File Metadata

Created
Fri, Nov 22, 11:27

parameter_map.py

# Copyright (C) 2018-2020 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import numpy as np
from numbers import Number
from rrompy.utilities.base.types import DictAny
from rrompy.utilities.exception_manager import RROMPyException, RROMPyAssert
__all__ = ['parameterMap']
def parameterMap(pMap = 1., npar : int = None) -> DictAny:
"""
Constructor of dictionary with keys "F" and "B" for evaluation of forward
and backward (inverse) map.
"""
if isinstance(pMap, (Number,)):
if npar is None: npar = 1
pMap = [pMap] * npar
if isinstance(pMap, (tuple,)): pMap = list(pMap)
if isinstance(pMap, (dict,)):
if (("F" not in pMap.keys() and "f" not in pMap.keys())
or ("B" not in pMap.keys() and "b" not in pMap.keys())):
raise RROMPyException("Keys missing from parameter map dict.")
parameterMap = {}
parameterMap["F"] = pMap["F"] if "F" in pMap.keys() else pMap["f"]
parameterMap["B"] = pMap["B"] if "B" in pMap.keys() else pMap["b"]
return parameterMap
if isinstance(pMap, (list,)):
if npar is not None:
RROMPyAssert(len(pMap), npar,
"Length of parameter map scaling exponent.")
parameterMap = {"F":[], "B":[]}
for e in pMap:
if np.isclose(e, 1., atol = 1e-10):
parameterMap["F"] += [('x')]
parameterMap["B"] += [('x')]
else:
parameterMap["F"] += [('x', '**', e)]
parameterMap["B"] += [('x', '**', 1. / e)]
return parameterMap
raise RROMPyException(("Parameter map not recognized. Only dict with keys "
"'F' and 'B', or list of scaling exponents are "
"allowed."))

Event Timeline