# WCS.all\_world2pix() is always returning me negative values. Can anyone help me what I'm going wrong with?

**URL:** <https://community.openastronomy.org/t/wcs-all-world2pix-is-always-returning-me-negative-values-can-anyone-help-me-what-im-going-wrong-with/844>\
**Category:** Astropy\
**Created:** [December 11, 2023, 3:32am UTC](https://community.openastronomy.org/t/wcs-all-world2pix-is-always-returning-me-negative-values-can-anyone-help-me-what-im-going-wrong-with/844 "2023-12-11T03:32:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![StandinKP](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/standinkp/32/481_2.png) [@StandinKP](https://community.openastronomy.org/u/StandinKP)\
**Post date:** [December 11, 2023, 3:32am UTC](https://community.openastronomy.org/t/wcs-all-world2pix-is-always-returning-me-negative-values-can-anyone-help-me-what-im-going-wrong-with/844/1 "2023-12-11T03:32:44Z")

</div>

WCS object:  
WCS Keywords

## Number of WCS axes: 2 CTYPE : ‘RA—TAN’ ‘DEC–TAN’ CRVAL : 324.446451596993 46.81134088650578 CRPIX : 936.0 936.0 CD1\_1 CD1\_2 : 0.000153555929276978 0.000107686700666058 CD2\_1 CD2\_2 : 0.000107603784351073 -0.00015354329398242 NAXIS : 1872 1872

## Code used for converting world coordinates to pixels: ps1\_imCoords = w.all\_world2pix(Q[0][‘RAJ2000’],Q[0][‘DEJ2000’], 1)

Q[0] is:  
_Table length=5_

| RAJ2000 | DEJ2000 |
| --- | --- |
| deg | deg |
| float64 | float64 |
| 322.36249999999995 | 46.54055555555556 |
| 323.3245833333333 | 45.85416666666667 |
| 323.49541666666664 | 45.591944444444444 |
| 324.01 | 45.374722222222225 |
| 325.53499999999997 | 45.76583333333333 |

Any help would be appreciated thanks. I am using astropy version ‘6.0.0’

---

<div class="post-metadata">

**Author:** ![ayshih](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/ayshih/32/84_2.png) [@ayshih](https://community.openastronomy.org/u/ayshih)\
**Post date:** [December 13, 2023, 2:41am UTC](https://community.openastronomy.org/t/wcs-all-world2pix-is-always-returning-me-negative-values-can-anyone-help-me-what-im-going-wrong-with/844/2 "2023-12-13T02:41:29Z")

</div>

Are you certain there’s something wrong? When I create a WCS header a la yours and call `all_world2pix()`, I get:

```python
[array([-6094.79371223, -5390.94435884, -5693.20144827, -4800.89749066,
         1066.08976008]),
 array([-2350.88257193, 2700.7730817 , 4207.42792534, 6268.54350065,
         7803.45284598])]

```

Sure, some of the pixel values are negative, but that is expected: all of the world coordinates in your table correspond to points outside of your data array, and being outside in a particular direction means a negative pixel value.

You pixel scale is small, so the RA of your data array ranges from 324.09 to 324.80 and the declination ranges from 46.57 to 47.06.
