cgse-coordinates 0.17.3__py3-none-any.whl → 0.18.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.
@@ -1,190 +1,202 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- This module defines some plotting functions for Reference Frames.
5
-
6
- @author: Pierre Royer
7
- """
1
+ """ " This module contains plotting utility functions for reference frames."""
8
2
 
3
+ import matplotlib
9
4
  import matplotlib.pyplot as plt
10
- from mpl_toolkits.mplot3d import Axes3D # needed for 3d projection
5
+ from egse.coordinates.reference_frame import ReferenceFrame
11
6
  import numpy as np
12
7
  import egse
13
- from egse.coordinates.referenceFrame import ReferenceFrame
14
8
  from egse.coordinates.point import Point, Points
15
9
 
16
10
 
17
- def plot_reference_frame(frame, master=None, figname=None, **kwargs):
18
- """Plot a Reference Frame.
11
+ def plot_reference_frame(
12
+ frame: ReferenceFrame, master: ReferenceFrame | None = None, fig_name: str | None = None, **kwargs
13
+ ) -> matplotlib.axes._subplots.Axes3DSubplot:
14
+ """Plots a reference frame.
15
+
16
+ Use ax.set_xlim3d(min, max) to properly set the ranges of the display.
19
17
 
20
18
  Args:
21
- frame : egse.coordinates.referenceFrame.ReferenceFrame
22
- master : master ReferenceFrame (optional)
23
- figname: string. Name of matplotlib figure (can be pre-existing)
24
- kwargs : passed to matplotlib.axes._subplots.Axes3DSubplot.quiver
19
+ frame (ReferenceFrame): Reference frame
20
+ master (ReferenceFrame | None): Optional master reference frame.
21
+ fig_name (str): Name of the plot figure.
22
+ kwargs : Keyword arguments passed to matplotlib.axes._subplots.Axes3DSubplot.quiver.
25
23
 
26
24
  Returns:
27
- matplotlib.axes._subplots.Axes3DSubplot displaying the reference frame.
28
-
29
- The three unit vectors are shown with the following colors ('RGB'):
25
+ matplotlib.axes._subplots.Axes3DSubplot displaying the reference frame. The three unit vectors are shown in
26
+ the following colours (RGB):
30
27
  x: Red
31
28
  y: Green
32
29
  z: Blue
