Skip to content

Commit

Permalink
Merge pull request #422 from sentinel-hub/feat/linear-function-dtype-…
Browse files Browse the repository at this point in the history
…update

Linear function dtype update
  • Loading branch information
zigaLuksic committed Jun 13, 2022
2 parents 85fad12 + a519b64 commit e1a04be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions features/eolearn/features/feature_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import datetime as dt
import logging
from functools import partial
from typing import Any, Optional, Tuple
from typing import Any, Optional, Tuple, Union

import numpy as np

Expand Down Expand Up @@ -213,7 +213,12 @@ class LinearFunctionTask(MapFeatureTask):
"""

def __init__(
self, input_features, output_features=None, slope: float = 1, intercept: float = 0, dtype: Optional[str] = None
self,
input_features,
output_features=None,
slope: float = 1,
intercept: float = 0,
dtype: Union[str, type, np.dtype, None] = None,
):
"""
:param input_features: Feature or features on which the function is used.
Expand All @@ -226,12 +231,14 @@ def __init__(
"""
if output_features is None:
output_features = input_features
super().__init__(input_features, output_features, slope=slope, intercept=intercept, dtype=dtype)
self.dtype = dtype if dtype is None else np.dtype(dtype)

super().__init__(input_features, output_features, slope=slope, intercept=intercept)

def map_method(self, feature: np.ndarray, slope: float, intercept: float, dtype: Optional[str]) -> np.ndarray:
def map_method(self, feature: np.ndarray, slope: float, intercept: float) -> np.ndarray:
"""A method where feature is multiplied by a slope"""
rescaled_feature = feature * slope + intercept
return rescaled_feature if dtype is None else rescaled_feature.astype(dtype)
return rescaled_feature if self.dtype is None else rescaled_feature.astype(self.dtype)


class SpatialResizeTask(EOTask):
Expand Down
2 changes: 1 addition & 1 deletion features/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
eo-learn-core
numba>=0.53.0
numpy
pillow
pillow>=9.0.0
python-dateutil
scikit-image>=0.19.0
scikit-learn
Expand Down

0 comments on commit e1a04be

Please sign in to comment.