<s> import argparse <EOL> import sys <EOL> import os <EOL> from contextlib import closing <EOL> import numpy as np <EOL> from PIL import Image <EOL> import cStringIO <EOL> import zlib <EOL> sys . path . append ( os . path . abspath ( '<STR_LIT>' ) ) <EOL> import OCP . settings <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> from django . conf import settings <EOL> import django <EOL> django . setup ( ) <EOL> from cube import Cube <EOL> import ocpcarest <EOL> import ocpcadb <EOL> import ocpcaproj <EOL> import ocplib <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , type = str , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , type = str , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:path>' , action = "<STR_LIT:store>" , type = str , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , type = int , help = '<STR_LIT>' ) <EOL> result = parser . parse_args ( ) <EOL> with closing ( ocpcaproj . OCPCAProjectsDB ( ) ) as projdb : <EOL> proj = projdb . loadToken ( result . token ) <EOL> with closing ( ocpcadb . OCPCADB ( proj ) ) as db : <EOL> ch = proj . getChannelObj ( result . channel ) <EOL> [ [ ximagesz , yimagesz , zimagesz ] , ( starttime , endtime ) ] = proj . datasetcfg . imageSize ( result . resolution ) <EOL> [ xcubedim , ycubedim , zcubedim ] = cubedim = proj . datasetcfg . getCubeDims ( ) [ result . resolution ] <EOL> [ xoffset , yoffset , zoffset ] = proj . datasetcfg . getOffset ( ) [ result . resolution ] <EOL> for slice_number in range ( zoffset , zimagesz + <NUM_LIT:1> , zcubedim ) : <EOL> slab = np . zeros ( [ zcubedim , yimagesz , ximagesz ] , dtype = np . uint32 ) <EOL> for b in range ( zcubedim ) : <EOL> if ( slice_number + b <= zimagesz ) : <EOL> try : <EOL> file_name = "<STR_LIT>" . format ( result . path , slice_number + b ) <EOL> print "<STR_LIT>" . format ( file_name ) <EOL> img = Image . open ( file_name , '<STR_LIT:r>' ) . convert ( "<STR_LIT>" ) <EOL> imgdata = np . asarray ( img ) <EOL> slab [ b , : , : ] = np . left_shift ( imgdata [ : , : , <NUM_LIT:3> ] , <NUM_LIT> , dtype = np . uint32 ) | np . left_shift ( imgdata [ : , : , <NUM_LIT:2> ] , <NUM_LIT:16> , dtype = np . uint32 ) | np . left_shift ( imgdata [ : , : , <NUM_LIT:1> ] , <NUM_LIT:8> , dtype = np . uint32 ) | np . uint32 ( imgdata [ : , : , <NUM_LIT:0> ] ) <EOL> except IOError , e : <EOL> print e <EOL> imgdata = np . zeros ( ( yimagesz , ximagesz ) , dtype = np . uint32 ) <EOL> slab [ b , : , : ] = imgdata <EOL> for y in range ( <NUM_LIT:0> , yimagesz + <NUM_LIT:1> , ycubedim ) : <EOL> for x in range ( <NUM_LIT:0> , ximagesz + <NUM_LIT:1> , xcubedim ) : <EOL> zidx = ocplib . XYZMorton ( [ x / xcubedim , y / ycubedim , ( slice_number - zoffset ) / zcubedim ] ) <EOL> cube = Cube . getCube ( cubedim , ch . getChannelType ( ) , ch . getDataType ( ) ) <EOL> cube . zeros ( ) <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 = min ( slice_number + zcubedim , zimagesz + <NUM_LIT:1> ) <EOL> cube . data [ <NUM_LIT:0> : zmax - zmin , <NUM_LIT:0> : ymax - ymin , <NUM_LIT:0> : xmax - xmin ] = slab [ zmin : zmax , ymin : ymax , xmin : xmax ] <EOL> db . putCube ( ch , zidx , result . resolution , cube , update = True ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
