Source code for ecpi.common.instru.array_convention

'''
Created on 1 avr. 2019

@author: Colley CNRS/IN2P3/APC


ECLAIRs general program pipeline convention (egp) of 2D array:
=============================================================

egp used cartesian coordinates where :
* first coordinate is the position on horizontal axis, same as y axis in ECLLos frame 
  defined by CNES
* second coordinate is the position on vertical axis, same as z axis in ECLLos frame defined by CNES
* so shield ECLAIRs is at the bottom and origin of epg is always in left corner
* the value is associated to "pixel" that has the lower  left corner at (y,z)
 

example : a_epg[1,2] = 1 


 z axis (same direction that z_ECCLos)
 
  ^
  |
  |
3 + +-+
  | |1| 
2 + +-+
  |
1 +
  | 
0 +-+-+-+----> y axis (same direction that y_ECCLos)
  0 1 2 3  
 +---------------------+
 |    SHIELD ECLAIRs   |
 +---------------------+ 
  
  
ijDet convention of 2D array:
=============================

ijdet used cartesian coordinates where :
* first coordinate is the row number along direction like z axis in ECLLos frame defined by CNES
* second coordinate is the column number along direction like inverse of y axis in ECLLos frame 
  defined by CNES
* so shield ECLAIRs is at the bottom and origin of ijDet is always in right corner


 example : a_epg[1,2] = 1 


                      i
                      ^
                      | 2
                +-+   +
                |1|   | 1
                +-+   + 
                      | 0
      j    <----+-+-+-+ 
                 2 1 0              
 +---------------------+
 |    SHIELD ECLAIRs   |
 +---------------------+  

'''
import numpy as np 


#
# on index
#

[docs]def ijdet_to_yzegp(idet, jdet, idx_max=79): """convert couple index in ijdet convention to yzegp convention :param idet: first coordinate of ijdet :type idet: integer :param jdet: second coordinate of ijdet :type jdet: integer :param idx_max: index max (ie MAX-1) :type idx_max: integer """ return idx_max - jdet, idet
[docs]def yzegp_to_ijdet(y_gp, z_gp, idx_max=79): """convert couple index in yzegp convention to ijdet convention :param y_gp: first coordinate of yzegp :type y_gp: integer :param z_gp: second coordinate of yzegp :type z_gp:integer :param idx_max: index max (ie MAX-1) :type idx_max:integer """ return z_gp, idx_max - y_gp
# # from array ijdet #
[docs]def ijdet_to_yzegp_array_slow(a_ijdet): """convert array 2D in ijdet convention to yzegp convention :param a_ijdet: array in ijdet convention :type a_ijdet: numpy 2D array """ out_array = np.empty_like(a_ijdet) in_shape = a_ijdet.shape # only square array assert in_shape[0] == in_shape[1] dim = in_shape[0] for idx_i in range(dim): for idx_j in range(dim): idx_out = ijdet_to_yzegp(idx_i, idx_j, dim-1) out_array[idx_out] = a_ijdet[idx_i, idx_j] return out_array
[docs]def ijdet_to_yzegp_array(a_ijdet): """convert array 2D in ijdet convention to yzegp convention :param a_ijdet: array in ijdet convention :type a_ijdet: numpy 2D array """ # this transformation is ok too np.flip(np.transpose(a_ijdet), 0) return np.rot90(a_ijdet)
# # from array yzegp #
[docs]def yzegp_to_ijdet_array(a_gpidx): """convert array 2D in yzegp convention to ijdet convention :param a_ijdet: array in ijdet convention :type a_ijdet: numpy 2D array """ return np.flip(a_gpidx, 0).transpose()