ecpi.common.num.array_square_cell module¶
Section author: ECLAIRs GP team
Tools to manage array square cell (index <=> position)
Summary¶
Classes:
Features between index and physical position for a square cell array |
Class diagram:
Functions:
Compute the rectangle formed by the intersection of two rectangles. |
|
|
Reference¶
-
class
ArraySquareCell(ncel_x=1, ncel_y=1, size_cm=1.0)[source]¶ Bases:
objectFeatures between index and physical position for a square cell array
In cartesian convention, ie index (0,0) is the corner left bottom of array.
Example : - ArraySquareCell[1, 2] = 1 - ArraySquareCell[0, 0] = 5 Second axis ^ | | 3 +-+-+ |2|1| 2 +-+-+ |3|4| 1 +-+-+ |5|6| 0 +-+-+-+----> First axis 0 1 2 3
-
add_hit(apos)[source]¶ Add one on pixel associated to position
- Parameters
apos (numpy array (n,2)) – array plan position of photon
-
array_pos_center_cells()[source]¶ Return 2 array x and y with center cells
- Returns
2 array x and y with center cells
- Return type
numpy array
-
idx2pos(array_idx, pos='CTR')[source]¶ return array position
- Parameters
array_idx (int) – array index
pos (string) – pos = {Center: CTR, left bottom :LB, right up :RU}
-
intersection(o_asc, vec_trans)[source]¶ Return the intersection rectangle between current array and o_asc translated of vec_trans
- Parameters
o_asc – array
:type o_asc : ArraySquareCell :param vec_trans: translation to apply at o_asc :type vec_trans : vector :return: intersection rectangle between current array and o_asc translated of vec_trans :rtype: rectangle [[x_lb, y_lb], [x_ru, y_ru]] lb: left bottom, ru: right upper in cm
-
pos2idx_rect(p_rect, p_boundary=False)[source]¶ return index rectangle associated to pos rectangle p_rect
- Parameters
p_rect – rectangle
p_boundary –
-
pos_center_cells()[source]¶ Return 2 array x and y with center cells
- Returns
2 array x and y with center cells
- Return type
numpy array
-
pos_corner_lb()[source]¶ Return position corner ‘l’eft ‘b’ottom in absolute referential
- Returns
[cm] position corner left bottom
- Return type
array (2,)
-
pos_corner_ru()[source]¶ Return position corner ‘r’ight ‘u’pper in absolute referential
- Returns
[cm] position corner right upper
- Return type
array (2,)
-
pos_rect_array()[source]¶ Return current rectangle [[x_lb, y_lb], [x_ru, y_ru]] where lb: left bottom, ru: right upper in cm
- Returns
rectangle [[x_lb, y_lb], [x_ru, y_ru]]
- Return type
array 2x2
-
pos_rect_cells(aidx)[source]¶ Returns physical position of the lower left and upper right corners.
- Parameters
aidx – list or numpy array-like containing the indices
of the lower left corner :type aidx: [[ll_x_idx1, ll_y_idx1], [ll_x_idx2, ll_y_idx2], …] :return: list of the physical coord. of the ll and ur corners. :rtype: list of numpy-like arrays
-
random_pos(nb_pos)[source]¶ random position in all array
- Parameters
nb_pos (int) – number position to random
-
random_pos_rect(nb_pos, rec)[source]¶ random position in rectangle given by parameter return : nb_pos random position in rec
-
set_array(p_ar)[source]¶ Set the current ArraySquareCell object number of cells with those the p_ar ndarray.
- Parameters
p_ar (array) – array model
-
set_pos_corner_lb(p_pos_ori: numpy.array)[source]¶ vector OP where P=pos_array_lb and O: origin lb = left bottom
- Parameters
p_pos_ori (array(float)) – position of the origin
-
set_to_origin(p_to_ori: numpy.array)[source]¶ vector PO where P=pos_array_lb and O: origin
- Parameters
p_to_ori (array(float)) – vector lb to origin
-
value(idx)[source]¶ Return value of a given pixel index.
- Parameters
idx ([idx_x, idx_y]) – pixel index
- Returns
value
- Return type
float
-
value_array(aidx: numpy.array)[source]¶ Return value at a given set of pixel indices. Generalisation of value() for several indices.
- Parameters
idx ([[idx_x, idx_y], .. ]) – pixel indices
- Returns
values
- Return type
array(float)
-
value_at_pos(pos)[source]¶ Return the value at a given physical position.
- Parameters
pos ([ll_x, ll_y]) – physical position
- Returns
value
- Return type
float
-
value_at_pos_check(pos)[source]¶ Value in cell associated to pos, with limit check
- Parameters
pos – x,y in array
-
zeros_like(p_asc)[source]¶ Initiation of current ArraySquareCell object with parameter of ArraySquareCell p_asc.
- Parameters
p_asc (ArraySquareCell) – array model
-
-
intersection_rect(p_r1, p_r2)[source]¶ Compute the rectangle formed by the intersection of two rectangles.
Each rectangle is formed by an array-like structure of the form [[ll_x, ll_y], [ur_x, ur_y]] where the lower left (ll) corner has coordinates (ll_x, ll_y) and the upper right (ur) corner has coordinates (ur_x, ur_y).
If the two rectangles do not overlap then the function returns an array filled with zeros.
- Parameters
p_r1 (array-like structured as [[ll_x, ll_y], [ur_x, ur_y]]) – first rectangle
p_r2 (array-like structured as [[ll_x, ll_y], [ur_x, ur_y]]) – second rectangle
- Returns
intersection of the two input rectangles
- Return type
array-like structured as [[ll_x, ll_y], [ur_x, ur_y]]