Page MenuHomec4science

base.py
No OneTemporary

File Metadata

Created
Thu, May 9, 23:02
# Copyright (C) 2018 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 rrompy.utilities.base.types import Np1D, Tuple
from rrompy.utilities.exception_manager import RROMPyException
__all__ = ['sparsekinds', 'sparseMap']
sparsekinds = ["UNIFORM", "LOBATTO"]
def sparseMap(x:Np1D, lims:Tuple[np.complex, np.complex], kind:str,
forward : bool = True) -> Np1D:
"""forward: U([-1, 1]) -> lims"""
kind = kind.upper().strip().replace(" ", "")
if kind == "UNIFORM":
if forward: return .5 * ((lims[-1] - lims[0]) * x + lims[0] + lims[-1])
return np.real((2. * x - lims[0] - lims[-1]) / (lims[-1] - lims[0]))
elif kind == "LOBATTO":
if forward:
x0 = np.cos(.5 * np.pi * (1. - x))
return sparseMap(x0, lims, "UNIFORM", True)
x0 = sparseMap(x, lims, "UNIFORM", False)
return 1. - 2. / np.pi * np.arccos(np.clip(x0, -1., 1.))
else:
raise RROMPyException("Sparse map kind not recognized.")

Event Timeline