<s> import numpy as np <EOL> from PIL import Image <EOL> import urllib2 <EOL> import zlib <EOL> import StringIO <EOL> import os <EOL> import sys <EOL> import cStringIO <EOL> import zindex <EOL> EM_BASE_PATH = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT:..>" ) ) <EOL> EM_UTIL_PATH = os . path . join ( EM_BASE_PATH , "<STR_LIT>" ) <EOL> EM_EMCA_PATH = os . path . join ( EM_BASE_PATH , "<STR_LIT>" ) <EOL> EM_DBCONFIG_PATH = os . path . join ( EM_BASE_PATH , "<STR_LIT>" ) <EOL> sys . path += [ EM_UTIL_PATH , EM_DBCONFIG_PATH , EM_EMCA_PATH ] <EOL> import emcaproj <EOL> import emcadb <EOL> import dbconfig <EOL> projdb = emcaproj . EMCAProjectsDB ( ) <EOL> proj = projdb . getProj ( '<STR_LIT>' ) <EOL> dbcfg = dbconfig . switchDataset ( proj . getDataset ( ) ) <EOL> db = emcadb . EMCADB ( dbcfg , proj ) <EOL> _ximagesz = <NUM_LIT> <EOL> _yimagesz = <NUM_LIT> <EOL> _xcubedim = <NUM_LIT> <EOL> _ycubedim = <NUM_LIT> <EOL> _zcubedim = <NUM_LIT:16> <EOL> fid = open ( "<STR_LIT>" , "<STR_LIT:r>" ) <EOL> resolution = <NUM_LIT:1> <EOL> for zstart in range ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:16> ) : <EOL> zend = min ( zstart + <NUM_LIT:16> , <NUM_LIT> ) <EOL> slab = np . fromfile ( fid , count = _ximagesz * _yimagesz * ( zend - zstart ) , dtype = np . uint8 ) <EOL> slab = slab . reshape ( [ ( zend - zstart ) , _yimagesz , _ximagesz ] ) <EOL> for y in range ( <NUM_LIT:0> , _yimagesz , _ycubedim ) : <EOL> for x in range ( <NUM_LIT:0> , _ximagesz , _xcubedim ) : <EOL> mortonidx = zindex . XYZMorton ( [ x / _xcubedim , y / _ycubedim , ( zstart - <NUM_LIT:1> ) / _zcubedim ] ) <EOL> cubedata = np . zeros ( [ _zcubedim , _ycubedim , _xcubedim ] , dtype = np . uint8 ) <EOL> xmin = x <EOL> ymin = y <EOL> xmax = min ( _ximagesz , x + _xcubedim ) <EOL> ymax = min ( _yimagesz , y + _ycubedim ) <EOL> zmin = <NUM_LIT:0> <EOL> zmax = zend - zstart <EOL> cubedata [ <NUM_LIT:0> : zmax - zmin , <NUM_LIT:0> : ymax - ymin , <NUM_LIT:0> : xmax - xmin ] = slab [ zmin : zmax , ymin : ymax , xmin : xmax ] <EOL> fileobj = cStringIO . StringIO ( ) <EOL> np . save ( fileobj , cubedata ) <EOL> cdz = zlib . compress ( fileobj . getvalue ( ) ) <EOL> cursor = db . conn . cursor ( ) <EOL> sql = "<STR_LIT>" <EOL> cursor . execute ( sql , ( mortonidx , cdz ) ) <EOL> cursor . close ( ) <EOL> print "<STR_LIT>" % ( x , y , zstart ) <EOL> db . conn . commit ( ) </s>
