def categorize_block_array(d, base_address, blocksize, pixelsize, addr_space = 'arm'):
    print 'Categorizing blocks in memory, following a 2D Hilbert curve'

    a = []
    timestamp = time.time()
    first_time = timestamp

    for y in xrange(pixelsize):
        row = []
        for x in xrange(pixelsize):
            addr = base_address + blocksize * hilbert(x, y, pixelsize)
            row.extend(categorize_block(d, addr, blocksize, addr_space=addr_space))

            # Keep the crowd informed!
            now = time.time()
            if now > timestamp + 0.5:

                # Estimate time
                completion = (x + y*pixelsize) / float(pixelsize*pixelsize)
                elapsed = now - first_time
                remaining = 0
                if completion > 0.00001:
                    total = elapsed / completion
                    if total > elapsed:
                        remaining = elapsed - total

                print 'block %08x - (%4d,%4d) of %d, %6.2f%% -- %2d:%02d:%02d elapsed, %2d:%02d:%02d est. remaining' % (
                    addr, x, y, pixelsize, 100 * completion,
                    elapsed / (60 * 60), (elapsed / 60) % 60, elapsed % 60,
                    remaining / (60 * 60), (remaining / 60) % 60, remaining % 60)
                timestamp = now
    
        a.append(row)

    print 'Calculating global scaling for blue channel'

    # The blue channel still has raw time deltas. Calculate pecentiles so we can scale them.

    times = []
    for row in a:
        for x in xrange(pixelsize):
            times.append(row[2 + 3*x])
    times.sort()

    percentile_low  = log(times[int( len(times) * 0.05 )])
    percentile_high = log(times[int( len(times) * 0.95 )])
    percentile_s    = 256.0 / (percentile_high - percentile_low)

    for row in a:
        for x in xrange(pixelsize):
            row[2+3*x] = min(255, max(0, int(0.5 + (log(row[2+3*x]) - percentile_low) * percentile_s)))

    print 'Done scaling'
    return a
dataset/ETHPy150Open scanlime/coastermelt/backdoor/memsquare.py/categorize_block_array/swapped operands of `-`