Skip to content

Commit

Permalink
fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nden committed Mar 12, 2024
1 parent 6818e21 commit 2e94d17
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
12 changes: 8 additions & 4 deletions docs/gwcs/using_wcs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ Calling the :meth:`~gwcs.WCS.footprint` returns the footprint on the sky.
.. doctest-skip::

>>> wcsobj.footprint()

array([[ 5.5264392 , -72.05149213],
... [ 5.54580408, -72.06422321],
... [ 5.63010439, -72.05426843],
... [ 5.610708 , -72.04173847]])

Manipulating Transforms
-----------------------
Expand All @@ -82,7 +85,7 @@ Transforms between frames can be retrieved and evaluated separately.

>>> dist = wcsobj.get_transform('detector', 'undistorted_frame')
>>> dist(1, 2) # doctest: +FLOAT_CMP
(-292.4150238489997, -616.8680129899999)
(41.62325692108675, -12.68101006210054)

Transforms in the pipeline can be replaced by new transforms.

Expand Down Expand Up @@ -119,6 +122,8 @@ inverse transformation converts world coordinates back to image coordinates.

.. doctest-skip::

>>> import asdf
>>> from astropy.utils.data import get_pkg_data_filename
>>> wcsobj = asdf.open(get_pkg_data_filename('imaging_wcs_wdist.asdf')).tree['wcs']

The most general method available for computing inverse coordinate
Expand All @@ -140,7 +145,7 @@ most situations:
(349.9999994163172, 200.00000017679295)
>>> world = wcsobj([2, 350, -5000], [2, 200, 6000])
>>> print(wcsobj.invert(*world)) # convert multiple points at once
(array([ 2.00000000e+00, 3.49999999e+02, -5.00000000e+03]), array([1.99999972e+00, 2.00000002e+02, 6.00000000e+03])
(array([ 1.99999752, 3.49999999e+02, -5.00000000e+03]), array([1.99999972e+00, 2.00000002e+02, 6.00000000e+03])

By default, parameter ``quiet`` is set to `True` in `WCS.numerical_inverse() <gwcs.wcs.WCS.numerical_inverse>`
and so it will return results "as is" without warning us about possible loss
Expand Down Expand Up @@ -178,4 +183,3 @@ point far away from the image for which numerical inverse fails.
[5.31656943e-06 2.72052603e-10]
[6.81557583e-06 1.06560533e-06]
[3.96365344e-04 6.41822468e-05]]

25 changes: 18 additions & 7 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ using `ASDF Standard <https://asdf-standard.readthedocs.io/en/latest/>`__

There are two ways to save the GWCS object to a files:

- `Save a WCS object as a pure ASDF file`_
- `Save a WCS object as a pure ASDF file`_

- `Save a WCS object as a pure ASDF file`_

Expand Down Expand Up @@ -222,11 +222,11 @@ expressed with no associated transform
... unit=(u.deg, u.deg))
>>> wcsobj = wcs.WCS([(detector_frame, det2sky),
... (sky_frame, None)
... ]
... ])
>>> print(wcsobj)
From Transform
-------- ----------------
detector linear_transform
detector detector_to_sky
icrs None

To convert a pixel (x, y) = (1, 2) to sky coordinates, call the WCS object as a function:
Expand All @@ -235,16 +235,27 @@ To convert a pixel (x, y) = (1, 2) to sky coordinates, call the WCS object as a

>>> sky = wcsobj(1, 2)
>>> print(sky)
<SkyCoord (ICRS): (ra, dec) in deg
(5.52515954, -72.05190935)>
(29.980402161089177, 44.98616499109102)

The :meth:`~gwcs.wcs.WCS.invert` method evaluates the :meth:`~gwcs.wcs.WCS.backward_transform`
if available, otherwise applies an iterative method to calculate the reverse coordinates.

.. doctest-skip::

>>> wcsobj.invert(sky)
(<Quantity 1. pix>, <Quantity 2. pix>)
>>> wcsobj.invert(*sky)
(0.9999999996185807, 1.999999999186798)

GWCS supports the common WCS interface which defines several methods
to work with high level Astropy objects:

.. doctest-skip::

>>> sky_obj = wcsobj.pixel_to_world(1, 2)
>>> print(sky)
<SkyCoord (ICRS): (ra, dec) in deg
(29.98040216, 44.98616499)>
>>> wcsobj.world_to_pixel(sky_obj)
(0.9999999996185807, 1.999999999186798)

.. _save_as_asdf:

Expand Down

0 comments on commit 2e94d17

Please sign in to comment.