mocpy icon indicating copy to clipboard operation
mocpy copied to clipboard

boxes and mocpy pixels do not match

Open samotracio opened this issue 1 year ago • 0 comments

This might be an issue with mocpy, but also from astropy.wcs or my own ignorance. Please excuse me if its related to the later.

I generated a rectangular region and investigated the positions of their flattened pixels. There seems to be an offset between these two.

from mocpy import MOC
import matplotlib.pyplot as plt
import numpy as np
from astropy.coordinates import Angle, Latitude, Longitude, SkyCoord
from astropy.table import Table
import regions

# define box
ra_center = Angle(131.0, 'deg')
dec_center = Angle(3.8, 'deg')
a = Angle(5.0, 'deg')
b = Angle(0.7, 'deg')
angle = Angle(90.0, 'deg')

box = regions.RectangleSkyRegion(SkyCoord(ra_center, dec_center, frame='icrs'), 2*a, 2*b, Angle(0, 'deg'))

# get moc from boxes
moc_box = MOC.from_box(lon=ra_center, lat=dec_center, a=a, b=b, angle=angle, max_depth=15)
hp_index = moc_box.flatten()

Now, the top-right corner of the box should be at (ra,dec)=(126, 4.5), but it is not (some wcs transformation?). Mocpy pixels seem to also follow this "shifted" box.

# plot moc and rectangle
fig = plt.figure(figsize=(7, 7))
wcs = moc_box.wcs(fig, projection='SIN')
ax = fig.add_subplot(projection=wcs)
moc_box.border(ax, wcs, color='r')
moc_box.fill(ax, wcs, alpha=0.2)
box.to_pixel(wcs).plot()
corner = [ra_center.value - a.value, dec_center.value + b.value]   # choose right-top corner
dwin = 0.1                                                         # half window size for plotting
ra_min, ra_max = corner[0]-dwin, corner[0]+dwin 
dec_min, dec_max = corner[1]-dwin, corner[1]+dwin
ax.set_xlim(wcs.wcs_world2pix(ra_max, dec_min, 1)[0], wcs.wcs_world2pix(ra_min, dec_max, 1)[0])
ax.set_ylim(wcs.wcs_world2pix(ra_max, dec_min, 1)[1], wcs.wcs_world2pix(ra_min, dec_max, 1)[1])
ax.coords['ra'].set_major_formatter('d.dddddd') ; ax.coords['dec'].set_major_formatter('d.dddddd')

Screenshot from 2024-08-18 16-58-46 Please correct me, but border pixels should be at order=15, so have a size of ~6.4", which is clearly not the case. Is there a way to increase the resolution while plotting?

After exporting the flattened list of pixels at max_depth and plotting using topcat, the shift is still present so there is little chance this could be an issue with matplotlib. Note, however that pixels are shown at the correct max_depth. Screenshot from 2024-08-18 17-04-21

Converting the moc to a healsparse map and generating random points within the rectangle pixels suggests there are pixels outside the original box. Screenshot from 2024-08-18 17-30-19

samotracio avatar Aug 18 '24 20:08 samotracio