regions icon indicating copy to clipboard operation
regions copied to clipboard

DOC: Conversion guide from pyregion

Open pllim opened this issue 2 years ago • 3 comments
trafficstars

As suggested by @prajwel in https://github.com/astropy/pyregion/pull/161#issuecomment-1326154571

I knew this was just a matter of time. Pyregion is part of many packages due to its age. Perhaps we can create easy porting guidelines for people wanting to port their code to Regions 🤔?

pllim avatar Nov 30 '22 19:11 pllim

Sorry if this isn't the right place to ask, but are there any equivalent to pyregion.open and pyregion.parse in regions per chance ?

neutrinoceros avatar Dec 05 '22 18:12 neutrinoceros

I think you are looking for Regions.read and Regions.parse. Examples here: https://astropy-regions.readthedocs.io/en/stable/region_io.html

larrybradley avatar Dec 05 '22 18:12 larrybradley

I think the following comparisson could be useful.

Pyregion

contours = pyregion.open('contours.reg').as_imagecoord(wcs.to_header())
patch_list, artist_list = contours.get_mpl_patches_texts()
    
for p in patch_list:
    ax.add_patch(p)
for t in artist_list:
    ax.add_artist(t)

Regions

contours = Regions.read('contours.reg', format='ds9')    
for sky_region in contours:
    pixel_region = sky_region.to_pixel(wcs)
    _ = pixel_region.plot(ax=ax)

prajwel avatar Dec 06 '22 05:12 prajwel