Skip to content

Commit

Permalink
Merge 8f9c1c4 into 0cf5b2a
Browse files Browse the repository at this point in the history
  • Loading branch information
bsipocz committed Jun 6, 2019
2 parents 0cf5b2a + 8f9c1c4 commit 7d5d89f
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 180 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ env:
- ASTROPY_VERSION=stable
- SETUP_CMD='test'
- MAIN_CMD='python setup.py'
- CONDA_DEPENDENCIES='Cython shapely pytest-arraydiff'
- CONDA_DEPENDENCIES='Cython shapely pytest-arraydiff matplotlib'
- CONDA_CHANNELS='astropy'
- SETUP_XVFB=True
- ASTROPY_USE_SYSTEM_PYTEST=1
Expand All @@ -61,7 +61,7 @@ matrix:

# Do a test without the optional dependencies
- env: SETUP_CMD='test'
CONDA_DEPENDENCIES='Cython pytest-arraydiff'
CONDA_DEPENDENCIES='Cython pytest-arraydiff matplotlib'


# Try Astropy development version
Expand Down
26 changes: 18 additions & 8 deletions docs/compound.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,28 @@ i.e. a `~regions.CompoundPixelRegion` or `~regions.CompoundSkyRegion` object.
... center=SkyCoord(-4,3, unit='deg', frame='galactic'),
... radius=Angle('3 deg'),
... )
>>> type(circle1 & circle2)
regions.core.compound.CompoundSkyRegion
>>> print(circle1 & circle2)
Region: CompoundSkyRegion
region1: Region: CircleSkyRegion
center: <SkyCoord (Galactic): (l, b) in deg
(1., 2.)>
radius: 5.0 deg
region2: Region: CircleSkyRegion
center: <SkyCoord (Galactic): (l, b) in deg
(356., 3.)>
radius: 3.0 deg
operator: <built-in function and_>
>>> print(circle1 ^ circle2)
(CircleSkyRegion
Region: CompoundSkyRegion
region1: Region: CircleSkyRegion
center: <SkyCoord (Galactic): (l, b) in deg
(1.0, 2.0)>
(1., 2.)>
radius: 5.0 deg
<built-in function xor>
CircleSkyRegion
region2: Region: CircleSkyRegion
center: <SkyCoord (Galactic): (l, b) in deg
(356.0, 3.0)>
radius: 3.0 deg)
(356., 3.)>
radius: 3.0 deg
operator: <built-in function xor>
.. plot:: plot_compound.py
:include-source: false
55 changes: 36 additions & 19 deletions docs/contains.rst
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
.. testsetup:
>>> from regions import make_example_dataset
>>> dataset = make_example_dataset(data='simulated')
>>> wcs = dataset.wcs
.. _gs-contain:

Checking for points inside regions
==================================

Let's continue with the ``sky_reg`` and ``pix_reg`` objects defined in the previous section:
Let's continue with sky and pixel regions defined in the :ref:`gs` section:

.. code-block:: python
>>> print(sky_reg)
CircleSkyRegion
center:<SkyCoord (ICRS): (ra, dec) in deg
(50.0, 10.0)>
radius:30.0 deg
>>> print(pix_reg)
CirclePixelRegion
center: PixCoord(x=55.35205711214607, y=40.0958313892697)
radius: 36.93290808340659
>>> from astropy.coordinates import Angle, SkyCoord
>>> from regions import CircleSkyRegion, PixCoord, CirclePixelRegion
>>> sky_center = SkyCoord(42, 43, unit='deg')
>>> sky_radius = Angle(25, 'deg')
>>> sky_region = CircleSkyRegion(sky_center, sky_radius)
>>> pixel_center = PixCoord(x=42, y=43)
>>> pixel_radius = 42
>>> pixel_region = CirclePixelRegion(pixel_center, pixel_radius)
>>> print(sky_region)
Region: CircleSkyRegion
center: <SkyCoord (ICRS): (ra, dec) in deg
(42., 43.)>
radius: 25.0 deg
>>> print(pixel_region)
Region: CirclePixelRegion
center: PixCoord(x=42, y=43)
radius: 42
To test if a given point is inside or outside the regions, the Python ``in`` operator
Expand All @@ -24,9 +39,9 @@ can be called, which calls the special ``__contains__`` method defined on the re
.. code-block:: python
>>> from regions import PixCoord
>>> PixCoord(55, 40) in pix_reg
>>> PixCoord(55, 40) in pixel_region
True
>>> PixCoord(55, 200) in pix_reg
>>> PixCoord(55, 200) in pixel_region
False
The ``in`` operator only works for scalar coordinates, because Python requires
Expand All @@ -36,23 +51,25 @@ try to use ``in`` for non-scalar coordinates, you'll get a ``ValueError``:
.. code-block:: python
>>> pixcoord = PixCoord([50, 50], [10, 60])
>>> pixcoord in pix_reg
ValueError: coord must be scalar. coord=<PixCoord [(50.0, 10.0), (50.0, 60.0)]>
>>> pixcoord in pixel_region
Traceback (most recent call last):
...
ValueError: coord must be scalar. coord=PixCoord(x=[50 50], y=[10 60])
If you have arrays of coordinates, use the `regions.SkyRegion.contains` or
`regions.PixelRegion.contains` methods:

