Skip to content

Commit

Permalink
Merge acdd6f5 into 66ab0cd
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Jun 11, 2019
2 parents 66ab0cd + acdd6f5 commit 9314bd5
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 35 deletions.
13 changes: 0 additions & 13 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,6 @@ environment:
ASTROPY_VERSION: "stable"
NUMPY_VERSION: "stable"


matrix:
allow_failures:
# Tests pass but there are some PermissionError as the process cannot
# access a file being used. Allow jobs to fail until it's worked around.
- PYTHON_VERSION: "2.7"
ASTROPY_VERSION: "stable"
NUMPY_VERSION: "1.15"

- PYTHON_VERSION: "3.7"
ASTROPY_VERSION: "stable"
NUMPY_VERSION: "stable"

platform:
-x64

Expand Down
13 changes: 11 additions & 2 deletions docs/masks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ example image::
>>> from astropy.io import fits
>>> from astropy.utils.data import get_pkg_data_filename
>>> filename = get_pkg_data_filename('photometry/M6707HH.fits') # doctest: +IGNORE_OUTPUT
>>> hdu = fits.open(filename)[0]
>>> pf = fits.open(filename)
>>> hdu = pf[0]

We then define the aperture::

Expand All @@ -160,6 +161,7 @@ as well as a cutout with the data multiplied by the mask::
>>> mask = aperture.to_mask(mode='exact')
>>> data = mask.cutout(hdu.data)
>>> weighted_data = mask.multiply(hdu.data)
>>> pf.close()

We can take a look at the results to make sure the source overlaps
with the aperture::
Expand Down Expand Up @@ -191,7 +193,8 @@ with the aperture::
from astropy.io import fits
from astropy.utils.data import get_pkg_data_filename
filename = get_pkg_data_filename('photometry/M6707HH.fits')
hdu = fits.open(filename)[0]
pf = fits.open(filename)
hdu = pf[0]
from regions.core import PixCoord
from regions.shapes.circle import CirclePixelRegion
center = PixCoord(158.5, 1053.5)
Expand Down Expand Up @@ -232,6 +235,12 @@ at the extent of the mask in the image:
ax.set_xlim(120, 180)
ax.set_ylim(1000, 1059)

.. plot::
:context:
:nofigs:

pf.close()

Finally, we can use the mask and data values to compute weighted
statistics::

Expand Down
2 changes: 1 addition & 1 deletion docs/plot_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

image_file = get_pkg_data_filename('tutorials/FITS-images/HorseHead.fits')
print(image_file)
image_data = fits.getdata(image_file, ext=0)
image_data = fits.getdata(image_file, ext=0, memmap=False)

ax = plt.gca()
plt.imshow(image_data, cmap='gray')
Expand Down
1 change: 1 addition & 0 deletions regions/_geometry/core.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# cython: language_level=3

# This file is needed in order to be able to cimport functions into other Cython files

Expand Down
1 change: 1 addition & 0 deletions regions/_geometry/pnpoly.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# cython: language_level=3

# This file is needed in order to be able to cimport functions into other Cython files

Expand Down
17 changes: 8 additions & 9 deletions regions/io/fits/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,13 @@ def read_fits_region(filename, errors='strict'):
"""
regions = []

hdul = fits.open(filename)

for hdu in hdul:
if hdu.name == 'REGION':
table = Table.read(hdu)
wcs = WCS(hdu.header, keysel=['image', 'binary', 'pixel'])
regions_list = FITSRegionParser(table, errors).shapes.to_regions()
for reg in regions_list:
regions.append(reg.to_sky(wcs))
with fits.open(filename) as hdul:
for hdu in hdul:
if hdu.name == 'REGION':
table = Table.read(hdu)
wcs = WCS(hdu.header, keysel=['image', 'binary', 'pixel'])
regions_list = FITSRegionParser(table, errors).shapes.to_regions() # noqa
for reg in regions_list:
regions.append(reg.to_sky(wcs))

return regions
12 changes: 5 additions & 7 deletions regions/io/fits/tests/test_fits_region.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

import distutils.version as vers
import pytest

from numpy.testing import assert_allclose
import astropy.version as astrov
from astropy.utils.data import get_pkg_data_filename
from astropy.table import Table
from astropy.coordinates import SkyCoord
Expand Down Expand Up @@ -64,10 +61,11 @@ def test_file_fits(filename):

# Reading the regions directly from file and converting to sky regions.
regs_sky = read_fits_region(filename)
header = fits.open(filename)[1].header
wcs = WCS(header, keysel=['image', 'binary', 'pixel'])
regs_pix = [reg.to_pixel(wcs) for reg in regs_sky]
shapes_roundtrip = to_shape_list(regs_pix, 'image')
with fits.open(filename) as pf:
header = pf[1].header
wcs = WCS(header, keysel=['image', 'binary', 'pixel'])
regs_pix = [reg.to_pixel(wcs) for reg in regs_sky]
shapes_roundtrip = to_shape_list(regs_pix, 'image')

for i in range(len(shapes)):
assert shapes[i].region_type == shapes_roundtrip[i].region_type
Expand Down
8 changes: 5 additions & 3 deletions regions/io/fits/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ def write_fits_region(filename, regions, header=None):
>>> from astropy.utils.data import get_pkg_data_filename
>>> from astropy.io import fits
>>> file_sample = get_pkg_data_filename('data/fits_region.fits', package='regions.io.fits.tests')
>>> file_sample = get_pkg_data_filename(
... 'data/fits_region.fits', package='regions.io.fits.tests')
>>> from regions import CirclePixelRegion, PixCoord, write_fits_region
>>> reg_pixel = CirclePixelRegion(PixCoord(1, 2), 5)
>>> hdul = fits.open(file_sample)
>>> write_fits_region('region_output.fits', regions=[reg_pixel], header=hdul[1].header)
>>> with fits.open(file_sample) as hdul:
... write_fits_region('region_output.fits', regions=[reg_pixel],
... header=hdul[1].header)
"""
output = fits_region_objects_to_table(regions)
Expand Down

0 comments on commit 9314bd5

Please sign in to comment.