def fromArraysAsImages(self, arrays): """Create a Series object from a sequence of numpy ndarrays resident in memory on the driver. The arrays will be interpreted as though each represents a single time point - effectively the same as if converting Images to a Series, with each array representing a volume image at a particular point in time. Thus in the resulting Series, the value of the record with key (0,0,0) will be array([arrays[0][0,0,0], arrays[1][0,0,0],... arrays[n][0,0,0]). The dimensions of the resulting Series will be *opposite* that of the passed numpy array. Their dtype will not be changed. """ # if passed a single array, cast it to a sequence of length 1 if isinstance(arrays, ndarray): arrays = [arrays] # check that shapes of passed arrays are consistent shape = arrays[0].shape dtype = arrays[0].dtype for ary in arrays: if not ary.shape == shape: raise ValueError("Inconsistent array shapes: first array had shape %s, but other array has shape %s" % (str(shape), str(ary.shape))) if not ary.dtype == dtype: raise ValueError("Inconsistent array dtypes: first array had dtype %s, but other array has dtype %s" % (str(dtype), str(ary.dtype))) # get indices so that fastest index changes first shapeiters = (xrange(n) for n in shape) keys = [idx[::-1] for idx in itertools.product(*shapeiters)] values = vstack([ary.ravel() for ary in arrays]).T dims = Dimensions.fromTuple(shape[::-1]) return Series(self.sc.parallelize(zip(keys, values), self.minPartitions), dims=dims, dtype=str(dtype))
def __init__(self, rdd, dims=None, nrecords=None, dtype=None): super(Images, self).__init__(rdd, nrecords=nrecords, dtype=dtype) if dims and not isinstance(dims, Dimensions): try: dims = Dimensions.fromTuple(dims) except: raise TypeError("Images dims parameter must be castable to Dimensions object, got: %s" % str(dims)) self._dims = dims
def populateParamsFromFirstRecord(self): record = super(Images, self).populateParamsFromFirstRecord() self._dims = Dimensions.fromTuple(record[1].shape) return record
def populateParamsFromFirstRecord(self): record = super(SimpleBlocks, self).populateParamsFromFirstRecord() self._dims = Dimensions.fromTuple(record[0].origShape) return record