# Q regarding equality tests with wcs\_world2pix()

**URL:** <https://community.openastronomy.org/t/q-regarding-equality-tests-with-wcs-world2pix/259>\
**Category:** Astropy\
**Created:** [January 27, 2022, 10:42am UTC](https://community.openastronomy.org/t/q-regarding-equality-tests-with-wcs-world2pix/259 "2022-01-27T10:42:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aewatkins](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@aewatkins](https://community.openastronomy.org/u/aewatkins)\
**Post date:** [January 27, 2022, 10:42am UTC](https://community.openastronomy.org/t/q-regarding-equality-tests-with-wcs-world2pix/259/1 "2022-01-27T10:42:48Z")

</div>

Hello. I am writing some unit tests for a bit of software I’m working on, and one of the functions I’ve written uses astropy.wcs to create image headers. I’ve written a simple unit test to validate the output, but it’s failing for reasons I can’t quite understand. Here is some sample code to reproduce the problem:

```auto
from astropy.wcs import WCS

pxScale = 1/3600.
wcs_dict = {'CTYPE1': 'RA---TAN',
                    'CTYPE2': 'DEC--TAN',
                    'CRVAL1': 180.,
                    'CRVAL2': 0.,
                    'CRPIX1': 250,
                    'CRPIX2': 300,
                    'CD1_1': -pxScale,
                    'CD1_2': 0.0,
                    'CD2_1': 0.0,
                    'CD2_2': pxScale}
w = WCS(wcs_dict)

cen = w.wcs_world2pix(180., 0., 1)

assert cen[0] == 250.
assert cen[1] == 300.

```

The first assertion succeeds for me, but the second fails. `cen[1]` here seems to be exactly the same data type as `cen[0]` (`numpy.ndarray`), so I can’t imagine why the first would succeed but the second wouldn’t.

Does anyone have a good explanation for this?

---

<div class="post-metadata">

**Author:** ![saimn](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/saimn/32/40_2.png) [@saimn](https://community.openastronomy.org/u/saimn)\
**Post date:** [January 27, 2022, 10:52am UTC](https://community.openastronomy.org/t/q-regarding-equality-tests-with-wcs-world2pix/259/2 "2022-01-27T10:52:38Z")

</div>

You are comparing floating point values:

```auto
In [3]: cen[1] - 300.
Out[3]: -1.261923898709938e-11

```

You should use `numpy.isclose` or similar to do the comparison.

---

<div class="post-metadata">

**Author:** ![aewatkins](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@aewatkins](https://community.openastronomy.org/u/aewatkins)\
**Post date:** [January 27, 2022, 11:27am UTC](https://community.openastronomy.org/t/q-regarding-equality-tests-with-wcs-world2pix/259/3 "2022-01-27T11:27:53Z")

</div>

So it was that simple. I suppose I got confused by the fact that `assert cen[0] == 250.` worked, then (also with any other number for the x origin). In all of my tests, it was only ever the y-axis that was failing.

Thanks for clearing that up!
