<s> import argparse <EOL> import sys <EOL> import os <EOL> import numpy as np <EOL> import urllib , urllib2 <EOL> import cStringIO <EOL> from contextlib import closing <EOL> import zlib <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 django <EOL> django . setup ( ) <EOL> from cube import Cube <EOL> import ocpcarest <EOL> import ocplib <EOL> import ocpcaproj <EOL> import ocpcadb <EOL> """<STR_LIT>""" <EOL> class ImgHist ( ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , token , channel , res , bits ) : <EOL> self . token = token <EOL> self . channel = channel <EOL> self . res = int ( res ) <EOL> self . numbins = <NUM_LIT:2> ** int ( bits ) <EOL> def getHist ( self ) : <EOL> with closing ( ocpcaproj . OCPCAProjectsDB ( ) ) as projdb : <EOL> proj = projdb . loadToken ( self . token ) <EOL> with closing ( ocpcadb . OCPCADB ( proj ) ) as db : <EOL> ch = proj . getChannelObj ( self . channel ) <EOL> [ [ ximagesz , yimagesz , zimagesz ] , timerange ] = proj . datasetcfg . imageSize ( self . res ) <EOL> [ xcubedim , ycubedim , zcubedim ] = cubedim = proj . datasetcfg . getCubeDims ( ) [ self . res ] <EOL> [ xoffset , yoffset , zoffset ] = proj . datasetcfg . getOffset ( ) [ self . res ] <EOL> xlimit = ( ximagesz - <NUM_LIT:1> ) / xcubedim + <NUM_LIT:1> <EOL> ylimit = ( yimagesz - <NUM_LIT:1> ) / ycubedim + <NUM_LIT:1> <EOL> zlimit = ( zimagesz - <NUM_LIT:1> ) / zcubedim + <NUM_LIT:1> <EOL> hist_sum = np . zeros ( self . numbins , dtype = np . uint32 ) <EOL> for z in range ( zlimit ) : <EOL> for y in range ( ylimit ) : <EOL> for x in range ( xlimit ) : <EOL> data = db . cutout ( ch , [ x * xcubedim , y * ycubedim , z * zcubedim ] , cubedim , self . res ) . data <EOL> ( hist , bins ) = np . histogram ( data [ data > <NUM_LIT:0> ] , bins = self . numbins , range = ( <NUM_LIT:0> , self . numbins ) ) <EOL> hist_sum = np . add ( hist_sum , hist ) <EOL> print "<STR_LIT>" . format ( x , y , z ) <EOL> return ( hist_sum , bins ) </s>
