lgrcia / prose

Modular image processing pipelines with Python. Built for Astronomy.
https://prose.readthedocs.io
MIT License
54 stars 11 forks source link

rounded sources new coordinates in image.cutout #132

Closed mathvdd closed 1 year ago

mathvdd commented 1 year ago

image.cutout round new coordinate of sources to an upper left pixel if the cutout coords argument is given as a float. It seem to work ok if coords are given as int. Exemples bellow

_s = image.sources[0]
print(image.sources[0])
fig = plt.figure(figsize=(9,3))
ax = plt.subplot(131, title="original image")
ax.set_xlim(_s.coords[0]-10,_s.coords[0]+10)
ax.set_ylim(_s.coords[1]-10,_s.coords[1]+10)
ax.imshow(image.data,vmin=np.median(image.data), vmax=_s.peak)
ax.scatter(_s.coords[0],_s.coords[1])

ax2 = plt.subplot(132, title="cutout with int coordinates")
cutout = image.cutout((int(_s.coords[0]),int(_s.coords[1])),20)
ax2.imshow(cutout.data, origin='lower',vmin=np.median(image.data), vmax=_s.peak)
ax2.scatter(cutout.sources[0].coords[0],cutout.sources[0].coords[1])

ax3 = plt.subplot(133, title="cutout with float coordinates")
cutout = image.cutout((_s.coords[0],_s.coords[1]),20)
ax3.imshow(cutout.data, origin='lower',vmin=np.median(image.data), vmax=_s.peak)
ax3.scatter(cutout.sources[0].coords[0],cutout.sources[0].coords[1])
⬭ ExtendedSource 0
  ----------------
  coords  517.66  510.20
  a, b      1.15    0.67
  e         0.58

TRAP 2021-11-21T07:02:46 579

? TraceSource 0
  -------------
  coords  520.35  510.97
  a, b      1.00    0.00
  e         0.00

TRAP 2021-11-21T07:05:22 890

EDIT: putting an uneven number for the cutout shape will give shifted coordinates in the cutout frame for int and float: TRAP 2021-11-21T07:02:46 579 TRAP 2021-11-21T07:05:22 890

lgrcia commented 1 year ago

Thanks for noticing! I just merged pull request #133 and release all as version 3.2.6. Can you pull/pip update and rerun your tests?

Just for the record: the expected behavior is a cutout around the center of the source but accounting for entire pixels shift (otherwise we need to interpolate on a new pixel grid). Anyway the coordinates of the source should now be correctly placed in the cutout

mathvdd commented 1 year ago

It works fine now, thanks!