33
-
34
- .. note::
35
- Use ax.set_xlim3d(min,max) to properly set the ranges of the display
36
-
37
30
  """
31
+
38
32
  if master is None:
39
- tmpmaster = ReferenceFrame.createMaster()
33
+ temp_master = ReferenceFrame.create_master()
40
34
  else:
41
- tmpmaster = master.__copy__()
42
-
43
- f0 = frame.getOrigin()
44
- fx = frame.getAxis("x", name="fx")
45
- fy = frame.getAxis("y", name="fy")
46
- fz = frame.getAxis("z", name="fz")
47
- f0m = f0.expressIn(tmpmaster)[:3]
48
- fxm = fx.expressIn(tmpmaster)[:3]
49
- fym = fy.expressIn(tmpmaster)[:3]
50
- fzm = fz.expressIn(tmpmaster)[:3]
51
- del tmpmaster
52
-
53
- # Origin of the X,Y and Z vectors (x = the 'x' coordinates of the origin of all 3 vectors)
54
- # Every vector independently (--> plot in diff. colors)
55
- x, y, z = np.array([f0m[0]]), np.array([f0m[1]]), np.array([f0m[2]])
56
-
57
- # Orientation of the X,Y and Z vectors
58
- vecxx, vecyx, veczx = np.array([fxm[0] - f0m[0]]), np.array([fym[0] - f0m[0]]), np.array([fzm[0] - f0m[0]])
59
- vecxy, vecyy, veczy = np.array([fxm[1] - f0m[1]]), np.array([fym[1] - f0m[1]]), np.array([fzm[1] - f0m[1]])
60
- vecxz, vecyz, veczz = np.array([fxm[2] - f0m[2]]), np.array([fym[2] - f0m[2]]), np.array([fzm[2] - f0m[2]])
35
+ temp_master = master.__copy__()
36
+
37
+ # Origin and unit axes of the reference frame
38
+
39
+ origin = frame.get_origin()
40
+ unit_axis_x = frame.get_axis("x", name="fx")
41
+ unit_axis_y = frame.get_axis("y", name="fy")
42
+ unit_axis_z = frame.get_axis("z", name="fz")
43
+
44
+ # Now expressed in the master reference frame
45
+
46
+ origin_master = origin.express_in(temp_master)[:3]
47
+ unit_axis_x_master = unit_axis_x.express_in(temp_master)[:3]
48
+ unit_axis_y_master = unit_axis_y.express_in(temp_master)[:3]
49
+ z_axis_master = unit_axis_z.express_in(temp_master)[:3]
50
+
51
+ del temp_master
52
+
53
+ # Coordinates of the origin, expressed in the master reference frame
54
+ origin_x_master, origin_y_master, origin_z_master = (
55
+ np.array([origin_master[0]]),
56
+ np.array([origin_master[1]]),
57
+ np.array([origin_master[2]]),
58
+ )
59
+
60
+ # Orientation of the unit vectors of the reference frame, expressed in the master reference frame
61
+
62
+ vecxx, vecyx, veczx = (
63
+ np.array([unit_axis_x_master[0] - origin_master[0]]),
64
+ np.array([unit_axis_y_master[0] - origin_master[0]]),
65
+ np.array([z_axis_master[0] - origin_master[0]]),
66
+ )
67
+ vecxy, vecyy, veczy = (
68
+ np.array([unit_axis_x_master[1] - origin_master[1]]),
69
+ np.array([unit_axis_y_master[1] - origin_master[1]]),
70
+ np.array([z_axis_master[1] - origin_master[1]]),
71
+ )
72
+ vecxz, vecyz, veczz = (
73
+ np.array([unit_axis_x_master[2] - origin_master[2]]),
74
+ np.array([unit_axis_y_master[2] - origin_master[2]]),
75
+ np.array([z_axis_master[2] - origin_master[2]]),
76
+ )
61
77
 
62
78
  kwargs.setdefault("length", 1)
63
79
  kwargs.setdefault("normalize", True)
64
80
  # kwargs.setdefault('figsize', (10,10))
65
81
 
66
- fig = plt.figure(figname, figsize=plt.figaspect(1.0))
82
+ fig = plt.figure(fig_name, figsize=plt.figaspect(1.0))
67
83
  ax = fig.add_subplot(projection="3d")
68
- ax.quiver(x, y, z, vecxx, vecxy, vecxz, color="r", **kwargs)
69
- ax.quiver(x, y, z, vecyx, vecyy, vecyz, color="g", **kwargs)
70
- ax.quiver(x, y, z, veczx, veczy, veczz, color="b", **kwargs)
84
+ ax.quiver(origin_x_master, origin_y_master, origin_z_master, vecxx, vecxy, vecxz, color="r", **kwargs)
85
+ ax.quiver(origin_x_master, origin_y_master, origin_z_master, vecyx, vecyy, vecyz, color="g", **kwargs)
86
+ ax.quiver(origin_x_master, origin_y_master, origin_z_master, veczx, veczy, veczz, color="b", **kwargs)
71
87
  # ax.axis('equal')
72
88
 
73
89
  return ax
74
90
 
75
91
 
76
- def plot_points(points, master=None, figname=None, **kwargs):
77
- """Plot the Points object.
92
+ def plot_points(
93
+ points: Points | list[Point], master=None, fig_name: str | None = None, **kwargs
94
+ ) -> matplotlib.axes._subplots.Axes3DSubplot:
95
+ """Plots the given collection of points.
96
+
97
+ Use ax.set_xlim3d(min, max) to properly set the ranges of the display.
78
98
 
79
99
  Args:
80
- points : either a (egse.coordinate.point.)Points object or a list of Point objects
81
- master : master ReferenceFrame (optional)
82
- figname: string. Name of matplotlib figure (can be pre-existing)
83
- kwargs : passed to matplotlib.axes._subplots.Axes3DSubplot.scatter
100
+ points (Points | list[Point]): Collection of points to plot.
101
+ master (ReferenceFrame | None): Optional master reference frame.
102
+ fig_name (str): Name of the plot figure.
103
+ kwargs : Keyword arguments passed to matplotlib.axes._subplots.Axes3DSubplot.scatter.
84
104
 
85
105
  Returns:
86
- matplotlib.axes._subplots.Axes3DSubplot displaying the reference frame.
87
-
88
- .. note::
89
- Use ax.set_xlim3d(min,max) to properly set the ranges of the display.
90
-
106
+ matplotlib.axes._subplots.Axes3DSubplot displaying the given collection of points
91
107
  """
108
+
92
109
  if master is None:
93
- tmpmaster = ReferenceFrame.createMaster()
110
+ temp_master = ReferenceFrame.create_master()
94
111
  else:
95
- tmpmaster = master.__copy__()
96
- #
112
+ temp_master = master.__copy__()
113
+
97
114
  if isinstance(points, list):
98
- allpoints = Points(points, ref=tmpmaster)
115
+ all_points = Points(points, reference_frame=temp_master)
99
116
  elif isinstance(points, Points) or isinstance(points, egse.coordinates.point.Points):
100
- allpoints = points
117
+ all_points = points
101
118
  else:
102
119
  raise ValueError("If the input is a list, all items in it must be Point objects")
103
- #
104
- del tmpmaster
105
- #
106
- coordinates = allpoints.coordinates
120
+
121
+ del temp_master
122
+
123
+ coordinates = all_points.coordinates
107
124
  xs = coordinates[0, :]
108
125
  ys = coordinates[1, :]
109
126
  zs = coordinates[2, :]
