Source code for opendrift.readers.operators.ops

from abc import abstractmethod
from numbers import Number
from typing import List

[docs] class Combine:
[docs] def __add__(self, other): from .readerops import Combined as ReaderCombined from .numops import Combined as NumCombined from ..basereader import BaseReader if isinstance(other, Number): return NumCombined.add(other, self) elif isinstance(other, BaseReader): return ReaderCombined(self, other, lambda a, b: a + b) else: return NotImplemented
[docs] def __mul__(self, other): from .numops import Combined as NumCombined if isinstance(other, Number): return NumCombined.mul(other, self) else: return NotImplemented
[docs] def __truediv__(self, other): from .numops import Combined as NumCombined if isinstance(other, Number): return NumCombined.div(other, self) else: return NotImplemented
[docs] def __sub__(self, other): return self + (-1 * other)
[docs] class Filter: @property @abstractmethod def variables(self) -> List[str]: pass
[docs] def filter_vars(self, vars): """ Only keep the specified variables. """ from .filter import FilterVariables return FilterVariables(self, vars)
[docs] def exclude_vars(self, vars): """ Remove the specified variables. """ from .filter import FilterVariables vars = list(set(self.variables) - set(vars)) return FilterVariables(self, vars)