Skip to content
Permalink
Browse files

Cleaned up Element range handling and fixed QuadMesh range

  • Loading branch information...
Philipp Rudiger Philipp Rudiger
Philipp Rudiger authored and Philipp Rudiger committed Sep 12, 2017
1 parent c061b2b commit 35e02c3bcc52da389bdf0f0ca6e003fb12102844
Showing with 34 additions and 48 deletions.
  1. +5 −16 holoviews/core/data/__init__.py
  2. +12 −0 holoviews/core/util.py
  3. +8 −16 holoviews/element/chart.py
  4. +9 −16 holoviews/element/raster.py
@@ -9,6 +9,7 @@
import param

from ..dimension import redim
from ..util import dimension_range
from .interface import Interface, iloc, ndloc
from .array import ArrayInterface
from .dictionary import DictInterface
@@ -240,23 +241,11 @@ def range(self, dim, data_range=True):
return (None, None)
elif None not in dim.range:
return dim.range
elif dim in self.dimensions() and data_range:
if len(self):
drange = self.interface.range(self, dim)
else:
drange = (np.NaN, np.NaN)
soft_range = [r for r in dim.soft_range if r is not None]
if soft_range:
drange = util.max_range([drange, soft_range])
else:
drange = dim.soft_range
if dim.range[0] is not None:
return (dim.range[0], drange[1])
elif dim.range[1] is not None:
return (drange[0], dim.range[1])
elif dim in self.dimensions() and data_range and len(self):
drange = self.interface.range(self, dim)
else:
return drange

drange = (np.NaN, np.NaN)
return dimension_range(*drange, dim)


def add_dimension(self, dimension, dim_pos, dim_val, vdim=False, **kwargs):
@@ -710,6 +710,18 @@ def max_range(ranges):
return (np.NaN, np.NaN)


def dimension_range(lower, upper, dimension):
"""
Computes the range along a dimension by combining the data range
with the Dimension soft_range and range.
"""
lower, upper = max_range([(lower, upper), dimension.soft_range])
dmin, dmax = dimension.range
lower = lower if dmin is None or not np.isfinite(dmin) else dmin
upper = upper if dmax is None or not np.isfinite(dmax) else dmax
return lower, upper


def max_extents(extents, zrange=False):
"""
Computes the maximal extent in 2D and 3D space from
@@ -88,23 +88,19 @@ class ErrorBars(Chart):


def range(self, dim, data_range=True):
drange = super(ErrorBars, self).range(dim, data_range)
didx = self.get_dimension_index(dim)
dim = self.get_dimension(dim)
if didx == 1 and data_range:
if didx == 1 and data_range and len(self):
mean = self.dimension_values(1)
neg_error = self.dimension_values(2)
pos_idx = 3 if len(self.dimensions()) > 3 else 2
pos_error = self.dimension_values(pos_idx)
if len(self.dimensions()) > 3:
pos_error = self.dimension_values(3)
else:
pos_error = neg_error
lower = np.nanmin(mean-neg_error)
upper = np.nanmax(mean+pos_error)
lower, upper = util.max_range([(lower, upper), drange])
dmin, dmax = dim.range
lower = lower if dmin is None or not np.isfinite(dmin) else dmin
upper = upper if dmax is None or not np.isfinite(dmax) else dmax
return lower, upper
else:
return drange
return util.dimension_range(lower, upper, dim)
return super(ErrorBars, self).range(dim, data_range)



@@ -248,11 +244,7 @@ def range(self, dimension, data_range=True):
if self.get_dimension_index(dimension) == 0 and data_range:
dim = self.get_dimension(dimension)
lower, upper = np.min(self.edges), np.max(self.edges)
lower, upper = util.max_range([(lower, upper), dim.soft_range])
dmin, dmax = dim.range
lower = lower if dmin is None or not np.isfinite(dmin) else dmin
upper = upper if dmax is None or not np.isfinite(dmax) else dmax
return lower, upper
return util.dimension_range(lower, upper, dim)
else:
return super(Histogram, self).range(dimension, data_range)

@@ -8,7 +8,7 @@
from ..core import Dimension, Element2D, Overlay, Dataset
from ..core.boundingregion import BoundingRegion, BoundingBox
from ..core.sheetcoords import SheetCoordinateSystem, Slice
from ..core.util import max_range
from ..core.util import max_range, dimension_range
from .chart import Curve
from .tabular import Table
from .util import compute_edges, compute_slice_bounds, categorical_aggregate2d
@@ -71,14 +71,8 @@ def range(self, dim, data_range=True):
idx = self.get_dimension_index(dim)
if data_range and idx == 2:
dimension = self.get_dimension(dim)
drange = self.data.min(), self.data.max()
drange = max_range([drange, dimension.soft_range])
if dimension.range[0] is not None:
return (dimension.range[0], drange[1])
elif dimension.range[1] is not None:
return (drange[0], dimension.range[1])
else:
return drange
lower, upper = np.nanmin(self.data), np.nanmax(self.data)
return dimension_range(lower, upper, dimension)
return super(Raster, self).range(dim, data_range)


@@ -720,15 +714,14 @@ def _coord2matrix(self, coord):
for i in [1, 0])


def range(self, dimension):
def range(self, dimension, data_range=True):
idx = self.get_dimension_index(dimension)
if idx in [0, 1]:
data = self.data[idx]
return np.min(data), np.max(data)
elif idx == 2:
dim = self.get_dimension(dimension)
if idx in [0, 1, 2] and data_range:
data = self.data[idx]
return np.nanmin(data), np.nanmax(data)
super(QuadMesh, self).range(dimension)
lower, upper = np.nanmin(data), np.nanmax(data)
return dimension_range(lower, upper, dim)
super(QuadMesh, self).range(dimension, data_range)


def dimension_values(self, dimension, expanded=True, flat=True):

0 comments on commit 35e02c3

Please sign in to comment.
You can’t perform that action at this time.