Skip to content
forked from pydata/xarray

Commit

Permalink
Better rescaling.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Aug 20, 2018
1 parent 9ac15ef commit 76f988f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions xarray/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def get_clean_interp_index(arr, dim, method, use_coordinate=True, **kwargs):
# The division can change the nearest-neighbour
# when compared to pandas (which does not divide).
# Let's keep that compatitibility
index = (index - index.min())
index = (index - index.mean())
if len(index) > 1:
index /= index.std()
index /= np.max(np.abs(index))

except (TypeError, ValueError):
# pandas raises a TypeError
Expand Down Expand Up @@ -417,11 +417,13 @@ def _floatize_x(x, new_x):
# We assume that the most of the bits are used to represent the
# offset (min(x)) and the variation (x - min(x)) can be
# represented by float.
# Let's be defensive and always rescale (x)
xmin = np.min(x[i])
xstd = np.std(x[i].astype(np.float64))
x[i] = (x[i] - xmin).astype(np.float64) / xstd
new_x[i] = (new_x[i] - xmin).astype(np.float64) / xstd
# Let's be defensive and always rescale x to be in [0, 1]
# Remove minimum instead of mean allows us to handle datetime
xfloat = (x[i] - np.min(x[i])).astype(np.float64)
newxfloat = (new_x[i] - np.min(x[i])).astype(np.float64)
xmax = np.max(xfloat)
x[i] = xfloat / xmax
new_x[i] = newxfloat / xmax
return x, new_x


Expand Down

0 comments on commit 76f988f

Please sign in to comment.