Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions docs/figures/region_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import matplotlib.cm as cm

import pyregion
try:
from astropy.io import fits as pyfits
except ImportError:
import pyfits
from astropy.io import fits

# read in the image
xray_name="pspc_skyview.fits"
f_xray = pyfits.open(xray_name)
f_xray = fits.open(xray_name)

try:
import pywcsgrid2
Expand Down
7 changes: 2 additions & 5 deletions docs/figures/region_drawing2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import matplotlib.cm as cm

import pyregion
try:
from astropy.io import fits as pyfits
except ImportError:
import pyfits
from astropy.io import fits

# read in the image
xray_name= "pspc_skyview.fits"
f_xray = pyfits.open(xray_name)
f_xray = fits.open(xray_name)

try:
import pywcsgrid2
Expand Down
13 changes: 0 additions & 13 deletions docs/users/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,6 @@ astropy
-------
* OPTIONAL
* `Astropy <https://github.com/astropy/astropy/>`__
* With astropy installed, pywcs and pyfits are not needed.

pywcs
-----
* OPTIONAL
* used for coordinate conversions
* `Homepage <https://trac.assembla.com/astrolib/>`__

pyfits
------
* OPTIONAL
* `Homepage <http://www.stsci.edu/resources/software_hardware/pyfits>`__


matplotlib
----------
Expand Down
6 changes: 3 additions & 3 deletions docs/users/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ The shape object has following attributes,
The ShapeList class have a few method that could be
useful. *ShapeList.as_imagecoord* returns a new ShapeList instance
with the coordinates converted to the image coordinate. It
requires the Pyfits.Header instance.::
requires the astropy.io.fits.Header instance.::

import pyfits
f = pyfits.open("t1.fits")
from astropy.io import fits
f = fits.open("t1.fits")
r2 = pyregion.parse(region_string).as_imagecoord(f[0].header)

The return value is a new ShapeList instance, but the coordinate is
Expand Down
25 changes: 0 additions & 25 deletions examples/demo_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,6 @@

import math

try:
from astropy.io import fits as pyfits
except ImportError:
import pyfits

# At some point, pyfits.Card.fromstring has changed from unbound
# method to bounded method.

if pyfits.Card.fromstring.__self__: #
def pyfits_card_fromstring(l):
return pyfits.Card.fromstring(l)
else:
def pyfits_card_fromstring(l):
c = pyfits.Card()
return c.fromstring(l)

def demo_header():
cards = pyfits.CardList()
for l in open("sample_fits01.header"):
card = pyfits_card_fromstring(l.strip())
cards.append(card)
h = pyfits.Header(cards)
return h


def show_region(fig, region_list):
h = demo_header()

Expand Down
14 changes: 2 additions & 12 deletions examples/demo_print_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@

import math

try:
from astropy.io import fits as pyfits
except ImportError:
import pyfits

from demo_helper import pyfits_card_fromstring
from astropy.io.fits import Header

def test_header():
cards = pyfits.CardList()
for l in open("test.header"):
card = pyfits_card_fromstring(l.strip())
cards.append(card)
h = pyfits.Header(cards)
return h
return Header.fromtextfile("test.header")

def print_region(r):
for i, l in enumerate(r):
Expand Down
16 changes: 2 additions & 14 deletions examples/demo_region03.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
try:
from astropy.io import fits as pyfits
except ImportError:
import pyfits
from astropy.io.fits import Header

import matplotlib.pyplot as plt
import pyregion
Expand All @@ -11,17 +8,8 @@
from mpl_toolkits.axes_grid1 import ImageGrid
import pywcsgrid2


from demo_helper import pyfits_card_fromstring


def get_test_header():
cards = pyfits.CardList()
for l in open("sample_fits01.header"):
card = pyfits_card_fromstring(l.strip())
cards.append(card)
h = pyfits.Header(cards)
return h
return Header.fromtextfile('sample_fits01.header')

if 1:

Expand Down
5 changes: 0 additions & 5 deletions examples/demo_region04.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
try:
from astropy.io import fits as pyfits
except ImportError:
import pyfits

import matplotlib.pyplot as plt
import pyregion

Expand Down
14 changes: 2 additions & 12 deletions examples/demo_region_filter01.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
try:
from astropy.io import fits as pyfits
except ImportError:
import pyfits

from demo_helper import pyfits_card_fromstring
from astropy.io.fits import Header

import matplotlib.pyplot as plt

import pyregion

