cgse-coordinates 2023.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.1
2
+ Name: cgse-coordinates
3
+ Version: 2023.1.0
4
+ Summary: Reference Frames and Coordinate Transofrmations for CGSE
5
+ License: Common-EGSE Software License Agreement
6
+ Requires-Dist: cgse-core
7
+ Requires-Dist: numpy
8
+ Requires-Dist: pandas
9
+ Requires-Dist: transforms3d
10
+
@@ -0,0 +1,15 @@
1
+ egse/coordinates/__init__.py,sha256=FmqTMtFRhAe7INUFi8RxeT2DgDpYll9cfU73OuijBmc,17171
2
+ egse/coordinates/avoidance.py,sha256=9qbGgVZLSIF2tQ5dMDBlLl0wBW3NAOBl_XchC1_t0Xw,3903
3
+ egse/coordinates/cslmodel.py,sha256=Z5KZP9yWmhkp4ZhMfv9fRaZ6zJo5CIazNloBxMW3U1k,4487
4
+ egse/coordinates/laser_tracker_to_dict.py,sha256=8Mav2No5pwWdMIlpwtPM5wUjD3qqiXXd76chHj4JxfM,3453
5
+ egse/coordinates/point.py,sha256=4hyg2-qH5vDi_Co6ohhvUx7pGazvl5EfA9BuAFBE-I8,25131
6
+ egse/coordinates/pyplot.py,sha256=QeLxJKlJDJTkZEIq27rgWj_AyZrdlASWLkoKoJGBMsg,6214
7
+ egse/coordinates/referenceFrame.py,sha256=InJ8iH2v7jlHHiELa9YnFQgf6UV68oye7ynF-XrLhBg,49726
8
+ egse/coordinates/refmodel.py,sha256=SMdFL1xShToMDN0yKsEtjU-na3mHrPyUapWih2W6fsQ,24014
9
+ egse/coordinates/rotationMatrix.py,sha256=0y2XwliE9tdCkxZAUSOIWNdq_rb6O6lojmCSTeSAkZQ,3012
10
+ egse/coordinates/transform3d_addon.py,sha256=_1-LwzdEh_LBVA1qGwco3NJVd_Hm81IHZPQXVncaCIA,15394
11
+ cgse_coordinates-2023.1.0.dist-info/METADATA,sha256=8W9EpaxRT87-92XtQTMWMQkYNgh7GGZyhlmOgkDcGhk,274
12
+ cgse_coordinates-2023.1.0.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
13
+ cgse_coordinates-2023.1.0.dist-info/entry_points.txt,sha256=POKGG7b9BZu4KwRUD33Zq323oxe4fZcCQ7DHNZc4ZHs,47
14
+ cgse_coordinates-2023.1.0.dist-info/top_level.txt,sha256=kKai1l5ns8L0l5J5wU01VKrxo3iW-Ck7TFq3ZJ96dOc,5
15
+ cgse_coordinates-2023.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.3.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [cgse.version]
2
+ cgse-coordinates = egse.plugins
@@ -0,0 +1 @@
1
+ egse
@@ -0,0 +1,531 @@
1
+ import ast
2
+ import logging
3
+ import re
4
+ from math import atan
5
+ from math import atan2
6
+ from math import cos
7
+ from math import degrees
8
+ from math import pow
9
+ from math import radians
10
+ from math import sin
11
+ from math import sqrt
12
+ from math import tan
13
+ from typing import Dict
14
+ from typing import List
15
+ from typing import Optional
16
+ from typing import Union
17
+
18
+ import numpy as np
19
+ from numpy.polynomial import Polynomial
20
+
21
+ from egse.coordinates.referenceFrame import ReferenceFrame
22
+ from egse.settings import Settings
23
+ from egse.state import GlobalState
24
+ from egse.setup import NavigableDict
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+ FOV_SETTINGS = Settings.load("Field-Of-View")
29
+ CCD_SETTINGS = Settings.load("CCD")
30
+
31
+
32
+ def undistorted_to_distorted_focal_plane_coordinates(
33
+ x_undistorted, y_undistorted, distortion_coefficients, focal_length
34
+ ):
35
+ """
36
+ Conversion from undistorted to distorted focal-plane coordinates. The distortion is a
37
+ radial effect and is defined as the difference in radial distance to the optical axis
38
+ between the distorted and undistorted coordinates, and can be expressed in terms of the
39
+ undistorted radial distance r as follows:
40
+
41
+ Δr = r * [(k1 * r**2) + (k2 * r**4) + (k3 * r**6)],
42
+
43
+ where the distortion and r are expressed in normalised focal-plane coordinates (i.e. divided
44
+ by the focal length, expressed in the same unit), and (k1, k2, k3) are the distortion
45
+ coefficients.
46
+
47
+ Args:
48
+ x_undistorted: Undistorted x-coordinate on the focal plane [mm].
49
+ y_undistorted: Undistorted y-coordinate on the focal plane [mm].
50
+ distortion_coefficients: List of polynomial coefficients for the field distortion.
51
+ focal_length: Focal length [mm].
52
+ Returns:
53
+ x_distorted: Distorted x-coordinate on the focal plane [mm].
54
+ y_distorted: Distorted y-coordinate on the focal plane [mm].
55
+ """
56
+
57
+ # Distortion coefficients -> (0, 0, 0, k1, 0, k2, 0, k3)
58
+
59
+ coefficients = [
60
+ 0,
61
+ 0,
62
+ 0,
63
+ distortion_coefficients[0],
64
+ 0,
65
+ distortion_coefficients[1],
66
+ 0,
67
+ distortion_coefficients[2],
68
+ ]
69
+ distortion_polynomial = Polynomial(coefficients)
70
+
71
+ # Position on the focal plane:
72
+ # - field angle [radians]
73
+ # - radial distance from the optical axis [normalised pixels]
74
+
75
+ angle = atan2(y_undistorted, x_undistorted)
76
+ distance_undistorted = sqrt(pow(x_undistorted, 2) + pow(y_undistorted, 2)) / focal_length
77
+
78
+ # Distortion [mm]
79
+ # Source moves away from the optical axis (radially)
80
+
81
+ distortion = distortion_polynomial(distance_undistorted) * focal_length
82
+
83
+ # The field angle remains the same
84
+
85
+ x_distorted = x_undistorted + cos(angle) * distortion
86
+ y_distorted = y_undistorted + sin(angle) * distortion
87
+
88
+ return x_distorted, y_distorted
89
+
90
+
91
+ def distorted_to_undistorted_focal_plane_coordinates(
92
+ x_distorted, y_distorted, inverse_distortion_coefficients, focal_length
93
+ ):
94
+ """
95
+ Conversion from distorted to undistorted focal-plane coordinates. The inverse distortion is a
96
+ radial effect and is defined as the difference in radial distance to the optical axis
97
+ between the distorted and undistorted coordinates, and can be expressed in terms of the
98
+ undistorted radial distance r as follows:
99
+
100
+ Δr = r * [(k1 * r**2) + (k2 * r**4) + (k3 * r**6)],
101
+
102
+ where the inverse distortion and r are expressed in normalised focal-plane coordinates (i.e. divided
103
+ by the focal length, expressed in the same unit), and (k1, k2, k3) are the inverse distortion
104
+ coefficients.
105
+
106
+ Args:
107
+ x_distorted: Distorted x-coordinate on the focal plane [mm].
108
+ y_distorted: Distorted y-coordinate on the focal plane [mm].
109
+ inverse_distortion_coefficients: List of polynomial coefficients for the inverse field distortion.
110
+ focal_length: Focal length [mm].
111
+ Returns:
112
+ x_undistorted: Undistorted x-coordinate on the focal plane [mm].
113
+ y_undistorted: Undistorted y-coordinate on the focal plane [mm].
114
+ """
115
+
116
+ # Inverse distortion coefficients -> (0, 0, 0, k1, 0, k2, 0, k3)
117
+
118
+ coefficients = [
119
+ 0,
120
+ 0,
121
+ 0,
122
+ inverse_distortion_coefficients[0],
123
+ 0,
124
+ inverse_distortion_coefficients[1],
125
+ 0,
126
+ inverse_distortion_coefficients[2],
127
+ ]
128
+ inverse_distortion_polynomial = Polynomial(coefficients)
129
+
130
+ # Position on the focal plane:
131
+ # - field angle [radians]
132
+ # - radial distance from the optical axis [normalised pixels]
133
+
134
+ angle = atan2(y_distorted, x_distorted)
135
+ distance_distorted = sqrt(pow(x_distorted, 2) + pow(y_distorted, 2)) / focal_length
136
+
137
+ # Inverse distortion [mm]
138
+ # Source moves towards the optical axis (radially) -> negative!
139
+
140
+ inverse_distortion = inverse_distortion_polynomial(distance_distorted) * focal_length
141
+
142
+ # The field angle remains the same
143
+
144
+ x_undistorted = x_distorted + cos(angle) * inverse_distortion
145
+ y_undistorted = y_distorted + sin(angle) * inverse_distortion
146
+
147
+ return x_undistorted, y_undistorted
148
+
149
+
150
+ def focal_plane_to_ccd_coordinates(x_fp, y_fp):
151
+ """
152
+ Conversion from focal-plane to pixel coordinates on the appropriate CCD.
153
+
154
+ Args:
155
+ x_fp: Focal-plane x-coordinate [mm].
156
+ y_fp: Focal-plane y-coordinate [mm].
157
+ Returns:
158
+ Pixel coordinates (row, column) and the corresponding CCD. If the given
159
+ focal-plane coordinates do not fall on any CCD, (None, None, None) is
160
+ returned.
161
+ """
162
+ setup = GlobalState.setup
163
+
164
+ if setup is not None:
165
+ num_rows = setup.camera.ccd.num_rows
166
+ num_cols = setup.camera.ccd.num_column
167
+ else:
168
+ num_rows = CCD_SETTINGS.NUM_ROWS
169
+ num_cols = CCD_SETTINGS.NUM_COLUMNS
170
+
171
+ for ccd_code in range(1, 5):
172
+
173
+ (row, column) = __focal_plane_to_ccd_coordinates__(x_fp, y_fp, ccd_code)
174
+
175
+ if (row < 0) or (column < 0):
176
+ continue
177
+
178
+ if (row >= num_rows) or (column >= num_cols):
179
+ continue
180
+
181
+ return row, column, ccd_code
182
+
183
+ return None, None, None
184
+
185
+
186
+ def __focal_plane_to_ccd_coordinates__(x_fp, y_fp, ccd_code):
187
+ """
188
+ Conversion from focal-plane coordinates to pixel coordinates on the given CCD.
189
+
190
+ Args:
191
+ x_fp: Focal-plane x-coordinate [mm].
192
+ y_fp: Focal-plane y-coordinate [mm].
193
+ ccd_code: Code of the CCD for which to calculate the pixel coordinates [1, 2, 3, 4].
194
+ Returns:
195
+ Pixel coordinates (row, column) on the given CCD.
196
+ """
197
+
198
+ setup = GlobalState.setup
199
+
200
+ if setup is not None:
201
+ ccd_orientation = setup.camera.ccd.orientation[int(ccd_code) - 1]
202
+ pixel_size = setup.camera.ccd.pixel_size / 1000.0 # [mm]
203
+ ccd_origin_x = GlobalState.setup.camera.ccd.origin_offset_x[int(ccd_code) - 1]
204
+ ccd_origin_y = GlobalState.setup.camera.ccd.origin_offset_y[int(ccd_code) - 1]
205
+ else:
206
+ ccd_orientation = CCD_SETTINGS.ORIENTATION[int(ccd_code) - 1]
207
+ pixel_size = CCD_SETTINGS.PIXEL_SIZE / 1000 # Pixel size [mm]
208
+ ccd_origin_x = CCD_SETTINGS.ZEROPOINT[0]
209
+ ccd_origin_y = CCD_SETTINGS.ZEROPOINT[1]
210
+
211
+ ccd_angle = radians(ccd_orientation)
212
+
213
+ # CCD coordinates [mm]
214
+
215
+ row = ccd_origin_y - x_fp * sin(ccd_angle) + y_fp * cos(ccd_angle)
216
+ column = ccd_origin_x + x_fp * cos(ccd_angle) + y_fp * sin(ccd_angle)
217
+
218
+ row /= pixel_size
219
+ column /= pixel_size
220
+
221
+ return row, column
222
+
223
+
224
+ def focal_plane_coordinates_to_angles(x_fp, y_fp):
225
+ """
226
+ Conversion from focal-plane coordinates to the gnomonic distance from the optical axis and
227
+ the in-field angle.
228
+
229
+ Args:
230
+ x_fp: Focal-plane x-coordinate [mm].
231
+ y_fp: Focal-plane y-coordinate [mm].
232
+ Returns:
233
+ Gnomonic distance from the optical axis and in-field angle [degrees].
234
+ """
235
+
236
+ setup = GlobalState.setup
237
+
238
+ if setup is not None:
239
+ focal_length_mm = GlobalState.setup.camera.fov.focal_length_mm
240
+ else:
241
+ focal_length_mm = FOV_SETTINGS.FOCAL_LENGTH
242
+
243
+ theta = degrees(atan(sqrt(pow(x_fp, 2) + pow(y_fp, 2)) / focal_length_mm))
244
+ phi = degrees(atan2(y_fp, x_fp))
245
+
246
+ return theta, phi
247
+
248
+
249
+ def ccd_to_focal_plane_coordinates(row, column, ccd_code):
250
+ """
251
+ Conversion from pixel-coordinates on the given CCD to focal-plane coordinates.
252
+
253
+ Args:
254
+ row: Row coordinate [pixels].
255
+ column: Column coordinate [pixels].
256
+ ccd_code: Code of the CCD for which the pixel coordinates are given.
257
+ Returns:
258
+ Focal-plane coordinates (x, y) [mm].
259
+ """
260
+
261
+ setup = GlobalState.setup
262
+
263
+ if setup is not None:
264
+ ccd_orientation = setup.camera.ccd.orientation[int(ccd_code) - 1]
265
+ pixel_size_mm = setup.camera.ccd.pixel_size / 1000.0 # [mm]
266
+ ccd_origin_x = GlobalState.setup.camera.ccd.origin_offset_x[int(ccd_code) - 1]
267
+ ccd_origin_y = GlobalState.setup.camera.ccd.origin_offset_y[int(ccd_code) - 1]
268
+ else:
269
+ ccd_orientation = CCD_SETTINGS.ORIENTATION[int(ccd_code) - 1]
270
+ pixel_size_mm = CCD_SETTINGS.PIXEL_SIZE / 1000 # Pixel size [mm]
271
+ ccd_origin_x = CCD_SETTINGS.ZEROPOINT[0]
272
+ ccd_origin_y = CCD_SETTINGS.ZEROPOINT[1]
273
+
274
+ # Convert the pixel coordinates into [mm] coordinates
275
+
276
+ row_mm = row * pixel_size_mm
277
+ column_mm = column * pixel_size_mm
278
+
279
+ # Convert the CCD coordinates into FP coordinates [mm]
280
+
281
+ ccd_angle = radians(ccd_orientation)
282
+
283
+ x_fp = (column_mm - ccd_origin_x) * cos(ccd_angle) - (row_mm - ccd_origin_y) * sin(ccd_angle)
284
+ y_fp = (column_mm - ccd_origin_x) * sin(ccd_angle) + (row_mm - ccd_origin_y) * cos(ccd_angle)
285
+
286
+ # That's it
287
+
288
+ return x_fp, y_fp
289
+
290
+ def angles_to_focal_plane_coordinates(theta, phi):
291
+ """
292
+ Conversion from the gnomonic distance from the optical axis and
293
+ the in-field angle to focal-plane coordinates.
294
+
295
+ Args:
296
+ theta: Gnomonic distance from the optical axis [degrees].
297
+ phi: In-field angle [degrees].
298
+ Returns:
299
+ Focal-plane coordinates (x, y) [mm].
300
+ """
301
+
302
+ setup = GlobalState.setup
303
+
304
+ if setup is not None:
305
+ focal_length_mm = GlobalState.setup.camera.fov.focal_length_mm
306
+ else:
307
+ focal_length_mm = FOV_SETTINGS.FOCAL_LENGTH
308
+
309
+ distance = focal_length_mm * tan(radians(theta)) # [mm]
310
+
311
+ phi_radians = radians(phi)
312
+
313
+ x_fp = distance * cos(phi_radians)
314
+ y_fp = distance * sin(phi_radians)
315
+
316
+ return x_fp, y_fp
317
+
318
+
319
+ def dict_to_ref_model(model_def: Union[Dict, List]) -> NavigableDict:
320
+ """
321
+ Creates a reference frames model from a dictionary or list of reference frame definitions.
322
+
323
+ When a list is provided, the items in the list must be ReferenceFrames.
324
+
325
+ The reference frame definitions are usually read from a YAML file or returned by a Setup,
326
+ but can also be just ReferenceFrame objects.
327
+
328
+ ReferenceFrame definitions have the following format:
329
+
330
+ ```
331
+ ReferenceFrame://(<definition>)
332
+ ```
333
+ where `<definition>` has the following elements, separated by '` | `':
334
+ * a translation matrix
335
+ * a rotation matrix
336
+ * the name of the reference frame
337
+ * the name of the reference for this reference frame
338
+ * a dictionary of links
339
+
340
+ Args:
341
+ model_def (dict or list): the definition of the reference model
342
+
343
+ Returns:
344
+ A dictionary representing the reference frames model.
345
+ """
346
+
347
+ ref_model = NavigableDict({})
348
+ ref_links = {}
349
+
350
+ def create_ref_frame(name, data) -> Union[ReferenceFrame, str]:
351
+
352
+ # This is a recursive function that creates a reference frame based on the given data.
353
+ # * When the data is already a ReferenceFrame, it just returns data
354
+ # * When data starts with the special string `ReferenceFrame//`, the data string is parsed
355
+ # and a corresponding ReferenceFrame is returned
356
+ # * When there is no match, the data is returned unaltered.
357
+ #
358
+ # SIDE EFFECT:
359
+ # * In the process, the outer ref-model and ref_links are updated.
360
+
361
+ if isinstance(data, ReferenceFrame):
362
+ return data
363
+
364
+ match = re.match(r"ReferenceFrame//\((.*)\)$", data)
365
+ if not match:
366
+ return data
367
+
368
+ translation, rotation, name, ref_name, links = match[1].split(" | ")
369
+
370
+ # all links are processed later..
371
+
372
+ ref_links[name] = ast.literal_eval(links)
373
+
374
+ if ref_name == name == "Master":
375
+ ref_model.add(ref_name, ReferenceFrame.createMaster())
376
+ return ref_model["Master"]
377
+
378
+ if ref_name not in ref_model:
379
+ ref_model.add(ref_name, create_ref_frame(ref_name, model_def[ref_name]))
380
+
381
+ ref_frame = ReferenceFrame.fromTranslationRotation(
382
+ deserialize_array(translation),
383
+ deserialize_array(rotation),
384
+ name=name,
385
+ ref=ref_model[ref_name],
386
+ )
387
+
388
+ return ref_frame
389
+
390
+ # if the given model_def is a list, turn it into a dict
391
+
392
+ if isinstance(model_def, list):
393
+ model_def = {frame.name: frame for frame in model_def}
394
+
395
+ for key, value in model_def.items():
396
+ if key not in ref_model:
397
+ ref_model.add(key, create_ref_frame(key, value))
398
+
399
+ # Process all the links
400
+
401
+ for ref_name, link_names in ref_links.items():
402
+ ref = ref_model[ref_name]
403
+ for link_name in link_names:
404
+ if link_name not in ref.linkedTo:
405
+ ref.addLink(ref_model[link_name])
406
+
407
+ return ref_model
408
+
409
+
410
+ def ref_model_to_dict(ref_model) -> NavigableDict:
411
+ """Creates a dictionary with reference frames definitions that define a reference model.
412
+
413
+ Args:
414
+ ref_model: A dictionary representing the reference frames model or a list of reference
415
+ frames.
416
+ Returns:
417
+ A dictionary of reference frame definitions.
418
+ """
419
+
420
+ if isinstance(ref_model, dict):
421
+ ref_model = ref_model.values()
422
+
423
+ # take each key (which is a reference frame) and serialize it
424
+
425
+ model_def = {}
426
+
427
+ for ref in ref_model:
428
+ translation, rotation = ref.getTranslationRotationVectors()
429
+ links = [ref.name for ref in ref.linkedTo]
430
+ model_def[ref.name] = (
431
+ f"ReferenceFrame//("
432
+ f"{serialize_array(translation, precision=6)} | "
433
+ f"{serialize_array(rotation, precision=6)} | "
434
+ f"{ref.name} | "
435
+ f"{ref.ref.name} | "
436
+ f"{links})"
437
+ )
438
+
439
+ return NavigableDict(model_def)
440
+
441
+
442
+ def serialize_array(arr: Union[np.ndarray, list], precision: int = 4) -> str:
443
+ """Returns a string representation of a numpy array.
444
+
445
+ >>> serialize_array([1,2,3])
446
+ '[1, 2, 3]'
447
+ >>> serialize_array([[1,2,3], [4,5,6]])
448
+ '[[1, 2, 3], [4, 5, 6]]'
449
+ >>> serialize_array([[1,2.2,3], [4.3,5,6]])
450
+ '[[1.0000, 2.2000, 3.0000], [4.3000, 5.0000, 6.0000]]'
451
+ >>> serialize_array([[1,2.2,3], [4.3,5,6]], precision=2)
452
+ '[[1.00, 2.20, 3.00], [4.30, 5.00, 6.00]]'
453
+
454
+ Args:
455
+ arr: a one or two dimensional numpy array or list.
456
+ precision (int): number of digits of precision
457
+ Returns:
458
+ A string representing the input array.
459
+ """
460
+ if isinstance(arr, list):
461
+ arr = np.array(arr)
462
+ msg = np.array2string(
463
+ arr,
464
+ separator=", ",
465
+ suppress_small=True,
466
+ formatter={"float_kind": lambda x: f"{x:.{precision}f}"},
467
+ ).replace("\n", "")
468
+ return msg
469
+
470
+
471
+ def deserialize_array(arr_str: str) -> Optional[np.ndarray]:
472
+ """Returns a numpy array from the given string.
473
+
474
+ The input string is interpreted as a one or two-dimensional array, with commas or spaces
475
+ separating the columns, and semi-colons separating the rows.
476
+
477
+ >>> deserialize_array('1,2,3')
478
+ array([1, 2, 3])
479
+ >>> deserialize_array('1 2 3')
480
+ array([1, 2, 3])
481
+ >>> deserialize_array('1,2,3;4,5,6')
482
+ array([[1, 2, 3],
483
+ [4, 5, 6]])
484
+ >>> deserialize_array("[[1,2,3], [4,5,6]]")
485
+ array([[1, 2, 3],
486
+ [4, 5, 6]])
487
+
488
+ Args:
489
+ arr_str: string representation of a numpy array
490
+ Returns:
491
+ A one or two-dimensional numpy array or `None` when input string cannot be parsed into a
492
+ numpy array.
493
+ """
494
+
495
+ import re
496
+
497
+ arr_str = re.sub(r"\],\s*\[", "];[", arr_str)
498
+ try:
499
+ arr = np.array(_convert_from_string(arr_str))
500
+ return arr if ";" in arr_str else arr.flatten()
501
+ except ValueError as exc:
502
+ logger.error(f"Input string could not be parsed into a numpy array: {exc}")
503
+ return None
504
+
505
+
506
+ def _convert_from_string(data):
507
+
508
+ # This function was copied from:
509
+ # https://github.com/numpy/numpy/blob/v1.19.0/numpy/matrixlib/defmatrix.py#L14
510
+ # We include the function here because the np.matrix class is deprecated and will be removed.
511
+ # This function is what we actually needed from np.matrix.
512
+
513
+ for char in "[]":
514
+ data = data.replace(char, "")
515
+
516
+ rows = data.split(";")
517
+ new_data = []
518
+ count = 0
519
+ for row in rows:
520
+ trow = row.split(",")
521
+ new_row = []
522
+ for col in trow:
523
+ temp = col.split()
524
+ new_row.extend(map(ast.literal_eval, temp))
525
+ if count == 0:
526
+ n_cols = len(new_row)
527
+ elif len(new_row) != n_cols:
528
+ raise ValueError("Rows not the same size.")
529
+ count += 1
530
+ new_data.append(new_row)
531
+ return new_data
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Wed Sep 9 17:19:47 2020
5
+
6
+ @author: pierre
7
+ """
8
+ import numpy as np
9
+ from egse.state import GlobalState
10
+ from egse.coordinates.point import Points
11
+
12
+
13
+ def is_avoidance_ok(hexusr,hexobj,setup=None,verbose=False):
14
+ """
15
+ is_avoidance_ok(hexusr,hexobj,setup=None)
16
+
17
+ INPUT
18
+ hexusr : ReferenceFrame
19
+ xy plane = maximal height of the FPA_SEN
20
+ z axis pointing away from the FPA
21
+
22
+ hexobj : ReferenceFrame
23
+ xy plane = FPA_SEN
24
+ z axis pointing towards L6
25
+
26
+ setup : GlobalSetup.setup, optional
27
+ if not provided, GlobalState.setup is used
28
+
29
+
30
+ OUTPUT : Boolean indicating wheather or not the FPA is outside of the avoidance volume around L6
31
+ """
32
+
33
+ if setup is None:
34
+ setup = GlobalState.setup
35
+
36
+ """
37
+ A. HORIZONTAL AVOIDANCE
38
+ Ensure that the center of L6, materialised by HEX_USR (incl. z-direction security wrt TOU_L6)
39
+ stays within a given radius of the origin of FPA_SEN
40
+ """
41
+
42
+ # Clearance = the tolerance in every horizontal direction (3 mm; PLATO-KUL-PL-ICD-0001 v1.2)
43
+ clearance_xy = setup.camera.fpa.avoidance.clearance_xy
44
+
45
+ # l6xy = the projection of the origin of HEX_USR on the X-Y plane of FPA_SEN
46
+ l6xy = hexusr.getOrigin().expressIn(hexobj)[:2]
47
+
48
+ # !! This is a verification of the current situation --> need to replace by a simulation of the forthcoming movement in the building block
49
+ horizontal_check = ((l6xy[0]**2.+l6xy[1]**2.) < clearance_xy*clearance_xy)
50
+
51
+
52
+ """
53
+ B. VERTICAL AVOIDANCE
54
+ Ensure that the CCD never hits L6.
55
+ The definition of HEX_USR includes a tolerance below L6 (1.65 mm)
56
+ We include a tolerance above FPA_SEN here (0.3 mm)
57
+ We define a collection of points to act at the vertices of the avoidance volume above the FPA
58
+ """
59
+
60
+ # Clearance = vertical uncertainty on the CCD location (0.3 mm; PLATO-KUL-PL-ICD-0001 v1.2)
61
+ clearance_z = setup.camera.fpa.avoidance.clearance_z
62
+
63
+ # Vertices = Points representing the vertices of the avoidance volume above the FPA (60)
64
+ vertices_nb = setup.camera.fpa.avoidance.vertices_nb
65
+ # All vertices are on a circle of radius 'vertices_radius' (100 mm)
66
+ vertices_radius = setup.camera.fpa.avoidance.vertices_radius
67
+
68
+ angles = np.linspace(0,np.pi * 2,vertices_nb,endpoint=False)
69
+ vertices_x = np.cos(angles) * vertices_radius
70
+ vertices_y = np.sin(angles) * vertices_radius
71
+ vertices_z = np.ones_like(angles) * clearance_z
72
+
73
+ # The collection of Points defining the avoidance volume around FPA_SEN
74
+ vert_obj = Points(coordinates=np.array([vertices_x,vertices_y,vertices_z]),ref=hexobj,name="vert_obj")
75
+
76
+ # Their coordinates in HEX_USR
77
+ # NB: vert_obj is a Points, vert_usr is an array
78
+ vert_usr = vert_obj.expressIn(hexusr)
79
+
80
+
81
+ # !! Same as above : this is verifying the current situation, not the one after a planned movement
82
+ # Verify that all vertices ("protecting" FPA_SEN) are below the x-y plane of HEX_USR ("protecting" L6)
83
+ vertical_check = (np.all(vert_usr[2,:] < 0.))
84
+
85
+ if verbose:
86
+ printdict = {True:"OK", False:"NOT OK"}
87
+ print(f"HORIZONTAL AVOIDANCE: {printdict[horizontal_check]}")
88
+ print(f" VERTICAL AVOIDANCE: {printdict[vertical_check]}")
89
+
90
+ if verbose > 1:
91
+ print(f"Points Coordinates")
92
+ coobj = vert_obj.coordinates
93
+ for i in range(vertices_nb):
94
+ print(f"{i} OBJ {np.round(coobj[:3,i],6)} --> USR {np.round(vert_usr[:3,i],6)}")
95
+ vert_z = vert_usr[2,:]
96
+ vert_zi = np.where(vert_z==np.max(vert_z))
97
+ print(f"#vertices at max z : {len(vert_zi[0])}")
98
+ print(f"First one: vertex {vert_zi[0][0]} : {np.round(vert_usr[:3,vert_zi[0][0]],6)}")
99
+
100
+ return horizontal_check and vertical_check
101
+
102
+
103
+