<s> import argparse <EOL> import sys <EOL> import os <EOL> import numpy as np <EOL> import urllib , urllib2 <EOL> import cStringIO <EOL> from PIL import Image <EOL> import zlib <EOL> import MySQLdb <EOL> import aerospike <EOL> import tempfile <EOL> import h5py <EOL> sys . path += [ os . path . abspath ( '<STR_LIT>' ) ] <EOL> import OCP . settings <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> from django . conf import settings <EOL> import ocpcaproj <EOL> import ocpcadb <EOL> import zindex <EOL> """<STR_LIT>""" <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , type = int ) <EOL> result = parser . parse_args ( ) <EOL> ascfg = { '<STR_LIT>' : [ ( '<STR_LIT:127.0.0.1>' , <NUM_LIT> ) ] } <EOL> ascli = aerospike . client ( ascfg ) . connect ( ) <EOL> projdb = ocpcaproj . OCPCAProjectsDB ( ) <EOL> proj = projdb . loadProject ( result . token ) <EOL> imgDB = ocpcadb . OCPCADB ( proj ) <EOL> [ ximagesz , yimagesz ] = proj . datasetcfg . imagesz [ result . resolution ] <EOL> [ xcubedim , ycubedim , zcubedim ] = cubedim = proj . datasetcfg . cubedim [ result . resolution ] <EOL> [ startslice , endslice ] = proj . datasetcfg . slicerange <EOL> slices = endslice - startslice + <NUM_LIT:1> <EOL> xlimit = ximagesz / xcubedim <EOL> ylimit = yimagesz / ycubedim <EOL> zlimit = ( ( ( slices - <NUM_LIT:1> ) / zcubedim + <NUM_LIT:1> ) * zcubedim ) / zcubedim <EOL> cursor = imgDB . conn . cursor ( ) <EOL> for z in range ( zlimit ) : <EOL> for y in range ( ylimit ) : <EOL> for x in range ( xlimit ) : <EOL> mysqlcube = imgDB . cutout ( [ x * xcubedim , y * ycubedim , z * zcubedim ] , cubedim , result . resolution ) <EOL> zidx = zindex . XYZMorton ( [ x , y , z ] ) <EOL> tmpfile = tempfile . NamedTemporaryFile ( ) <EOL> h5tocass = h5py . File ( tmpfile . name ) <EOL> h5tocass . create_dataset ( "<STR_LIT>" , tuple ( mysqlcube . data . shape ) , mysqlcube . data . dtype , <EOL> compression = '<STR_LIT>' , data = mysqlcube . data ) <EOL> h5tocass . close ( ) <EOL> tmpfile . seek ( <NUM_LIT:0> ) <EOL> askey = ( "<STR_LIT>" , str ( result . token ) + "<STR_LIT::>" + str ( result . resolution ) , str ( zidx ) ) <EOL> print askey <EOL> ascli . put ( askey , { '<STR_LIT>' : tmpfile . read ( ) . encode ( '<STR_LIT>' ) } ) <EOL> try : <EOL> import pdb ; pdb . set_trace ( ) <EOL> ascli . get ( askey ) <EOL> except : <EOL> print "<STR_LIT>" <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
