1
1
import abc
2
2
import copy
3
3
from numbers import Integral
4
+ from functools import partial
4
5
from collections import defaultdict
5
6
6
7
import gwcs
13
14
from astropy .modeling .models import tabular_model
14
15
from astropy .modeling .tabular import _Tabular
15
16
from astropy .time import Time
17
+ from astropy .utils import isiterable
16
18
from astropy .wcs .wcsapi .wrappers .sliced_wcs import combine_slices , sanitize_slices
17
19
18
20
try :
@@ -901,6 +903,17 @@ def frame(self):
901
903
902
904
return cf .CompositeFrame (frames )
903
905
906
+ @staticmethod
907
+ def _from_high_level_coordinates (dropped_frame , * highlevel_coords ):
908
+ """
909
+ This is a backwards compatibility wrapper for the new
910
+ from_high_level_coordinates method in gwcs.
911
+ """
912
+ quantities = dropped_frame .coordinate_to_quantity (* highlevel_coords )
913
+ if isiterable (quantities ):
914
+ quantities = tuple (q .value for q in quantities )
915
+ return quantities
916
+
904
917
@property
905
918
def dropped_world_dimensions (self ):
906
919
dropped_world_dimensions = defaultdict (list )
@@ -919,22 +932,31 @@ def dropped_world_dimensions(self):
919
932
dropped_world_dimensions ["world_axis_names" ] += [name or None for name in dropped_multi_table .frame .axes_names ]
920
933
dropped_world_dimensions ["world_axis_physical_types" ] += list (dropped_multi_table .frame .axis_physical_types )
921
934
dropped_world_dimensions ["world_axis_units" ] += [u .to_string () for u in dropped_multi_table .frame .unit ]
922
- dropped_world_dimensions ["world_axis_object_components" ] += dropped_multi_table .frame ._world_axis_object_components
923
- dropped_world_dimensions ["world_axis_object_classes" ].update (dropped_multi_table .frame ._world_axis_object_classes )
935
+ # In gwcs https://github.com/spacetelescope/gwcs/pull/457 the underscore was dropped
936
+ waocomp = getattr (dropped_multi_table .frame , "world_axis_object_components" , getattr (dropped_multi_table .frame , "_world_axis_object_components" , []))
937
+ dropped_world_dimensions ["world_axis_object_components" ] += waocomp
938
+ waocls = getattr (dropped_multi_table .frame , "world_axis_object_classes" , getattr (dropped_multi_table .frame , "_world_axis_object_classes" , {}))
939
+ dropped_world_dimensions ["world_axis_object_classes" ].update (waocls )
924
940
925
941
for dropped in self ._dropped_coords :
926
942
# If the table is a tuple (QuantityTableCoordinate) then we need to
927
943
# squish the input
944
+ # In gwcs https://github.com/spacetelescope/gwcs/pull/457 coordinate_to_quantity was removed
945
+ coord_meth = getattr (
946
+ dropped .frame ,
947
+ "from_high_level_coordinates" ,
948
+ partial (self ._from_high_level_coordinates , dropped .frame )
949
+ )
928
950
if isinstance (dropped .table , tuple ):
929
- coord = dropped . frame . coordinate_to_quantity (* dropped .table )
951
+ coord = coord_meth (* dropped .table )
930
952
else :
931
- coord = dropped . frame . coordinate_to_quantity (dropped .table )
953
+ coord = coord_meth (dropped .table )
932
954
933
955
# We want the value in the output dict to be a flat list of values
934
956
# in the order of world_axis_object_components, so if we get a
935
957
# tuple of coordinates out of gWCS then append them to the list, if
936
958
# we only get one quantity out then append to the list.
937
- if isinstance (coord , tuple ):
959
+ if isinstance (coord , ( tuple , list ) ):
938
960
dropped_world_dimensions ["value" ] += list (coord )
939
961
else :
940
962
dropped_world_dimensions ["value" ].append (coord )
0 commit comments