<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_opt <EOL> """<STR_LIT>""" <EOL> _xtilesz = <NUM_LIT> <EOL> _ytilesz = <NUM_LIT> <EOL> _resolution = <NUM_LIT:0> <EOL> """<STR_LIT>""" <EOL> _startslice = <NUM_LIT:1> <EOL> _startslice = <NUM_LIT> <EOL> _endslice = <NUM_LIT:1000> <EOL> _prefix = '<STR_LIT>' <EOL> _batchsz = <NUM_LIT:16> <EOL> _xoffset = <NUM_LIT> <EOL> _yoffset = <NUM_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: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 . uint32 ) <EOL> for b in range ( _batchsz ) : <EOL> if ( sl + b <= _endslice ) : <EOL> filenm = result . path + '<STR_LIT:/>' + _prefix + '<STR_LIT>' . format ( sl + b ) + '<STR_LIT>' <EOL> print filenm <EOL> tileimage = Image . open ( filenm , '<STR_LIT:r>' ) <EOL> imgdata = np . asarray ( tileimage ) <EOL> newdata [ b , : , : ] = kanno_opt . pngto32 ( imgdata ) <EOL> endz = b <EOL> url = '<STR_LIT>' % ( result . token , _resolution , _xoffset , _xoffset + _xtilesz , _yoffset , _yoffset + _ytilesz , sl , sl + endz + <NUM_LIT:1> ) <EOL> print url , newdata . shape <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>
