def getview(self, view, pbar): import numpy as np from pygeode.view import View, simplify out = np.empty(view.shape, dtype=self.dtype) out[()] = float('nan') out_axes = view.clip().axes # Loop over all available files. N = 0 # Number of points covered so far for filename, opener, axes in self._table: subaxes = [ self._axis_manager._get_axis_intersection([a1, a2]) for a1, a2 in zip(out_axes, axes) ] reorder = [] mask = [] if any(len(a) == 0 for a in subaxes): continue for a1, a2 in zip(out_axes, subaxes): # Figure out where the input chunk fits into the output re = np.searchsorted(a2.values, a1.values) # Mask out elements that we don't actually have in the chunk m = [ r < len(a2.values) and a2.values[r] == v for r, v in zip(re, a1.values) ] m = np.array(m) # Convert mask to integer indices m = np.arange(len(m))[m] # and then to a slice (where possible) m = simplify(m) re = re[m] # Try to simplify the re-ordering array if np.all(re == np.sort(re)): re = simplify(re) reorder.append(re) mask.append(m) var = [v for v in opener(filename) if v.name == self._varname][0] v = View(subaxes) chunk = v.get(var) # Note: this may break if there is more than one axis with integer indices. assert len([ r for r in reorder if isinstance(r, (tuple, np.ndarray)) ]) <= 1, "Unhandled advanced indexing case." assert len([m for m in mask if isinstance(m, (tuple, np.ndarray)) ]) <= 1, "Unhandled advanced indexing case." out[mask] = chunk[reorder] N = N + chunk.size pbar.update(100. * N / out.size) return out
def getview (self, view, pbar): import numpy as np from pygeode.view import View, simplify out = np.empty(view.shape, dtype=self.dtype) out[()] = float('nan') out_axes = view.clip().axes # Loop over all available files. N = 0 # Number of points covered so far for filename, opener, axes in self._table: subaxes = [self._axis_manager._get_axis_intersection([a1,a2]) for a1,a2 in zip(out_axes,axes)] reorder = [] mask = [] if any(len(a)==0 for a in subaxes): continue for a1,a2 in zip(out_axes,subaxes): # Figure out where the input chunk fits into the output re = np.searchsorted(a2.values, a1.values) # Mask out elements that we don't actually have in the chunk m = [r<len(a2.values) and a2.values[r]==v for r,v in zip(re,a1.values)] m = np.array(m) # Convert mask to integer indices m = np.arange(len(m))[m] # and then to a slice (where possible) m = simplify(m) re = re[m] # Try to simplify the re-ordering array if np.all(re == np.sort(re)): re = simplify(re) reorder.append(re) mask.append(m) var = [v for v in opener(filename) if v.name == self._varname][0] v = View(subaxes) chunk = v.get(var) # Note: this may break if there is more than one axis with integer indices. assert len([r for r in reorder if isinstance(r,(tuple,np.ndarray))]) <= 1, "Unhandled advanced indexing case." assert len([m for m in mask if isinstance(m,(tuple,np.ndarray))]) <= 1, "Unhandled advanced indexing case." out[mask] = chunk[reorder] N = N + chunk.size pbar.update(100.*N/out.size) return out