.. code-block:: python
>>> pixcoords = PixCoord.from_sky(skycoords, wcs)
>>> pix_reg.contains(pixcoords)
array([ True, False], dtype=bool)
>>> pixcoords = PixCoord.from_sky(sky_center, wcs)
>>> pixel_region.contains(pixcoords)
True
Note that `regions.SkyRegion.contains`
requires a WCS to be passed:

.. code-block:: python
>>> skycoord = SkyCoord([50, 50], [10, 60], unit='deg')
>>> sky_reg.contains(skycoord, wcs)
array([ True, False], dtype=bool)
>>> sky_region.contains(skycoord, wcs)
array([False, True])
9 changes: 3 additions & 6 deletions docs/crtf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Serialisation is done using the `~regions.crtf_objects_to_string` function
>>> from regions import crtf_objects_to_string
>>> crtf_objects_to_string(regions, coordsys='galactic')
'#CRTF\nglobal coord=galactic\n+circle[[144.559169deg, -14.923593deg], 3.000000deg], color=green\n'
'#CRTF\ncircle[[144.559169deg, -14.923593deg], 3.000000deg], coord=GALACTIC, color=green\n'
There's also `~regions.write_crtf` and `~regions.read_crtf` which write to and
read from a file in addition to doing the region serialisation and parsing.
Expand All @@ -59,8 +59,5 @@ read from a file in addition to doing the region serialisation and parsing.
>>> write_crtf(regions, filename)
>>> regions = read_crtf(filename)
>>> regions
[CircleSkyRegion
center: <SkyCoord (FK5: (equinox=J2000.000): (ra, dec) in deg
(245.3477, 24.4291)>
radius: 3.0 deg]
[<CircleSkyRegion(<SkyCoord (FK5: equinox=J2000.000): (ra, dec) in deg
(42., 43.)>, radius=3.0 deg)>]
8 changes: 3 additions & 5 deletions docs/ds9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Serialisation is done using the `~regions.ds9_objects_to_string` function

>>> from regions import ds9_objects_to_string
>>> ds9_objects_to_string(regions, coordsys='galactic')
'# Region file format: DS9 astropy/regions\ngalactic\ncircle(42.0000,43.0000,3.0000)\n'
'# Region file format: DS9 astropy/regions\ngalactic\ncircle(42.000000,43.000000,3.000000) # color=green\n'

There's also `~regions.write_ds9` and `~regions.read_ds9` which write to and
read from a file in addition to doing the region serialisation and parsing.
Expand All @@ -46,10 +46,8 @@ read from a file in addition to doing the region serialisation and parsing.
>>> write_ds9(regions, filename)
>>> regions = read_ds9(filename)
>>> regions
[CircleSkyRegion
center: <SkyCoord (FK5: (equinox=J2000.000): (ra, dec) in deg
(245.3477, 24.4291)>
radius: 3.0 deg]
[<CircleSkyRegion(<SkyCoord (FK5: equinox=J2000.000): (ra, dec) in deg
(245.347655, 24.429081)>, radius=3.0 deg)>]
The ``visual`` metadata includes items used for display, e.g.:

Expand Down
22 changes: 6 additions & 16 deletions docs/fits_region.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ package.
>>> from regions import FITSRegionParser
>>> from astropy.table import Table
>>> from astropy.utils.data import get_pkg_data_filename
>>> filename = get_pkg_data_filename('data/fits_regions.fits',
>>> filename = get_pkg_data_filename('data/fits_region.fits',
... package='regions.io.fits.tests')
>>> table = Table.read(filename)
>>> print(table)
Expand All @@ -41,6 +41,7 @@ package.
341.0 .. 0.0 345.0 .. 0.0 point 0.0 .. 0.0 0.0 6
341.0 .. 0.0 345.0 .. 0.0 point 0.0 .. 0.0 0.0 7
1.0 .. 4.0 5.0 .. 8.0 polygon 0.0 .. 0.0 0.0 8
10.0 .. 0.0 5.5 .. 0.0 BOX 10.0 .. 0.0 0.0 9
>>> parser = FITSRegionParser(table)
>>> print(parser.shapes[0])
Expand Down Expand Up @@ -79,25 +80,14 @@ Serialisation is done using the `~regions.fits_region_objects_to_table` function
341.0 .. 0.0 345.0 .. 0.0 point 0.0 .. 0.0 0.0 6
341.0 .. 0.0 345.0 .. 0.0 point 0.0 .. 0.0 0.0 7
1.0 .. 4.0 5.0 .. 8.0 polygon 0.0 .. 0.0 0.0 8
10.0 .. 0.0 5.5 .. 0.0 ROTBOX 10.0 .. 0.0 0.0 9
The `~regions.write_fits_region` and `~regions.read_fits_region` functions
write as well as read from a file in addition to doing the region serialisation
and parsing.

.. code-block:: python
>>> from astropy.io import fits
>>> from astropy.utils.data import get_pkg_data_filename
>>> from regions import read_fits_region, write_fits_region
>>> file_read = get_pkg_data_filename('data/fits_region.fits',
... package='regions.io.fits.tests')
>>> hdul = fits.open(file_read)
>>> regions = read_fits_region(file_read) # sky regions
>>> print(regions[0])
Region: CircleSkyRegion
center: <SkyCoord (ICRS): (ra, dec) in deg
(211.06231757, 54.49779926)>
radius: 0.052202298340895036 deg
>>> filename = 'region_ouput.fits'
>>> write_fits_region(filename, regions, hdul[1].header)
>>> from regions import CirclePixelRegion, PixCoord, write_fits_region
>>> reg_pixel = CirclePixelRegion(PixCoord(1, 2), 5)
>>> write_fits_region('regions_output.fits', regions=[reg_pixel])
34 changes: 17 additions & 17 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ represent sky coordinates.
>>> skycoord = SkyCoord(42, 43, unit='deg', frame='galactic')
>>> skycoord
<SkyCoord (Galactic): (l, b) in deg
(42.0, 43.0)>
(42., 43.)>
To represent pixel coordinates, :class:`~regions.PixCoord` objects are used.

Expand Down Expand Up @@ -109,7 +109,7 @@ transform back and forth between sky and pixel coordinates:
PixCoord(x=146.2575703393558, y=131.5998051082584)
>>> pixcoord.to_sky(wcs=wcs)
<SkyCoord (Galactic): (l, b) in deg
(42.0, 43.0)>
(42., 43.)>
This is an object-oriented thin wrapper around the functionality provided by
`~astropy.wcs.WCS` and `astropy.wcs.utils`.
Expand Down Expand Up @@ -156,22 +156,22 @@ This is how to create a sky region:

.. code-block:: python
from astropy.coordinates import Angle, SkyCoord
from regions import CircleSkyRegion
>>> from astropy.coordinates import Angle, SkyCoord
>>> from regions import CircleSkyRegion
center = SkyCoord(42, 43, unit='deg')
radius = Angle(3, 'deg')
region = CircleSkyRegion(center, radius)
>>> center = SkyCoord(42, 43, unit='deg')
>>> radius = Angle(3, 'deg')
>>> region = CircleSkyRegion(center, radius)
You can print the regions to get some info about its properties:

.. code-block:: python
>>> print(region)
CircleSkyRegion
center:<SkyCoord (ICRS): (ra, dec) in deg
(42.0, 43.0)>
radius:3.0 deg
Region: CircleSkyRegion
center: <SkyCoord (ICRS): (ra, dec) in deg
(42., 43.)>
radius: 3.0 deg
To see a list of all available sky regions, you can go to the API docs or in
IPython print the list using:
Expand All @@ -193,19 +193,19 @@ point, and a set of "pixel region" classes. One example is

.. code-block:: python
from astropy.coordinates import Angle, SkyCoord
from regions import PixCoord, CirclePixelRegion
>>> from astropy.coordinates import Angle, SkyCoord
>>> from regions import PixCoord, CirclePixelRegion
center = PixCoord(x=42, y=43)
radius = 4.2
region = CirclePixelRegion(center, radius)
>>> center = PixCoord(x=42, y=43)
>>> radius = 4.2
>>> region = CirclePixelRegion(center, radius)
You can print the regions to get some info about its properties:

.. code-block:: python
>>> print(region)
CirclePixelRegion
Region: CirclePixelRegion
center: PixCoord(x=42, y=43)
radius: 4.2
Expand Down
4 changes: 1 addition & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ User Documentation
shapely
changelog

These plots are made using :download:`plot_image.reg`.

+----------------------------------------+----------------------------------------+
| ds9 | regions + matplotlib |
+========================================+========================================+
Expand Down Expand Up @@ -113,4 +111,4 @@ Get Help
========

Besides github, you can `get help`_ from the community in a number of ways.
There is also a slack channel for regions hosted under the main astropy slack.
There is also a slack channel for regions hosted under the main astropy slack.

0 comments on commit 7d5d89f

Please sign in to comment.