"""
@summary: Module containing script to convert binary rasters to compressed 
             rasters via combo quad tree hilbert curve encoding
"""
import os
from matrix.matrix import Matrix
from combo.quadTreeHilbert import QuadtreeHilbertCompressedMatrix

inDir = '/data/geo716/final project/data/bins'
outDir = '/data/geo716/final project/data/combos'

orders = [6, 8, 10]

for i in xrange(1000):
   binFn = os.path.join(inDir, '%s.bin' % i)
   mtx = Matrix()
   mtx.readFile(binFn)
   for order in orders:
      print i, '-', order
      cmpFn = os.path.join('%s%s' % (outDir, order), '%s.combo%s' % (i, order))
      
      mtx2 = QuadtreeHilbertCompressedMatrix(rleThreshold=order)
      mtx2.compress(mtx)
      mtx2.writeFile(cmpFn)
예제 #2
0
"""
import csv
import os
from matrix.matrix import Matrix

inDir = '/data/geo716/final project/data/bins'
inCsvFn = '/data/geo716/final project/data/projectionsNew.csv'
outCsvFn = '/data/geo716/final project/data/projections2.csv'

with open(inCsvFn) as csvIn:
   with open(outCsvFn, 'w') as csvOut:
      reader = csv.reader(csvIn)
      writer = csv.writer(csvOut)
      
      headers = reader.next()
      headers.append('Number of presence')

      all = []
      all.append(headers)
      
      i = 0
      for row in reader:
         fn = os.path.join(inDir, '%s.bin' % i)
         mtx = Matrix()
         mtx.readFile(fn)
         row.append(sum([sum(r) for r in mtx.data]))
         all.append(row)         
         i += 1
      writer.writerows(all)
      
예제 #3
0
"""
@summary: Module containing script to convert binary rasters to compressed 
             rasters via normal run length encoding
"""
import os
from matrix.matrix import Matrix
from rle.normal import NormalRLECompressedMatrix

inDir = '/data/geo716/final project/data/bins'
outDir = '/data/geo716/final project/data/rles'

for i in xrange(1000):
    #i = 0
    print i
    binFn = os.path.join(inDir, '%s.bin' % i)
    rleFn = os.path.join(outDir, '%s.rle' % i)
    mtx = Matrix()
    mtx.readFile(binFn)
    mtx2 = NormalRLECompressedMatrix()
    mtx2.compress(mtx)
    mtx2.writeFile(rleFn)
예제 #4
0
   with open(OUT_CSV, 'w') as csvOutFile:
      writer = csv.writer(csvOutFile)
      headerRow = [
                   'Id', 'Projection Id', 'Occurrence Set Id', 'Scenario Id',
                   'Algorithm Code', 'Number of Presences', 'Morans I',
                   'Variance', 'ASCII Size', 'Tiff Size', 'Binary Size',
                   'RLE Size', 'Hilbert Size', 'Quadtree Size', 'S-Tree Size',
                   'Combo 6 Size', 'Combo 8 Size', 'Combo 10 Size'
                  ]
      writer.writerow(headerRow)
      for idStr, prjId, occId, scnId, algoCode, tiffSize in values[1:]:
         print idStr
         id = int(idStr)
         mtx = Matrix()
         mtx.readFile(getFileName('bins', id, 'bin'))
         numPres, variance = getNumPresencesAndVariance(mtx.data)
         mI = calculateMoransI(mtx.data)
         asciiSize = getFileSize(getFileName('ascs', id, 'asc'))
         tiffSize = tiffSize
         binSize = getFileSize(getFileName('bins', id, 'bin'))
         rleSize = getFileSize(getFileName('rles', id, 'rle'))
         hilbertSize = getFileSize(getFileName('hilberts', id, 'hilb'))
         qTreeSize = getFileSize(getFileName('qtrees', id, 'qtree'))
         sTreeSize = getFileSize(getFileName('strees', id, 'stree'))
         combo6Size = getFileSize(getFileName('combos6', id, 'combo6'))
         combo8Size = getFileSize(getFileName('combos8', id, 'combo8'))
         combo10Size = getFileSize(getFileName('combos10', id, 'combo10'))
         
         row = [id, prjId, occId, scnId, algoCode, numPres, mI, variance,
                asciiSize, tiffSize, binSize, rleSize, hilbertSize,
예제 #5
0
@summary: Get the number of presences in a layer
"""
import csv
import os
from matrix.matrix import Matrix

inDir = '/data/geo716/final project/data/bins'
inCsvFn = '/data/geo716/final project/data/projectionsNew.csv'
outCsvFn = '/data/geo716/final project/data/projections2.csv'

with open(inCsvFn) as csvIn:
    with open(outCsvFn, 'w') as csvOut:
        reader = csv.reader(csvIn)
        writer = csv.writer(csvOut)

        headers = reader.next()
        headers.append('Number of presence')

        all = []
        all.append(headers)

        i = 0
        for row in reader:
            fn = os.path.join(inDir, '%s.bin' % i)
            mtx = Matrix()
            mtx.readFile(fn)
            row.append(sum([sum(r) for r in mtx.data]))
            all.append(row)
            i += 1
        writer.writerows(all)
예제 #6
0
    with open(OUT_CSV, 'w') as csvOutFile:
        writer = csv.writer(csvOutFile)
        headerRow = [
            'Id', 'Projection Id', 'Occurrence Set Id', 'Scenario Id',
            'Algorithm Code', 'Number of Presences', 'Morans I', 'Variance',
            'ASCII Size', 'Tiff Size', 'Binary Size', 'RLE Size',
            'Hilbert Size', 'Quadtree Size', 'S-Tree Size', 'Combo 6 Size',
            'Combo 8 Size', 'Combo 10 Size'
        ]
        writer.writerow(headerRow)
        for idStr, prjId, occId, scnId, algoCode, tiffSize in values[1:]:
            print idStr
            id = int(idStr)
            mtx = Matrix()
            mtx.readFile(getFileName('bins', id, 'bin'))
            numPres, variance = getNumPresencesAndVariance(mtx.data)
            mI = calculateMoransI(mtx.data)
            asciiSize = getFileSize(getFileName('ascs', id, 'asc'))
            tiffSize = tiffSize
            binSize = getFileSize(getFileName('bins', id, 'bin'))
            rleSize = getFileSize(getFileName('rles', id, 'rle'))
            hilbertSize = getFileSize(getFileName('hilberts', id, 'hilb'))
            qTreeSize = getFileSize(getFileName('qtrees', id, 'qtree'))
            sTreeSize = getFileSize(getFileName('strees', id, 'stree'))
            combo6Size = getFileSize(getFileName('combos6', id, 'combo6'))
            combo8Size = getFileSize(getFileName('combos8', id, 'combo8'))
            combo10Size = getFileSize(getFileName('combos10', id, 'combo10'))

            row = [
                id, prjId, occId, scnId, algoCode, numPres, mI, variance,