radio-astro-tools / pvextractor

Position-Velocity diagram extract (but it can slice out other things too)
BSD 3-Clause "New" or "Revised" License
16 stars 13 forks source link

ValueError: Non-square pixels. Please resample data. #77

Closed esoPanda closed 3 years ago

esoPanda commented 8 years ago

I got this error and I checked the header:

CDELT1 = -0.00268754582783 CDELT2 = 0.00269177717671 CDELT3 = 0.20000000298

Really, this is not almost_equal? Any idea for a work around?

keflavich commented 8 years ago

The pixel axes only differ by about 0.1%, but that can still be significant over a large enough image. If you really want to assume they're the same, just edit the CDELT1/CDELT2 to be identical. Otherwise, reproject them to a header with truly square pixels

astrofrog commented 8 years ago

Just thinking out loud - maybe we could have a flag for relaxing this constraint to a certain tolerance?

esoPanda commented 8 years ago

Thanks. Why pixels are required to be strictly square?

Indeed, would be good to have an option to relax the matching to really 'almost' equal. For example, if abs(dx) * nx and abs(dy) * nx differs less than one pixel, this can be acceptable?

The small size difference in x and y was introduced when I projected the cube from EQ to Gal (not using python/reproject). In this case I solved by using the original EQ cube, which has square pixels.

keflavich commented 3 years ago

There are a lot of simplifications that we can and do employ when we assume the pixels are square. Since almost all astronomical images on a grid (not HEALPIX stuff) uses square pixels, and it is straightforward to regrid to square pixels, I'm going to tag dealing with non-square pixels as low priority and close this issue.

kmhess commented 2 years ago

Hi, I'm curious is any progress on this has been made? I have the following code:

slice = PathFromCenter(center=SkyCoord(ra=source['pos_x'], dec=source['pos_y'], unit='deg'),
                       length=opt_view, angle=source['kin_pa']*u.deg, width=1*u.arcsec)
mask = fits.open(filename)
mask_pv = extract_pv_slice(mask[0].data, slice, wcs=WCS(mask[0].header, fix=True, translate_units='shd'))

And I get the error:

AssertionError: 
Arrays are not almost equal to 7 decimals
 ACTUAL: 0.0016675802169471255
 DESIRED: 0.0016657532823994607

The error has me stumped. I don't know what I'm supposed to reproject to fix this since the WCS and the data come from the same fits files and the actual/desired really are almost equal. Thanks in advance. Also CDELT1 and CDELT2 in the mask[0].header are identical and equal to 1.6666670000E-3

kmhess commented 2 years ago

I just realized there is an open issue with a similar title. I'll put my question there (apologies, this closed one was the first Issue I found with google).