4747
4848# TODO: this may be cruft.
4949def get_geometry_value (
50- entity_name : str ,
51- frame_name : str ,
52- axis_name : str ,
53- data : pdr .Data
50+ entity_name : str , frame_name : str , axis_name : str , data : pdr .Data
5451) -> Union [float , int , str ]:
5552 """
5653 Fetch the value named `entity_name` for the axis named `axis_name` of the
5754 coordinate frame named `frame_name`, as defined in the metadata of `data`.
5855 """
5956 return get_from (
6057 data .metaget (f"{ frame_name } _DERIVED_GEOMETRY_PARMS" ),
61- (f"{ entity_name } _{ axis_name } " , "value" )
58+ (f"{ entity_name } _{ axis_name } " , "value" ),
6259 )
6360
6461
@@ -72,7 +69,8 @@ def get_coordinate_system_properties(
7269 If there is no coordinate system named `frame_name`, returns None.
7370 """
7471 syskeys = [
75- k for k in data .metadata .fieldcounts
72+ k
73+ for k in data .metadata .fieldcounts
7674 if re .match (f"{ frame_name } _COORD(INATE)?_SYSTEM(_PARMS)?$" , k )
7775 ]
7876 if len (syskeys ) == 0 :
@@ -83,12 +81,12 @@ def get_coordinate_system_properties(
8381 "reference_frame" : system .get ("REFERENCE_COORD_SYSTEM_NAME" ),
8482 "quaternion" : np .array (system .get ("ORIGIN_ROTATION_QUATERNION" )),
8583 "offset" : np .array (system .get ("ORIGIN_OFFSET_VECTOR" )),
86- "orientation" : system .get ("POSITIVE_AZIMUTH_DIRECTION" )
84+ "orientation" : system .get ("POSITIVE_AZIMUTH_DIRECTION" ),
8785 }
8886
8987
9088def get_coordinate_systems (
91- data : pdr .Data
89+ data : pdr .Data ,
9290) -> dict [str , dict [str , Union [np .ndarray , str , float ]]]:
9391 """
9492 Fetch and format information about all VICAR-style coordinate systems
@@ -120,10 +118,7 @@ def _check_unit_of_angle(unit: str) -> None:
120118
121119
122120def cart2sph (
123- x0 : ArrayLike ,
124- y0 : ArrayLike ,
125- z0 : ArrayLike ,
126- unit : UnitOfAngle = "degrees"
121+ x0 : ArrayLike , y0 : ArrayLike , z0 : ArrayLike , unit : UnitOfAngle = "degrees"
127122) -> Union [pd .DataFrame , tuple [Real , Real , Real ]]:
128123 """
129124 Classic Cartesian-to-spherical coordinate representation converter.
@@ -163,7 +158,7 @@ def sph2cart(
163158 lat : ArrayLike ,
164159 lon : ArrayLike ,
165160 radius : ArrayLike = 1 ,
166- unit : UnitOfAngle = "degrees"
161+ unit : UnitOfAngle = "degrees" ,
167162) -> Union [pd .DataFrame , tuple [Real , Real , Real ]]:
168163 """
169164 Classic spherical-to-Cartesian coordinate representation converter. By
@@ -217,10 +212,7 @@ def invert_quaternion(quat: Quaternion) -> Quaternion:
217212
218213
219214def rotate_unit_vector (
220- alt : float ,
221- az : float ,
222- quat : Quaternion ,
223- clockwise : bool = True
215+ alt : float , az : float , quat : Quaternion , clockwise : bool = True
224216) -> np .ndarray :
225217 """
226218 Apply a rotation expressed as a unit quaternion to a unit vector expressed
@@ -234,22 +226,20 @@ def rotate_unit_vector(
234226 source_cartesian *= np .array ([- 1 , - 1 , 1 ])
235227 zero_quaternion = np .array ([0 , * source_cartesian ])
236228 inverse_rotation = invert_quaternion (quat )
237- q_times_0_v = quaternion_multiplication (
238- quat , zero_quaternion
239- )
229+ q_times_0_v = quaternion_multiplication (quat , zero_quaternion )
240230 v_prime = quaternion_multiplication (q_times_0_v , inverse_rotation )
241231 assert np .isclose (v_prime [0 ], 0 )
242232 target_cartesian = v_prime [1 :]
243233 if clockwise is True :
244234 target_cartesian *= np .array ([- 1 , - 1 , 1 ])
245235 # TODO: it's pointless to return the third (radius) element, because
246- # the result will always be a unit vector. Will probably need to modify
236+ # the result will always be a unit vector. Will probably need to modify
247237 # downstream to make this change.
248238 return np .array (cart2sph (* target_cartesian ))
249239
250240
251241def get_coordinates (
252- data : pdr .Data
242+ data : pdr .Data ,
253243) -> dict [str , dict [str , dict [Literal ["AZIMUTH" , "ELEVATION" ], float ]]]:
254244 """
255245 Fetch and organize all VICAR-style azimuth/elevation values mentioned in
@@ -273,11 +263,13 @@ def get_coordinates(
273263 axes = ("AZIMUTH" , "ELEVATION" )
274264 entities = set ()
275265 for axis in axes :
276- entities .update ({
277- k .replace (f"_{ axis } " , "" )
278- for k in data .metadata .fieldcounts
279- if k .endswith (f"_{ axis } " )
280- })
266+ entities .update (
267+ {
268+ k .replace (f"_{ axis } " , "" )
269+ for k in data .metadata .fieldcounts
270+ if k .endswith (f"_{ axis } " )
271+ }
272+ )
281273 coordinates = NestingDict ()
282274 syskeys = filter (
283275 lambda k : k .endswith ("_GEOMETRY_PARMS" ), data .metadata .fieldcounts
@@ -288,7 +280,7 @@ def get_coordinates(
288280 continue
289281 record = block .get (f"{ entity } _{ axis } " )
290282 if record is not None :
291- coordinates [key .split ("_" )[0 ]][entity ][axis ] = record [' value' ]
283+ coordinates [key .split ("_" )[0 ]][entity ][axis ] = record [" value" ]
292284 return coordinates .todict ()
293285
294286
@@ -323,9 +315,9 @@ def transform_angle(
323315 quaternion = source_info ["quaternion" ]
324316 coord = coordinates [source_frame ][entity ]
325317 if target_info is not None :
326- clockwise = "clockwise" in target_info [' orientation' ].lower ()
318+ clockwise = "clockwise" in target_info [" orientation" ].lower ()
327319 else :
328- clockwise = "clockwise" in source_info [' orientation' ].lower ()
320+ clockwise = "clockwise" in source_info [" orientation" ].lower ()
329321 return rotate_unit_vector (
330- coord [' ELEVATION' ], coord [' AZIMUTH' ], quaternion , clockwise
322+ coord [" ELEVATION" ], coord [" AZIMUTH" ], quaternion , clockwise
331323 )
0 commit comments