gwcs.api.WCSAPIMixin¶
- class gwcs.api.WCSAPIMixin¶
Bases:
BaseLowLevelWCS,HighLevelWCSMixin,NativeAPIMixinA mix-in class that is intended to be inherited by the
WCSclass and provides the low- and high-level WCS API described in the astropy APE 14 (https://doi.org/10.5281/zenodo.1188875).
Attributes¶
The shape of the data that the WCS applies to as a tuple of length |
|
Returns an ( |
|
The input_frame's bounding box |
|
The forward transformation model from the input_frame to the output_frame. |
|
The input coordinate frame. |
|
Returns a reference to the underlying low-level WCS object. |
|
The output coordinate frame. |
|
An iterable of strings describing the name for each pixel axis. |
|
The bounds (in pixel coordinates) inside which the WCS is defined, as a list with |
|
The number of axes in the pixel coordinate system. |
|
The shape of the data that the WCS applies to as a tuple of length |
|
Indicates whether Python objects are given in serialized form or as actual Python objects. |
|
An iterable of strings describing the name for each world axis. |
|
A dictionary giving information on constructing high-level objects for the world coordinates. |
|
A list with |
|
An iterable of strings describing the physical type for each world axis. |
|
An iterable of strings given the units of the world coordinates for each axis. |
|
The number of axes in the world coordinate system. |
- property WCSAPIMixin.array_shape: tuple[int, ...] | None¶
The shape of the data that the WCS applies to as a tuple of length
pixel_n_dim. If the WCS is valid in the context of a dataset with a particular shape, then this property can be used to store the shape of the data. This can be used for example if implementing slicing of WCS objects. This is an optional property, and it should returnNoneif a shape is not known or relevant. The shape should be given in(row, column)order (the convention for arrays in Python).
- property WCSAPIMixin.axis_correlation_matrix¶
Returns an (
world_n_dim,pixel_n_dim) matrix that indicates using booleans whether a given world coordinate depends on a given pixel coordinate. This defaults to a matrix where all elements areTruein the absence of any further information. For completely independent axes, the diagonal would beTrueand all other entriesFalse.
- abstract property WCSAPIMixin.bounding_box: ModelBoundingBox | CompoundBoundingBox | None¶
The input_frame’s bounding box
- abstract property WCSAPIMixin.forward_transform: Model¶
The forward transformation model from the input_frame to the output_frame.
- abstract property WCSAPIMixin.input_frame: CoordinateFrameProtocol¶
The input coordinate frame.
- property WCSAPIMixin.low_level_wcs¶
Returns a reference to the underlying low-level WCS object.
- abstract property WCSAPIMixin.output_frame: CoordinateFrameProtocol¶
The output coordinate frame.
- property WCSAPIMixin.pixel_axis_names: tuple[str, ...]¶
An iterable of strings describing the name for each pixel axis.
- property WCSAPIMixin.pixel_bounds: tuple[tuple[float, float], ...] | None¶
The bounds (in pixel coordinates) inside which the WCS is defined, as a list with
pixel_n_dim(min, max)tuples. The bounds should be given in[(xmin, xmax), (ymin, ymax)]order. WCS solutions are sometimes only guaranteed to be accurate within a certain range of pixel values, for example when defining a WCS that includes fitted distortions. This is an optional property, and it should returnNoneif a shape is not known or relevant.
- property WCSAPIMixin.pixel_shape: tuple[int, ...] | None¶
The shape of the data that the WCS applies to as a tuple of length
pixel_n_dimin(x, y)order (where for an image,xis the horizontal coordinate andyis the vertical coordinate) (optional).If the WCS is valid in the context of a dataset with a particular shape, then this property can be used to store the shape of the data. This can be used for example if implementing slicing of WCS objects. This is an optional property, and it should return
Noneif a shape is neither known nor relevant.
- property WCSAPIMixin.serialized_classes: bool¶
Indicates whether Python objects are given in serialized form or as actual Python objects.
- property WCSAPIMixin.world_axis_names: tuple[str, ...]¶
An iterable of strings describing the name for each world axis.
- property WCSAPIMixin.world_axis_object_classes: WorldAxisObjectClasses¶
A dictionary giving information on constructing high-level objects for the world coordinates.
Each key of the dictionary is a string key from
world_axis_object_components, and each value is a tuple with three elements or four elements:The first element of the tuple must be a class or a string specifying the fully-qualified name of a class, which will specify the actual Python object to be created.
The second element, should be a tuple specifying the positional arguments required to initialize the class. If
world_axis_object_componentsspecifies that the world coordinates should be passed as a positional argument, this this tuple should includeNoneplaceholders for the world coordinates.The third tuple element must be a dictionary with the keyword arguments required to initialize the class.
Optionally, for advanced use cases, the fourth element (if present) should be a callable Python object that gets called instead of the class and gets passed the positional and keyword arguments. It should return an object of the type of the first element in the tuple.
Note that we don’t require the classes to be Astropy classes since there is no guarantee that Astropy will have all the classes to represent all kinds of world coordinates. Furthermore, we recommend that the output be kept as human-readable as possible.
The classes used here should have the ability to do conversions by passing an instance as the first argument to the same class with different arguments (e.g.
Time(Time(...), scale='tai')). This is a requirement for the implementation of the high-level interface.The second and third tuple elements for each value of this dictionary can in turn contain either instances of classes, or if necessary can contain serialized versions that should take the same form as the main classes described above (a tuple with three elements with the fully qualified name of the class, then the positional arguments and the keyword arguments). For low-level API objects implemented in Python, we recommend simply returning the actual objects (not the serialized form) for optimal performance. Implementations should either always or never use serialized classes to represent Python objects, and should indicate which of these they follow using the
serialized_classesattribute.See the document APE 14: A shared Python interface for World Coordinate Systems for examples.
- property WCSAPIMixin.world_axis_object_components: list[WorldAxisObjectComponent]¶
A list with
world_n_dimelements giving information on constructing high-level objects for the world coordinates.Each element of the list is a tuple with three items:
The first is a name for the world object this world array corresponds to, which must match the string names used in
world_axis_object_classes. Note that names might appear twice because two world arrays might correspond to a single world object (e.g. a celestial coordinate might have both “ra” and “dec” arrays, which correspond to a single sky coordinate object).The second element is either a string keyword argument name or a positional index for the corresponding class from
world_axis_object_classes.The third argument is a string giving the name of the property to access on the corresponding class from
world_axis_object_classesin order to get numerical values. Alternatively, this argument can be a callable Python object that takes a high-level coordinate object and returns the numerical values suitable for passing to the low-level WCS transformation methods.
See the document APE 14: A shared Python interface for World Coordinate Systems for examples.
- property WCSAPIMixin.world_axis_physical_types: tuple[str | None, ...] | None¶
An iterable of strings describing the physical type for each world axis. These should be names from the VO UCD1+ controlled Vocabulary (http://www.ivoa.net/documents/latest/UCDlist.html). If no matching UCD type exists, this can instead be
"custom:xxx", wherexxxis an arbitrary string. Alternatively, if the physical type is unknown/undefined, an element can beNone.
- property WCSAPIMixin.world_axis_units: tuple[str, ...]¶
An iterable of strings given the units of the world coordinates for each axis. The strings should follow the IVOA VOUnit standard (though as noted in the VOUnit specification document, units that do not follow this standard are still allowed, but just not recommended).
Methods¶
|
Convert array indices to world coordinates (represented by Astropy objects). |
|
Convert array indices to world coordinates. |
|
Executes the forward transform. |
|
Invert coordinates from output frame to input frame using analytical or user-supplied inverse. |
|
Convert pixel coordinates to world coordinates (represented by high-level objects). |
|
Convert pixel coordinates to world coordinates. |
|
Convert world coordinates (represented by Astropy objects) to array indices. |
|
Convert world coordinates to array indices. |
|
Convert world coordinates (represented by Astropy objects) to pixel coordinates. |
|
Convert world coordinates to pixel coordinates. |
- WCSAPIMixin.array_index_to_world(*index_arrays)¶
Convert array indices to world coordinates (represented by Astropy objects).
If a single high-level object is used to represent the world coordinates (i.e., if
len(wcs.world_axis_object_classes) == 1), it is returned as-is (not in a tuple/list), otherwise a tuple of high-level objects is returned. Seearray_index_to_world_valuesfor pixel indexing and ordering conventions.
- WCSAPIMixin.array_index_to_world_values(*index_arrays)¶
Convert array indices to world coordinates. This is the same as
pixel_to_world_valuesexcept that the indices should be given in(i, j)order, where for an imageiis the row andjis the column (i.e. the opposite order topixel_to_world_values).- Parameters:
index_arrays (
LowLevelInput)- Return type:
- abstractmethod WCSAPIMixin.evaluate(*args, with_bounding_box=True, fill_value=nan, **kwargs)¶
Executes the forward transform.
- Parameters:
args (
LowLevelInput) – Inputs in the input coordinate system, separate inputs for each dimension.with_bounding_box (
bool, default:True) – If True(default) values in the result which correspond to any of the inputs being outside the bounding_box are set tofill_value.fill_value (
float|number, default:nan) – Output value for inputs outside the bounding_box (default is np.nan).kwargs (dict) – Keyword arguments to be passed to the
forward_transformmodel.
- Return type:
- abstractmethod WCSAPIMixin.invert(*args, with_bounding_box=True, fill_value=nan, **kwargs)¶
Invert coordinates from output frame to input frame using analytical or user-supplied inverse. When neither analytical nor user-supplied inverses are defined, a numerical solution will be attempted using a numerical inverse algorithm.
Note
Currently numerical inverse is implemented only for 2D imaging WCS.
- Parameters:
args (
LowLevelInput) – Coordinates to be inverted. The number of arguments must be equal to the number of world coordinates given byworld_n_dim.with_bounding_box (
bool, default:True) – IfTrue(default) values in the result which correspond to any of the inputs being outside the bounding_box are set tofill_value.fill_value (
float|number, default:nan) – Output value for inputs outside the bounding_box (default isnp.nan).kwargs (dict) – Keyword arguments to be passed to the
backward_transformmodel (when defined) or to the iterative invert method.
- Returns:
result – Returns a tuple of scalar or array values for each axis. Unless
input_frame.naxes == 1when it shall return the value. The return type will beQuantityobjects if the transform returnsQuantityobjects, else values.- Return type:
- WCSAPIMixin.pixel_to_world(*pixel_arrays)¶
Convert pixel coordinates to world coordinates (represented by high-level objects).
If a single high-level object is used to represent the world coordinates (i.e., if
len(wcs.world_axis_object_classes) == 1), it is returned as-is (not in a tuple/list), otherwise a tuple of high-level objects is returned. Seepixel_to_world_valuesfor pixel indexing and ordering conventions.
- WCSAPIMixin.pixel_to_world_values(*pixel_arrays)¶
Convert pixel coordinates to world coordinates.
This method takes
pixel_n_dimscalars or arrays as input, and pixel coordinates should be zero-based. Returnsworld_n_dimscalars or arrays in units given byworld_axis_units. Note that pixel coordinates are assumed to be 0 at the center of the first pixel in each dimension. If a pixel is in a region where the WCS is not defined, NaN can be returned. The coordinates should be specified in the(x, y)order, where for an image,xis the horizontal coordinate andyis the vertical coordinate.- Parameters:
pixel_arrays (
LowLevelInput)- Return type:
- WCSAPIMixin.world_to_array_index(*world_objects)¶
Convert world coordinates (represented by Astropy objects) to array indices.
If
pixel_n_dimis1, this method returns a single scalar or array, otherwise a tuple of scalars or arrays is returned. Seeworld_to_array_index_valuesfor pixel indexing and ordering conventions. The indices should be returned as rounded integers.
- WCSAPIMixin.world_to_array_index_values(*world_arrays)¶
Convert world coordinates to array indices. This is the same as
world_to_pixel_valuesexcept that the indices should be returned in(i, j)order, where for an imageiis the row andjis the column (i.e. the opposite order topixel_to_world_values). The indices should be returned as rounded integers.- Parameters:
world_arrays (
LowLevelInput)- Return type:
- WCSAPIMixin.world_to_pixel(*world_objects)¶
Convert world coordinates (represented by Astropy objects) to pixel coordinates.
If
pixel_n_dimis1, this method returns a single scalar or array, otherwise a tuple of scalars or arrays is returned. Seeworld_to_pixel_valuesfor pixel indexing and ordering conventions.
- WCSAPIMixin.world_to_pixel_values(*world_arrays)¶
Convert world coordinates to pixel coordinates.
This method takes
world_n_dimscalars or arrays as input in units given byworld_axis_units. Returnspixel_n_dimscalars or arrays. Note that pixel coordinates are assumed to be 0 at the center of the first pixel in each dimension. If a world coordinate does not have a matching pixel coordinate, NaN can be returned. The coordinates should be returned in the(x, y)order, where for an image,xis the horizontal coordinate andyis the vertical coordinate.- Parameters:
world_arrays (
LowLevelInput)- Return type: