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

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’

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

[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.