Run Accumulate area according to Dinf flow direction
492312
def areadinf(np, angfile, sca, outlet=None, wg=None, edgecontaimination=False,
                 workingdir=None, mpiexedir=None, exedir=None,
                 log_file=None, runtime_file=None, hostfile=None):
        """"""
        # -nc means do not consider edge contaimination
        if edgecontaimination:
            in_params = {'-nc': None}
        else:
            in_params = None
        fname = TauDEM.func_name('areadinf')
        return TauDEM.run(FileClass.get_executable_fullpath(fname, exedir),
                          {'-ang': angfile, '-o': outlet, '-wg': wg}, workingdir,
                          in_params,
                          {'-sca': sca},
                          {'mpipath': mpiexedir, 'hostfile': hostfile, 'n': np},
                          {'logfile': log_file, 'runtimefile': runtime_file})
554152
def ffill(arr, dim=None, limit=None):
    ''''''
    import bottleneck as bn

    axis = arr.get_axis_num(dim)

    # work around for bottleneck 178
    _limit = limit if limit is not None else arr.shape[axis]

    return apply_ufunc(bn.push, arr,
                       dask='parallelized',
                       keep_attrs=True,
                       output_dtypes=[arr.dtype],
                       kwargs=dict(n=_limit, axis=axis)).transpose(*arr.dims)
668687
def _nanstd(array, axis=None, ddof=0):
    """"""

    if isinstance(axis, tuple):
        array = _move_tuple_axes_first(array, axis=axis)
        axis = 0
    return bottleneck.nanstd(array, axis=axis, ddof=ddof)
493011
def _accumulate(data_list, no_concat=()):
    
    acc = Accumulator()
    for data in data_list:
        for name, val in data.items():
            acc.add(name, val)
    out = {name: acc[name] for name in acc.names if name not in no_concat}

    # Some variables should not be concatenated but should be kept as lists.
    # This is when there can be several arrays of variable length (NumPy
    # doesn't support ragged arrays).
    out.update({name: acc.get(name) for name in no_concat})
    return out
506105
def Run(self, args):
    """"""
    # Make sure we limit the size of our output
    if args.length > constants.CLIENT_MAX_BUFFER_SIZE:
      raise RuntimeError("Can not read buffers this large.")

    data = vfs.ReadVFS(args.pathspec, args.offset, args.length)

    digest = hashlib.sha256(data).digest()

    # Now report the hash of this blob to our flow as well as the offset and
    # length.
    self.SendReply(
        rdf_client.BufferReference(
            offset=args.offset, length=len(data), data=digest))
755682
private void newDirections( WritableRaster pitWR, WritableRaster dirWR ) {
        int[][] odir = {{0, 0, 0}, {0, 1, 1}, {-1, 1, 2}, {-1, 0, 3}, {-1, -1, 4}, {0, -1, 5}, {1, -1, 6}, {1, 0, 7}, {1, 1, 8},
                {0, 0, 9}, {0, 0, 10}};
        int[] flow = new int[2], nflow = new int[2];
        RandomIter pitRandomIter = RandomIterFactory.create(pitWR, null);

        RandomIter flowFixedIter = CoverageUtilities.getRandomIterator(inFlownet);
        WritableRandomIter dirRandomIter = RandomIterFactory.createWritable(dirWR, null);
        WritableRaster modifiedFlowWR = CoverageUtilities.createWritableRaster(pitWR.getWidth(), pitWR.getHeight(), Integer.class,
                null, null);
        WritableRandomIter modflowRandomIter = RandomIterFactory.createWritable(modifiedFlowWR, null);

        try {
            pm.beginTask("Correcting drainage directions...", rows);
            for( int j = 0; j < rows; j++ ) {
                if (pm.isCanceled()) {
                    return;
                }
                for( int i = 0; i < cols; i++ ) {
                    if (!isNovalue(flowFixedIter.getSample(i, j, 0))) {
                        flow[0] = i;
                        flow[1] = j;
                        for( int k = 1; k <= 8; k++ ) {
                            nflow[0] = flow[0] + odir[k][1];
                            nflow[1] = flow[1] + odir[k][0];
                            if (modflowRandomIter.getSample(nflow[0], nflow[1], 0) == 0
                                    && isNovalue(flowFixedIter.getSample(nflow[0], nflow[1], 0))) {
                                double elev = pitRandomIter.getSampleDouble(nflow[0] + odir[1][1], nflow[1] + odir[1][0], 0);
                                for( int n = 2; n <= 8; n++ ) {
                                    if (nflow[0] + odir[n][0] >= 0 && nflow[0] + odir[n][1] < rows && nflow[1] + odir[n][0] >= 0
                                            && nflow[1] + odir[n][0] < cols) {
                                        double tmpElev = pitRandomIter.getSampleDouble(nflow[0] + odir[n][1],
                                                nflow[1] + odir[n][0], 0);
                                        if (tmpElev >= elev) {
                                            elev = tmpElev;
                                            dirRandomIter.setSample(nflow[0], nflow[1], 0, odir[n][2]);
                                        }
                                    }
                                }
                                for( int s = 1; s <= 8; s++ ) {
                                    if (nflow[0] + odir[s][0] >= 0 && nflow[0] + odir[s][0] < rows && nflow[1] + odir[s][1] >= 0
                                            && nflow[1] + odir[s][1] < cols) {
                                        if (!isNovalue(
                                                flowFixedIter.getSample(nflow[0] + odir[s][1], nflow[1] + odir[s][0], 0))) {
                                            double tmpElev = pitRandomIter.getSampleDouble(nflow[0] + odir[s][1],
                                                    nflow[1] + odir[s][0], 0);
                                            if (tmpElev <= elev) {
                                                elev = tmpElev;
                                                dirRandomIter.setSample(nflow[0], nflow[1], 0, odir[s][2]);
                                            }
                                        }
                                    }
                                }
                                modflowRandomIter.setSample(nflow[0], nflow[1], 0, 1);
                            }

                        }
                    }
                    if (!isNovalue(flowFixedIter.getSample(i, j, 0))) {
                        dirRandomIter.setSample(i, j, 0, flowFixedIter.getSample(i, j, 0));
                    }
                }
                pm.worked(1);
            }
            pm.done();

        } finally {
            dirRandomIter.done();
            pitRandomIter.done();
            modflowRandomIter.done();
            flowFixedIter.done();
        }
    }
