This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jesper Dramsch <[email protected]> Co-authored-by: S. Hahner <[email protected]>
- Loading branch information
1 parent
7fcaf43
commit 201b5c4
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from abc import ABC | ||
from abc import abstractmethod | ||
|
||
import numpy as np | ||
|
||
|
||
class BasePressureLevelScaler(ABC): | ||
"""Configurable method converting pressure level of variable to PTL scaling. | ||
Scaling variables depending on pressure levels (50 to 1000). | ||
""" | ||
|
||
def __init__(self, slope: float = 1.0 / 1000, minimum: float = 0.0) -> None: | ||
self.slope = slope | ||
self.minimum = minimum | ||
|
||
@abstractmethod | ||
def scaler(self, plev) -> np.ndarray: ... | ||
|
||
|
||
class LinearPressureLevelScaler(BasePressureLevelScaler): | ||
"""Linear with slope self.slope, yaxis shift by self.minimum.""" | ||
|
||
def scaler(self, plev) -> np.ndarray: | ||
return plev * self.slope + self.minimum | ||
|
||
|
||
class ReluPressureLevelScaler(BasePressureLevelScaler): | ||
"""Linear above self.minimum, taking constant value self.minimum below.""" | ||
|
||
def scaler(self, plev) -> np.ndarray: | ||
return max(self.minimum, plev * self.slope) | ||
|
||
|
||
class PolynomialPressureLevelScaler(BasePressureLevelScaler): | ||
"""Polynomial scaling, (slope * plev)^2, yaxis shift by self.minimum.""" | ||
|
||
def scaler(self, plev) -> np.ndarray: | ||
return (self.slope * plev) ** 2 + self.minimum | ||
|
||
|
||
class NoPressureLevelScaler(BasePressureLevelScaler): | ||
"""Constant scaling by 1.0.""" | ||
|
||
def __init__(self, slope=0.0, minimum=1.0) -> None: | ||
assert ( | ||
minimum == 1.0 and slope == 0 | ||
), "self.minimum must be 1.0 and self.slope 0.0 for no scaling to fit with definition of linear function." | ||
super().__init__(slope=0.0, minimum=1.0) | ||
|
||
def scaler(self, plev) -> np.ndarray: | ||
# no scaling, always return 1.0 | ||
return 1.0 |