# read in the image
def demo_header():
cards = pyfits.CardList()
for l in open("sample_fits02.header"):
card = pyfits_card_fromstring(l.strip())
cards.append(card)
h = pyfits.Header(cards)
return h
return Header.fromtextfile("sample_fits02.header")

header = demo_header() # sample fits header
shape = (header["NAXIS1"], header["NAXIS2"])
Expand Down
2 changes: 1 addition & 1 deletion pyregion/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

## Uncomment the following line to treat all DeprecationWarnings as
## exceptions
# enable_deprecations_as_exceptions()
enable_deprecations_as_exceptions()
2 changes: 1 addition & 1 deletion pyregion/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def read_region_as_imagecoord(s, header, rot_wrt_axis=1):

def get_mask(region, hdu, origin=1):
"""
f = pyfits.read("test.fits")
f = fits.read("test.fits")
reg = read_region_as_imagecoord(s, f[0].header)
mask = get_mask(reg, f[0])
"""
Expand Down
25 changes: 3 additions & 22 deletions pyregion/tests/test_get_mask.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
import os
from os.path import join

try:
from astropy.io import fits as pyfits
except ImportError:
import pyfits
from astropy.io.fits import Header

import numpy as np

from ..wcs_helper import fix_lon
from .. import open as pyregion_open
from .. import get_mask

# At some point, pyfits.Card.fromstring has changed from unbound
# method to bounded method.

if pyfits.Card.fromstring.__self__: #
def pyfits_card_fromstring(l):
return pyfits.Card.fromstring(l)
else:
def pyfits_card_fromstring(l):
c = pyfits.Card()
return c.fromstring(l)

rootdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'examples')

def demo_header():
cards = pyfits.CardList()
for l in open(join(rootdir, "sample_fits01.header")):
card = pyfits_card_fromstring(l.strip())
cards.append(card)
h = pyfits.Header(cards)
return h
return Header.fromtextfile(join(rootdir, "sample_fits01.header"))

def test_region():

Expand All @@ -53,4 +34,4 @@ def test_region():
# for reg_name in region_list:
# r = pyregion_open(join(rootdir,reg_name)).as_imagecoord(header)
# get_mask(r)

24 changes: 2 additions & 22 deletions pyregion/tests/test_region.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
import os
from os.path import join

try:
from astropy.io import fits as pyfits
except ImportError:
import pyfits
from astropy.io.fits import Header

import numpy as np

from ..wcs_helper import fix_lon
from .. import open as pyregion_open

# At some point, pyfits.Card.fromstring has changed from unbound
# method to bounded method.

if pyfits.Card.fromstring.__self__: #
def pyfits_card_fromstring(l):
return pyfits.Card.fromstring(l)
else:
def pyfits_card_fromstring(l):
c = pyfits.Card()
return c.fromstring(l)

rootdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'examples')

def demo_header():
cards = pyfits.CardList()
for l in open(join(rootdir, "sample_fits01.header")):
card = pyfits_card_fromstring(l.strip())
cards.append(card)
h = pyfits.Header(cards)
return h
return Header.fromtextfile(join(rootdir, "sample_fits01.header"))

def test_region():

Expand Down Expand Up @@ -66,4 +47,3 @@ def test_region():
assert np.allclose(reg0.coord_list, reg.coord_list,
atol=0.01)
assert reg0.exclude == reg.exclude

9 changes: 3 additions & 6 deletions pyregion/tests/test_wcs_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

from .. import parse

try:
from astropy import wcs as pywcs
except ImportError:
import pywcs
from astropy.wcs import WCS

def test_estimate_cdelt():
l,b=0,0
Expand All @@ -16,7 +13,7 @@ def test_estimate_cdelt():
# This is 'almost' the ra,dec of l,b=0,0 - works
# ra,dec=266.40,-28.93

wcs = pywcs.WCS(naxis=2)
wcs = WCS(naxis=2)

wcs.wcs.crpix = [5.5, 5.5]
wcs.wcs.cdelt = [0.1, -0.1]
Expand All @@ -26,7 +23,7 @@ def test_estimate_cdelt():
import pyregion.wcs_helper as wcs_helper
proj = wcs_helper.get_kapteyn_projection(wcs)
cdelt = wcs_helper.estimate_cdelt(proj, 5.5, 5.5)

assert np.allclose([cdelt], [0.1])

region_string="fk5; circle(%s, %s, 0.5000)" % (ra,dec)
Expand Down
Loading