110
- #
127
+
111
128
  kwargs.setdefault("s", 50)
112
129
  kwargs.setdefault("marker", "o")
113
130
  kwargs.setdefault("color", "k")
114
- #
115
- fig = plt.figure(figname)
131
+
132
+ fig = plt.figure(fig_name)
116
133
  ax = fig.add_subplot(projection="3d")
117
134
  ax.scatter(xs, ys, zs, **kwargs)
118
135
 
119
136
  return ax
120
137
 
121
138
 
122
- def plot_vectors(points, master=None, figname=None, fromorigin=True, **kwargs):
123
- """Plot the Points object.
139
+ def plot_vectors(
140
+ points: Points | list[Point], master=None, fig_name: str | None = None, from_origin: bool = True, **kwargs
141
+ ) -> matplotlib.axes._subplots.Axes3DSubplot:
142
+ """Plots the given collection of vectors.
143
+
144
+ Use ax.set_xlim3d(min, max) to properly set the ranges of the display.
124
145
 
125
146
  Args:
126
- points : either a (egse.coordinate.point.)Points object or a list of Point objects
127
- master : master ReferenceFrame (optional)
128
- figname: string. Name of matplotlib figure (can be pre-existing)
129
- fromorigin: bool
130
- if True, all vectors are displayed starting from the origin
131
- if False, all vectors go towards the origin
132
- kwargs : passed to matplotlib.axes._subplots.Axes3DSubplot.scatter
147
+ points (Points | list[Point]): Collection of vectors to plot.
148
+ master (ReferenceFrame | None): Optional master reference frame.
149
+ fig_name (str): Name of the plot figure.
150
+ kwargs : Keyword arguments passed to matplotlib.axes._subplots.Axes3DSubplot.scatter.
133
151
 
134
152
  Returns:
135
- matplotlib.axes._subplots.Axes3DSubplot displaying the reference frame.
136
-
137
- .. note::
138
- Use ax.set_xlim3d(min,max) to properly set the ranges of the display.
139
-
153
+ matplotlib.axes._subplots.Axes3DSubplot displaying the given collection of points
140
154
  """
141
155
 
142
156
  if master is None:
143
- tmpmaster = ReferenceFrame.createMaster()
157
+ temp_master = ReferenceFrame.create_master()
144
158
  else:
145
- tmpmaster = master.__copy__()
146
- #
159
+ temp_master = master.__copy__()
160
+
147
161
  if isinstance(points, list):
148
- allpoints = Points(points, ref=tmpmaster)
162
+ all_points = Points(points, reference_frame=temp_master)
149
163
  elif isinstance(points, Points) or isinstance(points, egse.coordinates.point.Points):
150
- allpoints = points
164
+ all_points = points
151
165
  else:
152
166
  raise ValueError("If the input is a list, all items in it must be Point objects")
153
- #
154
- del tmpmaster
155
- #
156
167
 
157
- # SET DEFAULTS
168
+ del temp_master
169
+
158
170
  kwargs.setdefault("color", "k")
159
- #
160
171
 
161
- # PREPARE VECTOR COORDINATES
162
- coordinates = allpoints.coordinates
172
+ # Prepare vector coordinates
173
+
174
+ coordinates = all_points.coordinates
163
175
  xs = coordinates[0, :]
164
176
  ys = coordinates[1, :]
165
177
  zs = coordinates[2, :]
166
178
 
167
- # Origin of the X,Y and Z vectors
168
- # ==> x = the 'x' coordinates of the origin of all vectors)
169
- # ==> [x,y,z] = the origin of points.ref
170
- x, y, z = points.ref.getOrigin().coordinates[:3]
179
+ # Origin of the x, y, and z vectors
180
+ # -> x = The x coordinates of the origin of all vectors
181
+ # -> [x,y,z] = Origin of points.reference_frame
182
+ x, y, z = points.reference_frame.get_origin().coordinates[:3]
171
183
  x = np.ones_like(xs) * x
172
184
  y = np.ones_like(xs) * y
173
185
  z = np.ones_like(xs) * z
174
186
 
175
- # PLOT
187
+ # Plot
176
188
 
177
- fig = plt.figure(figname)
189
+ fig = plt.figure(fig_name)
178
190
  ax = fig.gca(projection="3d")
179
191
 
180
- if fromorigin:
192
+ if from_origin:
181
193
  ax.quiver(x, y, z, xs - x, ys - y, zs - z, **kwargs)
182
194
 
183
- elif not fromorigin:
195
+ elif not from_origin:
184
196
  ax.quiver(xs, ys, zs, x - xs, y - ys, z - zs, **kwargs)
185
197
 
186
198
  else:
187
- print("Parameter 'fromorigin' must be True or False")
199
+ print("Parameter 'from_origin' must be True or False")
188
200
  print("Setting it to True by default")
189
201
  ax.quiver(x, y, z, xs - x, ys - y, zs - z, **kwargs)
190
202