diff --git a/doc/source/cookbook/fits_radio_cubes.ipynb b/doc/source/cookbook/fits_radio_cubes.ipynb index c34eafbb0f9..889ee3aacaa 100644 --- a/doc/source/cookbook/fits_radio_cubes.ipynb +++ b/doc/source/cookbook/fits_radio_cubes.ipynb @@ -18,7 +18,7 @@ "source": [ "This notebook demonstrates some of the capabilities of yt on some FITS \"position-position-spectrum\" cubes of radio data.\n", "\n", - "Note that it depends on some external dependencies, including `astropy` and `pyregion`." + "Note that it depends on some external dependencies, including `astropy` and `regions`." ] }, { @@ -413,7 +413,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Finally, we can also take an existing [ds9](http://ds9.si.edu/site/Home.html) region and use it to create a \"cut region\" as well, using `ds9_region` (the [pyregion](https://pyregion.readthedocs.io/) package needs to be installed for this):" + "Finally, we can also take an existing [ds9](http://ds9.si.edu/site/Home.html) region and use it to create a \"cut region\" as well, using `ds9_region` (the [regions](https://astropy-regions.readthedocs.io/) package needs to be installed for this):" ] }, { diff --git a/doc/source/cookbook/fits_xray_images.ipynb b/doc/source/cookbook/fits_xray_images.ipynb index d0b73f201a8..9124658317d 100644 --- a/doc/source/cookbook/fits_xray_images.ipynb +++ b/doc/source/cookbook/fits_xray_images.ipynb @@ -258,7 +258,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Finally, we can also take an existing [ds9](http://ds9.si.edu/site/Home.html) region and use it to create a \"cut region\", using `ds9_region` (the [pyregion](https://pyregion.readthedocs.io) package needs to be installed for this):" + "Finally, we can also take an existing [ds9](http://ds9.si.edu/site/Home.html) region and use it to create a \"cut region\", using `ds9_region` (the [regions](https://astropy-regions.readthedocs.io/) package needs to be installed for this):" ] }, { diff --git a/doc/source/examining/loading_data.rst b/doc/source/examining/loading_data.rst index bcda9eb14de..a06a1c97c67 100644 --- a/doc/source/examining/loading_data.rst +++ b/doc/source/examining/loading_data.rst @@ -1232,7 +1232,7 @@ and add them to the field registry for the dataset ``ds``. This function takes a `ds9 `_ region and creates a "cut region" data container from it, that can be used to select the cells in the FITS dataset that fall within the region. To use this -functionality, the `pyregion `_ +functionality, the `regions `_ package must be installed. .. code-block:: python diff --git a/setup.cfg b/setup.cfg index 7c4b5f4d36e..af6f7ab2b35 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,8 +66,8 @@ doc = jinja2<3.1.0 # see https://github.com/readthedocs/readthedocs.org/issues/9037 jupyter-client<7.0 nbconvert==5.6.1 - pyregion pyx>=0.15 + regions>=0.7 runnotebook scipy<=1.7.1 # see https://github.com/yt-project/yt/issues/3966 and https://github.com/scipy/scipy/issues/16602 sphinx==3.1.2 diff --git a/yt/frontends/fits/misc.py b/yt/frontends/fits/misc.py index 29d5381de2c..f4b7cb44e82 100644 --- a/yt/frontends/fits/misc.py +++ b/yt/frontends/fits/misc.py @@ -135,8 +135,8 @@ def create_spectral_slabs(filename, slab_centers, slab_width, **kwargs): def ds9_region(ds, reg, obj=None, field_parameters=None): r""" - Create a data container from a ds9 region file. Requires the pyregion - package (https://pyregion.readthedocs.io/en/latest/) to be installed. + Create a data container from a ds9 region file. Requires the regions + package (https://astropy-regions.readthedocs.io/) to be installed. Parameters ---------- @@ -157,19 +157,26 @@ def ds9_region(ds, reg, obj=None, field_parameters=None): >>> circle_region = ds9_region(ds, "circle.reg") >>> print(circle_region.quantities.extrema("flux")) """ - import pyregion + from regions import Regions from yt.frontends.fits.api import EventsFITSDataset if os.path.exists(reg): - r = pyregion.open(reg) + method = Regions.read else: - r = pyregion.parse(reg) + method = Regions.parse + r = method(reg, format="ds9").regions[0] + reg_name = reg header = ds.wcs_2d.to_header() # The FITS header only contains WCS-related keywords header["NAXIS1"] = nx = ds.domain_dimensions[ds.lon_axis] header["NAXIS2"] = ny = ds.domain_dimensions[ds.lat_axis] + + # it seems that the equivalent code with regions would involve something along the lines of + # mask = r.to_mask() + # however this method isn't implemented for e.g. RectanleSkyRegion, which is used in our examples + # see https://github.com/astropy/regions/issues/490 filter = r.get_filter(header=header) mask = filter.mask((ny, nx)).transpose() if isinstance(ds, EventsFITSDataset):