<s> import argparse <EOL> import sys <EOL> import os <EOL> import numpy as np <EOL> from PIL import Image <EOL> import urllib , urllib2 <EOL> import cStringIO <EOL> import collections <EOL> import zlib <EOL> import kanno_cy <EOL> """<STR_LIT>""" <EOL> xtilesz = <NUM_LIT> <EOL> ytilesz = <NUM_LIT> <EOL> _resolution = <NUM_LIT:0> <EOL> startslice = <NUM_LIT:0> <EOL> endslice = <NUM_LIT> <EOL> batchsz = <NUM_LIT:16> <EOL> xoffset = <NUM_LIT:0> <EOL> yoffset = <NUM_LIT:0> <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>" , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:path>' , action = "<STR_LIT:store>" , help = '<STR_LIT>' ) <EOL> result = parser . parse_args ( ) <EOL> for sl in range ( startslice , endslice + <NUM_LIT:1> , batchsz ) : <EOL> newdata = np . zeros ( [ batchsz , ytilesz , xtilesz ] , dtype = np . uint8 ) <EOL> for b in range ( batchsz ) : <EOL> if ( sl + b <= endslice ) : <EOL> filenm = result . path + '<STR_LIT:/>' + '<STR_LIT>' . format ( sl + b ) + '<STR_LIT>' <EOL> print "<STR_LIT>" + filenm <EOL> imgdata = np . fromfile ( filenm , dtype = np . uint8 ) . reshape ( [ ytilesz , xtilesz ] ) <EOL> newdata [ b , : , : ] = imgdata <EOL> endz = b <EOL> url = '<STR_LIT>' % ( result . baseurl , result . token , _resolution , xoffset , xoffset + xtilesz , yoffset , yoffset + ytilesz , sl , sl + endz + <NUM_LIT:1> ) <EOL> print url <EOL> fileobj = cStringIO . StringIO ( ) <EOL> np . save ( fileobj , newdata ) <EOL> cdz = zlib . compress ( fileobj . getvalue ( ) ) <EOL> try : <EOL> req = urllib2 . Request ( url , cdz ) <EOL> response = urllib2 . urlopen ( req ) <EOL> the_page = response . read ( ) <EOL> except Exception , e : <EOL> print "<STR_LIT>" , e <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
