#NEWLINE# def get_shape_view( self , shape_obj , avoid_oob = True ) : #NEWLINE# #INDENT# '\n        Calculate a bounding box in the data enclosing `shape_obj` and\n        return a view that accesses it and a mask that is True only for\n        pixels enclosed in the region.\n\n        If `avoid_oob` is True (default) then the bounding box is clipped\n        to avoid coordinates outside of the actual data.\n        ' #NEWLINE# ( x1 , y1 , x2 , y2 ) = map ( int , shape_obj . get_llur ( ) ) #NEWLINE# if avoid_oob : #NEWLINE# #INDENT# ( wd , ht ) = self . get_size ( ) #NEWLINE# ( x1 , x2 ) = ( max ( 0 , x1 ) , min ( x2 , ( wd - 1 ) ) ) #NEWLINE# ( y1 , y2 ) = ( max ( 0 , y1 ) , min ( y2 , ( ht - 1 ) ) ) #NEWLINE# #UNINDENT# yi = numpy . mgrid [ y1 : ( y2 + 1 ) ] . reshape ( ( - 1 ) , 1 ) #NEWLINE# xi = numpy . mgrid [ x1 : ( x2 + 1 ) ] . reshape ( 1 , ( - 1 ) ) #NEWLINE# contains = shape_obj . contains_arr ( xi , yi ) #NEWLINE# view = numpy . s_ [ y1 : ( y2 + 1 ) , x1 : ( x2 + 1 ) ] #NEWLINE# return ( view , contains )