#NEWLINE# def _calibrate_comp( comp , chs , row_names , col_names , mult_keys = ( 'range' , 'cal' ) , flip = False ) : #NEWLINE# #INDENT# 'Helper to get row and column cals' #NEWLINE# ch_names = [ c [ 'ch_name' ] for c in chs ] #NEWLINE# row_cals = np . zeros ( len ( row_names ) ) #NEWLINE# col_cals = np . zeros ( len ( col_names ) ) #NEWLINE# for ( names , cals , inv ) in zip ( ( row_names , col_names ) , ( row_cals , col_cals ) , ( False , True ) ) : #NEWLINE# #INDENT# for ii in range ( len ( cals ) ) : #NEWLINE# #INDENT# p = ch_names . count ( names [ ii ] ) #NEWLINE# if ( p != 1 ) : #NEWLINE# #INDENT# raise RuntimeError ( ( 'Channel %s does not appear exactly once in data' % names [ ii ] ) ) #NEWLINE# #UNINDENT# idx = ch_names . index ( names [ ii ] ) #NEWLINE# val = ( chs [ idx ] [ mult_keys [ 0 ] ] * chs [ idx ] [ mult_keys [ 1 ] ] ) #NEWLINE# val = ( float ( ( 1.0 / val ) ) if inv else float ( val ) ) #NEWLINE# val = ( ( 1.0 / val ) if flip else val ) #NEWLINE# cals [ ii ] = val #NEWLINE# #UNINDENT# #UNINDENT# comp [ 'rowcals' ] = row_cals #NEWLINE# comp [ 'colcals' ] = col_cals #NEWLINE# comp [ 'data' ] [ 'data' ] = ( ( row_cals [ : , None ] * comp [ 'data' ] [ 'data' ] ) * col_cals [ None , : ] )