803731
def flow_ramp(self):
        """"""
        return np.linspace(1 / self.n_rows, 1, self.n_rows)*self.q
555230
def apply(funcs, stack):
  ''''''
  return reduce(lambda x, y: y(x), funcs, stack)
1254464
def downstream_index_dinf(dinfdir_value, i, j):
        
        down_dirs = DinfUtil.dinf_downslope_direction(dinfdir_value)
        down_coors = []
        for dir_code in down_dirs:
            row, col = D8Util.downstream_index(dir_code, i, j)
            down_coors.append([row, col])
        return down_coors
869444
public double pushRelabel(double[][] flow, int source, int sink) {
        int[] seen = new int[n];
        int[] queue = new int[n-2];
        for (int i = 0, p = 0; i < n; i++) {
            if ((i != source) && (i != sink)) {
                queue[p++] = i;
            }
        }
        
        int[] height = new int[n];//dijkstra(sink, false);
        height[source] = n;
        
        double[] excess = new double[n];
        excess[source] = Double.MAX_VALUE;
        
        for (int i = 0; i < n; i++) {
            push(flow, excess, source, i);
        }

        int p = 0;
        while (p < n-2) {
            int u = queue[p];
            double oldHeight = height[u];
            discharge(flow, excess, height, seen, u);
            if (height[u] > oldHeight) {
                moveToFront(p, queue);
                p = 0;
            } else {
                p += 1;
            }
        }
        
        double maxflow = 0.0;
        for (int i = 0; i < n; i++) {
            maxflow += flow[source][i];
        }

        return maxflow;
    }
880030
function updateRun(nf, sin32, dw32, b32) {
            var temp = d
            d = c
            c = b
            //b = b + rol(a + (nf + (sin32 + dw32)), b32)
            b = _add(b, 
                rol( 
                    _add(a, 
                        _add(nf, _add(sin32, dw32))
                    ), b32
                )
            )
            a = temp
        }
1353790
public void polyAdd_S(GrowQueue_I8 polyA , GrowQueue_I8 polyB , GrowQueue_I8 output ) {
		output.resize(Math.max(polyA.size,polyB.size));
		int M = Math.min(polyA.size, polyB.size);

		for (int i = M; i < polyA.size; i++) {
			output.data[i] = polyA.data[i];
		}
		for (int i = M; i < polyB.size; i++) {
			output.data[i] = polyB.data[i];
		}

		for (int i = 0; i < M; i++) {
			output.data[i] = (byte)((polyA.data[i]&0xFF) ^ (polyB.data[i]&0xFF));
		}
	}
513528
function(input) {
      if(!_finish) {
        // not finishing, so fill the input buffer with more input
        _input.putBuffer(input);
      }

      while(_input.length() >= 8) {
        runPlan([
            [ 5, mixRound ],
            [ 1, mashRound ],
            [ 6, mixRound ],
            [ 1, mashRound ],
            [ 5, mixRound ]
          ]);
      }
    }
391699
private void calculateChunkedSums(
      byte[] data, int dataOffset, int dataLength,
      byte[] sums, int sumsOffset) {

    int remaining = dataLength;
    while (remaining > 0) {
      int n = Math.min(remaining, bytesPerChecksum);
      summer.reset();
      summer.update(data, dataOffset, n);
      dataOffset += n;
      remaining -= n;
      long calculated = summer.getValue();
      sums[sumsOffset++] = (byte) (calculated >> 24);
      sums[sumsOffset++] = (byte) (calculated >> 16);
      sums[sumsOffset++] = (byte) (calculated >> 8);
      sums[sumsOffset++] = (byte) (calculated);
    }
  }
1367629
def iterate_chunks(i, size=10):
    
    accumulator = []

    for n, i in enumerate(i):
        accumulator.append(i)
        if (n+1) % size == 0:
            yield accumulator
            accumulator = []

    if accumulator:
        yield accumulator
1182075
def bfill(arr, dim=None, limit=None):
    ''''''
    axis = arr.get_axis_num(dim)

    # work around for bottleneck 178
    _limit = limit if limit is not None else arr.shape[axis]

    return apply_ufunc(_bfill, arr,
                       dask='parallelized',
                       keep_attrs=True,
                       output_dtypes=[arr.dtype],
                       kwargs=dict(n=_limit, axis=axis)).transpose(*arr.dims)
742979
function reduceit(v, i) {
    if (i >= this.rmin) {
      return undefined;
    }
    this.accumulater[i] += (v / this.scale[i]);
    return this.accumulater[i];
  }