pyregion-1.1.4/0000775000175000017500000000000012423134227013557 5ustar jjleejjlee00000000000000pyregion-1.1.4/pyregion.egg-info/0000775000175000017500000000000012423134227017105 5ustar jjleejjlee00000000000000pyregion-1.1.4/pyregion.egg-info/SOURCES.txt0000664000175000017500000000246012423134227020773 0ustar jjleejjlee00000000000000LICENSE LICENSE_kapteyn.txt MANIFEST.in README distribute_setup.py setup.py examples/demo_helper.py examples/demo_print_region.py examples/demo_region01.py examples/demo_region02.py examples/demo_region03.py examples/demo_region04.py examples/demo_region_filter01.py examples/sample_fits01.header examples/sample_fits02.header examples/test.header examples/test.reg examples/test01.reg examples/test01_ciao.reg examples/test01_ciao_physical.reg examples/test01_ds9_physical.reg examples/test01_fk5.reg examples/test01_fk5_degree.reg examples/test01_fk5_sexagecimal.reg examples/test01_gal.reg examples/test01_img.reg examples/test01_mixed.reg examples/test01_print.reg examples/test02.reg examples/test04_img.reg examples/test_annuli.reg examples/test_annuli_ciao.reg examples/test_annuli_wcs.reg examples/test_context.reg examples/test_text.reg examples/ttt_region01.py lib/__init__.py lib/ds9_attr_parser.py lib/ds9_region_parser.py lib/kapteyn_celestial.py lib/mpl_helper.py lib/parser_helper.py lib/physical_coordinate.py lib/region_numbers.py lib/region_to_filter.py lib/version.py lib/wcs_converter.py lib/wcs_helper.py pyregion.egg-info/PKG-INFO pyregion.egg-info/SOURCES.txt pyregion.egg-info/dependency_links.txt pyregion.egg-info/requires.txt pyregion.egg-info/top_level.txt src/_region_filter.c src/_region_filter.pyxpyregion-1.1.4/pyregion.egg-info/top_level.txt0000664000175000017500000000001112423134226021626 0ustar jjleejjlee00000000000000pyregion pyregion-1.1.4/pyregion.egg-info/requires.txt0000664000175000017500000000002112423134226021475 0ustar jjleejjlee00000000000000pyparsing!=2.0.0 pyregion-1.1.4/pyregion.egg-info/PKG-INFO0000664000175000017500000000140412423134226020200 0ustar jjleejjlee00000000000000Metadata-Version: 1.1 Name: pyregion Version: 1.1.4 Summary: python parser for ds9 region files Home-page: http://leejjoon.github.com/pyregion/ Author: Jae-Joon Lee Author-email: lee.j.joon@gmail.com License: MIT Download-URL: http://github.com/leejjoon/pyregion/downloads Description: UNKNOWN Platform: Linux Platform: MacOS X Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Science/Research Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: POSIX :: Linux Classifier: Programming Language :: Cython Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Topic :: Scientific/Engineering :: Astronomy pyregion-1.1.4/pyregion.egg-info/dependency_links.txt0000664000175000017500000000000112423134226023152 0ustar jjleejjlee00000000000000 pyregion-1.1.4/LICENSE0000644000175000017500000000204012255736553014573 0ustar jjleejjlee00000000000000Copyright (c) 2009 Jae-Joon Lee Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pyregion-1.1.4/LICENSE_kapteyn.txt0000644000175000017500000000306612255736553017155 0ustar jjleejjlee00000000000000Copyright (c) 2009, Kapteyn Astronomical Institute, University of Groningen All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Kapteyn Astronomical Institute nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. pyregion-1.1.4/lib/0000775000175000017500000000000012423134227014325 5ustar jjleejjlee00000000000000pyregion-1.1.4/lib/physical_coordinate.py0000644000175000017500000000416512255736553020743 0ustar jjleejjlee00000000000000 class PhysicalCoordinate(object): def __init__(self, header): phys_coord = "" # check if physical coordinate is defined. FIXME! for C in ["P", "L"]: try: if (header["WCSTY1"+C].strip() == "PHYSICAL") \ and (header["WCSTY2"+C].strip() == "PHYSICAL"): phys_coord = C except KeyError: pass try: if (header["CTYPE1"+C].strip() == "X") \ and (header["CTYPE2"+C].strip() == "Y"): phys_coord = C except KeyError: pass if phys_coord: C = phys_coord cv1,cr1,cd1 = header["CRVAL1"+C], header["CRPIX1"+C], header[" CDELT1"+C] cv2,cr2,cd2 = header["CRVAL2"+C], header["CRPIX2"+C], header[" CDELT2"+C] self._physical_coord_not_defined = False self.cv1_cr1_cd1 = cv1,cr1,cd1 self.cv2_cr2_cd2 = cv2,cr2,cd2 self.cdelt = (cd1*cd2)**.5 else: self._physical_coord_not_defined = True self.cv1_cr1_cd1 = 0, 0, 1 self.cv2_cr2_cd2 = 0, 0, 1 self.cdelt = 1 def to_physical(self, imx, imy): if self._physical_coord_not_defined: return imx, imy cv1,cr1,cd1 = self.cv1_cr1_cd1 cv2,cr2,cd2 = self.cv2_cr2_cd2 phyx = cv1 + (imx - cr1) * cd1 phyy = cv2 + (imy - cr2) * cd2 return phyx, phyy def to_image(self, phyx, phyy): if self._physical_coord_not_defined: return phyx, phyy cv1,cr1,cd1 = self.cv1_cr1_cd1 cv2,cr2,cd2 = self.cv2_cr2_cd2 imx = cr1 + (phyx - cv1) / cd1 imy = cr2 + (phyy - cv2) / cd2 return imx, imy def to_physical_distance(self, im_distance): if self._physical_coord_not_defined: return im_distance return im_distance*self.cdelt def to_image_distance(self, im_physical): if self._physical_coord_not_defined: return im_physical return im_physical/self.cdelt pyregion-1.1.4/lib/mpl_helper.py0000644000175000017500000003330312255736553017043 0ustar jjleejjlee00000000000000import copy import matplotlib.patches as mpatches from matplotlib.text import Text from matplotlib.path import Path from matplotlib.lines import Line2D from matplotlib.transforms import Affine2D, Bbox, IdentityTransform from matplotlib.text import Annotation import numpy as np from math import cos, sin, pi, atan2 import warnings def rotated_polygon(xy, ox, oy, angle): # angle in degree theta = angle/180.*pi st = sin(theta) ct = cos(theta) xy = np.asarray(xy, dtype="d") x, y = xy[:,0], xy[:,1] x1 = x - ox y1 = y - oy x2 = ct*x1 + -st*y1 y2 = st*x1 + ct*y1 xp = x2 + ox yp = y2 + oy return np.hstack((xp.reshape((-1,1)), yp.reshape((-1,1)))) # sss3 = [s1[0] for s1 in sss2 if isinstance(s1[0], parser_ds9.Shape)] _point_type_dict=dict(circle="o", box="s", diamond="D", x="x", cross="+", arrow="^", boxcircle="*") _ds9_to_mpl_colormap = dict(green="lime", ) def properties_func_default(shape, saved_attrs): attr_list = copy.copy(shape.attr[0]) attr_dict = copy.copy(shape.attr[1]) attr_list.extend(saved_attrs[0]) attr_dict.update(saved_attrs[1]) color = attr_dict.get("color", None) color = _ds9_to_mpl_colormap.get(color, color) if shape.name == "text": kwargs = dict(color=color, rotation=attr_dict.get("textangle", 0), ) font = attr_dict.get("font") if font: a = font.split() if len(a) >= 3: fontsize=float(a[1]) kwargs["fontsize"]=fontsize elif shape.name == "point": point_attrs = attr_dict.get("point", "boxcircle").split() if len(point_attrs) == 1: point_type = point_attrs[0] point_size = 11 elif len(point_attrs) > 1: point_type = point_attrs[0] point_size = int(point_attrs[1]) marker = _point_type_dict.get(point_type, "o") kwargs = dict(markeredgecolor=color, markerfacecolor="none", marker=marker, markeredgewidth=int(attr_dict.get("width", 1)), markersize=point_size ) elif shape.name in ["line", "vector"]: fontsize = 10 # default font size font = attr_dict.get("font") if font: a = font.split() if len(a) >= 3: fontsize=float(a[1]) kwargs = dict(color=color, linewidth=int(attr_dict.get("width", 1)), mutation_scale=fontsize, ) if int(attr_dict.get("dash","0")): kwargs["linestyle"] = "dashed" else: kwargs = dict(edgecolor=color, linewidth=int(attr_dict.get("width", 1)), facecolor="none" ) if "background" in attr_list: kwargs["linestyle"] = "dashed" if int(attr_dict.get("dash","0")): kwargs["linestyle"] = "dashed" if shape.exclude: kwargs["hatch"] = "/" return kwargs def _get_text(txt, x, y, dx, dy, ha="center", va="center", **kwargs): if "color" in kwargs: textcolor = kwargs["color"] elif "markeredgecolor" in kwargs: textcolor = kwargs["markeredgecolor"] ann = Annotation(txt, (x, y), xytext=(dx, dy), xycoords='data', textcoords="offset points", ha=ha, va=va, **kwargs) ann.set_transform(IdentityTransform()) return ann def as_mpl_artists(shape_list, properties_func=None, text_offset=5.0, origin=1): """ Converts a region list to a list of patches and a list of artists. Optional Keywords: [ text_offset ] - If there is text associated with the regions, add some vertical offset (in pixels) to the text so that it doesn't overlap with the regions. Often, the regions files implicitly assume the lower-left corner of the image as a coordinate (1,1). However, the python convetion is that the array index starts from 0. By default (origin = 1), coordinates of the returned mpl artists have coordinate shifted by (1, 1). If you do not want this shift, set origin=0. """ patch_list = [] artist_list = [] if properties_func is None: properties_func = properties_func_default # properties for continued(? multiline?) regions saved_attrs = None for shape in shape_list: patches = [] if saved_attrs is None: _attrs = [], {} else: _attrs = copy.copy(saved_attrs[0]), copy.copy(saved_attrs[1]) kwargs = properties_func(shape, _attrs) if shape.name == "composite": saved_attrs = shape.attr continue if saved_attrs is None and shape.continued: saved_attrs = shape.attr # elif (shape.name in shape.attr[1]): # if (shape.attr[1][shape.name] != "ignore"): # saved_attrs = shape.attr if not shape.continued: saved_attrs = None # text associated with the shape txt = shape.attr[1].get("text") if shape.name == "polygon": xy = np.array(shape.coord_list) xy.shape = -1,2 # -1 for change origin to 0,0 patches=[mpatches.Polygon(xy-origin, closed=True, **kwargs)] elif shape.name == "rotbox" or shape.name == "box": xc, yc, w, h, rot = shape.coord_list # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin _box = np.array([[-w/2., -h/2.], [-w/2., h/2.], [w/2., h/2.], [w/2., -h/2.]]) box = _box + [xc, yc] rotbox = rotated_polygon(box, xc, yc, rot) patches = [mpatches.Polygon(rotbox, closed=True, **kwargs)] elif shape.name == "ellipse": xc, yc = shape.coord_list[:2] # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin angle = shape.coord_list[-1] maj_list, min_list = shape.coord_list[2:-1:2], shape.coord_list[3:-1:2] patches = [mpatches.Ellipse((xc, yc), 2*maj, 2*min, angle=angle, **kwargs) \ for maj, min in zip(maj_list, min_list)] elif shape.name == "annulus": xc, yc = shape.coord_list[:2] # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin r_list = shape.coord_list[2:] patches = [mpatches.Ellipse((xc, yc), 2*r, 2*r, **kwargs) \ for r in r_list] elif shape.name == "circle": xc, yc, major = shape.coord_list # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin patches = [mpatches.Ellipse((xc, yc), 2*major, 2*major, angle=0, **kwargs)] elif shape.name == "panda": xc, yc, a1, a2, an, r1, r2, rn = shape.coord_list # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin patches = [mpatches.Arc((xc, yc), rr*2, rr*2, angle=0, theta1=a1, theta2=a2, **kwargs) \ for rr in np.linspace(r1, r2, rn+1)] for aa in np.linspace(a1, a2, an+1): xx = np.array([r1, r2]) * np.cos(aa/180.*np.pi) + xc yy = np.array([r1, r2]) * np.sin(aa/180.*np.pi) + yc p = Path(np.transpose([xx,yy])) patches.append(mpatches.PathPatch(p, **kwargs)) elif shape.name == "pie": xc, yc, r1, r2, a1, a2 = shape.coord_list # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin patches = [mpatches.Arc((xc, yc), rr*2, rr*2, angle=0, theta1=a1, theta2=a2, **kwargs) \ for rr in [r1, r2]] for aa in [a1, a2]: xx = np.array([r1, r2]) * np.cos(aa/180.*np.pi) + xc yy = np.array([r1, r2]) * np.sin(aa/180.*np.pi) + yc p = Path(np.transpose([xx,yy])) patches.append(mpatches.PathPatch(p, **kwargs)) elif shape.name == "epanda": xc, yc, a1, a2, an, r11, r12,r21, r22, rn, angle = shape.coord_list # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin # mpl takes angle a1, a2 as angle as in circle before # transformation to ellipse. x1, y1 = cos(a1/180.*pi), sin(a1/180.*pi)*r11/r12 x2, y2 = cos(a2/180.*pi), sin(a2/180.*pi)*r11/r12 a1, a2 = atan2(y1, x1)/pi*180., atan2(y2, x2)/pi*180. patches = [mpatches.Arc((xc, yc), rr1*2, rr2*2, angle=angle, theta1=a1, theta2=a2, **kwargs) \ for rr1, rr2 in zip(np.linspace(r11, r21, rn+1), np.linspace(r12, r22, rn+1))] for aa in np.linspace(a1, a2, an+1): xx = np.array([r11, r21]) * np.cos(aa/180.*np.pi) yy = np.array([r11, r21]) * np.sin(aa/180.*np.pi) p = Path(np.transpose([xx,yy])) tr = Affine2D().scale(1, r12/r11).rotate_deg(angle).translate(xc, yc) p2 = tr.transform_path(p) patches.append(mpatches.PathPatch(p2, **kwargs)) elif shape.name == "text": xc, yc = shape.coord_list[:2] # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin if txt: _t = _get_text(txt, xc, yc, 0, 0, **kwargs) artist_list.append(_t) elif shape.name == "point": xc, yc = shape.coord_list[:2] # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin artist_list.append(Line2D([xc], [yc], **kwargs)) if txt: textshape = copy.copy(shape) textshape.name = "text" textkwargs = properties_func(textshape, _attrs) _t = _get_text(txt, xc, yc, 0, text_offset, va="bottom", **textkwargs) artist_list.append(_t) elif shape.name in ["line", "vector"]: if shape.name == "line": x1, y1, x2, y2 = shape.coord_list[:4] # -1 for change origin to 0,0 x1, y1, x2, y2 = x1-origin, y1-origin, x2-origin, y2-origin a1, a2 = shape.attr[1].get("line", "0 0").strip().split()[:2] arrowstyle = "-" if int(a1): arrowstyle = "<" + arrowstyle if int(a2): arrowstyle = arrowstyle + ">" else: # shape.name == "vector" x1, y1, l, a = shape.coord_list[:4] # -1 for change origin to 0,0 x1, y1 = x1-origin, y1-origin x2, y2 = x1 + l * np.cos(a/180.*np.pi), y1 + l * np.sin(a/180.*np.pi) v1 = int(shape.attr[1].get("vector", "0").strip()) if v1: arrowstyle="->" else: arrowstyle="-" patches = [mpatches.FancyArrowPatch(posA=(x1, y1), posB=(x2, y2), arrowstyle=arrowstyle, arrow_transmuter=None, connectionstyle="arc3", patchA=None, patchB=None, shrinkA=0, shrinkB=0, connector=None, **kwargs)] else: warnings.warn("'as_mpl_artists' does not know how to convert '%s' to mpl artist" % (shape.name,)) patch_list.extend(patches) if txt and patches: # the text associated with a shape uses different # matplotlib keywords than the shape itself for, e.g., # color textshape = copy.copy(shape) textshape.name = "text" textkwargs = properties_func(textshape, _attrs) # calculate the text position _bb = [p.get_window_extent() for p in patches] # this is to work around backward-incompatible change made # in matplotlib 1.2. This change is later reverted so only # some versions are affected. With affected version of # matplotlib, get_window_extent method calls get_transform # method which sets the _transformSet to True, which is # not desired. for p in patches: p._transformSet = False _bbox = Bbox.union(_bb) x0, y0, x1, y1 = _bbox.extents xc = .5*(x0+x1) _t = _get_text(txt, xc, y1, 0, text_offset, va="bottom", **textkwargs) artist_list.append(_t) return patch_list, artist_list if 0: import parser_ds9 regname = "az_region.reg" shape_list = region_read_as_imagecoord(regname, wcs) p = as_mpl_patches(shape_list) clf() ax = gca() [ax.add_patch(p1) for p1 in p] xlim(0,1500) ylim(0,1500) draw() pyregion-1.1.4/lib/region_to_filter.py0000644000175000017500000001050312255736553020243 0ustar jjleejjlee00000000000000import numpy as np import pyregion._region_filter as region_filter import warnings def as_region_filter(shape_list, origin=1): """ Often, the regions files implicitly assume the lower-left corner of the image as a coordinate (1,1). However, the python convetion is that the array index starts from 0. By default (origin = 1), coordinates of the returned mpl artists have coordinate shifted by (1, 1). If you do not want this shift, use origin=0. """ filter_list = [] for shape in shape_list: if shape.name == "composite": continue if shape.name == "polygon": xy = np.array(shape.coord_list) - origin f = region_filter.Polygon(xy[::2], xy[1::2]) elif shape.name == "rotbox" or shape.name == "box": xc, yc, w, h, rot = shape.coord_list # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin f = region_filter.Rotated(region_filter.Box(xc, yc, w, h), rot, xc, yc) elif shape.name == "ellipse": xc, yc = shape.coord_list[:2] # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin angle = shape.coord_list[-1] maj_list, min_list = shape.coord_list[2:-1:2], shape.coord_list[3:-1:2] if len(maj_list) > 1: w1, h1 = max(maj_list), max(min_list) w2, h2 = min(maj_list), min(min_list) f1 = region_filter.Ellipse(xc, yc, w1, h1) \ & ~region_filter.Ellipse(xc, yc, w2, h2) f = region_filter.Rotated(f1, angle, xc, yc) else: w, h = maj_list[0], min_list[0] f = region_filter.Rotated(region_filter.Ellipse(xc, yc, w, h), angle, xc, yc) elif shape.name == "annulus": xc, yc = shape.coord_list[:2] # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin r_list = shape.coord_list[2:] r1 = max(r_list) r2 = min(r_list) f = region_filter.Circle(xc, yc, r1) & ~region_filter.Circle(xc, yc, r2) elif shape.name == "circle": xc, yc, r = shape.coord_list # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin f = region_filter.Circle(xc, yc, r) elif shape.name == "panda": xc, yc, a1, a2, an, r1, r2, rn = shape.coord_list # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin f1 = region_filter.Circle(xc, yc, r2) & ~region_filter.Circle(xc, yc, r1) f = f1 & region_filter.AngleRange(xc, yc, a1, a2) elif shape.name == "pie": xc, yc, r1, r2, a1, a2 = shape.coord_list # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin f1 = region_filter.Circle(xc, yc, r2) & ~region_filter.Circle(xc, yc, r1) f = f1 & region_filter.AngleRange(xc, yc, a1, a2) elif shape.name == "epanda": xc, yc, a1, a2, an, r11, r12, r21, r22, rn, angle = shape.coord_list # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin f1 = region_filter.Ellipse(xc, yc, r21, r22) & ~region_filter.Ellipse(xc, yc, r11, r12) f2 = f1 & region_filter.AngleRange(xc, yc, a1, a2) f = region_filter.Rotated(f2, angle, xc, yc) #f = f2 & region_filter.AngleRange(xc, yc, a1, a2) elif shape.name == "bpanda": xc, yc, a1, a2, an, r11, r12, r21, r22, rn, angle = shape.coord_list # -1 for change origin to 0,0 xc, yc = xc-origin, yc-origin f1 = region_filter.Box(xc, yc, r21, r22) & ~region_filter.Box(xc, yc, r11, r12) f2 = f1 & region_filter.AngleRange(xc, yc, a1, a2) f = region_filter.Rotated(f2, angle, xc, yc) #f = f2 & region_filter.AngleRange(xc, yc, a1, a2) else: warnings.warn("'as_region_filter' does not know how to convert '%s' to a region filter." % (shape.name,)) continue if shape.exclude: filter_list = [region_filter.RegionOrList(*filter_list) & ~f] else: filter_list.append(f) return region_filter.RegionOrList(*filter_list) pyregion-1.1.4/lib/__init__.py0000664000175000017500000001726112423131217016441 0ustar jjleejjlee00000000000000from .version import __version__ from .ds9_region_parser import RegionParser from .wcs_converter import check_wcs as _check_wcs from itertools import cycle _builtin_open = open class ShapeList(list): """ A list of shape objects """ def __init__(self, shape_list, comment_list=None): """ Parameters ---------- shape_list : a list of 'pyregion.parse_helper.Shape' objects comment_list : list, None list of comment strings for each argument """ if comment_list is not None: if len(comment_list) != len(shape_list): err = "Ambiguous number of comments {} for number of shapes {}" raise ValueError(err.format(len(comment_list), len(shape_list))) self._comment_list = comment_list list.__init__(self, shape_list) def __getitem__(self, key): if isinstance(key, slice): return ShapeList(list.__getitem__(self, key)) else: return list.__getitem__(self, key) def __getslice__(self, i, j): return self[max(0, i):max(0, j):] def check_imagecoord(self): if [s for s in self if s.coord_format != "image"]: return False else: return True def as_imagecoord(self, header, rot_wrt_axis=1): """ Return a new ShapeList where the coordinate of the each shape is converted to the image coordinate using the given header information """ comment_list = self._comment_list if comment_list is None: comment_list = cycle([None]) r = RegionParser.sky_to_image(zip(self, comment_list), header, rot_wrt_axis=rot_wrt_axis) shape_list, comment_list = zip(*list(r)) return ShapeList(shape_list, comment_list=comment_list) def get_mpl_patches_texts(self, properties_func=None, text_offset=5.0, origin=1): """ Often, the regions files implicitly assume the lower-left corner of the image as a coordinate (1,1). However, the python convetion is that the array index starts from 0. By default (origin = 1), coordinates of the returned mpl artists have coordinate shifted by (1, 1). If you do not want this shift, use origin=0. """ from .mpl_helper import as_mpl_artists patches, txts = as_mpl_artists(self, properties_func, text_offset, origin=origin) return patches, txts def get_filter(self, header=None, origin=1, rot_wrt_axis=1): """ Often, the regions files implicitly assume the lower-left corner of the image as a coordinate (1,1). However, the python convetion is that the array index starts from 0. By default (origin = 1), coordinates of the returned mpl artists have coordinate shifted by (1, 1). If you do not want this shift, use origin=0. """ from .region_to_filter import as_region_filter if header is None: if not self.check_imagecoord(): raise RuntimeError("the region has non-image coordinate. header is required.") reg_in_imagecoord = self else: reg_in_imagecoord = self.as_imagecoord(header, rot_wrt_axis=rot_wrt_axis) region_filter = as_region_filter(reg_in_imagecoord, origin=1) return region_filter def get_mask(self, hdu=None, header=None, shape=None, rot_wrt_axis=1): """ creates a 2-d mask. get_mask(hdu=f[0]) get_mask(shape=(10,10)) get_mask(header=f[0].header, shape=(10,10)) """ if hdu and header is None: header = hdu.header if hdu and shape is None: shape = hdu.data.shape region_filter = self.get_filter(header=header, rot_wrt_axis=rot_wrt_axis) mask = region_filter.mask(shape) return mask def write(self, outfile): """ Writes the current shape list out as a region file """ if len(self) < 1: print("WARNING: The region list is empty. The region file "\ "'{:s}' will be empty.".format(outfile)) try: outf = open(outfile,'w') outf.close() return except IOError as e: cmsg = "Unable to create region file '{:s}'.".format(outfile) if e.args: e.args = (e.args[0] + '\n' + cmsg,) + e.args[1:] else: e.args=(cmsg,) raise e prev_cs = self[0].coord_format outf = None try: outf = _builtin_open(outfile,'w') attr0 = self[0].attr[1] defaultline = " ".join( [ "{:s}={:s}".format(a,attr0[a]) \ for a in attr0 if a != 'text' ] ) # first line is globals print >>outf, "global", defaultline # second line must be a coordinate format print >>outf, prev_cs for shape in self: shape_attr = '' if prev_cs == shape.coord_format \ else shape.coord_format+"; " shape_excl = '-' if shape.exclude else '' text_coordlist = [ "{:f}".format(f) for f in shape.coord_list ] shape_coords = "(" + ",".join(text_coordlist) + ")" shape_comment = " # " + shape.comment if shape.comment else '' shape_str = shape_attr + shape_excl + shape.name + \ shape_coords + shape_comment print >>outf, shape_str except IOError as e: cmsg = "Unable to create region file \'{:s}\'.".format(outfile) if e.args: e.args = (e.args[0] + '\n' + cmsg,) + e.args[1:] else: e.args=(cmsg,) raise e finally: if outf: outf.close() def parse(region_string): """ Parse the input string of a ds9 region definition. Returns a list of Shape instances. """ rp = RegionParser() ss = rp.parse(region_string) sss1 = rp.convert_attr(ss) sss2 = _check_wcs(sss1) shape_list, comment_list = rp.filter_shape2(sss2) return ShapeList(shape_list, comment_list=comment_list) def open(fname): region_string = _builtin_open(fname).read() return parse(region_string) # def parse_deprecated(region_string): # rp = RegionParser() # return rp.parseString(region_string) def read_region(s): rp = RegionParser() ss = rp.parse(s) sss1 = rp.convert_attr(ss) sss2 = _check_wcs(sss1) return rp.filter_shape(sss2) def read_region_as_imagecoord(s, header, rot_wrt_axis=1): rp = RegionParser() ss = rp.parse(s) sss1 = rp.convert_attr(ss) sss2 = _check_wcs(sss1) sss3 = rp.sky_to_image(sss2, header, rot_wrt_axis=rot_wrt_axis) return rp.filter_shape(sss3) def get_mask(region, hdu, origin=1): """ f = pyfits.read("test.fits") reg = read_region_as_imagecoord(s, f[0].header) mask = get_mask(reg, f[0]) """ from pyregion.region_to_filter import as_region_filter data = hdu.data region_filter = as_region_filter(region, origin=origin) mask = region_filter.mask(data) return mask if __name__ == '__main__': #reg = pyregion.open("../mos_fov.reg") import pyregion proposed_fov = 'fk5;circle(290.96388,14.019167,843.31194")' reg = pyregion.parse(proposed_fov) reg_imagecoord = reg.as_imagecoord(header) patches, txts = reg.get_mpl_patches_texts() m = reg.get_mask(hdu=f[0]) pyregion-1.1.4/lib/wcs_converter.py0000664000175000017500000000613612341145603017567 0ustar jjleejjlee00000000000000from .wcs_helper import estimate_cdelt, estimate_angle from .region_numbers import CoordOdd, CoordEven, Distance, Angle from .parser_helper import Shape, CoordCommand from .region_numbers import SimpleNumber, SimpleInteger import copy def convert_to_imagecoord(cl, fl, wcs_proj, sky_to_sky, xy0, rot_wrt_axis=1): fl0 = fl new_cl = [] while cl: if len(fl) == 0: fl = fl0 if fl[0] == CoordOdd and fl[1] == CoordEven: ll = sky_to_sky([cl[0]], [cl[1]]) x0, y0 = wcs_proj.topixel(ll) xy0 = [x0[0], y0[0]] new_cl.extend(xy0) cl = cl[2:] fl = fl[2:] elif fl[0] == Distance: degree_per_pixel = estimate_cdelt(wcs_proj, *xy0) new_cl.append(cl[0]/degree_per_pixel) cl = cl[1:] fl = fl[1:] elif fl[0] == Angle: rot1, rot2 = estimate_angle(wcs_proj, xy0[0], xy0[1], sky_to_sky) if rot_wrt_axis == 1: # use the angle between the X axis and North new_cl.append(cl[0]+rot1-180.) else: # use the angle between the Y axis and North new_cl.append(cl[0]+rot2-90.) cl = cl[1:] fl = fl[1:] else: new_cl.append(cl[0]) cl = cl[1:] fl = fl[1:] return new_cl, xy0 def convert_physical_to_imagecoord(cl, fl, pc): fl0 = fl new_cl = [] while cl: if len(fl) == 0: fl = fl0 if fl[0] == CoordOdd and fl[1] == CoordEven: xy0 = pc.to_image(cl[0], cl[1]) new_cl.extend(xy0) cl = cl[2:] fl = fl[2:] elif fl[0] == Distance: new_cl.append(pc.to_image_distance(cl[0])) cl = cl[1:] fl = fl[1:] else: new_cl.append(cl[0]) cl = cl[1:] fl = fl[1:] return new_cl def check_wcs_and_convert(args, all_dms=False): is_wcs = False value_list = [] for a in args: if isinstance(a, SimpleNumber) or isinstance(a, SimpleInteger) \ or all_dms: value_list.append(a.v) else: value_list.append(a.degree) is_wcs = True return is_wcs, value_list def check_wcs(l): default_coord = "physical" for l1, c1 in l: if isinstance(l1, CoordCommand): default_coord = l1.text.lower() continue if isinstance(l1, Shape): if default_coord == "galactic": is_wcs, coord_list = check_wcs_and_convert(l1.params, all_dms=True) else: is_wcs, coord_list = check_wcs_and_convert(l1.params) if is_wcs and (default_coord == "physical"): # ciao format coord_format = "fk5" else: coord_format = default_coord l1n = copy.copy(l1) l1n.coord_list = coord_list l1n.coord_format = coord_format yield l1n, c1 else: yield l1, c1 pyregion-1.1.4/lib/kapteyn_celestial.py0000644000175000017500000024476312255736553020432 0ustar jjleejjlee00000000000000#!/usr/bin/env python #---------------------------------------------------------------------- # FILE: celestial.py # PURPOSE: Build a matrix for conversions between sky systems and or # celestial reference systems. # Epochs are specified with an extra variable which represents # FK4, FK5 or ICRS. The sky systems are equatorial, ecliptic, # galactic, and supergalactic. # In the calling environment one is supposed to use the function # 'skymatrix' only. The other functions are helper functions. # AUTHOR: M.G.R. Vogelaar, University of Groningen, The Netherlands # DATE: December 12, 2007 # UPDATE: April 17, 2008 # VERSION: 0.6 # # (C) University of Groningen # Kapteyn Astronomical Institute # Groningen, The Netherlands # E: gipsy@astro.rug.nl #---------------------------------------------------------------------- import numpy as n import types import re # Some globals: eq, ecl, gal, sgal, fk4, fk4_no_e, fk5, icrs, j2000 = list(range(9)) # aliases equatorial = eq; ecliptic = ecl; galactic = gal; supergalactic = sgal # Conversion factors deg <-> rad convd2r = n.pi/180.0 convr2d = 180.0/n.pi #---------------------------------------------------------------------- # Some utility routines #--------------------------------------------------------------------- def d2r(degs): return degs * convd2r def r2d(rads): return rads * convr2d def I(): return n.identity(3, dtype='d') def JD(year, month, day): """ ---------------------------------------------------------------------- Purpose: Calculate Julian day number (Julian date) Input: year (nnnn), month (nn), day (nn.n), Returns: Julian day number 'jd' Reference: Meeus, Astronomical formula for Calculators, 2nd ed, 1982 Notes: Months start at 1. Days start at 1. The Julian day begins at Greenwich mean noon, i.e. at 12h. So Jan 1, 1984 at 0h is entered as JD(1984,1,1) and Jan 1, 1984 at 12h is entered as JD(1984,1,1.5) There is a jump at JD(1582,10,15) caused by the change of calendars. So for dates after 1582-10-15 one enters a date from the Julian calendar and before this date you enter a date from the Julian calendar. Examples: Julian date of JD reference: print celestial.JD(-4712,1,1.5) ==> 0.0 The first day of 1 B.C.: print celestial.JD(0,1,1) ==> 1721057.5 Last day before Gregorian reform: print celestial.JD(1582,10,4) ==> 2299159.5 First day of Gregorian reform: print celestial.JD(1582,10,15) ==> 2299170.5 Half a day later: print celestial.JD(1582,10,15.5) ==> 2299161.0 Unix reference: print celestial.JD(1970,1,1) ==> 2440587.5 ---------------------------------------------------------------------- """ if (month > 2): y = year m = month elif (month == 1 or month == 2): y = year - 1 m = month + 12 calday = year + month/100.0 + day / 10000.0 if (calday > 1582.1015): A = int(y/100.0) B = 2 - A + int(A/4.0) else: B = 0 if (calday > 0.0229): # Dates after 29 February year 0 jd = int(365.25*y) + int(30.6001*(m+1)) + day + 1720994.50 + B else: jd = int(365.25*y-0.75) + int(30.6001*(m+1)) + day + 1720994.50 + B return jd def longlat2xyz(longlat): """ ----------------------------------------------------------------------- Purpose: Given two angles in longitude and latitude return corresponding cartesian coordinates x,y,z Input: Sequence of positions e.g. ((a1,d1),(a2,d2), ...) Returns: Corresponding values of x,y,z in same order as input Reference: - Notes: The three coordinate axes x, y and z, the set of right-handed cartesian axes that correspond to the usual celestial spherical coordinate system. The xy-plane is the equator, the z-axis points toward the north celestial pole, and the x-axis points toward the origin of right ascension. ----------------------------------------------------------------------- """ lon = d2r( n.asarray(longlat[:,0],'d').flatten(1) ) lat = d2r( n.asarray(longlat[:,1],'d').flatten(1) ) x = n.cos(lon)*n.cos(lat) y = n.sin(lon)*n.cos(lat) z = n.sin(lat) return n.mat((x,y,z)) def xyz2longlat(xyz): """ ----------------------------------------------------------------------- Purpose: Given Cartesian x,y,z return corresponding longitude and latitude in degrees. Input: Sequence of tuples with values for x,y,z Returns: The same number of positions (longitude, lattitude) and in the same order as the input. Reference: - Notes: Note that one can expect strange behavior for the values of the longitudes very close to the pole. In fact, at the poles itself, the longitudes are meaningless. ----------------------------------------------------------------------- """ x = n.asarray(xyz[0],'d').flatten(1) y = n.asarray(xyz[1],'d').flatten(1) z = n.asarray(xyz[2],'d').flatten(1) lat = r2d( n.arctan2(z, n.sqrt(x*x+y*y)) ) lon = r2d( n.arctan2(y, x) ) # eps = n.array(0.00000001, 'd') # lon = n.where( ((abs(lat) > 89.9999) & (abs(x) < eps) & (abs(y) < eps)),\ # 0.0, r2d( n.arctan2(y, x))) lon = n.where(lon < 0.0, lon+360.0, lon) return n.mat([lon,lat]).T def lon2hms(a, prec=1, delta=None, tex=False): """ ---------------------------------------------------------------------- Purpose: Convert an angle in degrees to hours, minutes, seconds format Input: Angle in degrees and an integer for the wanted decimals in the seconds part of output Returns: String containing the converted angle Notes: Longitudes are forced into the raange 0, 360 deg. and then converted to hours, minutes and seconds. Examples: >>> ra = 359.9999 >>> dec = 0.0000123 >>> print celestial.lon2hms(ra), celestial.lat2dms(dec) 00h 00m 0.0s +00d 00m 0.0s >>> print celestial.lon2hms(ra, 2), celestial.lat2dms(dec, 2) 23h 59m 59.98s +00d 00m 0.04s >>> print celestial.lon2hms(ra, 4), celestial.lat2dms(dec, 4) 23h 59m 59.9760s +00d 00m 0.0443s ---------------------------------------------------------------------- """ degs = n.fmod(a, 360.0) # Now in range -360, 360 if degs < 0.0: degs += 360.0 if prec < 0: prec = 0 # How many seconds is this. Round to 'prec' sec = n.round(degs*240.0, prec) sec = n.fmod(sec, 360.0*240.0) # Rounding can result in 360 deg again, so correct Isec = n.int(sec) # Integer seconds Fsec = sec - Isec # Fractional remainder hours = Isec / 3600.0 Ihours = n.int(hours) secleft = Isec - Ihours*3600.0 Imin = int(secleft / 60.0) secleft = secleft - Imin*60.0 # print "\n prec Ideg, Imin, secleft, Fsec", prec, Ideg, Imin, secleft, Fsec if tex: if prec > 0: hms = "%d^h%.2d^m%.2d^s" % (Ihours, Imin, secleft) fsec = "%*.*d" % (prec, prec, int(round(Fsec*10.0**prec,0))) s = r"$" + hms + fsec + "$" else: s1 = r"$%d^h%.2d^m%.2d^s$" % (Ihours, Imin, secleft) if delta == None: s = s1 else: if (delta*3600.0) % (15.0*3600) == 0.0: # Only hours s = r"$%d^h$" % Ihours elif (delta*3600.0) % (15.0*60) == 0.0: # Only hours and minutes s = r"$%d^h%.2d^m$" % (Ihours, Imin) else: s = s1 else: if prec > 0: s = "%.2dh%.2dm%*.*fs" % (Ihours, Imin, prec+3, prec, secleft+Fsec) else: s = "%.2dh%.2dm%2ds" % (Ihours, Imin, secleft) return s def lat2dms(a, prec=1, delta=None, tex=False): """ ---------------------------------------------------------------------- Purpose: Convert an angle in degrees into the degrees, minutes, seconds format assuming it was a latitude which value should be in the range -90 to 90 degrees Input: a: Angle in degrees, wanted decimals in the seconds part of output There is not a check on the validity of the input angle. prec: Wanted precision in output. the value of prec cannot be smaller than 0. Returns: String containing the converted angle in dms format. Notes: Both longitudes and latitudes could be formatted in 'dms'. However they should be treated differently because their ranges are different. Longitudes should be in range of (0,360) degrees. So -10 deg is in fact 350 deg. and 370 deg is in fact 10 deg. Latitudes range from -90 to 90 degrees. Then 91 degrees is in fact 89 degrees but at a longitude that is separated 180 deg. from the stated longitude. But we don't have control over the longitudes here so the only thing we can do is reject the value and return a dummy string. ---------------------------------------------------------------------- """ if a > 90.0 or a < -90.0: return "##d##m##s"; sign = 1; si = ' ' # one space if a < 0.0: sign = -1 si = '-' degs = sign * a # Make positive if prec < 0: prec = 0 # How many seconds is this. Round to 'prec' sec = n.round(degs*3600.0, prec) Isec = n.int(sec) # Integer seconds Fsec = sec - Isec # Fractional remainder degs = Isec / 3600.0 Ideg = n.int(degs) secleft = Isec - Ideg*3600.0 Imin = int(secleft / 60.0) secleft = secleft - Imin*60.0 if tex: if prec > 0: dms = r"%c%d^{\circ}%.2d^{\prime}%.2d^{\prime\prime}" % (si, Ideg, Imin, secleft) fsec = ".%*.*d" % (prec, prec, int(round(Fsec*10.0**prec,0))) s = r"$" + dms + fsec + "$" else: s1 = r"$%c%d^{\circ}%.2d^{\prime}%.2d^{\prime\prime}$" % (si, Ideg, Imin, secleft) if delta == None: s = s1 else: if (delta*3600.0) % 3600 == 0.0: # Only degrees s = r"$%c%d^{\circ}$" % (si,Ideg) elif (delta*3600.0) % 60 == 0.0: # Only degrees and minutes s = r"$%c%d^{\circ}%.2d^{\prime}$" % (si, Ideg, Imin) else: s = s1 else: if prec > 0: s = "%c%.2dd%.2dm%*.*fs" % (si, Ideg, Imin, prec+3, prec, secleft+Fsec) else: s = "%c%.2dd%.2dm%2ds" % (si, Ideg, Imin, secleft) return s def lon2dms(a, prec=1, delta=None, tex=False): """ ---------------------------------------------------------------------- Purpose: Convert an angle in degrees to degrees, minutes, seconds format assuming the input is a longitude. Input: a: Angle in degrees, wanted decimals in the seconds part of output There is not a check on the validity of the input angle. prec: Wanted precision in output. the value of prec cannot be smaller than 0. Returns: String containing the converted angle Notes: See function lat2dms Examples: >>> print celestial.lon2dms(167.342, 4) 167d 20m 31.2000s >>> print celestial.lon2dms(-10, 4) 350d 0m 0.0000s ---------------------------------------------------------------------- """ degs = n.fmod(a, 360.0) # Now in range -360, 360 if (a < 0.0): degs += 360.0 # In range 0, 360 circle-wise if prec < 0: prec = 0 # How many seconds is this. Round to 'prec' sec = n.round(degs*3600.0, prec) Isec = n.int(sec) # Integer seconds Fsec = sec - Isec # Fractional remainder degs = Isec / 3600.0 Ideg = n.int(degs) secleft = Isec - Ideg*3600.0 Imin = int(secleft / 60.0) secleft = secleft - Imin*60.0 if tex: if prec > 0: dms = r"%d^{\circ}%.2d^{\prime}%.2d^{\prime\prime}" % (Ideg, Imin, secleft) fsec = ".%*.*d" % (prec, prec, int(round(Fsec*10.0**prec,0))) s = r"$" + dms + fsec + "$" else: s1 = r"$%d^{\circ}%.2d^{\prime}%.2d^{\prime\prime}$" % (Ideg, Imin, secleft) if delta == None: s = s1 else: if (delta*3600.0) % 3600 == 0.0: # Only degrees s = r"$%d^{\circ}$" % Ideg elif (delta*3600.0) % 60 == 0.0: # Only degrees and minutes s = r"$%d^{\circ}%.2d^{\prime}$" % (Ideg, Imin) else: s = s1 else: if prec > 0: s = "%4dd%2dm%*.*fs" % (Ideg, Imin, prec+3, prec, secleft+Fsec) else: s = "%4dd%2dm%2ds" % (Ideg, Imin, secleft) return s def JD2epochBessel(JD): """ ---------------------------------------------------------------------- Purpose: Convert a Julian date to a Besselian epoch Input: Julian date (e.g. 2445700.5) Returns: Besselian epoch (e.g. 1983.9) Reference: Standards Of Fundamental Astronomy, http://www.iau-sofa.rl.ac.uk/2003_0429/sofa/epb.html Notes: e.g. 2445700.5 -> 1983.99956681 1 Tropical Year is 365.242198781 days JD(1900) = 2415020.31352 If we know the JD then the Besselian epoch can be calculated with: BE = B[1900 + (JD - 2415020.31352)/365.242198781] Expression corresponds to IAU SOFA expression with: 2451545-36524.68648 = 2415020.31352 ---------------------------------------------------------------------- """ return 1900.0 + (JD-2415020.31352)/365.242198781 def epochBessel2JD(Bepoch): """ ---------------------------------------------------------------------- Purpose: Convert a Besselian epoch to a Julian date Input: Besselian epoch nnnn.nn Returns: Julian date Reference: See: JD2epochBessel Notes: e.g. 1983.99956681 converts into 2445700.5 Inverse of JD2epochBessel ---------------------------------------------------------------------- """ return (Bepoch-1900.0)*365.242198781 + 2415020.31352 def JD2epochJulian(JD): """ ---------------------------------------------------------------------- Purpose: Convert a Julian date to a Julian epoch Input: Julian date Returns: Julian epoch Reference: Standards Of Fundamental Astronomy, http://www.iau-sofa.rl.ac.uk/2003_0429/sofa/epj.html Notes: e.g. 2445700.5 converts into 1983.99863107 Assuming years of exactly 365.25 days, we can calculate a Julian epoch from a Julian date. Expression corresponds to IAU SOFA routine 'epj' ---------------------------------------------------------------------- """ return 2000.0 + (JD - 2451545.0)/365.25 def epochJulian2JD(Jepoch): """ ---------------------------------------------------------------------- Purpose: Convert a Julian epoch to a Julian date Input: Julian epoch (nnnn.nn) Returns: Julian date Reference: See JD2epochJulian Notes: e.g. 1983.99863107 converts into 2445700.5 Inverse of function JD2epochJulian ---------------------------------------------------------------------- """ return (Jepoch-2000.0)*365.25 + 2451545.0 def obliquity1980(jd): """ ---------------------------------------------------------------------- Purpose: What is the obliquity of the ecliptic at this Julian date? IAU 1980 model Input: Julian date Returns: Mean obliquity in degrees Reference: Explanatory Supplement to the Astronomical Almanac, P. Kenneth Seidelmann (ed), University Science Books (1992), Expression 3.222-1 (p114). Notes: The epoch is entered in Julian date and the time is calculated w.r.t. J2000 The obliquity is the angle between the mean equator and ecliptic, or, between the ecliptic pole and mean celestial pole of date ---------------------------------------------------------------------- """ # T = (Date - 1 jan, 2000, 12h noon) T = (jd-2451545.0)/36525.0 eps = (84381.448+(-46.8150+(-0.00059+0.001813*T)*T)*T) / 3600.0 return eps def obliquity2000(jd): """ ---------------------------------------------------------------------- Purpose: What is the obliquity of the ecliptic at this Julian date? IAU2000 Input: Julian date Returns: Mean obliquity in degrees Reference: Fukushima, T. 2003, AJ, 126,1 Kaplan, H., 2005, , The IAU Resolutions on Astronomical Reference Systems, Time Scales, and Earth Rotation Models, United States Naval Observatory circular no. 179, http://aa.usno.navy.mil/publications/docs/Circular_179.pdf (page 44) notes: The epoch is entered in Julian date and the time is calculated w.r.t. J2000 The obliquity is the angle between the mean equator and ecliptic, or, between the ecliptic pole and mean celestial pole of date. ---------------------------------------------------------------------- """ # T = (Date - 1 jan, 2000, 12h noon) T = (jd-2451545.0)/36525.0 eps = (84381.406 + ( -46.836769 + ( -0.0001831 + ( 0.00200340 + ( -0.000000576 + ( -0.0000000434 )*T)*T)*T)*T)*T) / 3600.0 return eps def IAU2006precangles(epoch): """ ---------------------------------------------------------------------- Purpose: Calculate IAU 2000 precession angles for precession from input epoch to J2000 Input: Julian epoch of observation Returns: Angles zeta, z, theta in degrees to setup a rotation matrix to transform from J2000 to input epoch Reference: N. Capitaine et al.: IAU 2000 precession A&A 412, 567-586 (2003) Notes: Input are Julian epochs! T = (jd-2451545.0)/36525.0 Combined with jd = Jepoch-2000.0)*365.25 + 2451545.0 gives: (see code at epochJulian2JD(epoch)) T = (epoch-2000.0)/100.0 Update this function as soon as there are IAU2006 adopted angles to replace the angles used below. ---------------------------------------------------------------------- """ # T = (Current epoch - 1 jan, 2000, 12h noon) T = (epoch-2000.0)/100.0 d0 = 2.5976176 d1 = 2306.0809506 d2 = 0.3019015 d3 = 0.0179663 d4 = -0.0000327 d5 = -0.0000002 zeta_a = T*(d1+T*(d2+T*(d3+T*(d4+T*(d5)))))+d0 d0 = -2.5976176 d1 = 2306.0803226 d2 = 1.0947790 d3 = 0.0182273 d4 = 0.0000470 d5 = -0.0000003 z_a = T*(d1+T*(d2+T*(d3+T*(d4+T*(d5)))))+d0 d0 = 0.0 d1 = 2004.1917476 d2 = -0.4269353 d3 = -0.0418251 d4 = -0.0000601 d5 = -0.0000001 theta_a = T*(d1+T*(d2+T*(d3+T*(d4+T*(d5)))))+d0 # Return values in degrees return zeta_a/3600.0, z_a/3600.0, theta_a/3600.0 def Lieskeprecangles(jd1, jd2): """ ---------------------------------------------------------------------- Purpose: Calculate IAU 1976 precession angles for a precession of epoch corresponding to Julian date jd1 to epoch corresponding to Julian date jd2. Input: Julian date jd1 for start epoch Julian date jd2 for end epoch Returns: Angles zeta, z, theta in degrees Reference: Lieske,J.H., 1979. Astron.Astrophys.,73,282. equations (6) & (7), p283. Notes: The ES (Explanatory Supplement to the Astronomical Almanac) lists for a IAU1976 precession from 1984, January 1d0h to J2000 the angles: xi_a=368.9985, ze_a=369.0188 and th_a=320.7279 Using the functions in this module, this can be calculated by applying: jd1 = JD(1984,1,1) and jd2 = JD(2000,1,1.5) print Lieskeprecangles(jd1, jd2) which returns the equivalent values in degrees of: 368.998509562 369.018811234 320.727934238 in arcsec. Lieske's fit belongs to the so called Quasi-Linear Types Precision (according to IAU SOFA): 1960AD to 2040AD: < 0.1" 1640AD to 2360AD: < 1" 500BC to 3000AD: < 3" 1200BC to 3900AD: > 10" < 4200BC or > 5600AD: > 100" < 6800BC or > 8200AD: > 1000" ---------------------------------------------------------------------- """ # T = (Current epoch - 1 jan, 2000, 12h noon) T = (jd1-2451545.0)/36525.0 t = (jd2-jd1)/36525.0 d1 = 2306.2181 d2 = 1.39656 d3 = -0.000139 d4 = 0.30188 d5 = 0.000344 d6 = 0.017998 D1 = d1 + T*(d2+T*d3) zeta_a = t*(D1 + t*((d4+d5*T) + t*d6)) # d1 = 2306.2181 # d2 = 1.39656 # d3 = -0.000139 d4 = 1.09468 d5 = -0.000066 d6 = 0.018203 z_a = t*(D1 + t*((d4+d5*T) + t*d6)) d1 = 2004.3109 d2 = -0.85330 d3 = -0.000217 d4 = -0.42665 d5 = -0.000217 d6 = -0.041833 D1 = d1 + T*(d2+T*d3) theta_a = t*(D1 + t*((d4+d5*T) + t*d6)) # Return values in degrees return zeta_a/3600.0, z_a/3600.0, theta_a/3600.0 def Newcombprecangles(epoch1, epoch2): """ ---------------------------------------------------------------------- Purpose: Calculate precession angles for a precession in FK4, using Newcombs method (Woolard and Clemence angles) Input: Besselian start epoch1 and Besselian end epoch2 Returns: Angles zeta, z, theta in degrees Reference: ES 3.214 p.106 Notes: Newcomb's precession angles for old catalogs (FK4), see ES 3.214 p.106 Input are Besselian epochs! Adopted accumulated precession angles from equator and equinox at B1950 to 1984 January 1d 0h according to ES (table 3.214.1, p 107) are: zeta=783.7092, z=783.8009 and theta=681.3883 The Woolard and Clemence angles (derived in this routine) are: zeta=783.70925, z=783.80093 and theta=681.38830 (same ES table) This routine found (in seconds of arc): zeta,z,theta = 783.709246271 783.800934641 681.388298284 for t1 = 0.1 and t2 = 0.133999566814 using the lines in the example Examples: >>> b1 = 1950.0 >>> b2 = celestial.epochs("F1984-01-01")[0] >>> print [x*3600 for x in celestial.Newcombprecangles(be1, be2)] [783.70924627097793, 783.80093464073127, 681.38829828393466] ---------------------------------------------------------------------- """ t1 = (epoch1-1850.0)/1000.0 #1000 tropical years t2 = (epoch2-1850.0)/1000.0 tau = t2 - t1 d0 = 23035.545; d1 = 139.720; d2 = 0.060; d3 = 30.240; d4 = -0.27; d5 = 17.995 a0 = d0 + t1*(d1+d2*t1); a1 = d3 + d4*t1; a2 = d5 zeta_a = tau*(a0+tau*(a1+tau*a2)) d0 = 23035.545; d1 = 139.720; d2 = 0.060; d3 = 109.480; d4 = 0.39; d5 = 18.325 a0 = d0 + t1*(d1+d2*t1); a1 = d3 + d4*t1; a2 = d5 z_a = tau*(a0+tau*(a1+tau*a2)) d0 = 20051.12; d1 = -85.29; d2 = -0.37; d3 = -42.65; d4 = -0.37; d5 = -41.80 a0 = d0 + t1*(d1+d2*t1); a1 = d3 + d4*t1; a2 = d5 theta_a = tau*(a0+tau*(a1+tau*a2)) # Return values in degrees return zeta_a/3600.0, z_a/3600.0, theta_a/3600.0 def rotX(angle): """ ----------------------------------------------------------------------- Purpose: Calculate the matrix that represents a 3d rotation around the X axis. Input: Rotation angle in degrees Returns: A 3x3 matrix representing the rotation about angle around X axis. Reference: Diebel, J. 2006, Stanford University, Representing Attitude: Euler angles, Unit Quaternions and Rotation Vectors. http://ai.stanford.edu/~diebel/attitude.html Notes: Return the rotation matrix for a rotation around the X axis. This is a rotation in the YZ plane. Note that we construct a new vector with: xnew = R1.x In the literature, this rotation is usually called R1 ----------------------------------------------------------------------- """ a = d2r(angle) v = n.asmatrix(n.zeros((3,3), 'd')) cosa = n.cos(a) sina = n.sin(a) v[0,0] = 1.0; v[0,1] = 0.0; v[0,2] = 0.0; v[1,0] = 0.0; v[1,1] = cosa; v[1,2] = sina; v[2,0] = 0.0; v[2,1] = -sina; v[2,2] = cosa; return v def rotY(angle): """ ----------------------------------------------------------------------- Documentation in 'rotX' Return rot. mat. for rot. around Y axis ----------------------------------------------------------------------- """ a = d2r(angle) v = n.asmatrix(n.zeros((3,3), 'd')) cosa = n.cos(a) sina = n.sin(a) v[0,0] = cosa; v[0,1] = 0.0; v[0,2] = -sina; v[1,0] = 0.0; v[1,1] = 1.0; v[1,2] = 0.0; v[2,0] = sina; v[2,1] = 0.0; v[2,2] = cosa; return v def rotZ(angle): """ ----------------------------------------------------------------------- Documentation in 'rotX' Return rot. mat. for rot. around Z axis ----------------------------------------------------------------------- """ a = d2r(angle) v = n.asmatrix(n.zeros((3,3), 'd')) cosa = n.cos(a) sina = n.sin(a) v[0,0] = cosa; v[0,1] = sina; v[0,2] = 0.0; v[1,0] = -sina; v[1,1] = cosa; v[1,2] = 0.0; v[2,0] = 0.0; v[2,1] = 0.0; v[2,2] = 1.0; return v def fitsdate(date): """ ----------------------------------------------------------------------- Purpose: Given a string from a FITS file, try to parse it and convert the string into three parts: an integer year, an integer month and a fractional day. Input: A string, representing a date in FITS format Returns: Integer year, integer month, fractional day. Reference: - Notes: Process the FITS dates as part of the 'epochs' function. It processes the following formats: DD/MM/YY or DD/MM/19YY YYYY-MM-DD YYYY-MM-DDTHH:MM:SS ----------------------------------------------------------------------- """ parts = date.split('/') if len(parts)==3: return ((int(parts[2])%1900)+1900, int(parts[1]), float(parts[0])) parts = date.split('T') if len(parts)==2: date = parts[0] parts = parts[1].split(':') facts = (3600.0, 60.0, 1.0) time = 0.0 for i in range(len(parts)): time += float(parts[i])*facts[i] else: time = 0.0 parts = date.split('-') return (int(parts[0]), int(parts[1]), float(parts[2])+time/86400.0) def epochs(spec): """ ----------------------------------------------------------------------- Purpose: Flexible epoch parser. Input: An epoch specification (see below) Returns: Corresponding Besselian epoch, Julian epoch and Julian date Return in order: B, J, JD Reference: Various sources listing Julian dates Notes: An epoch can be set in various ways. The options are distinguished by a prefix. Only the 'B' and 'J' epochs can be negative. Prefix Epoch ============================================================= B Besselian epoch. Example 'B 1950', 'b1950', 'B1983.5', '-B1100' J Julian epoch. Example: 'j2000.7', 'J 2000', '-j100.0' JD Julian date. This number of days (with decimals) that have elapsed since the initial epoch defined as noon Universal Time (UT) Monday, January 1, 4713 BC in the proleptic Julian calendar Example: 'JD2450123.7' MJD The Modified Julian Day (MJD) is the number of days that have elapsed since midnight at the beginning of Wednesday November 17, 1858. In terms of the Julian day: MJD = JD - 2400000.5 Example: 'mJD 24034', 'MJD50123.2' RJD The Reduced Julian Day (RJD): Julian date counted from nearly the same day as the MJD, but lacks the additional offset of 12 hours that MJD has. It therefore starts from the previous noon UT or TT, on Tuesday November 16, 1858. It is defined as: RJD = JD - 2400000 Example: 'rJD50123.2', 'Rjd 23433' F 1) DD/MM/YY Old FITS format Example: 'F29/11/57' 2) YYYY-MM-DD FITS format Example: 'F2000-01-01' 3) YYYY-MM-DDTHH:MM:SS FITS format with date and time. Example: 'F2002-04-04T09:42:42.1' Examples: >>> epochs('F2008-03-31T8:09') should return: (2008.2474210134737, 2008.2459673739454, 2454556.8395833336) >>> epochs('F2007-01-14T13:18:59.9'): (2007.0378545262108, 2007.0364267212976, 2454115.0548599539) >>> epochs("j2007.0364267212976"): (2007.0378545262108, 2007.0364267212976, 2454115.0548599539) >>> epochs("b2007.0378545262108"): (2007.0378545262108, 2007.0364267212976, 2454115.0548599539) ----------------------------------------------------------------------- """ if not spec: mes = "No epoch in string" raise Exception(mes) b = j = jd = None parts = re.split(r'(\d.*)', spec, 1) try: prefix = (parts[0].strip().upper()) if prefix == 'B' or prefix == '-B': b = float(parts[1]) if prefix == '-B': b *= -1.0 jd = epochBessel2JD(b) j = JD2epochJulian(jd) elif prefix == 'J' or prefix == '-J': j = float(parts[1]) if prefix == '-J': j *= -1.0 jd = epochJulian2JD(j) b = JD2epochBessel(jd) elif prefix == 'JD': jd = float(parts[1]) b = JD2epochBessel(jd) j = JD2epochJulian(jd) elif prefix == 'MJD': mjd = float(parts[1]) # MJD = JD - 2400000.5 jd = mjd + 2400000.5 b = JD2epochBessel(jd) j = JD2epochJulian(jd) elif prefix == 'RJD': rjd = float(parts[1]) # RJD = JD - 2400000 jd = rjd + 2400000 b = JD2epochBessel(jd) j = JD2epochJulian(jd) elif prefix == 'F': epoch = parts[1]; fd = fitsdate(parts[1]) jd = JD(fd[0], fd[1], fd[2]) b = JD2epochBessel(jd) j = JD2epochJulian(jd) else: raise Exception("Unknown prefix for epoch") except: mes = "No prefix or cannot convert epoch to a number" raise Exception(mes) return (b, j, jd) def MatrixEqJ20002Gal(): """ ----------------------------------------------------------------------- Purpose: (Experimental) Return the rotation matrix for a transformation between equatorial (FK5, J2000) and galactic IAU 1958 coordinate systems. This function is not used because it could be composed of two fundamental transformations. Input: - Returns: Matrix M as in: XYZgal = M * XYZj2000 Reference:-Murray, C.A. The Transformation of coordinates between the systems B1950.0 and J2000.0, and the principal galactix axis referred to J2000.0, Astronomy and Astrophysics (ISSN 0004-6361), vol. 218, no. 1-2, July 1989, p. 325-329. -Blaauw, A., Gum C.S., Pawsey, J.L., Westerhout, G.: 1958, Monthly Notices Roy. Astron. Soc. 121, 123 Notes: The position of the galactic pole is defined in the fk4, B1950 system (without e-terms). For a position in fk5 J2000 one could consider to create a rotation matrix based on J2000 coordinates of the galactic pole. 192.85948121 -RA of galactic north pole (mean b1950.0) 27.12825118 -Dec of galactic north pole 122.93191857 -Galactic longitude of celestial equator >>> print celestial.sky2sky(celestial.fk4_no_e, celestial.fk5,192.25,27.4) [[ 192.85948121 27.12825118]] >>> print celestial.sky2sky( celestial.fk5, celestial.gal, 0,90) [[ 122.93191857 27.12825118]] According to the Hipparcos explanatory supplement the angles in J2000 are: 192.85948 Right Ascension of Galactic North Pole 27.12825 Declination of Galactic North Pole 32.93192 Galactic longitude of celestial equator HOWEVER: Murray (1989) however objects against the transformation of these principal directions because in the J2000 system the axes are not orthogonal, which is unacceptable. Therefore the transformation from fk5 to galactic is calculated in two steps. First a position is transformed to fk4 (no e-terms) and then to a galactic coordinate (lII, bII) The result matrix in celestial.py is calculated with: skymatrix((eq,2000.0,fk5),gal) and produces the numbers: [[-0.054875539396 -0.873437104728 -0.48383499177 ] [ 0.494109453628 -0.444829594298 0.7469822487 ] [-0.867666135683 -0.198076389613 0.455983794521]] which are all consistent with equation (33) in Murray, 1989. If, on the other hand we calculate the rotation matrix for the J2000 coordinates: >>> R = rotZ(180-122.93191857)*rotY(90-27.12825118)*rotZ(192.85948121) >>> print skymatrix((eq,2000.0,fk5),gal)[0] - R [[ -4.26766400e-11 -1.39604994e-11 3.00424130e-11] [ -9.72683045e-12 4.29156710e-12 8.98969787e-12] [ -2.84006152e-12 5.19224108e-11 1.71504477e-11]] then we cannot conclude that these different methods differ significantly. In the 2MASS All-Sky Data Release Explanatory Supplement: we read: 'There is an ambiguity in the appropriate way to convert J2000 ICRS coordinates to the galactic system. Galactic coordinates could be derived by precessing J2000.0 coordinates to B1950, then using the rotation transformations into the lII,bII system (as in MatrixEqB19502Gal(), VOG). This transformation method produces galactic coordinates that can differ by up to 0.4'' from those, e.g., produced using the direct J2000-to-galactic transformations, proposed by Murray (1989, AsAp, 218, 325).' Murray's matrix however is composed of the transformation fk5 to fk4 without e-terms and fk4 without e-terms to Galactic. So the differences can only be explained by wrongly adding e-terms in fk4 before transforming these to galactic coordinates. ----------------------------------------------------------------------- """ M1 = FK52FK4Matrix() M2 = MatrixEqB19502Gal() return M2*M1 def MatrixEqB19502Gal(): """ ----------------------------------------------------------------------- Purpose: Create matrix to convert equatorial fk4 coordinates (without e-terms) to IAU 1958 lII,bII system of galactic coordinates Input: - Result: Matrix M as in XYZgal = M * XYZb1950 Reference:- Blaauw, A., Gum C.S., Pawsey, J.L., Westerhout, G.: 1958, Monthly Notices Roy. Astron. Soc. 121, 123 Blaauw, A., 2007. Private communications. Notes: Original definitions: 1) The new north galactic pole lies in the direction alpha = 12h49m (192.25d) delta=27.4d (equinox(1950.0) 2) The new zero of longitude is the great semicircle originating at the new north galactic pole at the position angle theta = 123d with respect to the equatorial pole for 1950.0 3) Longitude increases from 0d to 360d. The sense is such that, on the galactic equator increasing galactic longitude corresponds to increasing Right Ascension. Latitude increases from -90deg through 0deg to 90deg at the new galactic pole. Given the RA and Dec of the galactic pole, and using the Euler angles scheme rotZ(a3).rotY(a2).rotZ(a1), we first rotate the spin vector of the XY plane about an angle a1 = ra_pole and then rotate the spin vector in the XZ plane (i.e. around the Y axis) with an angle a2=90-dec_pole to point it in the right declination. Now think of a circle with the galactic pole as its center. The radius is equal to the distance between this center and the equatorial pole. The zero point now is on the circle and opposite to this pole. We need to rotate along this circle (i.e. a rotation around the new Z-axis) in a way that the angle between the zero point and the equatorial pole is equal to 123d. So first we need to compensate for the 180 degrees of the current zero longitude, opposite to the pole. Then we need to rotate about an angle 123d but in a way that increasing galactic longitude corresponds to increasing Right Ascension which is opposite to the standard rotation of this circle (note that we rotated the original X axis about 192.25d). The last rotation angle therefore is a3=+180-123 The composed rotation matrix is the same as in Slalib's 'ge50.f' and the matrix in eq. (32) of Murray (1989). ----------------------------------------------------------------------- """ return rotZ(180-123.0)*rotY(90-27.4)*rotZ(192.25) # Alternative: rotZ(-33.0)*rotX(62.6)*rotZ(90+192.25) def MatrixGal2Sgal(): """ ----------------------------------------------------------------------- Purpose: Transform galactic to super galactic coordinates Input: - Returns: Matrix M as in XYZsgal = M * XYZgal Reference: Lahav, O., The supergalactic plane revisited with the Optical Redshift Survey Mon. Not. R. Astron. Soc. 312, 166-176 (2000) Notes: Supergalactic equator is conceptually defined by the plane of the local (Virgo-Hydra-Centaurus) supercluster, and the origin of supergalactic longitude is at the intersection of the supergalactic and galactic planes. (de Vaucouleurs) North SG pole at l=47.37 deg, b=6.32 deg. Node at l=137.37, sgl=0 (inclination 83.68 deg). Older references give for he position of the SG node 137.29 which differs from 137.37 deg in the official definition. For the rotation matrix we chose the scheme Rz.Ry.Rz Then first we rotate about 47.37 degrees along the Z-axis followed by a rotation about 90-6.32 degrees is needed to set the pole to the right declination. The new plane intersects the old one at two positions. One of them is l=137.37, b=0 (in galactic coordinates. If we want this to be sgl=0 we have rotate this plane along the new Z-axis about an angle of 90 degrees. So the composed rotation matrix is: R = Rz(90)*Ry(90-6.32)*Rz(47.37) ---------------------------------------------------------------------- """ # Alternative rotX(90-6.32)*rotZ(90+47.37) return rotZ(90.0)*rotY(90-6.32)*rotZ(47.37) def MatrixEq2Ecl(epoch, S1): """ ---------------------------------------------------------------------- Purpose: Calculate a rotation matrix to convert equatorial coordinates to ecliptical coordinates Input: Epoch of the equator and equinox of date and the equatorial system to determine if one entered B or J coordinates. Returns: Matrix M as in XYZecl = M * XYZeq Reference: Representations of celestial coordinates in FITS", Calabretta. M.R., & Greisen, E.W., (2002) Astronomy & Astrophysics, 395, 1077-1122. http://www.atnf.csiro.au/people/mcalabre/WCS/ccs.pdf Notes: 1) The origin for ecliptic longitude is the vernal equinox. Therefore the coordinates of a fixed object is subject to shifts due to precession. The rotation matrix uses the obliquity to do the conversion to the wanted ecliptic coordinates. So we always need to enter an epoch. Usually this is J2000, but it can also be the epoch of date. The additional reference system indicates whether we need a Besselian or a Julian epoch. 2) In the FITS paper of Calabretta and Greisen (2002), one observes the following relations to FITS: - Keyword RADESYSa sets the catalog system fk4, fk4-no-e or fk5 This applies to equatorial and ecliptical coordinates with the exception of fk4-no-e. - fk4 coordinates are not strictly spherical since they include a contribution from the elliptic terms of aberration, the so-called e-terms which amount to max. 343 milliarcsec. FITS paper: Strictly speaking, therefore, a map obtained from, say, a radio synthesis telescope, should be regarded as fk4-no-e unless it has been appropriately resampled or a distortion correction provided. In common usage, however, CRVALia for such maps is usually given in fk4 coordinates. In doing so, the e-terms are effectively corrected to first order only. (See also ES, eq. 3.531-1 page 170. - Keyword EQUINOX sets the epoch of the mean equator and equinox. - Keyword EPOCH refers to the time of observation. - Ecliptic coordinates require the epoch of the equator and equinox of date. This will be taken as the time of observation (EPOCH=) rather than EQUINOXa. FITS paper: 'The time of observation may also be required for other astrometric purposes in addition to the usual astrophysical uses, for example, to specify when the mean place was correct in accounting for proper motion, including "fictitious" proper motions in the conversion between the fk4 and fk5 systems. The old DATE-OBS keyword may be used for this purpose. However, to provide a more convenient specification we here introduce the new keyword MJD-OBS 3) Equatorial to ecliptic transformations use the time dependent obliquity of the equator (also known as the obliquity of the ecliptic) Again, start with: rotZ(0).rotX(eps).rotZ(0) = E.rotX(eps).E = rotX(eps) In fact this is only a rotation around the X axis ---------------------------------------------------------------------- """ if (S1 == fk4): jd = epochBessel2JD(epoch) else: # For all other systems the epochs are Julian jd = epochJulian2JD(epoch) if (S1 == icrs or S1 == j2000): eps = obliquity2000(jd) else: eps = obliquity1980(jd) return rotX(eps) def getEterms(epoch): """ ---------------------------------------------------------------------- Purpose: Compute the E-terms for a given epoch Input: epoch, a Besselian epoch Returns: A tuple containing the e-terms vector (DeltaD,DeltaC,DeltaC.tan(e0)) Reference: Seidelman, P.K., 1992. Explanatory Supplement to the Astronomical Almanac. University Science Books, Mill Valley Notes: The method is described on page 170/171 of the ES. One needs to process the e-terms for the appropriate epoch This routine returns the e-term vector for arbitrary epoch. ---------------------------------------------------------------------- """ # Julian centuries since B1950 T = (epoch-1950.0)*1.00002135903/100.0 # Eccentricity of the Earth's orbit ec = 0.01673011-(0.00004193+0.000000126*T)*T # Mean obliquity of the ecliptic. Method is different compared to # functions for the obliquity defined earlier. This function depends # on time wrt. epoch 1950 not epoch 2000. ob = (84404.836-(46.8495+(0.00319+0.00181*T)*T)*T) ob = d2r(ob/3600.0) # Mean longitude of perihelion of the solar orbit p = (1015489.951+(6190.67+(1.65+0.012*T)*T)*T) p = d2r(p/3600.0) # Calculate the E-terms vector ek = ec*d2r(20.49522/3600.0) # 20.49552 is constant of aberration at J2000 cp = n.cos(p) # -DeltaD DeltaC DeltaC.tan(e0) return (ek*n.sin(p), -ek*cp*n.cos(ob), -ek*cp*n.sin(ob)) def addEterms(xyz, a=None): """ ---------------------------------------------------------------------- Purpose: Add the elliptic component of annual aberration when the result must be a catalogue fk4 position. Input: xyz: Cartesian position a: E-terms vector (as returned by getEterms()) If input a is omitted, the e-terms for 1950 will be substituted. Result: Apparent place Reference: Seidelman, P.K., 1992. Explanatory Supplement to the Astronomical Almanac. University Science Books, Mill Valley. Yallop et al, Transformation of mean star places, AJ, 1989, vol 97, page 274 Stumpff, On the relation between Classical and Relativistic Theory of Stellar Aberration, Astron, Astrophys, 84, 257-259 (1980) Notes: There is a so called ecliptic component in the stellar aberration. This vector depends on the epoch at which we want to process these terms. It corresponds to the component of the earth's velocity perpendicular to the major axis of the ellipse in the ecliptic. The E-term corrections are as follows. A catalog FK4 position include corrections for elliptic terms of aberration. These positions are apparent places. For precession and/or rotations to other sky systems, one processes only mean places. So to get a mean place, one has to remove the E-terms vector. The ES suggests for the removal to use a decompositions of the E-term vector along the unit circle to get the approximate new vector, which has almost the correct angle and has almost length 1. The advantage is that when we add the E-term vector to this new vector, we obtain a new vector with the original angle, but with a length unequal to 1, which makes it suitable for closure tests. However, the procedure can be made more rigorous: For the subtraction we subtract the E-term vector from the start vector and normalize it afterwards. Then we have an exact new angle (opposed to the approximation in the ES). The procedure to go from a vector in the mean place system to a vector in the system of apparent places is a bit more complicated: Find a value for lambda so that the current vector is adjusted in length so that adding the e-term vector gives a new vector with length 1. This is by definition the new vector with the right angle. The conditions are: r' = L.r + A with ||r|| = ||r'|| = 1 where L = lamda, a number Then: L.(x^2+y^2+z^2) + 2.L.(a0.x+a1.y+a2.z) + a0^2+a1^2+a2^2 = 1 and note that x^2+y^2+z^2 = 1 Set w = 2.(a0.x+a1.y+a2.z) and p = a0^2+a1^2+a2^2 - 1 Then L^2 + w.L + p = 0 Which has solutions: L1,2 = 0.5 * (-w +- sqrt(w^2-4p)) We observe that p ~ -1 so sqrt(w^2-4p) > w The positive value of L1 then is: L1 = 0.5 * (-w + sqrt(w^2-4p)) Note that the other value for L is negative which results in the solution that has an offset of nearly 180 deg. ---------------------------------------------------------------------- """ xyzeterm = xyz.copy() if a == None: a = getEterms(1950.0) for i in range(xyz.shape[1]): # Loop over all vectors x = xyz[0,i]; y = xyz[1,i]; z = xyz[2,i] # Normalize to get a vector of length 1. Our algorithm is based on that fact. d = n.sqrt(x*x + y*y + z*z) x /= d; y /= d; z /= d # Find the lambda to stretch the vector w = 2.0 * (a[0]*x + a[1]*y + a[2]*z) p = a[0]*a[0] + a[1]*a[1] + a[2]*a[2] - 1.0 lambda1 = (-w + n.sqrt(w*w-4.0*p))/2.0 # Vector a is small. We want only the positive lambda xyzeterm[0,i] = lambda1*x + a[0] xyzeterm[1,i] = lambda1*y + a[1] xyzeterm[2,i] = lambda1*z + a[2] return xyzeterm def removeEterms(xyz, a=None): """ ---------------------------------------------------------------------- Purpose: Remove the elliptic component of annual aberration when this is included in a catalogue fk4 position. Input: xyz, a Cartesian position a: E-terms vector (as returned by getEterms()) If input a is omitted, the e-terms for 1950 will be substituted. Result: Mean place Notes: Return a new position where the elliptic terms of aberration are removed i.e. convert a apparent position from a catalog to a mean place. The effects of ecliptic aberration were included in the catalog positions to facilitate telescope pointing. See also notes at 'addEterms'. ---------------------------------------------------------------------- """ xyzeterm = xyz.copy() if a == None: a = getEterms(1950.0) # a(1950) should be: = n.array([-1.62557e-6, -0.31919e-6, -0.13843e-6]) for i in range(xyz.shape[1]): # Loop over all vectors data x = xyz[0,i]; y = xyz[1,i]; z = xyz[2,i] x -= a[0]; y -= a[1]; z -= a[2] xyzeterm[0,i] = x xyzeterm[1,i] = y xyzeterm[2,i] = z return xyzeterm def precessionmatrix(zeta, z, theta): """ ---------------------------------------------------------------------- Purpose: Given three precession angles, create the corresponding rotation matrix Input: zeta, z, theta Returns: Rotation matrix M as in XYZepoch1 = M * XYZepoch2 Notes: Return the precession matrix for the three precession angles zeta, z and theta. Rotation matrix: R = rotZ(-z).rotY(th).rotZ(-zeta) (ES 3.21-7, p 103) Also allowed is the expression: rotZ(-90-z)*rotX(th)*rotZ(90-zeta) ---------------------------------------------------------------------- """ return rotZ(-z)*rotY(theta)*rotZ(-zeta) def IAU2006MatrixEpoch12Epoch2(epoch1, epoch2): """ ---------------------------------------------------------------------- Purpose: Create a rotation matrix for a precession based on IAU 2000/2006 expressions. Input: epoch1, Julian epoch to start with. epoch2, Julian epoch to precess to. Returns: Matrix to transform equatorial coordinates from epoch1 to epoch2 as in XYZepoch2 = M * XYZepoch1 Reference: N. Capitaine et al.: IAU 2000 precession A&A 412, 567-586 (2003) Notes: Note that we apply this precession only to equatorial coordinates in the system of dynamical J2000 coordinates. When converting from ICRS coordinates this means applying a frame bias. Therefore the angles differ from the precession Fukushima-Williams angles (IAU 2006) ---------------------------------------------------------------------- """ if (epoch1 == epoch2): return I() if epoch1 == 2000.0: zeta, z, theta = IAU2006precangles(epoch2) return precessionmatrix(zeta, z, theta) elif epoch2 == 2000.0: zeta, z, theta = IAU2006precangles(epoch1) return (precessionmatrix(zeta, z, theta)).T else: # If both epochs are not J2000.0 zeta, z, theta = IAU2006precangles(epoch1) M1 = (precessionmatrix(zeta, z, theta)).T zeta, z, theta = IAU2006precangles(epoch2) M2 = precessionmatrix(zeta, z, theta) return M2*M1 def BMatrixEpoch12Epoch2(Bepoch1, Bepoch2): """ ---------------------------------------------------------------------- Purpose: Precession from one epoch to another in the fk4 system. Input: epoch1, Besselian start epoch epoch2, Besselian epoch to precess to. Returns: Rotation matrix M as in XYZepoch2 = M * XYZepoch1 Reference: Seidelman, P.K., 1992. Explanatory Supplement to the Astronomical Almanac. University Science Books, Mill Valley. 3.214 p 106 Notes: The precession matrix is rotZ(-z).rotY(+theta).rotZ(-zeta) ---------------------------------------------------------------------- """ zeta, z, theta = Newcombprecangles(Bepoch1, Bepoch2) return precessionmatrix(zeta, z, theta) def JMatrixEpoch12Epoch2(Jepoch1, Jepoch2): """ ---------------------------------------------------------------------- Purpose: Precession from one epoch to another in the fk5 system. Input: epoch1, Julian start epoch epoch2, Julian epoch to precess to. Returns: Rotation matrix M as in XYZepoch2 = M * XYZepoch1 Reference: Seidelman, P.K., 1992. Explanatory Supplement to the Astronomical Almanac. University Science Books, Mill Valley. 3.214 p 106 Notes: The precession matrix is rotZ(-z).rotY(+theta).rotZ(-zeta) ---------------------------------------------------------------------- """ jd1 = epochJulian2JD(Jepoch1) jd2 = epochJulian2JD(Jepoch2) zeta, z, theta = Lieskeprecangles(jd1, jd2) return precessionmatrix(zeta, z, theta) def FK42FK5Matrix(t=None): """ ---------------------------------------------------------------------- Purpose: Create a matrix to precess from B1950 in FK4 to J2000 in FK5 following to Murray's (1989) procedure. Input: t, a Besselian epoch as epoch of observation. Returns: Transformation matrix M as in XYZfk5 = M * XYZfk4 Reference: Murray, C.A. The Transformation of coordinates between the systems B1950.0 and J2000.0, and the principal galactic axis referred to J2000.0, Astronomy and Astrophysics (ISSN 0004-6361), vol. 218, no. 1-2, July 1989, p. 325-329. Poppe P.C.R.,, Martin, V.A.F., Sobre as Bases de Referencia Celeste SitientibusSerie Ciencias Fisicas Notes: Murray precesses from B1950 to J2000 using a precession matrix by Lieske. Then applies the equinox correction and ends up with a transformation matrix X(0) as given in this function. In Murray's article it is proven that using the procedure as described in the article, r_fk5 = X(0).r_fk4 for extra galactic sources where we assumed that the proper motion in FK5 is zero. This procedure is independent of the epoch of observation. Note that the matrix is not a rotation matrix. FK4 is not an inertial coordinate frame (because of the error in precession and the motion of the equinox. This has consequences for the proper motions. e.g. a source with zero proper motion in FK5 has a fictious proper motion in FK4. This affects the actual positions in a way that the correction is bigger if the epoch of observation is further away from 1950.0 The focus of this library is on data of which we do not have information about the proper motions. So for positions of which we allow non zero proper motion in FK5 one needs to supply the epoch of observation ---------------------------------------------------------------------- """ r11 = 0.9999256794956877; r12 = -0.0111814832204662; r13 = -0.0048590038153592 r21 = 0.0111814832391717; r22 = 0.9999374848933135; r23 = -0.0000271625947142 r31 = 0.0048590037723143; r32 = -0.0000271702937440; r33 = 0.9999881946023742 if t != None: # i.e. we also assuming that v != 0 in FK5 !! jd = epochBessel2JD(t) T = (jd-2433282.423)/36525.0 # t-1950 in Julian centuries = F^-1.t1 from Murray (1989) r11 += -0.0026455262*T/1000000.0 r12 += -1.1539918689*T/1000000.0 r13 += 2.1111346190*T/1000000.0 r21 += 1.1540628161*T/1000000.0 r22 += -0.0129042997*T/1000000.0 r23 += 0.0236021478*T/1000000.0 r31 += -2.1112979048*T/1000000.0 r32 += -0.0056024448*T/1000000.0 r33 += 0.0102587734*T/1000000.0 return n.matrix( ([r11,r12,r13],[r21,r22,r23],[r31,r32,r33]) ) def FK42FK5MatrixAOKI(): """ ---------------------------------------------------------------------- Experimental. Create matrix to precess from B1950 in FK4 to J2000 in FK5 The method is described in section 3.59 of the ES. Proper motions are not taken into account. Parallax and radial velocity are set to zero and not taken into account. We do not repeat the procedures here, but copy part of the matrix from ES, 3.591-4, p 185 See also reference below: Author(s): Aoki, S., Soma, M., Kinoshita, H., Inoue, K. Title: Conversion matrix of epoch B 1950.0 FK4-based positions of stars to epoch J 2000.0 positions in accordance with the new IAU resolutions Source: Astron. Astrophys. 128, 263-267 Year: 1983 The matrix in the Yallop (1989) article has more digits than the matrix from the ES. Yallop, B.D. et al, 1989. "Transformation of mean star places from FK4 B1950.0 to FK5 J2000.0 using matrices in 6-space". Astron.J. 97, 274. ---------------------------------------------------------------------- """ r0 = [0.999925678186902, -0.011182059642247, -0.004857946558960] r1 = [0.011182059571766, 0.999937478448132, -0.00002717441185] r3 = [0.004857946721186, -0.000027147426498, 0.999988199738770] return n.matrix( (r0,r1,r3) ) def FK42FK5MatrixLOWPREC(): """ ---------------------------------------------------------------------- Experimental. Create matrix to precess from B1950 in FK4 to J2000 in FK5 The method is described in section 3.59 of the ES. Proper motions are not taken into account. Parallax and radial velocity are set to zero and not taken into account. We do not repeat the procedures here, but copy part of the matrix from ES, 3.591-4, p 185 See also reference below: Author(s): Aoki, S., Soma, M., Kinoshita, H., Inoue, K. Title: Conversion matrix of epoch B 1950.0 FK4-based positions of stars to epoch J 2000.0 positions in accordance with the new IAU resolutions Source: Astron. Astrophys. 128, 263-267 Year: 1983 ---------------------------------------------------------------------- """ r0 = [0.9999256782, -0.0111820611, -0.0048579477] r1 = [0.0111820610, 0.9999374784, -0.0000271765] r3 = [0.0048579479, -0.0000271474, 0.9999881997] return n.matrix( (r0,r1,r3) ) def FK52FK4Matrix(t=None): """ ---------------------------------------------------------------------- Purpose: Create a matrix to convert a position in fk5 to fk4 using the inverse matrix FK42FK5Matrix Input: Epoch of observation for those situations where we allow no-zero proper motion in fk4 Returns: Rotation matrix M as in XYZfk5 = M * XYZfk4 Notes: For this matrix we know that the inverse is not the transpose. ---------------------------------------------------------------------- """ return FK42FK5Matrix(t).I def FK42FK5MatrixOLDATTEMPT(): """ ---------------------------------------------------------------------- Experimental. Create matrix to precess from an epoch in FK4 to an epoch in FK5 So epoch1 is Besselian and epoch2 is Julian 1) Do an epoch transformation in FK4 from input epoch to 1984 January 1d 0h 2) Apply a zero point correction for the right ascension w.r.t. B1950. The formula is: E = E0 + E1*(jd-jd1950)/Cb E0 = 0.525; E1 = 1.275 and Cb = the length of the tropical century (ES 3.59 p 182) = 36524.21987817305 For the correction at 1984,1,1 the ES lists 0.06390s which is 0.06390*15=0.9585" This function calculated E = 0.958494476885" which agrees with the literature. 3) Transform in FK5 from 1984 January 1d 0h to epoch2 Note that we do not use the adopted values for the precession angles, but use the Woolward and Clemence expressions to calculate the angles. These are one digit more accurae than the adopted values. ---------------------------------------------------------------------- """ # Epoch transformation from B1950 to 1984, 1,1 in FK4 jd = JD(1984,1,1) epoch1984 = JD2epochBessel(jd) M1 = BMatrixEpoch12Epoch2(1950.0, epoch1984) # Equinox correction to the right ascension jd1950 = epochBessel2JD(1950.0) E0 = 0.525; E1 = 1.275 Cb = 36524.21987817305 # In days = length of the tropical century E = E0 + E1*(jd-jd1950)/Cb E /= 3600.0 # From seconds of arc to degree M2 = rotZ(-E) # The correction is positive so we have to rotate # around the z-axis in the negative direction. # Epoch transformation from 1984,1,1 to J2000 epoch1984 = JD2epochJulian(jd) M3 = JMatrixEpoch12Epoch2(epoch1984, 2000.0) return M3*M2*M1 def addpropermotion(xyz): """ ---------------------------------------------------------------------- Experimental. Input is a cartesian position xyz. Return a new position where the input position is corrected for assumed proper motion in the FK4 system. For convenience we assume the epoch of observation is 1950 ---------------------------------------------------------------------- """ twopi=6.283185307179586476925287 pmf = 100.0*60*60*360/twopi d = 1950.0 mjd = 15019.81352 + (d-1900)*365.242198781 # Convert to Modified Julian date Julianepoch = 2000.0 + (mjd-51544.5)/365.25 # Convert this mjd to Julian epoch w = (Julianepoch-2000.0)/pmf # Correction factor xyzpm = xyz.copy() r0 = [-0.000551, +0.238514, -0.435623] # Matrix from the ES. r1 = [-0.238565, -0.002667, +0.012254] r2 = [+0.435739, -0.008541, +0.002117] M = n.matrix( (r0,r1,r2) ) # print "Matrix M=", M for i in range(xyz.shape[1]): # Loop over all vectors p = n.array([xyz[0,i], xyz[1,i], xyz[2,i]]).T # print "p=",p, p[0], p[1],p[2] v = p.copy() v[0] = r0[0]*p[0]+r0[1]*p[1]+r0[2]*p[2] v[1] = r1[0]*p[0]+r1[1]*p[1]+r1[2]*p[2] v[2] = r2[0]*p[0]+r2[1]*p[1]+r2[2]*p[2] # print "v=", v for j in range(2): xyzpm[j,i] = p[j] + w * v[j] return xyzpm def EquinoxCorrection(): """ ---------------------------------------------------------------------- Experimental. Purpose: Calculate the equinox correction according to Murray ---------------------------------------------------------------------- """ F = 1.000021359027778 #Converts the rate of change of Newcomb's precession from tropical centuries to Julian centuries. jd1 = epochs('B1950.0')[2] jd2 = epochs('J2000.0')[2] juliancenturies = (jd2-jd1) / 36525.0 # 1 Julian century is 36525 days E0 = 0.525; E1 = 1.275 E = E0 + 0.0 * juliancenturies * F # print ", Juliancenturies, Juliancenturies-0.500002095577002 (Murray)", juliancenturies, juliancenturies-0.500002095577002 E /= 3600.0 # From seconds of arc to degree M = rotZ(-E) # The correction is positive so we have to rotate # around the z-axis in the negative direction. return M def ICRS2FK5Matrix(): """ ---------------------------------------------------------------------- Purpose: Create a rotation matrix to convert a position from ICRS to fk5, J2000 Input: - Returns: Rotation matrix M as in XYZfk5 = M * XYZicrs Reference: Kaplan G.H., The IAU Resolutions on Astronomical Reference systems, Time scales, and Earth Rotation Models, US Naval Observatory, Circular No. 179 Notes: Return a matrix that converts a position vector in ICRS to FK5, J2000. We do not use the first or second order approximations given in the reference, but use the three rotation matrices from the same paper to obtain the exact result. ---------------------------------------------------------------------- """ eta0 = -19.9/(3600*1000) # Convert mas to degree xi0 = 9.1/(3600*1000) da0 = -22.9/(3600*1000) return rotX(-eta0)*rotY(xi0)*rotZ(da0) def ICRS2J2000Matrix(): """ ---------------------------------------------------------------------- Purpose: Return a rotation matrix for conversion of a position in the ICRS to the dynamical reference system based on the dynamical mean equuator and equinox of J2000.0 (called the dynamical J2000 system) Input: - Returns: Rotation matrix to transform positions from ICRS to dyn J2000 Reference: Hilton and Hohenkerk (2004), Astronomy and Astrophysics 413, 765-770 Kaplan G.H., The IAU Resolutions on Astronomical Reference systems, Time scales, and Earth Rotation Models, US Naval Observatory, Circular No. 179 Notes: Return a matrix that converts a position vector in ICRS to Dyn. J2000. We do not use the first or second order approximations given in the reference, but use the three rotation matrices to obtain the exact result. ---------------------------------------------------------------------- """ eta0 = -6.8192/(3600*1000) # Convert mas to degree xi0 = -16.617/(3600*1000) da0 = -14.6/(3600*1000) return rotX(-eta0)*rotY(xi0)*rotZ(da0) def MatrixEpoch12Epoch2(epoch1, epoch2, S1, S2, epobs=None): """ ---------------------------------------------------------------------- Purpose: Helper function for 'skymatrix' It handles precession and the transformation between equatorial systems. Input: epoch1, belonging to system S1 depending on the reference system either Besselian or Julian. epoch2, same but connected to system S2 S1, S2, the input and output equatorial systems. Returns: Rotation matrix to transform a position in one of the equatorial systems, epoch1 to an equatorial system with equator and equinox at epoch2 Notes: Return matrix to transform equatorial coordinates from epoch1 to epoch2 in either reference system fk4 or fk5. Or transform from epoch, fk4 or fk5 to ICRS vice versa. Systems S1 and S2 are one of 0,1 or 2 (i.e. fk4, fk5 or ICRS) Note that if no systems are entered and the one epoch is > 1984 and the other < 1984, then the transformation involves both sky reference systems fk4 and fk5. ---------------------------------------------------------------------- """ # note that if S1 or S2 is equal to ICRS, then corresponding epoch is irrelevant if (S1==fk5 and S2==fk5): return JMatrixEpoch12Epoch2(epoch1, epoch2) elif (S1==fk4 and S2==fk4): return BMatrixEpoch12Epoch2(epoch1, epoch2) elif (S1==fk4 and S2==fk5): M1 = BMatrixEpoch12Epoch2(epoch1, 1950.0) M2 = FK42FK5Matrix(epobs) M3 = JMatrixEpoch12Epoch2(2000.0, epoch2) return M3*M2*M1 elif (S1==fk5 and S2==fk4): M1 = JMatrixEpoch12Epoch2(epoch1, 2000.0) M2 = FK52FK4Matrix(epobs) M3 = BMatrixEpoch12Epoch2(1950.0, epoch2) return M3*M2*M1 elif (S1==icrs and S2==icrs): return I() elif (S1==icrs and S2==fk4): M1 = ICRS2FK5Matrix() M2 = FK52FK4Matrix(epobs) M3 = BMatrixEpoch12Epoch2(1950.0, epoch2) return M3*M2*M1 elif (S1==icrs and S2==fk5): M1 = ICRS2FK5Matrix() M2 = JMatrixEpoch12Epoch2(2000.0, epoch2) return M2*M1 elif (S1==fk5 and S2==icrs): M1 = JMatrixEpoch12Epoch2(epoch1, 2000.0) M2 = ICRS2FK5Matrix().T return M2*M1 elif (S1==fk4 and S2==icrs): M1 = BMatrixEpoch12Epoch2(epoch1, 1950.0) M2 = FK42FK5Matrix(epobs) M3 = ICRS2FK5Matrix().T return M3*M2*M1 elif (S1==j2000 and S2==j2000): M1 = IAU2006MatrixEpoch12Epoch2(epoch1, epoch2) return M1 elif (S1==j2000 and S2==icrs): M1 = IAU2006MatrixEpoch12Epoch2(epoch1, 2000.0) M2 = ICRS2J2000Matrix().T return M2*M1 elif (S1==j2000 and S2==fk5): M1 = IAU2006MatrixEpoch12Epoch2(epoch1, 2000.0) M2 = ICRS2J2000Matrix().T M3 = ICRS2FK5Matrix() M4 = JMatrixEpoch12Epoch2(2000.0, epoch2) return M4*M3*M2*M1 elif (S1==j2000 and S2==fk4): M1 = IAU2006MatrixEpoch12Epoch2(epoch1, 2000.0) M2 = ICRS2J2000Matrix().T M3 = ICRS2FK5Matrix() M4 = FK52FK4Matrix(epobs) M5 = BMatrixEpoch12Epoch2(1950.0, epoch2) return M5*M4*M3*M2*M1 elif (S1==icrs and S2==j2000): M1 = ICRS2J2000Matrix() M2 = IAU2006MatrixEpoch12Epoch2(2000.0, epoch2) return M2*M1 elif (S1==fk5 and S2==j2000): M1 = JMatrixEpoch12Epoch2(epoch1, 2000.0) M2 = ICRS2FK5Matrix().T M3 = ICRS2J2000Matrix() M4 = IAU2006MatrixEpoch12Epoch2(2000.0, epoch2) return M4*M3*M2*M1 elif (S1==fk4 and S2==j2000): M1 = BMatrixEpoch12Epoch2(epoch1, 1950.0) M2 = FK52FK4Matrix(epobs).T M3 = ICRS2FK5Matrix().T M4 = ICRS2J2000Matrix() M5 = IAU2006MatrixEpoch12Epoch2(2000.0, epoch2) return M5*M4*M3*M2*M1 else: mes = "Unknown celestial reference system: %s or %s" % (S1, S2) raise Exception(mes) def rotmatrix(skyin, skyout, epoch1=2000.0, epoch2=2000.0, S1=fk5, S2=fk5, epobs=None): """ ---------------------------------------------------------------------- Purpose: Calculate and return the wanted rotation matrix. Input: A complete specification of input and output sky systems. The sky systems are equatorial, ecliptic, galactic, supergalactic which are represented by numbers 0,1,2 and 3 The reference systems are fk4, fk4_no_e, fk5, icrs, j2000 which are represented by the numbers. Returns: Transformation matrix as in XYZout = M * XYZin Reference: - --------------------------------------------------------------------- """ if skyin == equatorial: if skyout == equatorial: M1 = MatrixEpoch12Epoch2(epoch1, epoch2, S1, S2, epobs) # eq -> eq epoch1 to epoch2 return M1 if skyout == ecliptic: M1 = MatrixEpoch12Epoch2(epoch1, epoch2, S1, S2) M2 = MatrixEq2Ecl(epoch2, S2) return M2*M1 if skyout == galactic: # eq(epoch1) -> galactic M1 = MatrixEpoch12Epoch2(epoch1, 1950.0, S1, fk4) M2 = MatrixEqB19502Gal() return M2*M1 if skyout == supergalactic: # eq(epoch1) -> super galactic M1 = MatrixEpoch12Epoch2(epoch1, 1950.0, S1, fk4) M2 = MatrixEqB19502Gal() M3 = MatrixGal2Sgal() return M3*M2*M1 else: mes = "Unknown output sky system: %s" % (S2,) raise Exception(mes) elif skyin == ecliptic: if skyout == equatorial: M1 = MatrixEq2Ecl(epoch1, S1).T # S2 sets epoch to Besselian or Julian M2 = MatrixEpoch12Epoch2(epoch1, epoch2, S1, S2) return M2*M1 if skyout == ecliptic: # ecl -> ecl epoch1 to epoch2 # This is an epoch transformation only M1 = MatrixEq2Ecl(epoch1, S1).T # to eq(epoch1) M2 = MatrixEpoch12Epoch2(epoch1, epoch2, S1, S2) # epoch1 to epoch2 M3 = MatrixEq2Ecl(epoch2, S2) # return to ecl(epoch2) return M3*M2*M1 if skyout == galactic: # ecl(epoch1) -> galactic M1 = MatrixEq2Ecl(epoch1, S1).T # to eq(epoch1) M2 = MatrixEpoch12Epoch2(epoch1, 1950.0, S1, fk4) # to eq(2000.0) M3 = MatrixEqB19502Gal() # eq(2000) to gal return M3*M2*M1 if skyout == supergalactic: # ecl(epoch1) -> super galactic M1 = MatrixEq2Ecl(epoch1, S1).T # to eq(epoch1) M2 = MatrixEpoch12Epoch2(epoch1, 1950.0, S1, fk4) # to eq(2000.0) M3 = MatrixEqB19502Gal() # eq(2000) to gal M4 = MatrixGal2Sgal() # gal to sgal return M4*M3*M2*M1 else: mes = "Unknown output sky system: %s" % (S2,) raise Exception(mes) elif skyin == galactic: if skyout == equatorial: # gal -> eq, epoch2 M1 = MatrixEqB19502Gal().T # gal to fk4 B1950 M2 = MatrixEpoch12Epoch2(1950.0, epoch2, fk4, S2) # fk4 B1950 to eq, epoch2 return M2*M1 if skyout == ecliptic: # gal -> ecl(epoch1) M1 = MatrixEqB19502Gal().T # gal to fk4 B1950 M2 = MatrixEpoch12Epoch2(1950.0, epoch2, fk4, S2) # fk4 B1950 to fk5 any epoch,equinox M3 = MatrixEq2Ecl(epoch2, S2) # eq(epoch2) to ecl(epoch2) return M3*M2*M1 if skyout == galactic: # gal -> gal return I() if skyout == supergalactic: # gal -> sgal M1 = MatrixGal2Sgal() return M1 else: mes = "Unknown output sky system: %s" % (S2,) raise Exception(mes) elif skyin == supergalactic: if skyout == equatorial: # sgal -> eq(epoch2) M1 = MatrixGal2Sgal().T # sgal to gal M2 = MatrixEqB19502Gal().T # gal to eq(2000) M3 = MatrixEpoch12Epoch2(1950.0, epoch2, fk4, S2) # epoch 2000 to epoch2 return M3*M2*M1 if skyout == ecliptic: # sgal -> ecl(epoch2) M1 = MatrixGal2Sgal().T # sgal to gal M2 = MatrixEqB19502Gal().T # gal to eq(2000) M3 = MatrixEpoch12Epoch2(1950.0, epoch2, fk4, S2) # 1950 to epoch2 M4 = MatrixEq2Ecl(epoch2, S2) # eq(epoch2) to ecl(epoch2) return M4*M3*M2*M1 if skyout == galactic: # sgal -> gal M1 = MatrixGal2Sgal().T return M1 if skyout == supergalactic: # sgal -> sgal return I() else: mes = "Unknown output sky system: %s" % (S2,) raise Exception(mes) else: mes = "Unknown input sky system: %s" % (S1,) raise Exception(mes) def skyparser(skyin): """ ---------------------------------------------------------------------- Purpose: Get the parameters for this sky system Input: The input or output sky system from function skymatrix() Returns: skysystem, reference system, equinox, epoch of observation Notes: See skymatrix() Input is either a single value (the sky system) or a tuple for an equatorial system with parameters. The skysystem is a number or one can use one of the constants eq, ecl, gal or sgal. The reference systems are fk4, fk4_no_e, fk5, icrs, j2000. In the tuple the order is important i.e. you first need to specify the sky system before a reference system and an equinox before an epoch of observation. Examples: See skymatrix() ---------------------------------------------------------------------- """ epochin = None epochinset = None refin = None epobs = None first = True if type(skyin) == tuple: try: # Try to parse this tuple sysin = skyin[0] for element in skyin[1:]: if type(element)==bytes: # If it is a string it must be an epoch if first: epochinset = epochs(element) first = False else: epobs = epochs(element)[0] # Corresponding Besselian data else: refin = element except: # Scalar sysin = skyin else: sysin = skyin # If input was a reference system only (not part of a tuple). if skyin == fk4: sysin = eq; epochin = 1950.0; refin = fk4 if skyin == fk4_no_e: sysin = eq; epochin = 1950.0; refin = fk4_no_e if skyin == fk5: sysin = eq; epochin = 2000.0; refin = fk5 if skyin == icrs: sysin = eq; epochin = 0.0; refin = icrs if skyin == j2000: sysin = eq; epochin = 2000.0; refin = j2000 #------------------------------------------------------------------------- # Standard in FITS: RADESYS defaults to IRCS unless EQUINOX is given alone, # in which case it defaults to FK4 prior to 1984 and FK5 after 1984. # # EQUINOX defaults to 2000 unless RADESYS is FK4, in which case it defaults # to 1950. #-------------------------------------------------------------------------- if sysin == eq or sysin == ecl: if epochinset == None: epochin = 2000.0 if refin is None: # No celestial system, no epoch -> ICRS,2000 refin = icrs if refin == fk4 or refin == fk4_no_e: # The ref. system belongs to the fk4 family, epochin = 1950.0 # therefore the default equinox is 1950 else: # There was an epoch for the equinox if refin == None: # ... but no reference system if epochinset != None: jd = epochinset[2] if jd < epochJulian2JD(1984.0): epochin = JD2epochBessel(jd) # Always Besselian even if epoch was specified as Julian else: epochin = JD2epochJulian(jd) if epochin < 1984.0: refin = fk4 # Dangerous default. Could also be fk4_no_e for radio data else: refin = fk5 elif epochinset != None: if refin == fk4 or refin == fk4_no_e: epochin = epochinset[0] # Besselian epoch else: epochin = epochinset[1] # Julian epoch if not (sysin == eq and (refin == fk4 or refin == fk4_no_e)): epobs = None return sysin, refin, epochin, epobs def skymatrix(skyin, skyout): """ ---------------------------------------------------------------------- Purpose: Create a transformation matrix to transform a position from one sky system to another and combines this with epoch transformations. Input: skyin: one of the sky systems as stand alone element or as a tuple for equatorial systems to specify an equinox and a reference system. skyout: as skyin Input variables skyin, skyout can be one of: eq, ecl, gal, sgal Equatorial systems can also be specified by one of: fk4, fk4_no_e, fk5, icrs, j2000 Then defaults are set for the equinox Usually equatorial systems are entered with a tuple. Then the first element must be eq. The other elements are either an epoch or a reference system (fk4, fk4_no_e, fk5, icrs, j2000) or both. epobs: Epoch of observation. Only used in conversions between fk4 and fk5. Returns: The transformation matrix M as in XYZskyout = M * XYZskyin 'None' or a tuple with the e-term vector belonging to the first epoch. 'None' or a tuple with the e-term vector belonging to the second epoch. See Notes. Reference: - Notes: The reference systems fk4 and fk4_no_e are special. We consider fk4 as a catalog position where the e-terms are included So besides a transformation matrix, this function should also return a flag for the addition or removal of e-terms. Besides the flag, also the e-term vector, which depends on the epoch, is returned. The stucture of the output then is as follows: M, (A1,A2,A3), (A4,A5,A6) where M: The transformation matrix (A1,A2,A3) or None: Start with removing e-terms using this e-term vector (A4,A5,A6) or None: End transformation procedure by removing e-terms using this e-term vector This function is the main function of this module. It calls skyparser() for the parsing of the input and rotmatrix() to get the rotation matrix. Examples: M, E1, E2 = skymatrix(gal,(eq,2000,fk5)) skymatrix(fk4, fk5) skymatrix((eq,1975.0,fk4_no_e),(eq,1950.0,fk4)) skymatrix((eq,'b1950',fk4, 'j1983.5'), (eq,'J2000',fk5)), xyz ) skymatrix((eq,'J2000',fk4, 'F1984-1-1T0:30'), (eq,'J2000',fk5)) See the docstring at epochs() for the possible epoch formats. --------------------------------------------------------------------- """ sysin, refin, epochin, epobsin = skyparser(skyin) sysout, refout, epochout, epobsout = skyparser(skyout) epobs = None if epobsin != None: epobs = epobsin elif epobsout != None: epobs = epobsout # Take care of the e-terms Aep1 = None; Aep2 = None if sysin == eq: if refin == fk4: # This is a catalog value. We should remove e-terms before we transform anything Aep1 = getEterms(epochin) if refin == fk4_no_e: refin = fk4 if sysout == eq: if refout == fk4: Aep2 = getEterms(epochout) if refout == fk4_no_e: refout = fk4 # No e-terms for ecliptic coordinates in fk4 if sysin == ecl: if refin == fk4_no_e: refin = fk4 if sysout == ecl: if refout == fk4_no_e: refout = fk4 return rotmatrix(sysin, sysout, epochin, epochout, refin, refout, epobs), Aep1, Aep2 def dotrans(skytuple, xyz): """ ---------------------------------------------------------------------- Purpose: Utility function that performs the rotation and adding or removing e-terms Input: -The tuple as produced by skymatrix -one or more positions on cartesian coordinates (xyz) Returns: The transformed (cartesian) coordinates Notes: Function skymatrix returns a tuple with the rotation matrix and e-terms if necessary. Tuple element 0 is the rotation matrix. Function dotrans() does the rotation for a vector in Cartesian coordinates. Examples: >>> lonlat = n.array( [(lon,lat)] ) >>> xyz = longlat2xyz(lonlat) >>> M = skymatrix((eq,fk4,'j1950','b1995.0'), (eq,'J2000',fk5)) >>> xyz2 = dotrans(M , xyz) ---------------------------------------------------------------------- """ M, A1, A2 = skytuple if A1: xyz2 = removeEterms(xyz, A1) else: xyz2 = xyz xyz3 = M*xyz2 if A2: xyz3 = addEterms(xyz3, A2) return xyz3 def sky2sky(skyin, skyout, lons, lats): """ ---------------------------------------------------------------------- Purpose: Utility function to facilitate command line use of skymatrix. Input: An input sky system An output sky system One or a series of longitudes One or a series of latitudes ---------------------------------------------------------------------- """ lonlat = n.array( [(lons,lats)] ) xyz = longlat2xyz(lonlat) xyz2 = dotrans(skymatrix(skyin, skyout), xyz) newlonlats = xyz2longlat(xyz2) return newlonlats pyregion-1.1.4/lib/parser_helper.py0000644000175000017500000001322112255736553017544 0ustar jjleejjlee00000000000000from pyparsing import Literal, CaselessKeyword, CaselessLiteral, \ Word, Optional, OneOrMore, Group, Combine, ZeroOrMore, nums, \ Forward, StringEnd, restOfLine, alphas, alphanums, CharsNotIn, \ MatchFirst, And, Or def as_comma_separated_list(al): l = [al[0]] comma = Literal(",").suppress() for a1 in al[1:]: l.append(comma) l.append(a1) return And(l) class wcs_shape(object): def __init__(self, *kl, **kw): self.args_list = kl self.args_repeat = kw.get("repeat", None) def get_pyparsing(self): return [a.parser for a in self.args_list] def define_shape(name, shape_args, args_repeat=None): lparen = Literal("(").suppress() rparen = Literal(")").suppress() comma = Literal(",").suppress() shape_name = CaselessKeyword(name) if args_repeat is None: shape_with_parens = And([shape_name, lparen, as_comma_separated_list(shape_args), rparen]) shape_with_spaces = shape_name + And(shape_args) else: n1, n2 = args_repeat sl = [] ss = shape_args[:n1] if ss: sl.append(as_comma_separated_list(ss)) ss = shape_args[n1:n2] if ss: ar = as_comma_separated_list(ss) if sl: sl.extend([comma+ ar, ZeroOrMore(comma + ar)]) else: sl.extend([ar, ZeroOrMore(comma + ar)]) ss = shape_args[n2:] if ss: if sl: sl.extend([comma, as_comma_separated_list(ss)]) else: sl.extend([as_comma_separated_list(ss)]) sl = [shape_name, lparen] + sl + [rparen] shape_with_parens = And(sl) shape_with_spaces = shape_name + OneOrMore(And(shape_args)) return (shape_with_parens | shape_with_spaces) def test_define_shape(): from .region_numbers import CoordOdd, CoordEven, Distance args = [s.parser for s in [CoordOdd, CoordEven, Distance]] circle_parser = define_shape("circle", args, args_repeat=None) p = circle_parser.parseString("circle(1:2:3, 2:4:5, 3.)") assert p[0] == "circle" assert isinstance(p[1], CoordOdd.type) assert isinstance(p[2], CoordEven.type) args = [s.parser for s in [CoordEven]] circle_parser = define_shape("circle", args, args_repeat=None) p = circle_parser.parseString("circle(1:2:3)") p = circle_parser.parseString("circle(1d2m3s)") assert p[0] == "circle" assert isinstance(p[1], CoordEven.type) args = [s.parser for s in [CoordOdd, CoordEven, Distance, Distance]] ell_parser = define_shape("ell", args, args_repeat=(2,4)) p = ell_parser.parseString("ell(1:2:2, 2:2:2, 3, 4, 5, 6)") assert p[0] == "ell" assert isinstance(p[1], CoordOdd.type) assert isinstance(p[2], CoordEven.type) args = [s.parser for s in [CoordOdd, CoordEven]] polygon_parser = define_shape("polygon", args, args_repeat=(0,2)) p = polygon_parser.parseString("polygon(3:2:4.22, 3:3:4., 3:2:3, 3.2)") assert p[0] == "polygon" assert isinstance(p[-2], CoordOdd.type) assert isinstance(p[2], CoordEven.type) #assert isinstance(p[-1], float) def define_shape_helper(shape_defs): l = [] for n, args in shape_defs.items(): s = define_shape(n, args.get_pyparsing(), args_repeat = args.args_repeat) l.append(s) return Or(l) def define_expr(regionShape, negate_func): minus = Literal("-").suppress() regionExclude = (minus + regionShape).setParseAction(negate_func) regionExpr = (regionShape | regionExclude) return regionExpr def define_line(atom, separator, comment): atomSeparator = separator.suppress() atomList = atom + ZeroOrMore(atomSeparator + atom) line = (atomList + Optional(comment)) | \ comment return line def comment_shell_like(comment_begin, parseAction=None): c = comment_begin + restOfLine if parseAction: c = c.setParseAction(parseAction) return c def define_simple_literals(literal_list, parseAction=None): l = MatchFirst([CaselessKeyword(k) for k in literal_list]) if parseAction: l = l.setParseAction(parseAction) return l class Shape(object): def __init__(self, shape_name, shape_params): self.name = shape_name self.params = shape_params self.comment = None self.exclude = False self.continued = False def __repr__(self): params_string = ",".join(map(repr, self.params)) if self.exclude: return "Shape : -%s ( %s )" % (self.name, params_string) else: return "Shape : %s ( %s )" % (self.name, params_string) def set_exclude(self): self.exclude = True class Property(object): def __init__(self, text): self.text = text def __repr__(self): return "Property : " + repr(self.text) class CoordCommand(Property): def __repr__(self): return "CoordCommand : " + repr(self.text) class Global(Property): def __repr__(self): return "Global : " + repr(self.text) class Comment(Property): def __repr__(self): return "Comment : " + repr(self.text) class RegionPusher(object): def __init__(self): self.flush() def flush(self): self.stack = [] self.comment = None self.continued = None def pushAtom(self, s, l, tok): self.stack.append(tok[-1]) def pushComment(self, s, l, tok): self.comment = tok[-1].strip() def set_continued(self, s, l, tok): self.continued = True pyregion-1.1.4/lib/wcs_helper.py0000664000175000017500000004101612341145603017033 0ustar jjleejjlee00000000000000import numpy as np from .kapteyn_celestial import skymatrix, longlat2xyz, dotrans, xyz2longlat from . import kapteyn_celestial pywcs = None try: from astropy import wcs as pywcs except ImportError: try: import pywcs except ImportError: pass import sys if sys.version < '3': def as_str(x): return x else: def as_str(x): if hasattr(x, "decode"): return x.decode() else: return x FK4 = (kapteyn_celestial.equatorial, kapteyn_celestial.fk4) FK5 = (kapteyn_celestial.equatorial, kapteyn_celestial.fk5) GAL = kapteyn_celestial.galactic ECL = kapteyn_celestial.ecliptic ICRS = (kapteyn_celestial.equatorial, kapteyn_celestial.fk5) # FIXME coord_system = dict(fk4=FK4, fk5=FK5, gal=GAL, galactic=GAL, ecl=ECL, icrs=ICRS) select_wcs = coord_system.get UnknownWcs = "unknown wcs" image_like_coordformats = ["image", "physical","detector","logical"] def is_equal_coord_sys(src, dest): return (src.lower() == dest.lower()) def is_string_like(obj): 'Return True if *obj* looks like a string' import sys if sys.version_info >= (3,0): if isinstance(obj, str): return True else: if isinstance(obj, (str, unicode)): return True try: obj + '' except: return False return True class sky2sky(object): def __init__(self, src, dest): if is_string_like(src): src = coord_system[src.lower()] if is_string_like(dest): dest = coord_system[dest.lower()] self.src = src self.dest = dest self._skymatrix = skymatrix(src, dest) #self.tran = wcs.Transformation(src, dest) def inverted(self): return sky2sky(self.dest, self.src) def _dotran(self, lonlat): xyz = longlat2xyz(lonlat) xyz2 = dotrans(self._skymatrix, xyz) lonlats2 = xyz2longlat(xyz2) return lonlats2 def __call__(self, lon, lat): lon, lat = np.asarray(lon), np.asarray(lat) lonlat = np.concatenate([lon[:,np.newaxis], lat[:,np.newaxis]],1) ll_dest = np.asarray(self._dotran(lonlat)) return ll_dest[:,0], ll_dest[:,1] import re _pattern_ra = re.compile(r"^RA") _pattern_dec = re.compile(r"^DEC") _pattern_glon = re.compile(r"^GLON") _pattern_glat = re.compile(r"^GLAT") _pattern_vel = re.compile(r"^VEL") def coord_system_guess(ctype1_name, ctype2_name, equinox): if ctype1_name.upper().startswith("RA") and \ ctype2_name.upper().startswith("DEC"): if equinox == 2000.0: return "fk5" elif equinox == 1950.0: return "fk4" elif equinox is None or np.isnan(equinox): return "fk5" else: return None if ctype1_name.upper().startswith("GLON") and \ ctype2_name.upper().startswith("GLAT"): return "gal" elif ctype1_name.upper().startswith("ELON") and \ ctype2_name.upper().startswith("ELAT"): return "ecl" return None def fix_header(header): "return a new fixed header" if hasattr(header, "cards"): old_cards = header.cards else: old_cards = header.ascardlist() new_cards = [] from operator import attrgetter if old_cards and hasattr(old_cards[0], "keyword"): get_key = attrgetter("keyword") else: get_key = attrgetter("key") for c in old_cards: key = get_key(c) # ignore comments and history if key in ["COMMENT", "HISTORY"]: continue # use "deg" if key.startswith("CUNIT") and c.value.lower().startswith("deg"): c = type(c)(key, "deg") new_cards.append(c) h = type(header)(new_cards) return h def fix_lon(lon, lon_ref): lon_ = lon - lon_ref lon2 = lon_ - 360*np.floor_divide(lon_, 360.) if lon_ == 360: lon2 = 360 return lon2 + lon_ref class ProjectionBase(object): """ A wrapper for kapteyn.projection or pywcs """ def __init__(self): self._lon_ref = None for i, ct in enumerate(self.ctypes): ct = ct.upper() if _pattern_ra.match(ct) or _pattern_glon.match(ct): self._lon_axis = i break else: self._lon_axis = None def get_lon(self): pass def set_lon_ref(self, ref): self._lon_ref = ref def _fix_lon(self, lon, lon_ref=None): """ transform lon into values in range [self._lon_ref, self._lon_ref+360] """ if lon_ref is None: lon_ref = self._lon_ref if lon_ref is not None: lon_ = lon - lon_ref lon2 = lon_ - 360*np.floor_divide(lon_, 360.) lon2[lon_==360] = 360 return lon2 + lon_ref else: return lon def fix_lon(self, lon_lat): """ """ if self._lon_axis is not None: lon_lat[self._lon_axis] = self._fix_lon(lon_lat[self._lon_axis]) # def _get_ctypes(self): # pass # def _get_equinox(self): # pass # def _get_naxis(self): # pass def topixel(self): """ 1, 1 base """ pass def toworld(self): """ 1, 1 base """ pass def sub(self, axes): pass def _get_radesys(self): ctype1, ctype2 = self.ctypes equinox = self.equinox radecsys = coord_system_guess(ctype1, ctype2, equinox) if radecsys is None: raise RuntimeError("Cannot determine the coordinate system with (CTYPE1=%s, CTYPE2=%s, EQUINOX=%s)." % (ctype1, ctype2, equinox)) return radecsys radesys = property(_get_radesys) class _ProjectionSubInterface: def substitute(self, axis_nums_to_keep, ref_pixel): for i in axis_nums_to_keep: if i >= self.naxis: raise ValueError("Incorrect axis number") if axis_nums_to_keep == range(self.naxis): return self proj_sub = ProjectionPywcsSub(self, axis_nums_to_keep, ref_pixel) return proj_sub def sub(self, axes): axis_nums_to_keep = [i-1 for i in axes] return self.substitute(axis_nums_to_keep, [0] * self.naxis) class ProjectionPywcsNd(_ProjectionSubInterface, ProjectionBase): """ A wrapper for pywcs """ def __init__(self, header): """ header could be pyfits.Header instance of pywcs.WCS instance. """ # We can't check the header type using isinstance since we don't know # if it comes from PyFITS or Astropy, so instead we check if it has # the 'ascard' attribute that both header classes define. if hasattr(header, 'ascard'): header = fix_header(header) # Since we don't know if PyFITS or PyWCS are from Astropy, and the # WCS object in PyWCS and Astropy both accept a string # representation of the header, we use this instead (both # internally use `repr(header.ascard)` which returns str, # and is compatible with Python 3 header = repr(header.ascard).encode('latin1') self._pywcs = pywcs.WCS(header=header) elif hasattr(header, "wcs"): self._pywcs = header else: raise ValueError("header must be an instance of pyfits.Header or astropy.io.fits.Header") ProjectionBase.__init__(self) def _get_ctypes(self): return tuple(as_str(s) for s in self._pywcs.wcs.ctype) ctypes = property(_get_ctypes) def _get_equinox(self): return self._pywcs.wcs.equinox equinox = property(_get_equinox) def _get_naxis(self): return self._pywcs.wcs.naxis naxis = property(_get_naxis) def topixel(self, xy): """ 1, 1 base """ lon_lat = np.array(xy) self.fix_lon(lon_lat) xy1 = lon_lat.transpose() # somehow, wcs_world2pix does not work for some cases xy21 = [self._pywcs.wcs_world2pix([xy11], 1)[0] for xy11 in xy1] #xy21 = self._pywcs.wcs_world2pix(xy1, 1) xy2 = np.array(xy21).transpose() return xy2 def toworld(self, xy): """ 1, 1 base """ xy2 = self._pywcs.wcs_pix2world(np.asarray(xy).T, 1) lon_lat = xy2.T # fixme self.fix_lon(lon_lat) return lon_lat #def sub(self, axes): # wcs = self._pywcs.sub(axes=axes) # return ProjectionPywcs(wcs) class ProjectionPywcsSub(_ProjectionSubInterface, ProjectionBase): """ A wrapper for pywcs """ def __init__(self, proj, axis_nums_to_keep, ref_pixel): """ ProjectionPywcsSub(proj, [0, 1], (0, 0, 0)) """ self.proj = proj self._nsub = len(axis_nums_to_keep) self._axis_nums_to_keep = axis_nums_to_keep[:] self._ref_pixel = ref_pixel _ref_pixel0 = np.array(ref_pixel).reshape((len(ref_pixel),1)) _ref_world0 = np.asarray(proj.toworld(_ref_pixel0)) self._ref_world = _ref_world0.reshape((len(ref_pixel),)) ProjectionBase.__init__(self) def _get_ctypes(self): return [self.proj.ctypes[i] for i in self._axis_nums_to_keep] ctypes = property(_get_ctypes) def _get_equinox(self): return self.proj.equinox equinox = property(_get_equinox) def _get_naxis(self): #return self.proj.naxis - self._nsub return self._nsub naxis = property(_get_naxis) def topixel(self, xy): """ 1, 1 base """ template = xy[0] iter_xy = iter(xy) xyz = [None]*self.proj.naxis for i in self._axis_nums_to_keep: xyz[i] = next(iter_xy) for i in range(self.proj.naxis): if i not in self._axis_nums_to_keep: s = np.empty_like(template) s.fill(self._ref_world[i]) xyz[i] = s #xyz2 = self._pywcs.wcs_world2pix(np.asarray(xyz).T, 1) xyz2 = self.proj.topixel(np.array(xyz)) #xyz2r = [d for (i, d) in enumerate(xyz2) if i in self._axis_nums_to_keep] xyz2r = [xyz2[i] for i in self._axis_nums_to_keep] return xyz2r def toworld(self, xy): """ 1, 1 base """ template = xy[0] iter_xy = iter(xy) xyz = [None]*self.proj.naxis for i in self._axis_nums_to_keep: xyz[i] = next(iter_xy) for i in range(self.proj.naxis): if i not in self._axis_nums_to_keep: s = np.empty_like(template) s.fill(self._ref_pixel[i]) xyz[i] = s xyz2 = self.proj.toworld(np.asarray(xyz)) xyz2r = [xyz2[i] for i in self._axis_nums_to_keep] # fixme #xyz2r[0] = self._fix_lon(xyz2r[0]) return xyz2r class ProjectionPywcs(ProjectionBase): """ A wrapper for pywcs """ def __init__(self, header): if hasattr(header, "ascard"): self._pywcs = pywcs.WCS(header=header) else: self._pywcs = header ProjectionBase.__init__(self) def _get_ctypes(self): return tuple(as_str(s) for s in self._pywcs.wcs.ctype) ctypes = property(_get_ctypes) def _get_equinox(self): return self._pywcs.wcs.equinox equinox = property(_get_equinox) def topixel(self, xy): """ 1, 1 base """ xy2 = self._pywcs.wcs_world2pix(np.asarray(xy).T, 1) return xy2.T[:2] def toworld(self, xy): """ 1, 1 base """ xy2 = self._pywcs.wcs_pix2world(np.asarray(xy).T, 1) return xy2.T[:2] def sub(self, axes): wcs = self._pywcs.sub(axes=axes) return ProjectionPywcs(wcs) class ProjectionSimple(ProjectionBase): """ A wrapper for pywcs """ def __init__(self, header): ProjectionBase.__init__(self) self._pywcs = pywcs.WCS(header=header) self._simple_init(header) def _get_ctypes(self): return tuple(as_str(s) for s in self._pywcs.wcs.ctype) ctypes = property(_get_ctypes) def _get_equinox(self): return self._pywcs.wcs.equinox equinox = property(_get_equinox) def _get_naxis(self): return self._pywcs.wcs.naxis naxis = property(_get_naxis) def _simple_init(self, header): self.crpix1 = header["CRPIX1"] self.crval1 = header["CRVAL1"] self.cdelt1 = header["CDELT1"] self.crpix2 = header["CRPIX2"] self.crval2 = header["CRVAL2"] self.cdelt2 = header["CDELT2"] self.cos_phi = np.cos(self.crval2/180.*np.pi) def _simple_to_pixel(self, lon, lat): lon, lat = np.asarray(lon), np.asarray(lat) lon = self._fix_lon(lon) x = (lon - self.crval1)/self.cdelt1*self.cos_phi + self.crpix1 y = (lat - self.crval2)/self.cdelt2 + self.crpix2 return x, y def _simple_to_world(self, x, y): x, y = np.asarray(x), np.asarray(y) lon = (x - self.crpix1)*self.cdelt1/self.cos_phi + self.crval1 lat = (y - self.crpix2)*self.cdelt2 + self.crval2 lon = self._fix_lon(lon) return lon, lat def topixel(self, xy): """ 1, 1 base """ lon, lat = xy[0], xy[1] x, y = self._simple_to_pixel(lon, lat) return np.array([x, y]) def toworld(self, xy): """ 1, 1 base """ x, y = xy[0], xy[1] lon, lat = self._simple_to_world(x, y) return np.array([lon, lat]) def substitute(self, axis_nums, values): return self def sub(self, axis_nums): return self # def sub(self, axes): # wcs = self._pywcs.sub(axes=axes) # return ProjectionPywcs(wcs) ProjectionDefault = ProjectionPywcsNd def get_kapteyn_projection(header): if isinstance(header, ProjectionBase): projection = header else: projection = ProjectionPywcsNd(header) #projection = projection.sub(axes=[1,2]) return projection def estimate_cdelt_trans(transSky2Pix, x0, y0): transPix2Sky = transSky2Pix.inverted() lon0, lat0 = transPix2Sky.transform_point((x0, y0)) lon1, lat1 = transPix2Sky.transform_point((x0+1, y0)) dlon = (lon1-lon0)*np.cos(lat0/180.*np.pi) dlat = (lat1-lat0) cd1 = (dlon**2 + dlat**2)**.5 lon2, lat2 = transPix2Sky.transform_point((x0, y0+1)) dlon = (lon2-lon0)*np.cos(lat0/180.*np.pi) dlat = (lat2-lat0) cd2 = (dlon**2 + dlat**2)**.5 return (cd1*cd2)**.5 def estimate_angle_trans(transSky2Pix, x0, y0): """ return a tuple of two angles (in degree) of increasing direction of 1st and 2nd coordinates. note that x, y = wcs_proj.topixel(sky_to_sky((l1, l2))) """ cdelt = estimate_cdelt_trans(transSky2Pix, x0, y0) transPix2Sky = transSky2Pix.inverted() lon0, lat0 = transPix2Sky.transform_point((x0, y0)) x1, y1 = transSky2Pix.transform_point((lon0 + cdelt*np.cos(lat0/180.*np.pi), lat0)) x2, y2 = transSky2Pix.transform_point((lon0, lat0+cdelt)) a1 = np.arctan2(y1-y0, x1-x0)/np.pi*180. a2 = np.arctan2(y2-y0, x2-x0)/np.pi*180. return a1, a2 def estimate_cdelt(wcs_proj, x0, y0): #, sky_to_sky): lon0, lat0 = wcs_proj.toworld(([x0], [y0])) if lat0 == 90 or lat0 == -90: raise ValueError("estimate_cdelt does not work at poles.") lon_ref = lon0 - 180. lon1, lat1 = wcs_proj.toworld(([x0+1], [y0])) lon1 = fix_lon(lon1, lon_ref) dlon = (lon1[0]-lon0[0])*np.cos(lat0[0]/180.*np.pi) dlat = (lat1[0]-lat0[0]) cd1 = (dlon**2 + dlat**2)**.5 lon2, lat2 = wcs_proj.toworld(([x0], [y0+1])) lon2 = fix_lon(lon2, lon_ref) dlon = (lon2[0]-lon0[0])*np.cos(lat0[0]/180.*np.pi) dlat = (lat2[0]-lat0[0]) cd2 = (dlon**2 + dlat**2)**.5 return ((cd1*cd2)**.5) def estimate_angle(wcs_proj, x0, y0, sky_to_sky=None): """ return a tuple of two angles (in degree) of increasing direction of 1st and 2nd coordinates. note that x, y = wcs_proj.topixel(sky_to_sky((l1, l2))) """ cdelt = estimate_cdelt(wcs_proj, x0, y0) #x0, y0 = wcs_proj.topixel((lon0, lat0)) ll = wcs_proj.toworld(([x0], [y0])) lon0, lat0 = sky_to_sky.inverted()(ll[0], ll[1]) ll = sky_to_sky(lon0 + cdelt*np.cos(lat0/180.*np.pi), lat0) x1, y1 = wcs_proj.topixel(ll) a1 = np.arctan2(y1-y0, x1-x0)/np.pi*180. ll = sky_to_sky(lon0, lat0+cdelt) x2, y2 = wcs_proj.topixel(ll) a2 = np.arctan2(y2-y0, x2-x0)/np.pi*180. return a1[0], a2[0] if __name__ == "__main__": fk5_to_fk4 = sky2sky(FK5, FK4) #print fk5_to_fk4([47.37], [6.32]) #print fk5_to_fk4([47.37, 47.37], [6.32, 6.32]) #print sky2sky("fk5", "FK4")([47.37, 47.37], [6.32, 6.32]) pyregion-1.1.4/lib/version.py0000664000175000017500000000002612423133756016370 0ustar jjleejjlee00000000000000__version__ = "1.1.4" pyregion-1.1.4/lib/region_numbers.py0000644000175000017500000002114112255736553017727 0ustar jjleejjlee00000000000000 import pyparsing from pyparsing import Literal, CaselessKeyword, CaselessLiteral, \ Word, Optional, OneOrMore, Group, Combine, ZeroOrMore, nums, \ Forward, StringEnd, restOfLine, alphas, alphanums, Empty, \ Or def _unsigned_simple_number(): # fnumber : 102.43, 12304.3e10, # .32??? point = Literal( "." ) e = Literal("e") | Literal("E") #CaselessLiteral( "E" ) fnumber = Combine( Word(nums) + Optional( point + Optional( Word( nums ) ) ) + Optional( e + Word( "+-"+nums, nums ) ) ) return fnumber #.setParseAction(lambda s,l,t: (float(t[0]), t[0])) #return fnumber.leaveWhitespace().setParseAction(lambda s,l,t: [ float(t[0])]) #simple_number = _simple_number() usn = _unsigned_simple_number() def getSign(s, l, tok): if not tok: return (1, "") if tok[0] == "-": return -1, "-" else: return 1, "+" def get_default(v): def _f(s, l, tok): if tok: return tok return v return _f optional_sign = Optional(Literal("+") | Literal("-")).setParseAction(get_default("")) #optional_sign = Optional(Literal("+") | Literal("-")) #.setParseAction(getSign) class SimpleNumber(object): def __repr__(self): return "Number(%s)" % (self.text,) def __str__(self): return self.__repr__() def __init__(self, text): self.text = text self.v = float(text) def _simple_number(): s = Combine(optional_sign + usn) s.setParseAction(lambda s, l, tok: SimpleNumber(tok[0])) return s simple_number = _simple_number() def test_usn(): for f in ["32.4", "0.23", "0.3e-7", "1.234e+7"]: assert usn.parseString(f)[0] == f #assert usn.parseString(f)[0][0] == float(f) class SimpleInteger(object): def __repr__(self): return "Number(%s)" % (self.text,) def __str__(self): return self.__repr__() def __init__(self, text): self.text = text self.v = int(text) def _unsigned_integer(): s = Combine(Optional("+") + Word(nums)) s.setParseAction(lambda s, l, tok: SimpleInteger(tok[0])) return s simple_integer = _unsigned_integer() def test_integer(): for f in ["32", "+3"]: assert simple_integer.parseString(f)[0].text == f def get_degree(s, l, tok): pass class Sixty(object): def __init__(self, sn, d, m, s): self.v = sn * (d +(m + s/60.)/60.) self.degree = self.v class HMS(object): def __repr__(self): return "HMS(%s)" % (self.text,) def __init__(self, kl): self.text = "".join(kl) if kl[0] == "-": sn = -1 else: sn = +1 kkl = kl[1::2] if len(kkl) == 3: d, m, s = float(kl[1]), float(kl[3]), float(kl[5]) elif len(kkl) == 2: d, m, s = float(kl[1]), float(kl[3]), 0. else: d, m, s = float(kl[1]), 0., 0. self.v = sn * (d +(m + s/60.)/60.) self.degree = self.v * 15 class DMS(object): def __repr__(self): return "DMS(%s)" % (self.text,) def __init__(self, kl): self.text = "".join(kl) if kl[0] == "-": sn = -1 else: sn = +1 kkl = kl[1::2] if len(kkl) == 3: d, m, s = float(kl[1]), float(kl[3]), float(kl[5]) elif len(kkl) == 2: d, m, s = float(kl[1]), float(kl[3]), 0. else: d, m, s = float(kl[1]), 0., 0. self.v = sn * (d +(m + s/60.)/60.) self.degree = self.v class AngularDistance(object): def __repr__(self): return "Ang(%s)" % (self.text,) def __init__(self, kl): self.text = "".join(kl) m, s = 0, 0 if kl[1] == "'": m = float(kl[0]) if len(kl) == 4: s = float(kl[2]) else: s = float(kl[0]) self.v = (m + s/60.)/60. self.degree = self.v def _sexadecimal(): colon = Literal(":") s = optional_sign + usn + colon + usn + \ Optional(colon + usn) #Optional(colon + usn).setParseAction(get_default(0)) #s = s.leaveWhitespace() return s #sexadecimal = _sexadecimal() sexadecimal60 = _sexadecimal().setParseAction(lambda s, l, tok: DMS(tok)) sexadecimal24 = _sexadecimal().setParseAction(lambda s, l, tok: HMS(tok)) def test_sexadecimal(): s = sexadecimal60.parseString assert s("32:24:32.2")[0].v == Sixty(1, 32, 24, 32.2).v assert s("-32:24:32.2")[0].v == Sixty(-1, 32, 24, 32.2).v assert s("+32:24:32.2")[0].v == Sixty(1, 32, 24, 32.2).v def _hms_number(): _h = (usn + Literal("h")).leaveWhitespace() _m = (usn + Literal("m")).leaveWhitespace() _s = (usn + Literal("s")).leaveWhitespace() hms = optional_sign + _h + Optional(_m + Optional(_s)) hms = hms.setParseAction(lambda s, l, tok: HMS(tok)) return hms def _dms_number(): _d = (usn + Literal("d")).leaveWhitespace() _m = (usn + Literal("m")).leaveWhitespace() _s = (usn + Literal("s")).leaveWhitespace() dms = optional_sign + _d + Optional(_m + Optional(_s)) dms = dms.setParseAction(lambda s, l, tok: DMS(tok)) return dms #zzz = Empty().setParseAction(lambda s, l, tok: 0) #_hms = optional_sign + Or([_h + Optional(_m).setParseAction(get_default(0)) \ # + Optional(_s).setParseAction(get_default(0)), # zzz + _m + Optional(_s).setParseAction(get_default(0)), # zzz + zzz + _s]) #_hms = _hms.leaveWhitespace() hms_number = _hms_number() dms_number = _dms_number() def test_hms(): s = hms_number.parseString assert s("32h24m32.2s")[0].v == Sixty(1, 32, 24, 32.2).v assert s("0h24m32.2s")[0].v == Sixty(1, 0, 24, 32.2).v assert s("32h")[0].v == Sixty(1, 32, 0, 0).v # def _dms_number(): # _d = (usn + Literal("d")).leaveWhitespace() # _m = (usn + Literal("m")).leaveWhitespace() # _s = (usn + Literal("s")).leaveWhitespace() # zzz = Empty().setParseAction(lambda s, l, tok: 0) # _dms = optional_sign + Or([_d + Optional(_m).setParseAction(get_default(0)) + Optional(_s).setParseAction(get_default(0)), # zzz + _m + Optional(_s).setParseAction(get_default(0)), # zzz + zzz + _s]) # #_hms = _hms.leaveWhitespace() # dms = _dms.setParseAction(lambda s, l, tok: DMS(*tok)) # return dms def test_dms(): s = dms_number.parseString assert s("32d24m32.2s")[0].v == Sixty(1, 32, 24, 32.2).v assert s("-32d24m32.2s")[0].v == Sixty(-1, 32, 24, 32.2).v assert s("32d")[0].v == Sixty(1, 32, 0, 0).v def _angular_distance(): _m = (usn + Literal("\'")).leaveWhitespace() _s = (usn + Literal("\"")).leaveWhitespace() ms = Or([ _m + Optional(_s), _s]) #_hms = _hms.leaveWhitespace() ms = ms.setParseAction(lambda s, l, tok: AngularDistance(tok)) return ms angular_distance = _angular_distance() def test_ang_distance(): s = angular_distance.parseString assert s("32.3'")[0].v == Sixty(1, 0, 32.3, 0.).v assert s("32\'24\"")[0].v == Sixty(1, 0, 32, 24).v class Arg(object): def __init__(self, type, parser): self.type = type self.parser = parser class CoordOdd: parser = (hms_number | sexadecimal24 | simple_number) type = HMS class CoordEven: parser = (dms_number | sexadecimal60 | simple_number) type = DMS class Distance: parser = (angular_distance | simple_number) type = AngularDistance class Angle: parser = (simple_number) type = simple_number class Integer: parser = simple_integer type = simple_number # CoordOdd = Arg(type=HMS, # parser=(hms_number | sexadecimal24 | simple_number) # ) # CoordEven = Arg(type=DMS, # parser=(dms_number | sexadecimal60 | simple_number) # ) # Distance = Arg(type=AngularDistance, # parser=(angular_distance | simple_number) # ) # Angle = Arg(type=float, # parser=(simple_number) # ) def test_coord_odd(): s = CoordOdd.parser.parseString assert s("32h24m32.2s")[0].v == Sixty(1, 32, 24, 32.2).v assert s("32:24:32.2s")[0].v == Sixty(1, 32, 24, 32.2).v assert s("32.24")[0].v == 32.24 s1 = s("32:24:32.2s")[0] assert isinstance(s1, HMS) def test_coord_odd(): s = CoordOdd.parser.parseString assert s("32h24m32.2s")[0].v == Sixty(1, 32, 24, 32.2).v assert s("32:24:32.2s")[0].v == Sixty(1, 32, 24, 32.2).v assert s("32.24")[0].v == 32.24 s1 = s("32:24:32.2s")[0] assert isinstance(s1, HMS) pyregion-1.1.4/lib/ds9_region_parser.py0000664000175000017500000002630512423133465020326 0ustar jjleejjlee00000000000000import copy from pyparsing import Literal, CaselessKeyword, CaselessLiteral, \ Word, Optional, OneOrMore, Group, Combine, ZeroOrMore, nums, \ Forward, StringEnd, restOfLine, alphas, alphanums, CharsNotIn, \ MatchFirst, And, Or, ParseException from .region_numbers import CoordOdd, CoordEven, Distance, Angle, Integer from .region_numbers import SimpleNumber, SimpleInteger from .wcs_helper import get_kapteyn_projection, sky2sky import warnings from .ds9_attr_parser import Ds9AttrParser, get_attr from .wcs_helper import UnknownWcs, image_like_coordformats, select_wcs from .wcs_converter import convert_to_imagecoord, convert_physical_to_imagecoord from .parser_helper import as_comma_separated_list, wcs_shape, \ define_shape, define_shape_helper, define_expr, define_line, \ comment_shell_like, define_simple_literals, \ Shape, Property, CoordCommand, Global, Comment, RegionPusher from .physical_coordinate import PhysicalCoordinate ds9_shape_defs = dict(circle=wcs_shape(CoordOdd, CoordEven, Distance), rotbox=wcs_shape(CoordOdd, CoordEven, Distance, Distance, Angle), box=wcs_shape(CoordOdd, CoordEven, Distance, Distance, Angle), polygon=wcs_shape(CoordOdd, CoordEven, repeat=(0,2)), ellipse=wcs_shape(CoordOdd, CoordEven, Distance, Distance, Angle, repeat=(2,4)), annulus=wcs_shape(CoordOdd, CoordEven, Distance, repeat=(2,3)), panda=wcs_shape(CoordOdd, CoordEven, Angle, Angle, Integer, Distance, Distance, Integer), pie=wcs_shape(CoordOdd, CoordEven, Distance, Distance, Angle, Angle), epanda=wcs_shape(CoordOdd, CoordEven, Angle, Angle, Integer, Distance, Distance, Distance, Distance, Integer, Angle), bpanda=wcs_shape(CoordOdd, CoordEven, Angle, Angle, Integer, Distance, Distance, Distance, Distance, Integer, Angle), point=wcs_shape(CoordOdd, CoordEven), line=wcs_shape(CoordOdd, CoordEven, CoordOdd, CoordEven), vector=wcs_shape(CoordOdd, CoordEven, Distance, Angle), text=wcs_shape(CoordOdd, CoordEven) ) class RegionParser(RegionPusher): def __init__(self): RegionPusher.__init__(self) self.shape_definition = ds9_shape_defs regionShape = define_shape_helper(self.shape_definition) regionShape = regionShape.setParseAction(lambda s, l, tok: Shape(tok[0], tok[1:])) regionExpr = define_expr(regionShape, negate_func=lambda s, l, tok: tok[-1].set_exclude(), ) coord_command_keys = "PHYSICAL IMAGE FK4 B1950 FK5 J2000 GALACTIC ECLIPTIC ICRS LINEAR AMPLIFIER DETECTOR".split() coordCommand = define_simple_literals(coord_command_keys, parseAction=lambda s, l, tok:CoordCommand(tok[-1])) regionGlobal = comment_shell_like(CaselessKeyword("global"), lambda s, l, tok:Global(tok[-1])) regionAtom = (regionExpr | coordCommand | regionGlobal) regionAtom = regionAtom.setParseAction(self.pushAtom) regionComment = comment_shell_like(Literal("#"), parseAction=self.pushComment) line_simple = define_line(atom=regionAtom, separator=Literal(";"), comment=regionComment ) line_w_composite = And([regionAtom, CaselessKeyword("||").setParseAction(self.set_continued) ]) \ + Optional(regionComment) line = Or([line_simple, line_w_composite]) self.parser = Optional(line) + StringEnd() def parseLine(self, l): self.parser.parseString(l) s, c, continued = self.stack, self.comment, self.continued self.flush() return s, c, continued def parse(self, s): for l in s.split("\n"): try: s, c, continued = self.parseLine(l) except ParseException: warnings.warn("Failed to parse : " + l) self.flush() continue if len(s) > 1: for s1 in s[:-1]: yield s1, None s[-1].comment = c s[-1].continued = continued yield s[-1], c elif len(s) == 1: s[-1].comment = c s[-1].continued = continued yield s[-1], c elif c: yield None, c self.flush() def convert_attr(self, l): global_attr = [], {} parser = Ds9AttrParser() for l1, c1 in l: if isinstance(l1, Global): for kv in parser.parse_default(l1.text): if len(kv) == 1: global_attr[0].append(kv[0]) elif len(kv) == 2: if kv[0] == 'tag': global_attr[1].setdefault(kv[0],set()).add(kv[1]) else: global_attr[1][kv[0]] = kv[1] elif isinstance(l1, Shape): if c1: attr_list = parser.parse_default(c1) attr0, attr1 = get_attr(attr_list, global_attr) else: attr0, attr1 = global_attr l1n = copy.copy(l1) l1n.attr = attr0, attr1 yield l1n, c1 elif not l1 and c1: shape, attr_list = parser.parse_check_shape(c1) if shape: shape.attr = get_attr(attr_list, global_attr) yield shape, c1 else: yield l1, c1 @staticmethod def sky_to_image(l, header, rot_wrt_axis=1): try: # this is a hack to test if header is fits header of wcs object. header["NAXIS"] except (KeyError, TypeError, ValueError): pc = None else: pc = PhysicalCoordinate(header) wcs_proj = get_kapteyn_projection(header) for l1, c1 in l: if isinstance(l1, Shape) and \ (l1.coord_format not in image_like_coordformats): tgt = wcs_proj.radesys if l1.coord_format == UnknownWcs: src = tgt else: src = select_wcs(l1.coord_format) sky_to_sky = sky2sky(src, tgt) cl = l1.coord_list fl = ds9_shape_defs[l1.name].args_list # take care of repeated items if ds9_shape_defs[l1.name].args_repeat: n1, n2 = ds9_shape_defs[l1.name].args_repeat else: n1 = 0 n2 = len(cl) #new_cl = [] xy0 = None cl1, fl1 = cl[:n1], fl[:n1] cl10, xy0 = convert_to_imagecoord(cl1, fl1, wcs_proj, sky_to_sky, xy0, rot_wrt_axis=rot_wrt_axis) nn2 = len(cl)-(len(fl) - n2) cl2, fl2 = cl[n1:nn2], fl[n1:n2] cl20, xy0 = convert_to_imagecoord(cl2, fl2, wcs_proj, sky_to_sky, xy0, rot_wrt_axis=rot_wrt_axis) cl3, fl3 = cl[nn2:], fl[n2:] cl30, xy0 = convert_to_imagecoord(cl3, fl3, wcs_proj, sky_to_sky, xy0, rot_wrt_axis=rot_wrt_axis) new_cl = cl10 + cl20 + cl30 l1n = copy.copy(l1) l1n.coord_list = new_cl l1n.coord_format = "image" yield l1n, c1 elif isinstance(l1, Shape) and (l1.coord_format == "physical"): if pc is None: raise RuntimeError("Physical coordinate is not known.") cl = l1.coord_list fl = ds9_shape_defs[l1.name].args_list # take care of repeated items if ds9_shape_defs[l1.name].args_repeat: n1, n2 = ds9_shape_defs[l1.name].args_repeat else: n1 = 0 n2 = len(cl) #new_cl = [] xy0 = None cl1, fl1 = cl[:n1], fl[:n1] cl10 = convert_physical_to_imagecoord(cl1, fl1, pc) #cl10, xy0 = convert_to_imagecoord(cl1, fl1, wcs_proj, # sky_to_sky, xy0, rot_wrt_axis=rot_wrt_axis) nn2 = len(cl)-(len(fl) - n2) cl2, fl2 = cl[n1:nn2], fl[n1:n2] cl20 = convert_physical_to_imagecoord(cl2, fl2, pc) #cl20, xy0 = convert_to_imagecoord(cl2, fl2, wcs_proj, # sky_to_sky, xy0, rot_wrt_axis=rot_wrt_axis) cl3, fl3 = cl[nn2:], fl[n2:] cl30 = convert_physical_to_imagecoord(cl3, fl3, pc) new_cl = cl10 + cl20 + cl30 l1n = copy.copy(l1) l1n.coord_list = new_cl l1n.coord_format = "image" yield l1n, c1 else: yield l1, c1 def filter_shape(self, sss): return [s1[0] for s1 in sss if isinstance(s1[0], Shape)] @staticmethod def filter_shape2(sss): r = [s1 for s1 in sss if isinstance(s1[0], Shape)] return zip(*r) def test_regionLine(): test_string_1 = ["circle(109,253,28.950304) # comment 1", "polygon(257,290,300.78944,271.78944,300.78944,178.21056,258,216,207.21056,178.21056)", "polygon(273.98971,175.01029,274.01029,175.01029,274.01029,174.98971,273.98971,174.98971)", "-rotbox(162,96.5,134,41,43.801537)", "ellipse(172,328,23,41,27.300813)"] test_names = ["circle", "polygon", "polygon", "rotbox", "ellipse"] rp = RegionParser() for s, n in zip(test_string_1, test_names): s = rp.parseLine(s)[0] assert len(s) == 1 assert s[0].name == n def test_comment(): s = "circle(3323, 423, 423) # comment" rp = RegionParser() c = rp.parseLine(s)[1] assert c == "comment" s = " # comment2" c = rp.parseLine(s)[1] assert c == "comment2" def test_global(): s = 'global color=green font="helvetica 10 normal" select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 source' rp = RegionParser() ss = rp.parseLine(s)[0] assert isinstance(ss[0], Global) pyregion-1.1.4/lib/ds9_attr_parser.py0000664000175000017500000001124512341354151020006 0ustar jjleejjlee00000000000000import copy from pyparsing import Literal, CaselessKeyword, CaselessLiteral, \ Word, Optional, OneOrMore, Group, Combine, ZeroOrMore, nums, \ Forward, StringEnd, restOfLine, alphas, alphanums, CharsNotIn, \ MatchFirst, And, Or, quotedString, QuotedString, White from .region_numbers import CoordOdd, CoordEven, Distance, Angle from .parser_helper import as_comma_separated_list, wcs_shape, \ define_shape, define_shape_helper, define_expr, define_line, \ comment_shell_like, define_simple_literals, \ Shape def get_ds9_attr_parser(): lhs = Word(alphas) paren = QuotedString("(",endQuoteChar=")") rhs = Or([Word(alphas+nums), Combine(Word(alphas) + White() + Word(nums)), # for point quotedString, QuotedString("{",endQuoteChar="}"), paren + ZeroOrMore(paren), Word(nums+" "), Word(nums+".") ]) expr = lhs + Optional(Literal("=").suppress() + rhs) expr.setParseAction(lambda s, l, tok: tuple(tok)) return ZeroOrMore(expr) class Ds9AttrParser(object): def set_continued(self, s, l, tok): self.continued = True def __init__(self): self.continued = False ds9_attr_parser = get_ds9_attr_parser() ds9_shape_in_comment_defs = dict(text=wcs_shape(CoordOdd, CoordEven), vector=wcs_shape(CoordOdd, CoordEven, Distance, Angle), composite=wcs_shape(CoordOdd, CoordEven, Angle), projection=wcs_shape(CoordOdd, CoordEven, CoordOdd, CoordEven, Distance), segment=wcs_shape(CoordOdd, CoordEven, repeat=(0,2)), ) regionShape = define_shape_helper(ds9_shape_in_comment_defs) regionShape = regionShape.setParseAction(lambda s, l, tok: Shape(tok[0], tok[1:])) self.parser_default = ds9_attr_parser cont = CaselessKeyword("||").setParseAction(self.set_continued).suppress() line = Optional(And([regionShape, Optional(cont)])) \ + ds9_attr_parser self.parser_with_shape = line def parse_default(self, s): return self.parser_default.parseString(s) def parse_check_shape(self, s): l = self.parser_with_shape.parseString(s) if l and isinstance(l[0], Shape): if self.continued: l[0].continued = True return l[0], l[1:] else: return None, l def get_attr(attr_list, global_attrs): """ Parameters ---------- attr_list : list A list of (keyword,value) tuple pairs global_attrs : tuple(list,dict) has the global attributes which update the local attributes """ local_attr = [], {} for kv in attr_list: keyword = kv[0] if len(kv) == 1: local_attr[0].append(keyword) continue elif len(kv) == 2: value = kv[1] elif len(kv) > 2: value = kv[1:] if keyword == 'tag': local_attr[1].setdefault(keyword,set()).add(value) else: local_attr[1][keyword] = value attr0 = copy.copy(global_attrs[0]) attr1 = copy.copy(global_attrs[1]) if local_attr[0]: attr0.extend(local_attr[0]) if local_attr[1]: attr1.update(local_attr[1]) return attr0, attr1 def test_attr(): p = get_ds9_attr_parser() assert p.parseString("color = green")[0] == ("color", "green") assert p.parseString("font=\"123 123\"")[0] == ("font", '"123 123"') assert p.parseString("color")[0] == ("color",) assert p.parseString("tag={group 1}")[0] == ("tag","group 1") def test_get_attr (): attr_list = [('tag','group1'),('tag','group2'),('tag','group3'),('color','green')] global_attrs = [],{} attr = get_attr(attr_list, global_attrs) assert attr[0] == [] assert attr[1] == {'color': 'green', 'tag': set(['group1', 'group3', 'group2'])} def test_shape_in_comment(): parser = Ds9AttrParser() r = parser.parse_check_shape("segment(0, 2)") assert r[0].name == "segment" assert r[1] == [] r = parser.parse_check_shape("projection(0, 2, 3, 2, 4)") assert r[0].name == "projection" assert r[1] == [] if __name__ == "__main__": p = get_ds9_attr_parser() s = 'point=cross 40 color=green dashlist= 8 4 font="helvetica 10 normal" tag={group 1} select=1 source panda=(1 3 2)(2 3 4)' #s = 'dashlist= 8 4 font=1' ss = p.parseString(s) pyregion-1.1.4/PKG-INFO0000664000175000017500000000140412423134227014653 0ustar jjleejjlee00000000000000Metadata-Version: 1.1 Name: pyregion Version: 1.1.4 Summary: python parser for ds9 region files Home-page: http://leejjoon.github.com/pyregion/ Author: Jae-Joon Lee Author-email: lee.j.joon@gmail.com License: MIT Download-URL: http://github.com/leejjoon/pyregion/downloads Description: UNKNOWN Platform: Linux Platform: MacOS X Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Science/Research Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: POSIX :: Linux Classifier: Programming Language :: Cython Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Topic :: Scientific/Engineering :: Astronomy pyregion-1.1.4/src/0000775000175000017500000000000012423134227014346 5ustar jjleejjlee00000000000000pyregion-1.1.4/src/_region_filter.c0000644000175000017500000137311312255736553017525 0ustar jjleejjlee00000000000000/* Generated by Cython 0.14.1 on Tue Nov 8 18:34:50 2011 */ #define PY_SSIZE_T_CLEAN #include "Python.h" #ifndef Py_PYTHON_H #error Python headers needed to compile C extensions, please install development version of Python. #else #include /* For offsetof */ #ifndef offsetof #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) #endif #if !defined(WIN32) && !defined(MS_WINDOWS) #ifndef __stdcall #define __stdcall #endif #ifndef __cdecl #define __cdecl #endif #ifndef __fastcall #define __fastcall #endif #endif #ifndef DL_IMPORT #define DL_IMPORT(t) t #endif #ifndef DL_EXPORT #define DL_EXPORT(t) t #endif #ifndef PY_LONG_LONG #define PY_LONG_LONG LONG_LONG #endif #if PY_VERSION_HEX < 0x02040000 #define METH_COEXIST 0 #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) #define PyDict_Contains(d,o) PySequence_Contains(d,o) #endif #if PY_VERSION_HEX < 0x02050000 typedef int Py_ssize_t; #define PY_SSIZE_T_MAX INT_MAX #define PY_SSIZE_T_MIN INT_MIN #define PY_FORMAT_SIZE_T "" #define PyInt_FromSsize_t(z) PyInt_FromLong(z) #define PyInt_AsSsize_t(o) PyInt_AsLong(o) #define PyNumber_Index(o) PyNumber_Int(o) #define PyIndex_Check(o) PyNumber_Check(o) #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) #endif #if PY_VERSION_HEX < 0x02060000 #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) #define PyVarObject_HEAD_INIT(type, size) \ PyObject_HEAD_INIT(type) size, #define PyType_Modified(t) typedef struct { void *buf; PyObject *obj; Py_ssize_t len; Py_ssize_t itemsize; int readonly; int ndim; char *format; Py_ssize_t *shape; Py_ssize_t *strides; Py_ssize_t *suboffsets; void *internal; } Py_buffer; #define PyBUF_SIMPLE 0 #define PyBUF_WRITABLE 0x0001 #define PyBUF_FORMAT 0x0004 #define PyBUF_ND 0x0008 #define PyBUF_STRIDES (0x0010 | PyBUF_ND) #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) #endif #if PY_MAJOR_VERSION < 3 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" #endif #if PY_MAJOR_VERSION >= 3 #define Py_TPFLAGS_CHECKTYPES 0 #define Py_TPFLAGS_HAVE_INDEX 0 #endif #if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) #define Py_TPFLAGS_HAVE_NEWBUFFER 0 #endif #if PY_MAJOR_VERSION >= 3 #define PyBaseString_Type PyUnicode_Type #define PyStringObject PyUnicodeObject #define PyString_Type PyUnicode_Type #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact #endif #if PY_VERSION_HEX < 0x02060000 #define PyBytesObject PyStringObject #define PyBytes_Type PyString_Type #define PyBytes_Check PyString_Check #define PyBytes_CheckExact PyString_CheckExact #define PyBytes_FromString PyString_FromString #define PyBytes_FromStringAndSize PyString_FromStringAndSize #define PyBytes_FromFormat PyString_FromFormat #define PyBytes_DecodeEscape PyString_DecodeEscape #define PyBytes_AsString PyString_AsString #define PyBytes_AsStringAndSize PyString_AsStringAndSize #define PyBytes_Size PyString_Size #define PyBytes_AS_STRING PyString_AS_STRING #define PyBytes_GET_SIZE PyString_GET_SIZE #define PyBytes_Repr PyString_Repr #define PyBytes_Concat PyString_Concat #define PyBytes_ConcatAndDel PyString_ConcatAndDel #endif #if PY_VERSION_HEX < 0x02060000 #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) #endif #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) #if PY_MAJOR_VERSION >= 3 #define PyIntObject PyLongObject #define PyInt_Type PyLong_Type #define PyInt_Check(op) PyLong_Check(op) #define PyInt_CheckExact(op) PyLong_CheckExact(op) #define PyInt_FromString PyLong_FromString #define PyInt_FromUnicode PyLong_FromUnicode #define PyInt_FromLong PyLong_FromLong #define PyInt_FromSize_t PyLong_FromSize_t #define PyInt_FromSsize_t PyLong_FromSsize_t #define PyInt_AsLong PyLong_AsLong #define PyInt_AS_LONG PyLong_AS_LONG #define PyInt_AsSsize_t PyLong_AsSsize_t #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) #else #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) #endif #if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) #else #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) #endif #if PY_MAJOR_VERSION >= 3 #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) #endif #if PY_VERSION_HEX < 0x02050000 #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) #else #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) #endif #if PY_VERSION_HEX < 0x02050000 #define __Pyx_NAMESTR(n) ((char *)(n)) #define __Pyx_DOCSTR(n) ((char *)(n)) #else #define __Pyx_NAMESTR(n) (n) #define __Pyx_DOCSTR(n) (n) #endif #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" #else #define __PYX_EXTERN_C extern #endif #if defined(WIN32) || defined(MS_WINDOWS) #define _USE_MATH_DEFINES #endif #include #define __PYX_HAVE_API___region_filter #include "stdio.h" #include "stdlib.h" #include "numpy/arrayobject.h" #include "math.h" #ifdef PYREX_WITHOUT_ASSERTIONS #define CYTHON_WITHOUT_ASSERTIONS #endif /* inline attribute */ #ifndef CYTHON_INLINE #if defined(__GNUC__) #define CYTHON_INLINE __inline__ #elif defined(_MSC_VER) #define CYTHON_INLINE __inline #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_INLINE inline #else #define CYTHON_INLINE #endif #endif /* unused attribute */ #ifndef CYTHON_UNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif # elif defined(__ICC) || defined(__INTEL_COMPILER) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif #endif typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ /* Type Conversion Predeclarations */ #define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) #define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) #define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) #ifdef __GNUC__ /* Test for GCC > 2.95 */ #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else /* __GNUC__ > 2 ... */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ > 2 ... */ #else /* __GNUC__ */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ static PyObject *__pyx_m; static PyObject *__pyx_b; static PyObject *__pyx_empty_tuple; static PyObject *__pyx_empty_bytes; static int __pyx_lineno; static int __pyx_clineno = 0; static const char * __pyx_cfilenm= __FILE__; static const char *__pyx_filename; static const char *__pyx_f[] = { "_region_filter.pyx", "c_numpy.pxd", }; typedef int __pyx_t_14_region_filter_Py_ssize_t; /* Type declarations */ /* "_region_filter.pyx":38 * * * cdef struct Metric: # <<<<<<<<<<<<<< * double x0 * double y0 */ struct __pyx_t_14_region_filter_Metric { double x0; double y0; double g_x; double g_y; }; /* "_region_filter.pyx":52 * * * cdef struct _RegionContext: # <<<<<<<<<<<<<< * int (*update_metric)(Metric *m) * */ struct __pyx_t_14_region_filter__RegionContext { int (*update_metric)(struct __pyx_t_14_region_filter_Metric *); }; /* "_region_filter.pyx":55 * int (*update_metric)(Metric *m) * * cdef class RegionContext: # <<<<<<<<<<<<<< * #cdef int (*init_metric)(Metric *m, double x0, double y0) * cdef _RegionContext c */ struct __pyx_obj_14_region_filter_RegionContext { PyObject_HEAD struct __pyx_vtabstruct_14_region_filter_RegionContext *__pyx_vtab; struct __pyx_t_14_region_filter__RegionContext c; }; /* "_region_filter.pyx":92 * pass * * cdef class RegionBase: # <<<<<<<<<<<<<< * #cdef double sin_theta * #cdef double cos_theta */ struct __pyx_obj_14_region_filter_RegionBase { PyObject_HEAD struct __pyx_vtabstruct_14_region_filter_RegionBase *__pyx_vtab; struct __pyx_t_14_region_filter_Metric m; struct __pyx_obj_14_region_filter_RegionContext *c; }; /* "_region_filter.pyx":323 * * * cdef class RegionList(RegionBase): # <<<<<<<<<<<<<< * cdef object child_regions * */ struct __pyx_obj_14_region_filter_RegionList { struct __pyx_obj_14_region_filter_RegionBase __pyx_base; PyObject *child_regions; }; /* "_region_filter.pyx":387 * * * cdef class RegionAndList(RegionList): # <<<<<<<<<<<<<< * * """ */ struct __pyx_obj_14_region_filter_RegionAndList { struct __pyx_obj_14_region_filter_RegionList __pyx_base; }; /* "_region_filter.pyx":683 * * * cdef class Ellipse(RegionBase): # <<<<<<<<<<<<<< * """ * Ellipse */ struct __pyx_obj_14_region_filter_Ellipse { struct __pyx_obj_14_region_filter_RegionBase __pyx_base; double xc; double yc; double radius_major; double radius_major_2; double radius_minor; double radius_minor_2; double radius_major_2_radius_minor_2; }; /* "_region_filter.pyx":310 * * * cdef class RegionNot(RegionBase): # <<<<<<<<<<<<<< * """ * >>> r = RegionNot(r2) */ struct __pyx_obj_14_region_filter_RegionNot { struct __pyx_obj_14_region_filter_RegionBase __pyx_base; struct __pyx_obj_14_region_filter_RegionBase *child_region; }; /* "_region_filter.pyx":367 * * * cdef class RegionOrList(RegionList): # <<<<<<<<<<<<<< * """ * >>> r = RegionOrList(r1, r2, r3, r4, ...) */ struct __pyx_obj_14_region_filter_RegionOrList { struct __pyx_obj_14_region_filter_RegionList __pyx_base; }; /* "_region_filter.pyx":731 * * * cdef class Box(RegionBase): # <<<<<<<<<<<<<< * """ * Box */ struct __pyx_obj_14_region_filter_Box { struct __pyx_obj_14_region_filter_RegionBase __pyx_base; double x1; double x2; double y1; double y2; }; /* "_region_filter.pyx":523 * * * cdef class Transform(RegionBase): # <<<<<<<<<<<<<< * cdef RegionBase child_region * */ struct __pyx_obj_14_region_filter_Transform { struct __pyx_obj_14_region_filter_RegionBase __pyx_base; struct __pyx_obj_14_region_filter_RegionBase *child_region; }; /* "_region_filter.pyx":560 * * * cdef class Rotated(Transform): # <<<<<<<<<<<<<< * """ * Rotated */ struct __pyx_obj_14_region_filter_Rotated { struct __pyx_obj_14_region_filter_Transform __pyx_base; double sin_theta; double cos_theta; double origin_x; double origin_y; }; /* "_region_filter.pyx":844 * * * cdef class AngleRange(RegionBase): # <<<<<<<<<<<<<< * """ * AngleRange */ struct __pyx_obj_14_region_filter_AngleRange { struct __pyx_obj_14_region_filter_RegionBase __pyx_base; double xc; double yc; double degree1; double degree2; double radian1; double radian2; }; /* "_region_filter.pyx":637 * # Basic Shapes * * cdef class Circle(RegionBase): # <<<<<<<<<<<<<< * """ * Circle */ struct __pyx_obj_14_region_filter_Circle { struct __pyx_obj_14_region_filter_RegionBase __pyx_base; double xc; double yc; double radius; double radius2; }; /* "_region_filter.pyx":607 * * * cdef class Translated(Transform): # <<<<<<<<<<<<<< * """ * Translated region */ struct __pyx_obj_14_region_filter_Translated { struct __pyx_obj_14_region_filter_Transform __pyx_base; double dx; double dy; }; /* "_region_filter.pyx":766 * * * cdef class Polygon(RegionBase): # <<<<<<<<<<<<<< * """ * Polygon */ struct __pyx_obj_14_region_filter_Polygon { struct __pyx_obj_14_region_filter_RegionBase __pyx_base; PyArrayObject *xa; PyArrayObject *ya; double *x; double *y; int n; }; /* "_region_filter.pyx":92 * pass * * cdef class RegionBase: # <<<<<<<<<<<<<< * #cdef double sin_theta * #cdef double cos_theta */ struct __pyx_vtabstruct_14_region_filter_RegionBase { PyObject *(*update_metric)(struct __pyx_obj_14_region_filter_RegionBase *); PyObject *(*metric_set_origin)(struct __pyx_obj_14_region_filter_RegionBase *, double, double, struct __pyx_obj_14_region_filter_RegionContext *); npy_bool (*_inside)(struct __pyx_obj_14_region_filter_RegionBase *, double, double); PyArrayObject *(*_mask)(struct __pyx_obj_14_region_filter_RegionBase *, npy_intp, npy_intp); }; static struct __pyx_vtabstruct_14_region_filter_RegionBase *__pyx_vtabptr_14_region_filter_RegionBase; /* "_region_filter.pyx":637 * # Basic Shapes * * cdef class Circle(RegionBase): # <<<<<<<<<<<<<< * """ * Circle */ struct __pyx_vtabstruct_14_region_filter_Circle { struct __pyx_vtabstruct_14_region_filter_RegionBase __pyx_base; PyObject *(*_set_v)(struct __pyx_obj_14_region_filter_Circle *, double, double, double); PyObject *(*_get_v)(struct __pyx_obj_14_region_filter_Circle *); }; static struct __pyx_vtabstruct_14_region_filter_Circle *__pyx_vtabptr_14_region_filter_Circle; /* "_region_filter.pyx":310 * * * cdef class RegionNot(RegionBase): # <<<<<<<<<<<<<< * """ * >>> r = RegionNot(r2) */ struct __pyx_vtabstruct_14_region_filter_RegionNot { struct __pyx_vtabstruct_14_region_filter_RegionBase __pyx_base; }; static struct __pyx_vtabstruct_14_region_filter_RegionNot *__pyx_vtabptr_14_region_filter_RegionNot; /* "_region_filter.pyx":323 * * * cdef class RegionList(RegionBase): # <<<<<<<<<<<<<< * cdef object child_regions * */ struct __pyx_vtabstruct_14_region_filter_RegionList { struct __pyx_vtabstruct_14_region_filter_RegionBase __pyx_base; }; static struct __pyx_vtabstruct_14_region_filter_RegionList *__pyx_vtabptr_14_region_filter_RegionList; /* "_region_filter.pyx":387 * * * cdef class RegionAndList(RegionList): # <<<<<<<<<<<<<< * * """ */ struct __pyx_vtabstruct_14_region_filter_RegionAndList { struct __pyx_vtabstruct_14_region_filter_RegionList __pyx_base; }; static struct __pyx_vtabstruct_14_region_filter_RegionAndList *__pyx_vtabptr_14_region_filter_RegionAndList; /* "_region_filter.pyx":367 * * * cdef class RegionOrList(RegionList): # <<<<<<<<<<<<<< * """ * >>> r = RegionOrList(r1, r2, r3, r4, ...) */ struct __pyx_vtabstruct_14_region_filter_RegionOrList { struct __pyx_vtabstruct_14_region_filter_RegionList __pyx_base; }; static struct __pyx_vtabstruct_14_region_filter_RegionOrList *__pyx_vtabptr_14_region_filter_RegionOrList; /* "_region_filter.pyx":844 * * * cdef class AngleRange(RegionBase): # <<<<<<<<<<<<<< * """ * AngleRange */ struct __pyx_vtabstruct_14_region_filter_AngleRange { struct __pyx_vtabstruct_14_region_filter_RegionBase __pyx_base; double (*_fix_angle)(struct __pyx_obj_14_region_filter_AngleRange *, double); }; static struct __pyx_vtabstruct_14_region_filter_AngleRange *__pyx_vtabptr_14_region_filter_AngleRange; /* "_region_filter.pyx":766 * * * cdef class Polygon(RegionBase): # <<<<<<<<<<<<<< * """ * Polygon */ struct __pyx_vtabstruct_14_region_filter_Polygon { struct __pyx_vtabstruct_14_region_filter_RegionBase __pyx_base; }; static struct __pyx_vtabstruct_14_region_filter_Polygon *__pyx_vtabptr_14_region_filter_Polygon; /* "_region_filter.pyx":731 * * * cdef class Box(RegionBase): # <<<<<<<<<<<<<< * """ * Box */ struct __pyx_vtabstruct_14_region_filter_Box { struct __pyx_vtabstruct_14_region_filter_RegionBase __pyx_base; }; static struct __pyx_vtabstruct_14_region_filter_Box *__pyx_vtabptr_14_region_filter_Box; /* "_region_filter.pyx":523 * * * cdef class Transform(RegionBase): # <<<<<<<<<<<<<< * cdef RegionBase child_region * */ struct __pyx_vtabstruct_14_region_filter_Transform { struct __pyx_vtabstruct_14_region_filter_RegionBase __pyx_base; int (*_transform)(struct __pyx_obj_14_region_filter_Transform *, double, double, double *, double *); }; static struct __pyx_vtabstruct_14_region_filter_Transform *__pyx_vtabptr_14_region_filter_Transform; /* "_region_filter.pyx":607 * * * cdef class Translated(Transform): # <<<<<<<<<<<<<< * """ * Translated region */ struct __pyx_vtabstruct_14_region_filter_Translated { struct __pyx_vtabstruct_14_region_filter_Transform __pyx_base; }; static struct __pyx_vtabstruct_14_region_filter_Translated *__pyx_vtabptr_14_region_filter_Translated; /* "_region_filter.pyx":55 * int (*update_metric)(Metric *m) * * cdef class RegionContext: # <<<<<<<<<<<<<< * #cdef int (*init_metric)(Metric *m, double x0, double y0) * cdef _RegionContext c */ struct __pyx_vtabstruct_14_region_filter_RegionContext { PyObject *(*set_update_func)(struct __pyx_obj_14_region_filter_RegionContext *, int (*)(struct __pyx_t_14_region_filter_Metric *)); }; static struct __pyx_vtabstruct_14_region_filter_RegionContext *__pyx_vtabptr_14_region_filter_RegionContext; /* "_region_filter.pyx":683 * * * cdef class Ellipse(RegionBase): # <<<<<<<<<<<<<< * """ * Ellipse */ struct __pyx_vtabstruct_14_region_filter_Ellipse { struct __pyx_vtabstruct_14_region_filter_RegionBase __pyx_base; }; static struct __pyx_vtabstruct_14_region_filter_Ellipse *__pyx_vtabptr_14_region_filter_Ellipse; /* "_region_filter.pyx":560 * * * cdef class Rotated(Transform): # <<<<<<<<<<<<<< * """ * Rotated */ struct __pyx_vtabstruct_14_region_filter_Rotated { struct __pyx_vtabstruct_14_region_filter_Transform __pyx_base; }; static struct __pyx_vtabstruct_14_region_filter_Rotated *__pyx_vtabptr_14_region_filter_Rotated; #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif #if CYTHON_REFNANNY typedef struct { void (*INCREF)(void*, PyObject*, int); void (*DECREF)(void*, PyObject*, int); void (*GOTREF)(void*, PyObject*, int); void (*GIVEREF)(void*, PyObject*, int); void* (*SetupContext)(const char*, int, const char*); void (*FinishContext)(void**); } __Pyx_RefNannyAPIStruct; static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) { PyObject *m = NULL, *p = NULL; void *r = NULL; m = PyImport_ImportModule((char *)modname); if (!m) goto end; p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); if (!p) goto end; r = PyLong_AsVoidPtr(p); end: Py_XDECREF(p); Py_XDECREF(m); return (__Pyx_RefNannyAPIStruct *)r; } #define __Pyx_RefNannySetupContext(name) void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) #define __Pyx_RefNannyFinishContext() __Pyx_RefNanny->FinishContext(&__pyx_refnanny) #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0) #else #define __Pyx_RefNannySetupContext(name) #define __Pyx_RefNannyFinishContext() #define __Pyx_INCREF(r) Py_INCREF(r) #define __Pyx_DECREF(r) Py_DECREF(r) #define __Pyx_GOTREF(r) #define __Pyx_GIVEREF(r) #define __Pyx_XDECREF(r) Py_XDECREF(r) #endif /* CYTHON_REFNANNY */ #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0) #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0) static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/ static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact); /*proto*/ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name); /*proto*/ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; if (!j) return NULL; r = PyObject_GetItem(o, j); Py_DECREF(j); return r; } #define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_GetItemInt_List_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { if (likely(o != Py_None)) { if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { PyObject *r = PyList_GET_ITEM(o, i); Py_INCREF(r); return r; } else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); Py_INCREF(r); return r; } } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } #define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_GetItemInt_Tuple_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { if (likely(o != Py_None)) { if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, i); Py_INCREF(r); return r; } else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); Py_INCREF(r); return r; } } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } #define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_GetItemInt_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { PyObject *r; if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) { r = PyList_GET_ITEM(o, i); Py_INCREF(r); } else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { r = PyTuple_GET_ITEM(o, i); Py_INCREF(r); } else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) { r = PySequence_GetItem(o, i); } else { r = __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } return r; } #define __Pyx_SetItemInt(o, i, v, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_SetItemInt_Fast(o, i, v) : \ __Pyx_SetItemInt_Generic(o, to_py_func(i), v)) static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { int r; if (!j) return -1; r = PyObject_SetItem(o, j, v); Py_DECREF(j); return r; } static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v) { if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) { Py_INCREF(v); Py_DECREF(PyList_GET_ITEM(o, i)); PyList_SET_ITEM(o, i, v); return 1; } else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_ass_item && (likely(i >= 0))) return PySequence_SetItem(o, i, v); else { PyObject *j = PyInt_FromSsize_t(i); return __Pyx_SetItemInt_Generic(o, j, v); } } #define __Pyx_DelItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_DelItemInt_Fast(o, i) : \ __Pyx_DelItem_Generic(o, to_py_func(i))) static CYTHON_INLINE int __Pyx_DelItem_Generic(PyObject *o, PyObject *j) { int r; if (!j) return -1; r = PyObject_DelItem(o, j); Py_DECREF(j); return r; } static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i) { if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_ass_item && likely(i >= 0)) return PySequence_DelItem(o, i); else { PyObject *j = PyInt_FromSsize_t(i); return __Pyx_DelItem_Generic(o, j); } } static CYTHON_INLINE long __Pyx_NegateNonNeg(long b) { return unlikely(b < 0) ? b : !b; } static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) { return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b); } static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases); /*proto*/ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, PyObject *modname); /*proto*/ static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_bool(npy_bool); static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); static void __Pyx_WriteUnraisable(const char *name); /*proto*/ static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size, int strict); /*proto*/ static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ static void __Pyx_AddTraceback(const char *funcname); /*proto*/ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from numpy */ /* Module declarations from c_numpy */ static PyTypeObject *__pyx_ptype_7c_numpy_dtype = 0; static PyTypeObject *__pyx_ptype_7c_numpy_ndarray = 0; static PyTypeObject *__pyx_ptype_7c_numpy_flatiter = 0; static PyTypeObject *__pyx_ptype_7c_numpy_broadcast = 0; /* Module declarations from c_python */ /* Module declarations from _region_filter */ static PyTypeObject *__pyx_ptype_14_region_filter_RegionContext = 0; static PyTypeObject *__pyx_ptype_14_region_filter_RegionBase = 0; static PyTypeObject *__pyx_ptype_14_region_filter_RegionNot = 0; static PyTypeObject *__pyx_ptype_14_region_filter_RegionList = 0; static PyTypeObject *__pyx_ptype_14_region_filter_RegionOrList = 0; static PyTypeObject *__pyx_ptype_14_region_filter_RegionAndList = 0; static PyTypeObject *__pyx_ptype_14_region_filter_Transform = 0; static PyTypeObject *__pyx_ptype_14_region_filter_Rotated = 0; static PyTypeObject *__pyx_ptype_14_region_filter_Translated = 0; static PyTypeObject *__pyx_ptype_14_region_filter_Circle = 0; static PyTypeObject *__pyx_ptype_14_region_filter_Ellipse = 0; static PyTypeObject *__pyx_ptype_14_region_filter_Box = 0; static PyTypeObject *__pyx_ptype_14_region_filter_Polygon = 0; static PyTypeObject *__pyx_ptype_14_region_filter_AngleRange = 0; static struct __pyx_obj_14_region_filter_RegionContext *__pyx_v_14_region_filter_metric_wcs = 0; static int __pyx_f_14_region_filter_MetricSetOrigin(struct __pyx_t_14_region_filter_Metric *, double, double); /*proto*/ static int __pyx_f_14_region_filter__update_metric_default(struct __pyx_t_14_region_filter_Metric *); /*proto*/ static int __pyx_f_14_region_filter__update_metric_wcs(struct __pyx_t_14_region_filter_Metric *); /*proto*/ #define __Pyx_MODULE_NAME "_region_filter" static int __pyx_module_is_main__region_filter = 0; /* Implementation of _region_filter */ static PyObject *__pyx_builtin_Exception; static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_TypeError; static char __pyx_k_1[] = "BaseClassInitException"; static char __pyx_k_2[] = "RegionFilterException"; static char __pyx_k_3[] = "the inut needs to be a numpy 2-d array or a tuple of two integers"; static char __pyx_k_5[] = "shape of the input image must be 2d: %s is given"; static char __pyx_k_6[] = "input array has a wrong shape"; static char __pyx_k_8[] = "All elements should be subclass of RegionBase type: %s"; static char __pyx_k_9[] = "Circle(%f, %f, %f)"; static char __pyx_k_10[] = "radius_major_2_radius_minor_2"; static char __pyx_k_11[] = "Ellipse(%f, %f, %f, %f)"; static char __pyx_k_12[] = "AngleRange(%f, %f, %f, %f)"; static char __pyx_k_13[] = "RegionAnd (line 409)"; static char __pyx_k_14[] = "\n >>> r = RegionAnd(reg1, reg2)\n "; static char __pyx_k_15[] = "RegionOr (line 426)"; static char __pyx_k_16[] = "\n >>> r = RegionOr(reg1, reg2)\n "; static char __pyx_k__c[] = "c"; static char __pyx_k__m[] = "m"; static char __pyx_k__n[] = "n"; static char __pyx_k__x[] = "x"; static char __pyx_k__y[] = "y"; static char __pyx_k__Or[] = "Or"; static char __pyx_k__dx[] = "dx"; static char __pyx_k__dy[] = "dy"; static char __pyx_k__nd[] = "nd"; static char __pyx_k__x0[] = "x0"; static char __pyx_k__x1[] = "x1"; static char __pyx_k__x2[] = "x2"; static char __pyx_k__xa[] = "xa"; static char __pyx_k__xc[] = "xc"; static char __pyx_k__y0[] = "y0"; static char __pyx_k__y1[] = "y1"; static char __pyx_k__y2[] = "y2"; static char __pyx_k__ya[] = "ya"; static char __pyx_k__yc[] = "yc"; static char __pyx_k__And[] = "And"; static char __pyx_k__g_x[] = "g_x"; static char __pyx_k__g_y[] = "g_y"; static char __pyx_k___mask[] = "_mask"; static char __pyx_k__shape[] = "shape"; static char __pyx_k__width[] = "width"; static char __pyx_k___set_v[] = "_set_v"; static char __pyx_k__asList[] = "asList"; static char __pyx_k__degree[] = "degree"; static char __pyx_k__height[] = "height"; static char __pyx_k__radius[] = "radius"; static char __pyx_k___inside[] = "_inside"; static char __pyx_k__degree1[] = "degree1"; static char __pyx_k__degree2[] = "degree2"; static char __pyx_k__radian1[] = "radian1"; static char __pyx_k__radian2[] = "radian2"; static char __pyx_k__radius2[] = "radius2"; static char __pyx_k__region1[] = "region1"; static char __pyx_k__region2[] = "region2"; static char __pyx_k__RegionOr[] = "RegionOr"; static char __pyx_k____init__[] = "__init__"; static char __pyx_k____main__[] = "__main__"; static char __pyx_k____test__[] = "__test__"; static char __pyx_k__origin_x[] = "origin_x"; static char __pyx_k__origin_y[] = "origin_y"; static char __pyx_k__Exception[] = "Exception"; static char __pyx_k__RegionAnd[] = "RegionAnd"; static char __pyx_k__TypeError[] = "TypeError"; static char __pyx_k__cos_theta[] = "cos_theta"; static char __pyx_k__inside_xy[] = "inside_xy"; static char __pyx_k__sin_theta[] = "sin_theta"; static char __pyx_k__ValueError[] = "ValueError"; static char __pyx_k___fix_angle[] = "_fix_angle"; static char __pyx_k___transform[] = "_transform"; static char __pyx_k__dimensions[] = "dimensions"; static char __pyx_k__inside_x_y[] = "inside_x_y"; static char __pyx_k__set_context[] = "set_context"; static char __pyx_k__child_region[] = "child_region"; static char __pyx_k__radius_major[] = "radius_major"; static char __pyx_k__radius_minor[] = "radius_minor"; static char __pyx_k__child_regions[] = "child_regions"; static char __pyx_k__update_metric[] = "update_metric"; static char __pyx_k___region_filter[] = "_region_filter"; static char __pyx_k__radius_major_2[] = "radius_major_2"; static char __pyx_k__radius_minor_2[] = "radius_minor_2"; static char __pyx_k__set_update_func[] = "set_update_func"; static char __pyx_k__NotYetImplemented[] = "NotYetImplemented"; static char __pyx_k__metric_set_origin[] = "metric_set_origin"; static char __pyx_k___check_type_of_list[] = "_check_type_of_list"; static PyObject *__pyx_n_s_1; static PyObject *__pyx_n_s_10; static PyObject *__pyx_kp_s_11; static PyObject *__pyx_kp_s_12; static PyObject *__pyx_kp_u_13; static PyObject *__pyx_kp_u_14; static PyObject *__pyx_kp_u_15; static PyObject *__pyx_kp_u_16; static PyObject *__pyx_n_s_2; static PyObject *__pyx_kp_s_3; static PyObject *__pyx_kp_s_5; static PyObject *__pyx_kp_s_6; static PyObject *__pyx_kp_s_8; static PyObject *__pyx_kp_s_9; static PyObject *__pyx_n_s__And; static PyObject *__pyx_n_s__Exception; static PyObject *__pyx_n_s__NotYetImplemented; static PyObject *__pyx_n_s__Or; static PyObject *__pyx_n_s__RegionAnd; static PyObject *__pyx_n_s__RegionOr; static PyObject *__pyx_n_s__TypeError; static PyObject *__pyx_n_s__ValueError; static PyObject *__pyx_n_s____init__; static PyObject *__pyx_n_s____main__; static PyObject *__pyx_n_s____test__; static PyObject *__pyx_n_s___check_type_of_list; static PyObject *__pyx_n_s___fix_angle; static PyObject *__pyx_n_s___inside; static PyObject *__pyx_n_s___mask; static PyObject *__pyx_n_s___region_filter; static PyObject *__pyx_n_s___set_v; static PyObject *__pyx_n_s___transform; static PyObject *__pyx_n_s__asList; static PyObject *__pyx_n_s__c; static PyObject *__pyx_n_s__child_region; static PyObject *__pyx_n_s__child_regions; static PyObject *__pyx_n_s__cos_theta; static PyObject *__pyx_n_s__degree; static PyObject *__pyx_n_s__degree1; static PyObject *__pyx_n_s__degree2; static PyObject *__pyx_n_s__dimensions; static PyObject *__pyx_n_s__dx; static PyObject *__pyx_n_s__dy; static PyObject *__pyx_n_s__g_x; static PyObject *__pyx_n_s__g_y; static PyObject *__pyx_n_s__height; static PyObject *__pyx_n_s__inside_x_y; static PyObject *__pyx_n_s__inside_xy; static PyObject *__pyx_n_s__m; static PyObject *__pyx_n_s__metric_set_origin; static PyObject *__pyx_n_s__n; static PyObject *__pyx_n_s__nd; static PyObject *__pyx_n_s__origin_x; static PyObject *__pyx_n_s__origin_y; static PyObject *__pyx_n_s__radian1; static PyObject *__pyx_n_s__radian2; static PyObject *__pyx_n_s__radius; static PyObject *__pyx_n_s__radius2; static PyObject *__pyx_n_s__radius_major; static PyObject *__pyx_n_s__radius_major_2; static PyObject *__pyx_n_s__radius_minor; static PyObject *__pyx_n_s__radius_minor_2; static PyObject *__pyx_n_s__region1; static PyObject *__pyx_n_s__region2; static PyObject *__pyx_n_s__set_context; static PyObject *__pyx_n_s__set_update_func; static PyObject *__pyx_n_s__shape; static PyObject *__pyx_n_s__sin_theta; static PyObject *__pyx_n_s__update_metric; static PyObject *__pyx_n_s__width; static PyObject *__pyx_n_s__x; static PyObject *__pyx_n_s__x0; static PyObject *__pyx_n_s__x1; static PyObject *__pyx_n_s__x2; static PyObject *__pyx_n_s__xa; static PyObject *__pyx_n_s__xc; static PyObject *__pyx_n_s__y; static PyObject *__pyx_n_s__y0; static PyObject *__pyx_n_s__y1; static PyObject *__pyx_n_s__y2; static PyObject *__pyx_n_s__ya; static PyObject *__pyx_n_s__yc; static PyObject *__pyx_int_2; static PyObject *__pyx_k_tuple_4; static PyObject *__pyx_k_tuple_7; /* "_region_filter.pyx":45 * * * cdef int MetricSetOrigin(Metric *m, double x0, double y0): # <<<<<<<<<<<<<< * m.x0 = x0 * m.y0 = y0 */ static int __pyx_f_14_region_filter_MetricSetOrigin(struct __pyx_t_14_region_filter_Metric *__pyx_v_m, double __pyx_v_x0, double __pyx_v_y0) { int __pyx_r; __Pyx_RefNannySetupContext("MetricSetOrigin"); /* "_region_filter.pyx":46 * * cdef int MetricSetOrigin(Metric *m, double x0, double y0): * m.x0 = x0 # <<<<<<<<<<<<<< * m.y0 = y0 * #m.g_x = 1. */ __pyx_v_m->x0 = __pyx_v_x0; /* "_region_filter.pyx":47 * cdef int MetricSetOrigin(Metric *m, double x0, double y0): * m.x0 = x0 * m.y0 = y0 # <<<<<<<<<<<<<< * #m.g_x = 1. * #m.g_y = 1. */ __pyx_v_m->y0 = __pyx_v_y0; __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":59 * cdef _RegionContext c * * def __init__(self): # <<<<<<<<<<<<<< * pass * */ static int __pyx_pf_14_region_filter_13RegionContext___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pf_14_region_filter_13RegionContext___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { int __pyx_r; __Pyx_RefNannySetupContext("__init__"); if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":62 * pass * * cdef set_update_func(self, int (*update_metric)(Metric *m)): # <<<<<<<<<<<<<< * self.c.update_metric = update_metric * */ static PyObject *__pyx_f_14_region_filter_13RegionContext_set_update_func(struct __pyx_obj_14_region_filter_RegionContext *__pyx_v_self, int (*__pyx_v_update_metric)(struct __pyx_t_14_region_filter_Metric *)) { PyObject *__pyx_r = NULL; __Pyx_RefNannySetupContext("set_update_func"); /* "_region_filter.pyx":63 * * cdef set_update_func(self, int (*update_metric)(Metric *m)): * self.c.update_metric = update_metric # <<<<<<<<<<<<<< * * */ __pyx_v_self->c.update_metric = __pyx_v_update_metric; __pyx_r = Py_None; __Pyx_INCREF(Py_None); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":66 * * * cdef int _update_metric_default(Metric *m): # <<<<<<<<<<<<<< * m.g_x = 1. * m.g_y = 1. */ static int __pyx_f_14_region_filter__update_metric_default(struct __pyx_t_14_region_filter_Metric *__pyx_v_m) { int __pyx_r; __Pyx_RefNannySetupContext("_update_metric_default"); /* "_region_filter.pyx":67 * * cdef int _update_metric_default(Metric *m): * m.g_x = 1. # <<<<<<<<<<<<<< * m.g_y = 1. * */ __pyx_v_m->g_x = 1.; /* "_region_filter.pyx":68 * cdef int _update_metric_default(Metric *m): * m.g_x = 1. * m.g_y = 1. # <<<<<<<<<<<<<< * * */ __pyx_v_m->g_y = 1.; __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":71 * * * cdef int _update_metric_wcs(Metric *m): # <<<<<<<<<<<<<< * cdef double theta * theta = m.y0/180.*3.1415926; */ static int __pyx_f_14_region_filter__update_metric_wcs(struct __pyx_t_14_region_filter_Metric *__pyx_v_m) { double __pyx_v_theta; int __pyx_r; __Pyx_RefNannySetupContext("_update_metric_wcs"); /* "_region_filter.pyx":73 * cdef int _update_metric_wcs(Metric *m): * cdef double theta * theta = m.y0/180.*3.1415926; # <<<<<<<<<<<<<< * * m.g_x = cos(theta) */ __pyx_v_theta = ((__pyx_v_m->y0 / 180.) * 3.1415926); /* "_region_filter.pyx":75 * theta = m.y0/180.*3.1415926; * * m.g_x = cos(theta) # <<<<<<<<<<<<<< * m.g_y = 1. * */ __pyx_v_m->g_x = cos(__pyx_v_theta); /* "_region_filter.pyx":76 * * m.g_x = cos(theta) * m.g_y = 1. # <<<<<<<<<<<<<< * * */ __pyx_v_m->g_y = 1.; __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":102 * # MetricInit(&(self.m), xc, yc) * * def __init__(self): # <<<<<<<<<<<<<< * #selc.c = metric_default * #self.update_context(metric_default) */ static int __pyx_pf_14_region_filter_10RegionBase___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pf_14_region_filter_10RegionBase___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { int __pyx_r; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__init__"); if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; /* "_region_filter.pyx":106 * #self.update_context(metric_default) * #MetricInit(&(self.m), x0, y0) * raise BaseClassInitException() # <<<<<<<<<<<<<< * * cdef update_metric(self): */ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_2, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("_region_filter.RegionBase.__init__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":108 * raise BaseClassInitException() * * cdef update_metric(self): # <<<<<<<<<<<<<< * if self.c: * self.c.c.update_metric(&(self.m)) */ static PyObject *__pyx_f_14_region_filter_10RegionBase_update_metric(struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_self) { PyObject *__pyx_r = NULL; int __pyx_t_1; __Pyx_RefNannySetupContext("update_metric"); /* "_region_filter.pyx":109 * * cdef update_metric(self): * if self.c: # <<<<<<<<<<<<<< * self.c.c.update_metric(&(self.m)) * else: */ __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->c)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { /* "_region_filter.pyx":110 * cdef update_metric(self): * if self.c: * self.c.c.update_metric(&(self.m)) # <<<<<<<<<<<<<< * else: * _update_metric_default(&(self.m)) */ __pyx_v_self->c->c.update_metric((&__pyx_v_self->m)); goto __pyx_L3; } /*else*/ { /* "_region_filter.pyx":112 * self.c.c.update_metric(&(self.m)) * else: * _update_metric_default(&(self.m)) # <<<<<<<<<<<<<< * * def set_context(self, RegionContext cnt): */ __pyx_f_14_region_filter__update_metric_default((&__pyx_v_self->m)); } __pyx_L3:; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("_region_filter.RegionBase.update_metric"); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":114 * _update_metric_default(&(self.m)) * * def set_context(self, RegionContext cnt): # <<<<<<<<<<<<<< * self.c = cnt * self.update_metric() */ static PyObject *__pyx_pf_14_region_filter_10RegionBase_1set_context(PyObject *__pyx_v_self, PyObject *__pyx_v_cnt); /*proto*/ static PyObject *__pyx_pf_14_region_filter_10RegionBase_1set_context(PyObject *__pyx_v_self, PyObject *__pyx_v_cnt) { PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("set_context"); if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_cnt), __pyx_ptype_14_region_filter_RegionContext, 1, "cnt", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":115 * * def set_context(self, RegionContext cnt): * self.c = cnt # <<<<<<<<<<<<<< * self.update_metric() * */ __Pyx_INCREF(__pyx_v_cnt); __Pyx_GIVEREF(__pyx_v_cnt); __Pyx_GOTREF(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self)->c); __Pyx_DECREF(((PyObject *)((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self)->c)); ((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self)->c = ((struct __pyx_obj_14_region_filter_RegionContext *)__pyx_v_cnt); /* "_region_filter.pyx":116 * def set_context(self, RegionContext cnt): * self.c = cnt * self.update_metric() # <<<<<<<<<<<<<< * * */ __pyx_t_1 = ((struct __pyx_vtabstruct_14_region_filter_RegionBase *)((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self)->__pyx_vtab)->update_metric(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.RegionBase.set_context"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":119 * * * cdef metric_set_origin(self, double xc, double yc, # <<<<<<<<<<<<<< * RegionContext cnt): * */ static PyObject *__pyx_f_14_region_filter_10RegionBase_metric_set_origin(struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_self, double __pyx_v_xc, double __pyx_v_yc, struct __pyx_obj_14_region_filter_RegionContext *__pyx_v_cnt) { PyObject *__pyx_r = NULL; int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("metric_set_origin"); /* "_region_filter.pyx":122 * RegionContext cnt): * * MetricSetOrigin(&(self.m), xc, yc) # <<<<<<<<<<<<<< * if cnt: * self.set_context(cnt) */ __pyx_f_14_region_filter_MetricSetOrigin((&__pyx_v_self->m), __pyx_v_xc, __pyx_v_yc); /* "_region_filter.pyx":123 * * MetricSetOrigin(&(self.m), xc, yc) * if cnt: # <<<<<<<<<<<<<< * self.set_context(cnt) * else: */ __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_cnt)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { /* "_region_filter.pyx":124 * MetricSetOrigin(&(self.m), xc, yc) * if cnt: * self.set_context(cnt) # <<<<<<<<<<<<<< * else: * self.update_metric() */ __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__set_context); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_INCREF(((PyObject *)__pyx_v_cnt)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_cnt)); __Pyx_GIVEREF(((PyObject *)__pyx_v_cnt)); __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L3; } /*else*/ { /* "_region_filter.pyx":126 * self.set_context(cnt) * else: * self.update_metric() # <<<<<<<<<<<<<< * * */ __pyx_t_4 = ((struct __pyx_vtabstruct_14_region_filter_RegionBase *)__pyx_v_self->__pyx_vtab)->update_metric(__pyx_v_self); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_L3:; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("_region_filter.RegionBase.metric_set_origin"); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":130 * * * def __invert__(self): # <<<<<<<<<<<<<< * return RegionNot(self) * */ static PyObject *__pyx_pf_14_region_filter_10RegionBase_2__invert__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pf_14_region_filter_10RegionBase_2__invert__(PyObject *__pyx_v_self) { PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__invert__"); /* "_region_filter.pyx":131 * * def __invert__(self): * return RegionNot(self) # <<<<<<<<<<<<<< * * def __and__(self, RegionBase o): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_INCREF(__pyx_v_self); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self); __Pyx_GIVEREF(__pyx_v_self); __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_14_region_filter_RegionNot)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("_region_filter.RegionBase.__invert__"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":133 * return RegionNot(self) * * def __and__(self, RegionBase o): # <<<<<<<<<<<<<< * return RegionAnd(self, o) * */ static PyObject *__pyx_pf_14_region_filter_10RegionBase_3__and__(PyObject *__pyx_v_self, PyObject *__pyx_v_o); /*proto*/ static PyObject *__pyx_pf_14_region_filter_10RegionBase_3__and__(PyObject *__pyx_v_self, PyObject *__pyx_v_o) { PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__and__"); if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_o), __pyx_ptype_14_region_filter_RegionBase, 1, "o", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":134 * * def __and__(self, RegionBase o): * return RegionAnd(self, o) # <<<<<<<<<<<<<< * * def __or__(self, RegionBase o): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__RegionAnd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_self); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self); __Pyx_GIVEREF(__pyx_v_self); __Pyx_INCREF(__pyx_v_o); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_o); __Pyx_GIVEREF(__pyx_v_o); __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("_region_filter.RegionBase.__and__"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":136 * return RegionAnd(self, o) * * def __or__(self, RegionBase o): # <<<<<<<<<<<<<< * return RegionOr(self, o) * */ static PyObject *__pyx_pf_14_region_filter_10RegionBase_4__or__(PyObject *__pyx_v_self, PyObject *__pyx_v_o); /*proto*/ static PyObject *__pyx_pf_14_region_filter_10RegionBase_4__or__(PyObject *__pyx_v_self, PyObject *__pyx_v_o) { PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__or__"); if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_o), __pyx_ptype_14_region_filter_RegionBase, 1, "o", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":137 * * def __or__(self, RegionBase o): * return RegionOr(self, o) # <<<<<<<<<<<<<< * * cdef npy_bool _inside(self, double x, double y): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__RegionOr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_self); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self); __Pyx_GIVEREF(__pyx_v_self); __Pyx_INCREF(__pyx_v_o); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_o); __Pyx_GIVEREF(__pyx_v_o); __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("_region_filter.RegionBase.__or__"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":139 * return RegionOr(self, o) * * cdef npy_bool _inside(self, double x, double y): # <<<<<<<<<<<<<< * return (0) * */ static npy_bool __pyx_f_14_region_filter_10RegionBase__inside(struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_self, double __pyx_v_x, double __pyx_v_y) { npy_bool __pyx_r; __Pyx_RefNannySetupContext("_inside"); /* "_region_filter.pyx":140 * * cdef npy_bool _inside(self, double x, double y): * return (0) # <<<<<<<<<<<<<< * * def mask(self, img_or_shape): */ __pyx_r = 0; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":142 * return (0) * * def mask(self, img_or_shape): # <<<<<<<<<<<<<< * """ * Create a mask ( a 2-d image whose pixel value is 1 if the */ static PyObject *__pyx_pf_14_region_filter_10RegionBase_5mask(PyObject *__pyx_v_self, PyObject *__pyx_v_img_or_shape); /*proto*/ static char __pyx_doc_14_region_filter_10RegionBase_5mask[] = "\n Create a mask ( a 2-d image whose pixel value is 1 if the\n pixel is inside the filter, otherwise 0). It takes a single\n argument which is numpy 2d array (or any python object with\n *shape* attribute) or a tuple of two integer representing the\n image shape.\n "; static PyObject *__pyx_pf_14_region_filter_10RegionBase_5mask(PyObject *__pyx_v_self, PyObject *__pyx_v_img_or_shape) { int __pyx_v_nx; int __pyx_v_ny; PyObject *__pyx_v_shape; PyObject *__pyx_r = NULL; int __pyx_t_1; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("mask"); __pyx_v_shape = Py_None; __Pyx_INCREF(Py_None); /* "_region_filter.pyx":153 * cdef int l, nx, ny * * if hasattr(img_or_shape, "shape"): # <<<<<<<<<<<<<< * shape = img_or_shape.shape * elif c_python.PySequence_Check(img_or_shape): */ __pyx_t_1 = PyObject_HasAttr(__pyx_v_img_or_shape, ((PyObject *)__pyx_n_s__shape)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { /* "_region_filter.pyx":154 * * if hasattr(img_or_shape, "shape"): * shape = img_or_shape.shape # <<<<<<<<<<<<<< * elif c_python.PySequence_Check(img_or_shape): * shape = img_or_shape */ __pyx_t_2 = PyObject_GetAttr(__pyx_v_img_or_shape, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_v_shape); __pyx_v_shape = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L5; } /* "_region_filter.pyx":155 * if hasattr(img_or_shape, "shape"): * shape = img_or_shape.shape * elif c_python.PySequence_Check(img_or_shape): # <<<<<<<<<<<<<< * shape = img_or_shape * else: */ __pyx_t_3 = PySequence_Check(__pyx_v_img_or_shape); if (__pyx_t_3) { /* "_region_filter.pyx":156 * shape = img_or_shape.shape * elif c_python.PySequence_Check(img_or_shape): * shape = img_or_shape # <<<<<<<<<<<<<< * else: * raise RegionFilterException("the inut needs to be a numpy 2-d array or a tuple of two integers") */ __Pyx_INCREF(__pyx_v_img_or_shape); __Pyx_DECREF(__pyx_v_shape); __pyx_v_shape = __pyx_v_img_or_shape; goto __pyx_L5; } /*else*/ { /* "_region_filter.pyx":158 * shape = img_or_shape * else: * raise RegionFilterException("the inut needs to be a numpy 2-d array or a tuple of two integers") # <<<<<<<<<<<<<< * * if c_python.PySequence_Length(shape) != 2: */ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_4, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L5:; /* "_region_filter.pyx":160 * raise RegionFilterException("the inut needs to be a numpy 2-d array or a tuple of two integers") * * if c_python.PySequence_Length(shape) != 2: # <<<<<<<<<<<<<< * raise RegionFilterException("shape of the input image must be 2d: %s is given" % (str(shape))) * */ __pyx_t_1 = (PySequence_Length(__pyx_v_shape) != 2); if (__pyx_t_1) { /* "_region_filter.pyx":161 * * if c_python.PySequence_Length(shape) != 2: * raise RegionFilterException("shape of the input image must be 2d: %s is given" % (str(shape))) # <<<<<<<<<<<<<< * * ny = c_python.PySequence_GetItem(shape, 0) */ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_shape); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape); __Pyx_GIVEREF(__pyx_v_shape); __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_5), __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __Pyx_Raise(__pyx_t_2, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; /* "_region_filter.pyx":163 * raise RegionFilterException("shape of the input image must be 2d: %s is given" % (str(shape))) * * ny = c_python.PySequence_GetItem(shape, 0) # <<<<<<<<<<<<<< * nx = c_python.PySequence_GetItem(shape, 1) * */ __pyx_t_2 = PySequence_GetItem(__pyx_v_shape, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_ny = __pyx_t_3; /* "_region_filter.pyx":164 * * ny = c_python.PySequence_GetItem(shape, 0) * nx = c_python.PySequence_GetItem(shape, 1) # <<<<<<<<<<<<<< * * return self._mask(nx, ny) */ __pyx_t_2 = PySequence_GetItem(__pyx_v_shape, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_nx = __pyx_t_3; /* "_region_filter.pyx":166 * nx = c_python.PySequence_GetItem(shape, 1) * * return self._mask(nx, ny) # <<<<<<<<<<<<<< * * cdef c_numpy.ndarray _mask(self, c_numpy.npy_intp nx, c_numpy.npy_intp ny): */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_14_region_filter_RegionBase *)((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self)->__pyx_vtab)->_mask(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self), __pyx_v_nx, __pyx_v_ny)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("_region_filter.RegionBase.mask"); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(__pyx_v_shape); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":168 * return self._mask(nx, ny) * * cdef c_numpy.ndarray _mask(self, c_numpy.npy_intp nx, c_numpy.npy_intp ny): # <<<<<<<<<<<<<< * * cdef c_numpy.npy_intp ny_nx[2] */ static PyArrayObject *__pyx_f_14_region_filter_10RegionBase__mask(struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_self, npy_intp __pyx_v_nx, npy_intp __pyx_v_ny) { npy_intp __pyx_v_ny_nx[2]; PyArrayObject *__pyx_v_ra; npy_bool *__pyx_v_rd; int __pyx_v_iy; int __pyx_v_ix; PyArrayObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; npy_intp __pyx_t_2; npy_intp __pyx_t_3; __Pyx_RefNannySetupContext("_mask"); __pyx_v_ra = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); /* "_region_filter.pyx":175 * cdef int iy, ix * * ny_nx[0] = ny # <<<<<<<<<<<<<< * ny_nx[1] = nx * */ (__pyx_v_ny_nx[0]) = __pyx_v_ny; /* "_region_filter.pyx":176 * * ny_nx[0] = ny * ny_nx[1] = nx # <<<<<<<<<<<<<< * * ra = c_numpy.PyArray_EMPTY(2, ny_nx, */ (__pyx_v_ny_nx[1]) = __pyx_v_nx; /* "_region_filter.pyx":179 * * ra = c_numpy.PyArray_EMPTY(2, ny_nx, * c_numpy.NPY_BOOL, 0) # <<<<<<<<<<<<<< * * rd = c_numpy.PyArray_DATA(ra) */ __pyx_t_1 = PyArray_EMPTY(2, __pyx_v_ny_nx, NPY_BOOL, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7c_numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_v_ra)); __pyx_v_ra = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":181 * c_numpy.NPY_BOOL, 0) * * rd = c_numpy.PyArray_DATA(ra) # <<<<<<<<<<<<<< * * for iy from 0 <= iy < ny: */ __pyx_v_rd = ((npy_bool *)PyArray_DATA(__pyx_v_ra)); /* "_region_filter.pyx":183 * rd = c_numpy.PyArray_DATA(ra) * * for iy from 0 <= iy < ny: # <<<<<<<<<<<<<< * for ix from 0 <= ix < nx: * #rd[iy*nx + ix] = self._inside(i, j) */ __pyx_t_2 = __pyx_v_ny; for (__pyx_v_iy = 0; __pyx_v_iy < __pyx_t_2; __pyx_v_iy++) { /* "_region_filter.pyx":184 * * for iy from 0 <= iy < ny: * for ix from 0 <= ix < nx: # <<<<<<<<<<<<<< * #rd[iy*nx + ix] = self._inside(i, j) * # altenatively more optimized */ __pyx_t_3 = __pyx_v_nx; for (__pyx_v_ix = 0; __pyx_v_ix < __pyx_t_3; __pyx_v_ix++) { /* "_region_filter.pyx":188 * # altenatively more optimized * #rd[0] = self._inside(ix+1, iy+1) # +1 for (1,1) based.. * rd[0] = self._inside(ix, iy) # <<<<<<<<<<<<<< * rd = rd + 1 * */ (__pyx_v_rd[0]) = ((struct __pyx_vtabstruct_14_region_filter_RegionBase *)__pyx_v_self->__pyx_vtab)->_inside(__pyx_v_self, __pyx_v_ix, __pyx_v_iy); /* "_region_filter.pyx":189 * #rd[0] = self._inside(ix+1, iy+1) # +1 for (1,1) based.. * rd[0] = self._inside(ix, iy) * rd = rd + 1 # <<<<<<<<<<<<<< * * return ra */ __pyx_v_rd = (__pyx_v_rd + 1); } } /* "_region_filter.pyx":191 * rd = rd + 1 * * return ra # <<<<<<<<<<<<<< * * def inside1(self, double x, double y): */ __Pyx_XDECREF(((PyObject *)__pyx_r)); __Pyx_INCREF(((PyObject *)__pyx_v_ra)); __pyx_r = __pyx_v_ra; goto __pyx_L0; __pyx_r = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.RegionBase._mask"); __pyx_r = 0; __pyx_L0:; __Pyx_DECREF((PyObject *)__pyx_v_ra); __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":193 * return ra * * def inside1(self, double x, double y): # <<<<<<<<<<<<<< * """ * inside1(float, float) : returns True if the point (x,y) is inside the filter. */ static PyObject *__pyx_pf_14_region_filter_10RegionBase_6inside1(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_14_region_filter_10RegionBase_6inside1[] = "\n inside1(float, float) : returns True if the point (x,y) is inside the filter.\n "; static PyObject *__pyx_pf_14_region_filter_10RegionBase_6inside1(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { double __pyx_v_x; double __pyx_v_y; PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__x,&__pyx_n_s__y,0}; __Pyx_RefNannySetupContext("inside1"); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[2] = {0,0}; switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("inside1", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "inside1") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_x = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_x == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_y = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_y == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { __pyx_v_x = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_x == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_y = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_y == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("inside1", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.RegionBase.inside1"); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; /* "_region_filter.pyx":197 * inside1(float, float) : returns True if the point (x,y) is inside the filter. * """ * return self._inside(x, y) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_to_py_npy_bool(((struct __pyx_vtabstruct_14_region_filter_RegionBase *)((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self)->__pyx_vtab)->_inside(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self), __pyx_v_x, __pyx_v_y)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.RegionBase.inside1"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":200 * * * def inside(self, x, y=None): # <<<<<<<<<<<<<< * if y is None: * if len(x.shape) == 2 and x.shape[-1] == 2: */ static PyObject *__pyx_pf_14_region_filter_10RegionBase_7inside(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_pf_14_region_filter_10RegionBase_7inside(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_x = 0; PyObject *__pyx_v_y = 0; PyObject *__pyx_r = NULL; int __pyx_t_1; PyObject *__pyx_t_2 = NULL; Py_ssize_t __pyx_t_3; PyObject *__pyx_t_4 = NULL; int __pyx_t_5; int __pyx_t_6; PyObject *__pyx_t_7 = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__x,&__pyx_n_s__y,0}; __Pyx_RefNannySetupContext("inside"); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[2] = {0,0}; values[1] = ((PyObject *)Py_None); switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y); if (value) { values[1] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "inside") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_x = values[0]; __pyx_v_y = values[1]; } else { __pyx_v_y = ((PyObject *)Py_None); switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: __pyx_v_y = PyTuple_GET_ITEM(__pyx_args, 1); case 1: __pyx_v_x = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("inside", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.RegionBase.inside"); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; /* "_region_filter.pyx":201 * * def inside(self, x, y=None): * if y is None: # <<<<<<<<<<<<<< * if len(x.shape) == 2 and x.shape[-1] == 2: * return self.inside_xy(x) */ __pyx_t_1 = (__pyx_v_y == Py_None); if (__pyx_t_1) { /* "_region_filter.pyx":202 * def inside(self, x, y=None): * if y is None: * if len(x.shape) == 2 and x.shape[-1] == 2: # <<<<<<<<<<<<<< * return self.inside_xy(x) * else: */ __pyx_t_2 = PyObject_GetAttr(__pyx_v_x, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_1 = (__pyx_t_3 == 2); if (__pyx_t_1) { __pyx_t_2 = PyObject_GetAttr(__pyx_v_x, __pyx_n_s__shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_int_2, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_6 = __pyx_t_5; } else { __pyx_t_6 = __pyx_t_1; } if (__pyx_t_6) { /* "_region_filter.pyx":203 * if y is None: * if len(x.shape) == 2 and x.shape[-1] == 2: * return self.inside_xy(x) # <<<<<<<<<<<<<< * else: * raise ValueError("input array has a wrong shape") */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__inside_xy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __Pyx_INCREF(__pyx_v_x); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_x); __Pyx_GIVEREF(__pyx_v_x); __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L0; goto __pyx_L7; } /*else*/ { /* "_region_filter.pyx":205 * return self.inside_xy(x) * else: * raise ValueError("input array has a wrong shape") # <<<<<<<<<<<<<< * else: * return self.inside_x_y(x, y) */ __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_Raise(__pyx_t_7, 0, 0); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L7:; goto __pyx_L6; } /*else*/ { /* "_region_filter.pyx":207 * raise ValueError("input array has a wrong shape") * else: * return self.inside_x_y(x, y) # <<<<<<<<<<<<<< * * def inside_xy(self, xy): */ __Pyx_XDECREF(__pyx_r); __pyx_t_7 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__inside_x_y); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __Pyx_INCREF(__pyx_v_x); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_x); __Pyx_GIVEREF(__pyx_v_x); __Pyx_INCREF(__pyx_v_y); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_y); __Pyx_GIVEREF(__pyx_v_y); __pyx_t_2 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; } __pyx_L6:; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("_region_filter.RegionBase.inside"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":209 * return self.inside_x_y(x, y) * * def inside_xy(self, xy): # <<<<<<<<<<<<<< * """ * inside(x, y) : given the numpy array of x and y, returns an */ static PyObject *__pyx_pf_14_region_filter_10RegionBase_8inside_xy(PyObject *__pyx_v_self, PyObject *__pyx_v_xy); /*proto*/ static char __pyx_doc_14_region_filter_10RegionBase_8inside_xy[] = "\n inside(x, y) : given the numpy array of x and y, returns an\n array b of same shape, where b[i] = inside1(x[i], y[i])\n "; static PyObject *__pyx_pf_14_region_filter_10RegionBase_8inside_xy(PyObject *__pyx_v_self, PyObject *__pyx_v_xy) { PyArrayObject *__pyx_v_xya; PyArrayObject *__pyx_v_ra; double *__pyx_v_xyd; npy_bool *__pyx_v_rd; int __pyx_v_i; int __pyx_v_n; PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; int __pyx_t_2; __Pyx_RefNannySetupContext("inside_xy"); __pyx_v_xya = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_v_ra = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); /* "_region_filter.pyx":221 * cdef int n * * xya = c_numpy.PyArray_ContiguousFromAny(xy, c_numpy.NPY_DOUBLE, 1, 0) # <<<<<<<<<<<<<< * * ra = c_numpy.PyArray_EMPTY(1, xya.dimensions, */ __pyx_t_1 = PyArray_ContiguousFromAny(__pyx_v_xy, NPY_DOUBLE, 1, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7c_numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_v_xya)); __pyx_v_xya = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":224 * * ra = c_numpy.PyArray_EMPTY(1, xya.dimensions, * c_numpy.NPY_BOOL, 0) # <<<<<<<<<<<<<< * * xyd = c_numpy.PyArray_DATA(xya) */ __pyx_t_1 = PyArray_EMPTY(1, __pyx_v_xya->dimensions, NPY_BOOL, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7c_numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_v_ra)); __pyx_v_ra = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":226 * c_numpy.NPY_BOOL, 0) * * xyd = c_numpy.PyArray_DATA(xya) # <<<<<<<<<<<<<< * rd = c_numpy.PyArray_DATA(ra) * */ __pyx_v_xyd = ((double *)PyArray_DATA(__pyx_v_xya)); /* "_region_filter.pyx":227 * * xyd = c_numpy.PyArray_DATA(xya) * rd = c_numpy.PyArray_DATA(ra) # <<<<<<<<<<<<<< * * n = xya.dimensions[0] # c_numpy.PyArray_SIZE(xya) / 2 */ __pyx_v_rd = ((npy_bool *)PyArray_DATA(__pyx_v_ra)); /* "_region_filter.pyx":229 * rd = c_numpy.PyArray_DATA(ra) * * n = xya.dimensions[0] # c_numpy.PyArray_SIZE(xya) / 2 # <<<<<<<<<<<<<< * #_inside_ptr = self._inside * for i from 0 <= i < n: */ __pyx_v_n = (__pyx_v_xya->dimensions[0]); /* "_region_filter.pyx":231 * n = xya.dimensions[0] # c_numpy.PyArray_SIZE(xya) / 2 * #_inside_ptr = self._inside * for i from 0 <= i < n: # <<<<<<<<<<<<<< * rd[i] = self._inside(xyd[2*i], xyd[2*i+1]) * return ra */ __pyx_t_2 = __pyx_v_n; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { /* "_region_filter.pyx":232 * #_inside_ptr = self._inside * for i from 0 <= i < n: * rd[i] = self._inside(xyd[2*i], xyd[2*i+1]) # <<<<<<<<<<<<<< * return ra * */ (__pyx_v_rd[__pyx_v_i]) = ((struct __pyx_vtabstruct_14_region_filter_RegionBase *)((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self)->__pyx_vtab)->_inside(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self), (__pyx_v_xyd[(2 * __pyx_v_i)]), (__pyx_v_xyd[((2 * __pyx_v_i) + 1)])); } /* "_region_filter.pyx":233 * for i from 0 <= i < n: * rd[i] = self._inside(xyd[2*i], xyd[2*i+1]) * return ra # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_ra)); __pyx_r = ((PyObject *)__pyx_v_ra); goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.RegionBase.inside_xy"); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF((PyObject *)__pyx_v_xya); __Pyx_DECREF((PyObject *)__pyx_v_ra); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":236 * * * def inside_x_y(self, x, y): # <<<<<<<<<<<<<< * """ * inside(x, y) : given the numpy array of x and y, returns an */ static PyObject *__pyx_pf_14_region_filter_10RegionBase_9inside_x_y(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_14_region_filter_10RegionBase_9inside_x_y[] = "\n inside(x, y) : given the numpy array of x and y, returns an\n array b of same shape, where b[i] = inside1(x[i], y[i])\n "; static PyObject *__pyx_pf_14_region_filter_10RegionBase_9inside_x_y(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_x = 0; PyObject *__pyx_v_y = 0; PyArrayObject *__pyx_v_xa; PyArrayObject *__pyx_v_ya; PyArrayObject *__pyx_v_ra; double *__pyx_v_xd; double *__pyx_v_yd; npy_bool *__pyx_v_rd; int __pyx_v_i; int __pyx_v_n; PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; int __pyx_t_2; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__x,&__pyx_n_s__y,0}; __Pyx_RefNannySetupContext("inside_x_y"); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[2] = {0,0}; switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("inside_x_y", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "inside_x_y") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_x = values[0]; __pyx_v_y = values[1]; } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { __pyx_v_x = PyTuple_GET_ITEM(__pyx_args, 0); __pyx_v_y = PyTuple_GET_ITEM(__pyx_args, 1); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("inside_x_y", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.RegionBase.inside_x_y"); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_v_xa = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_v_ya = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_v_ra = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); /* "_region_filter.pyx":253 * # FIX : check if two input has identical shape * * xa = c_numpy.PyArray_ContiguousFromAny(x, c_numpy.NPY_DOUBLE, 1, 0) # <<<<<<<<<<<<<< * ya = c_numpy.PyArray_ContiguousFromAny(y, c_numpy.NPY_DOUBLE, 1, 0) * */ __pyx_t_1 = PyArray_ContiguousFromAny(__pyx_v_x, NPY_DOUBLE, 1, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7c_numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_v_xa)); __pyx_v_xa = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":254 * * xa = c_numpy.PyArray_ContiguousFromAny(x, c_numpy.NPY_DOUBLE, 1, 0) * ya = c_numpy.PyArray_ContiguousFromAny(y, c_numpy.NPY_DOUBLE, 1, 0) # <<<<<<<<<<<<<< * * ra = c_numpy.PyArray_EMPTY(xa.nd, xa.dimensions, */ __pyx_t_1 = PyArray_ContiguousFromAny(__pyx_v_y, NPY_DOUBLE, 1, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7c_numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_v_ya)); __pyx_v_ya = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":257 * * ra = c_numpy.PyArray_EMPTY(xa.nd, xa.dimensions, * c_numpy.NPY_BOOL, 0) # <<<<<<<<<<<<<< * * xd = c_numpy.PyArray_DATA(xa) */ __pyx_t_1 = PyArray_EMPTY(__pyx_v_xa->nd, __pyx_v_xa->dimensions, NPY_BOOL, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7c_numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_v_ra)); __pyx_v_ra = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":259 * c_numpy.NPY_BOOL, 0) * * xd = c_numpy.PyArray_DATA(xa) # <<<<<<<<<<<<<< * yd = c_numpy.PyArray_DATA(ya) * rd = c_numpy.PyArray_DATA(ra) */ __pyx_v_xd = ((double *)PyArray_DATA(__pyx_v_xa)); /* "_region_filter.pyx":260 * * xd = c_numpy.PyArray_DATA(xa) * yd = c_numpy.PyArray_DATA(ya) # <<<<<<<<<<<<<< * rd = c_numpy.PyArray_DATA(ra) * */ __pyx_v_yd = ((double *)PyArray_DATA(__pyx_v_ya)); /* "_region_filter.pyx":261 * xd = c_numpy.PyArray_DATA(xa) * yd = c_numpy.PyArray_DATA(ya) * rd = c_numpy.PyArray_DATA(ra) # <<<<<<<<<<<<<< * * n = c_numpy.PyArray_SIZE(xa) */ __pyx_v_rd = ((npy_bool *)PyArray_DATA(__pyx_v_ra)); /* "_region_filter.pyx":263 * rd = c_numpy.PyArray_DATA(ra) * * n = c_numpy.PyArray_SIZE(xa) # <<<<<<<<<<<<<< * #_inside_ptr = self._inside * for i from 0 <= i < n: */ __pyx_v_n = PyArray_SIZE(__pyx_v_xa); /* "_region_filter.pyx":265 * n = c_numpy.PyArray_SIZE(xa) * #_inside_ptr = self._inside * for i from 0 <= i < n: # <<<<<<<<<<<<<< * #self._inside(xd[0], yd[0]) * #rd[i] = _inside_ptr(self, xd[i], yd[i]) */ __pyx_t_2 = __pyx_v_n; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { /* "_region_filter.pyx":268 * #self._inside(xd[0], yd[0]) * #rd[i] = _inside_ptr(self, xd[i], yd[i]) * rd[i] = self._inside(xd[i], yd[i]) # <<<<<<<<<<<<<< * #rd[i] = _inside_ptr(self, xd[i], yd[i]) * #print xd[i], yd[i], rd[i] */ (__pyx_v_rd[__pyx_v_i]) = ((struct __pyx_vtabstruct_14_region_filter_RegionBase *)((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self)->__pyx_vtab)->_inside(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self), (__pyx_v_xd[__pyx_v_i]), (__pyx_v_yd[__pyx_v_i])); } /* "_region_filter.pyx":271 * #rd[i] = _inside_ptr(self, xd[i], yd[i]) * #print xd[i], yd[i], rd[i] * return ra # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_ra)); __pyx_r = ((PyObject *)__pyx_v_ra); goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.RegionBase.inside_x_y"); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF((PyObject *)__pyx_v_xa); __Pyx_DECREF((PyObject *)__pyx_v_ya); __Pyx_DECREF((PyObject *)__pyx_v_ra); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":316 * cdef RegionBase child_region * * def __init__(self, RegionBase child_region): # <<<<<<<<<<<<<< * self.child_region = child_region * */ static int __pyx_pf_14_region_filter_9RegionNot___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pf_14_region_filter_9RegionNot___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_child_region = 0; int __pyx_r; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__child_region,0}; __Pyx_RefNannySetupContext("__init__"); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[1] = {0}; switch (PyTuple_GET_SIZE(__pyx_args)) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__child_region); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)values[0]); } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; } else { __pyx_v_child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)PyTuple_GET_ITEM(__pyx_args, 0)); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.RegionNot.__init__"); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_child_region), __pyx_ptype_14_region_filter_RegionBase, 1, "child_region", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":317 * * def __init__(self, RegionBase child_region): * self.child_region = child_region # <<<<<<<<<<<<<< * * cdef npy_bool _inside(self, double x, double y): */ __Pyx_INCREF(((PyObject *)__pyx_v_child_region)); __Pyx_GIVEREF(((PyObject *)__pyx_v_child_region)); __Pyx_GOTREF(((struct __pyx_obj_14_region_filter_RegionNot *)__pyx_v_self)->child_region); __Pyx_DECREF(((PyObject *)((struct __pyx_obj_14_region_filter_RegionNot *)__pyx_v_self)->child_region)); ((struct __pyx_obj_14_region_filter_RegionNot *)__pyx_v_self)->child_region = __pyx_v_child_region; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("_region_filter.RegionNot.__init__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":319 * self.child_region = child_region * * cdef npy_bool _inside(self, double x, double y): # <<<<<<<<<<<<<< * return not(self.child_region._inside(x, y)) * */ static npy_bool __pyx_f_14_region_filter_9RegionNot__inside(struct __pyx_obj_14_region_filter_RegionNot *__pyx_v_self, double __pyx_v_x, double __pyx_v_y) { npy_bool __pyx_r; __Pyx_RefNannySetupContext("_inside"); /* "_region_filter.pyx":320 * * cdef npy_bool _inside(self, double x, double y): * return not(self.child_region._inside(x, y)) # <<<<<<<<<<<<<< * * */ __pyx_r = (!((struct __pyx_vtabstruct_14_region_filter_RegionBase *)__pyx_v_self->child_region->__pyx_vtab)->_inside(__pyx_v_self->child_region, __pyx_v_x, __pyx_v_y)); goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":326 * cdef object child_regions * * def _check_type_of_list(self, kl): # <<<<<<<<<<<<<< * for k in kl: * if not isinstance(k, RegionBase): */ static PyObject *__pyx_pf_14_region_filter_10RegionList__check_type_of_list(PyObject *__pyx_v_self, PyObject *__pyx_v_kl); /*proto*/ static PyObject *__pyx_pf_14_region_filter_10RegionList__check_type_of_list(PyObject *__pyx_v_self, PyObject *__pyx_v_kl) { PyObject *__pyx_v_k; PyObject *__pyx_r = NULL; Py_ssize_t __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; int __pyx_t_5; PyObject *__pyx_t_6 = NULL; __Pyx_RefNannySetupContext("_check_type_of_list"); __pyx_v_k = Py_None; __Pyx_INCREF(Py_None); /* "_region_filter.pyx":327 * * def _check_type_of_list(self, kl): * for k in kl: # <<<<<<<<<<<<<< * if not isinstance(k, RegionBase): * raise TypeError("All elements should be subclass of RegionBase type: %s" % k) */ if (PyList_CheckExact(__pyx_v_kl) || PyTuple_CheckExact(__pyx_v_kl)) { __pyx_t_1 = 0; __pyx_t_2 = __pyx_v_kl; __Pyx_INCREF(__pyx_t_2); } else { __pyx_t_1 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_kl); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); } for (;;) { if (likely(PyList_CheckExact(__pyx_t_2))) { if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_2)) break; __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; } else if (likely(PyTuple_CheckExact(__pyx_t_2))) { if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_2)) break; __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; } else { __pyx_t_3 = PyIter_Next(__pyx_t_2); if (!__pyx_t_3) { if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;} break; } __Pyx_GOTREF(__pyx_t_3); } __Pyx_DECREF(__pyx_v_k); __pyx_v_k = __pyx_t_3; __pyx_t_3 = 0; /* "_region_filter.pyx":328 * def _check_type_of_list(self, kl): * for k in kl: * if not isinstance(k, RegionBase): # <<<<<<<<<<<<<< * raise TypeError("All elements should be subclass of RegionBase type: %s" % k) * */ __pyx_t_4 = __Pyx_TypeCheck(__pyx_v_k, ((PyObject*)__pyx_ptype_14_region_filter_RegionBase)); __pyx_t_5 = (!__pyx_t_4); if (__pyx_t_5) { /* "_region_filter.pyx":329 * for k in kl: * if not isinstance(k, RegionBase): * raise TypeError("All elements should be subclass of RegionBase type: %s" % k) # <<<<<<<<<<<<<< * * def __init__(self, *kl): */ __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), __pyx_v_k); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_6)); PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; __Pyx_Raise(__pyx_t_3, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L7; } __pyx_L7:; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("_region_filter.RegionList._check_type_of_list"); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(__pyx_v_k); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":331 * raise TypeError("All elements should be subclass of RegionBase type: %s" % k) * * def __init__(self, *kl): # <<<<<<<<<<<<<< * self._check_type_of_list(kl) * self.child_regions = list(kl) */ static int __pyx_pf_14_region_filter_10RegionList_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pf_14_region_filter_10RegionList_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_kl = 0; int __pyx_r; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannySetupContext("__init__"); if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; __Pyx_INCREF(__pyx_args); __pyx_v_kl = __pyx_args; /* "_region_filter.pyx":332 * * def __init__(self, *kl): * self._check_type_of_list(kl) # <<<<<<<<<<<<<< * self.child_regions = list(kl) * */ __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___check_type_of_list); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(((PyObject *)__pyx_v_kl)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_kl)); __Pyx_GIVEREF(((PyObject *)__pyx_v_kl)); __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "_region_filter.pyx":333 * def __init__(self, *kl): * self._check_type_of_list(kl) * self.child_regions = list(kl) # <<<<<<<<<<<<<< * * def __len__(self): */ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_INCREF(((PyObject *)__pyx_v_kl)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_kl)); __Pyx_GIVEREF(((PyObject *)__pyx_v_kl)); __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(((struct __pyx_obj_14_region_filter_RegionList *)__pyx_v_self)->child_regions); __Pyx_DECREF(((struct __pyx_obj_14_region_filter_RegionList *)__pyx_v_self)->child_regions); ((struct __pyx_obj_14_region_filter_RegionList *)__pyx_v_self)->child_regions = __pyx_t_2; __pyx_t_2 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("_region_filter.RegionList.__init__"); __pyx_r = -1; __pyx_L0:; __Pyx_DECREF(__pyx_v_kl); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":335 * self.child_regions = list(kl) * * def __len__(self): # <<<<<<<<<<<<<< * return len(self.child_regions) * */ static Py_ssize_t __pyx_pf_14_region_filter_10RegionList_2__len__(PyObject *__pyx_v_self); /*proto*/ static Py_ssize_t __pyx_pf_14_region_filter_10RegionList_2__len__(PyObject *__pyx_v_self) { Py_ssize_t __pyx_r; PyObject *__pyx_t_1 = NULL; Py_ssize_t __pyx_t_2; __Pyx_RefNannySetupContext("__len__"); /* "_region_filter.pyx":336 * * def __len__(self): * return len(self.child_regions) # <<<<<<<<<<<<<< * * def __getitem__(self, Py_ssize_t x): */ __pyx_t_1 = ((struct __pyx_obj_14_region_filter_RegionList *)__pyx_v_self)->child_regions; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.RegionList.__len__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":338 * return len(self.child_regions) * * def __getitem__(self, Py_ssize_t x): # <<<<<<<<<<<<<< * return self.child_regions[x] * */ static PyObject *__pyx_pf_14_region_filter_10RegionList_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_x); /*proto*/ static PyObject *__pyx_pf_14_region_filter_10RegionList_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_x) { Py_ssize_t __pyx_v_x; PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__getitem__"); assert(__pyx_arg_x); { __pyx_v_x = __Pyx_PyIndex_AsSsize_t(__pyx_arg_x); if (unlikely((__pyx_v_x == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.RegionList.__getitem__"); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; /* "_region_filter.pyx":339 * * def __getitem__(self, Py_ssize_t x): * return self.child_regions[x] # <<<<<<<<<<<<<< * * def __setitem__(self, Py_ssize_t x, RegionBase y): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_GetItemInt(((struct __pyx_obj_14_region_filter_RegionList *)__pyx_v_self)->child_regions, __pyx_v_x, sizeof(Py_ssize_t), PyInt_FromSsize_t); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.RegionList.__getitem__"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":341 * return self.child_regions[x] * * def __setitem__(self, Py_ssize_t x, RegionBase y): # <<<<<<<<<<<<<< * self.child_regions[x] = y * */ static int __pyx_pf_14_region_filter_10RegionList_4__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_x, PyObject *__pyx_v_y); /*proto*/ static int __pyx_pf_14_region_filter_10RegionList_4__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_x, PyObject *__pyx_v_y) { Py_ssize_t __pyx_v_x; int __pyx_r; __Pyx_RefNannySetupContext("__setitem__"); assert(__pyx_arg_x); { __pyx_v_x = __Pyx_PyIndex_AsSsize_t(__pyx_arg_x); if (unlikely((__pyx_v_x == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.RegionList.__setitem__"); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_14_region_filter_RegionBase, 1, "y", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":342 * * def __setitem__(self, Py_ssize_t x, RegionBase y): * self.child_regions[x] = y # <<<<<<<<<<<<<< * * def __delitem__(self, Py_ssize_t x): */ if (__Pyx_SetItemInt(((struct __pyx_obj_14_region_filter_RegionList *)__pyx_v_self)->child_regions, __pyx_v_x, __pyx_v_y, sizeof(Py_ssize_t), PyInt_FromSsize_t) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("_region_filter.RegionList.__setitem__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":344 * self.child_regions[x] = y * * def __delitem__(self, Py_ssize_t x): # <<<<<<<<<<<<<< * del self.child_regions[x] * */ static int __pyx_pf_14_region_filter_10RegionList_5__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_x); /*proto*/ static int __pyx_pf_14_region_filter_10RegionList_5__delitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_x) { Py_ssize_t __pyx_v_x; int __pyx_r; __Pyx_RefNannySetupContext("__delitem__"); assert(__pyx_arg_x); { __pyx_v_x = __Pyx_PyIndex_AsSsize_t(__pyx_arg_x); if (unlikely((__pyx_v_x == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.RegionList.__delitem__"); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; /* "_region_filter.pyx":345 * * def __delitem__(self, Py_ssize_t x): * del self.child_regions[x] # <<<<<<<<<<<<<< * * # def __getslice__(self, Py_ssize_t i, Py_ssize_t j): */ if (__Pyx_DelItemInt(((struct __pyx_obj_14_region_filter_RegionList *)__pyx_v_self)->child_regions, __pyx_v_x, sizeof(Py_ssize_t), PyInt_FromSsize_t) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("_region_filter.RegionList.__delitem__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":357 * # del self.child_regions[i:j] * * def __contains__(self, RegionBase x): # <<<<<<<<<<<<<< * return x in self.child_regions * */ static int __pyx_pf_14_region_filter_10RegionList_6__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_x); /*proto*/ static int __pyx_pf_14_region_filter_10RegionList_6__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_x) { int __pyx_r; int __pyx_t_1; __Pyx_RefNannySetupContext("__contains__"); if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_14_region_filter_RegionBase, 1, "x", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":358 * * def __contains__(self, RegionBase x): * return x in self.child_regions # <<<<<<<<<<<<<< * * def __repr__(self): */ __pyx_t_1 = ((PySequence_Contains(((struct __pyx_obj_14_region_filter_RegionList *)__pyx_v_self)->child_regions, __pyx_v_x))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_t_1; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("_region_filter.RegionList.__contains__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":360 * return x in self.child_regions * * def __repr__(self): # <<<<<<<<<<<<<< * return repr(self.child_regions) * */ static PyObject *__pyx_pf_14_region_filter_10RegionList_7__repr__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pf_14_region_filter_10RegionList_7__repr__(PyObject *__pyx_v_self) { PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__repr__"); /* "_region_filter.pyx":361 * * def __repr__(self): * return repr(self.child_regions) # <<<<<<<<<<<<<< * * def asList(self): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = ((struct __pyx_obj_14_region_filter_RegionList *)__pyx_v_self)->child_regions; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = PyObject_Repr(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("_region_filter.RegionList.__repr__"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":363 * return repr(self.child_regions) * * def asList(self): # <<<<<<<<<<<<<< * return self.child_regions * */ static PyObject *__pyx_pf_14_region_filter_10RegionList_8asList(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pf_14_region_filter_10RegionList_8asList(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = NULL; __Pyx_RefNannySetupContext("asList"); /* "_region_filter.pyx":364 * * def asList(self): * return self.child_regions # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((struct __pyx_obj_14_region_filter_RegionList *)__pyx_v_self)->child_regions); __pyx_r = ((struct __pyx_obj_14_region_filter_RegionList *)__pyx_v_self)->child_regions; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":371 * >>> r = RegionOrList(r1, r2, r3, r4, ...) * """ * cdef npy_bool _inside(self, double x, double y): # <<<<<<<<<<<<<< * cdef c_python.PyListObject *child_regions * cdef int i, n */ static npy_bool __pyx_f_14_region_filter_12RegionOrList__inside(struct __pyx_obj_14_region_filter_RegionOrList *__pyx_v_self, double __pyx_v_x, double __pyx_v_y) { PyListObject *__pyx_v_child_regions; int __pyx_v_i; int __pyx_v_n; npy_bool __pyx_r; int __pyx_t_1; void *__pyx_t_2; npy_bool __pyx_t_3; __Pyx_RefNannySetupContext("_inside"); /* "_region_filter.pyx":375 * cdef int i, n * * child_regions = self.child_regions # <<<<<<<<<<<<<< * n = c_python.PyList_GET_SIZE(child_regions) * for i from 0 <= i < n: */ __pyx_v_child_regions = ((PyListObject *)__pyx_v_self->__pyx_base.child_regions); /* "_region_filter.pyx":376 * * child_regions = self.child_regions * n = c_python.PyList_GET_SIZE(child_regions) # <<<<<<<<<<<<<< * for i from 0 <= i < n: * if ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): */ __pyx_v_n = PyList_GET_SIZE(__pyx_v_child_regions); /* "_region_filter.pyx":377 * child_regions = self.child_regions * n = c_python.PyList_GET_SIZE(child_regions) * for i from 0 <= i < n: # <<<<<<<<<<<<<< * if ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): * return 1 */ __pyx_t_1 = __pyx_v_n; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { /* "_region_filter.pyx":378 * n = c_python.PyList_GET_SIZE(child_regions) * for i from 0 <= i < n: * if ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): # <<<<<<<<<<<<<< * return 1 * return 0 */ __pyx_t_2 = PyList_GET_ITEM(__pyx_v_child_regions, __pyx_v_i); __pyx_t_3 = ((struct __pyx_vtabstruct_14_region_filter_RegionBase *)((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_t_2)->__pyx_vtab)->_inside(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_t_2), __pyx_v_x, __pyx_v_y); if (__pyx_t_3) { /* "_region_filter.pyx":379 * for i from 0 <= i < n: * if ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): * return 1 # <<<<<<<<<<<<<< * return 0 * */ __pyx_r = 1; goto __pyx_L0; goto __pyx_L5; } __pyx_L5:; } /* "_region_filter.pyx":380 * if ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): * return 1 * return 0 # <<<<<<<<<<<<<< * * */ __pyx_r = 0; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":383 * * * def __repr__(self): # <<<<<<<<<<<<<< * return "Or"+repr(self.child_regions) * */ static PyObject *__pyx_pf_14_region_filter_12RegionOrList___repr__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pf_14_region_filter_12RegionOrList___repr__(PyObject *__pyx_v_self) { PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__repr__"); /* "_region_filter.pyx":384 * * def __repr__(self): * return "Or"+repr(self.child_regions) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = ((struct __pyx_obj_14_region_filter_RegionOrList *)__pyx_v_self)->__pyx_base.child_regions; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = PyObject_Repr(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_n_s__Or), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("_region_filter.RegionOrList.__repr__"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":393 * """ * * cdef npy_bool _inside(self, double x, double y): # <<<<<<<<<<<<<< * cdef c_python.PyListObject *child_regions * cdef int i, n */ static npy_bool __pyx_f_14_region_filter_13RegionAndList__inside(struct __pyx_obj_14_region_filter_RegionAndList *__pyx_v_self, double __pyx_v_x, double __pyx_v_y) { PyListObject *__pyx_v_child_regions; int __pyx_v_i; int __pyx_v_n; npy_bool __pyx_r; int __pyx_t_1; void *__pyx_t_2; int __pyx_t_3; __Pyx_RefNannySetupContext("_inside"); /* "_region_filter.pyx":397 * cdef int i, n * * child_regions = self.child_regions # <<<<<<<<<<<<<< * n = c_python.PyList_GET_SIZE(child_regions) * for i from 0 <= i < n: */ __pyx_v_child_regions = ((PyListObject *)__pyx_v_self->__pyx_base.child_regions); /* "_region_filter.pyx":398 * * child_regions = self.child_regions * n = c_python.PyList_GET_SIZE(child_regions) # <<<<<<<<<<<<<< * for i from 0 <= i < n: * if not ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): */ __pyx_v_n = PyList_GET_SIZE(__pyx_v_child_regions); /* "_region_filter.pyx":399 * child_regions = self.child_regions * n = c_python.PyList_GET_SIZE(child_regions) * for i from 0 <= i < n: # <<<<<<<<<<<<<< * if not ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): * return 0 */ __pyx_t_1 = __pyx_v_n; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { /* "_region_filter.pyx":400 * n = c_python.PyList_GET_SIZE(child_regions) * for i from 0 <= i < n: * if not ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): # <<<<<<<<<<<<<< * return 0 * return 1 */ __pyx_t_2 = PyList_GET_ITEM(__pyx_v_child_regions, __pyx_v_i); __pyx_t_3 = (!((struct __pyx_vtabstruct_14_region_filter_RegionBase *)((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_t_2)->__pyx_vtab)->_inside(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_t_2), __pyx_v_x, __pyx_v_y)); if (__pyx_t_3) { /* "_region_filter.pyx":401 * for i from 0 <= i < n: * if not ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): * return 0 # <<<<<<<<<<<<<< * return 1 * */ __pyx_r = 0; goto __pyx_L0; goto __pyx_L5; } __pyx_L5:; } /* "_region_filter.pyx":402 * if not ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): * return 0 * return 1 # <<<<<<<<<<<<<< * * */ __pyx_r = 1; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":405 * * * def __repr__(self): # <<<<<<<<<<<<<< * return "And"+repr(self.child_regions) * */ static PyObject *__pyx_pf_14_region_filter_13RegionAndList___repr__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pf_14_region_filter_13RegionAndList___repr__(PyObject *__pyx_v_self) { PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("__repr__"); /* "_region_filter.pyx":406 * * def __repr__(self): * return "And"+repr(self.child_regions) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = ((struct __pyx_obj_14_region_filter_RegionAndList *)__pyx_v_self)->__pyx_base.child_regions; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = PyObject_Repr(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_n_s__And), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("_region_filter.RegionAndList.__repr__"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":409 * * * def RegionAnd(RegionBase region1, RegionBase region2): # <<<<<<<<<<<<<< * """ * >>> r = RegionAnd(reg1, reg2) */ static PyObject *__pyx_pf_14_region_filter_RegionAnd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_14_region_filter_RegionAnd[] = "\n >>> r = RegionAnd(reg1, reg2)\n "; static PyMethodDef __pyx_mdef_14_region_filter_RegionAnd = {__Pyx_NAMESTR("RegionAnd"), (PyCFunction)__pyx_pf_14_region_filter_RegionAnd, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14_region_filter_RegionAnd)}; static PyObject *__pyx_pf_14_region_filter_RegionAnd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_region1 = 0; struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_region2 = 0; PyObject *__pyx_v_region1_list; PyObject *__pyx_v_region2_list; PyObject *__pyx_r = NULL; int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__region1,&__pyx_n_s__region2,0}; __Pyx_RefNannySetupContext("RegionAnd"); __pyx_self = __pyx_self; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[2] = {0,0}; switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region1); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region2); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("RegionAnd", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "RegionAnd") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_region1 = ((struct __pyx_obj_14_region_filter_RegionBase *)values[0]); __pyx_v_region2 = ((struct __pyx_obj_14_region_filter_RegionBase *)values[1]); } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { __pyx_v_region1 = ((struct __pyx_obj_14_region_filter_RegionBase *)PyTuple_GET_ITEM(__pyx_args, 0)); __pyx_v_region2 = ((struct __pyx_obj_14_region_filter_RegionBase *)PyTuple_GET_ITEM(__pyx_args, 1)); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("RegionAnd", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.RegionAnd"); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_v_region1_list = Py_None; __Pyx_INCREF(Py_None); __pyx_v_region2_list = Py_None; __Pyx_INCREF(Py_None); if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_region1), __pyx_ptype_14_region_filter_RegionBase, 1, "region1", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_region2), __pyx_ptype_14_region_filter_RegionBase, 1, "region2", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":413 * >>> r = RegionAnd(reg1, reg2) * """ * if isinstance(region1, RegionAndList): # <<<<<<<<<<<<<< * region1_list = region1.asList() * else: */ __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_region1), ((PyObject*)__pyx_ptype_14_region_filter_RegionAndList)); if (__pyx_t_1) { /* "_region_filter.pyx":414 * """ * if isinstance(region1, RegionAndList): * region1_list = region1.asList() # <<<<<<<<<<<<<< * else: * region1_list = [region1] */ __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_region1), __pyx_n_s__asList); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_v_region1_list); __pyx_v_region1_list = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L6; } /*else*/ { /* "_region_filter.pyx":416 * region1_list = region1.asList() * else: * region1_list = [region1] # <<<<<<<<<<<<<< * * if isinstance(region2, RegionAndList): */ __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_INCREF(((PyObject *)__pyx_v_region1)); PyList_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_region1)); __Pyx_GIVEREF(((PyObject *)__pyx_v_region1)); __Pyx_DECREF(__pyx_v_region1_list); __pyx_v_region1_list = ((PyObject *)__pyx_t_3); __pyx_t_3 = 0; } __pyx_L6:; /* "_region_filter.pyx":418 * region1_list = [region1] * * if isinstance(region2, RegionAndList): # <<<<<<<<<<<<<< * region2_list = region2.asList() * else: */ __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_region2), ((PyObject*)__pyx_ptype_14_region_filter_RegionAndList)); if (__pyx_t_1) { /* "_region_filter.pyx":419 * * if isinstance(region2, RegionAndList): * region2_list = region2.asList() # <<<<<<<<<<<<<< * else: * region2_list = [region2] */ __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_region2), __pyx_n_s__asList); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_v_region2_list); __pyx_v_region2_list = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L7; } /*else*/ { /* "_region_filter.pyx":421 * region2_list = region2.asList() * else: * region2_list = [region2] # <<<<<<<<<<<<<< * * return RegionAndList(*(region1_list + region2_list)) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(((PyObject *)__pyx_v_region2)); PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_region2)); __Pyx_GIVEREF(((PyObject *)__pyx_v_region2)); __Pyx_DECREF(__pyx_v_region2_list); __pyx_v_region2_list = ((PyObject *)__pyx_t_2); __pyx_t_2 = 0; } __pyx_L7:; /* "_region_filter.pyx":423 * region2_list = [region2] * * return RegionAndList(*(region1_list + region2_list)) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyNumber_Add(__pyx_v_region1_list, __pyx_v_region2_list); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_14_region_filter_RegionAndList)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("_region_filter.RegionAnd"); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(__pyx_v_region1_list); __Pyx_DECREF(__pyx_v_region2_list); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":426 * * * def RegionOr(RegionBase region1, RegionBase region2): # <<<<<<<<<<<<<< * """ * >>> r = RegionOr(reg1, reg2) */ static PyObject *__pyx_pf_14_region_filter_1RegionOr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_14_region_filter_1RegionOr[] = "\n >>> r = RegionOr(reg1, reg2)\n "; static PyMethodDef __pyx_mdef_14_region_filter_1RegionOr = {__Pyx_NAMESTR("RegionOr"), (PyCFunction)__pyx_pf_14_region_filter_1RegionOr, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14_region_filter_1RegionOr)}; static PyObject *__pyx_pf_14_region_filter_1RegionOr(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_region1 = 0; struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_region2 = 0; PyObject *__pyx_v_region1_list; PyObject *__pyx_v_region2_list; PyObject *__pyx_r = NULL; int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__region1,&__pyx_n_s__region2,0}; __Pyx_RefNannySetupContext("RegionOr"); __pyx_self = __pyx_self; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[2] = {0,0}; switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region1); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region2); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("RegionOr", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "RegionOr") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_region1 = ((struct __pyx_obj_14_region_filter_RegionBase *)values[0]); __pyx_v_region2 = ((struct __pyx_obj_14_region_filter_RegionBase *)values[1]); } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { __pyx_v_region1 = ((struct __pyx_obj_14_region_filter_RegionBase *)PyTuple_GET_ITEM(__pyx_args, 0)); __pyx_v_region2 = ((struct __pyx_obj_14_region_filter_RegionBase *)PyTuple_GET_ITEM(__pyx_args, 1)); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("RegionOr", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.RegionOr"); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_v_region1_list = Py_None; __Pyx_INCREF(Py_None); __pyx_v_region2_list = Py_None; __Pyx_INCREF(Py_None); if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_region1), __pyx_ptype_14_region_filter_RegionBase, 1, "region1", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_region2), __pyx_ptype_14_region_filter_RegionBase, 1, "region2", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":430 * >>> r = RegionOr(reg1, reg2) * """ * if isinstance(region1, RegionOrList): # <<<<<<<<<<<<<< * region1_list = region1.asList() * else: */ __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_region1), ((PyObject*)__pyx_ptype_14_region_filter_RegionOrList)); if (__pyx_t_1) { /* "_region_filter.pyx":431 * """ * if isinstance(region1, RegionOrList): * region1_list = region1.asList() # <<<<<<<<<<<<<< * else: * region1_list = [region1] */ __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_region1), __pyx_n_s__asList); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_v_region1_list); __pyx_v_region1_list = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L6; } /*else*/ { /* "_region_filter.pyx":433 * region1_list = region1.asList() * else: * region1_list = [region1] # <<<<<<<<<<<<<< * * if isinstance(region2, RegionOrList): */ __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_INCREF(((PyObject *)__pyx_v_region1)); PyList_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_region1)); __Pyx_GIVEREF(((PyObject *)__pyx_v_region1)); __Pyx_DECREF(__pyx_v_region1_list); __pyx_v_region1_list = ((PyObject *)__pyx_t_3); __pyx_t_3 = 0; } __pyx_L6:; /* "_region_filter.pyx":435 * region1_list = [region1] * * if isinstance(region2, RegionOrList): # <<<<<<<<<<<<<< * region2_list = region2.asList() * else: */ __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_region2), ((PyObject*)__pyx_ptype_14_region_filter_RegionOrList)); if (__pyx_t_1) { /* "_region_filter.pyx":436 * * if isinstance(region2, RegionOrList): * region2_list = region2.asList() # <<<<<<<<<<<<<< * else: * region2_list = [region2] */ __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_region2), __pyx_n_s__asList); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_v_region2_list); __pyx_v_region2_list = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L7; } /*else*/ { /* "_region_filter.pyx":438 * region2_list = region2.asList() * else: * region2_list = [region2] # <<<<<<<<<<<<<< * * return RegionOrList(*(region1_list + region2_list)) */ __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(((PyObject *)__pyx_v_region2)); PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_region2)); __Pyx_GIVEREF(((PyObject *)__pyx_v_region2)); __Pyx_DECREF(__pyx_v_region2_list); __pyx_v_region2_list = ((PyObject *)__pyx_t_2); __pyx_t_2 = 0; } __pyx_L7:; /* "_region_filter.pyx":440 * region2_list = [region2] * * return RegionOrList(*(region1_list + region2_list)) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyNumber_Add(__pyx_v_region1_list, __pyx_v_region2_list); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_14_region_filter_RegionOrList)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("_region_filter.RegionOr"); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(__pyx_v_region1_list); __Pyx_DECREF(__pyx_v_region2_list); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":526 * cdef RegionBase child_region * * def __init__(self, RegionBase child_region): # <<<<<<<<<<<<<< * self.child_region = child_region * */ static int __pyx_pf_14_region_filter_9Transform___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pf_14_region_filter_9Transform___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_child_region = 0; int __pyx_r; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__child_region,0}; __Pyx_RefNannySetupContext("__init__"); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[1] = {0}; switch (PyTuple_GET_SIZE(__pyx_args)) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__child_region); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)values[0]); } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; } else { __pyx_v_child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)PyTuple_GET_ITEM(__pyx_args, 0)); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.Transform.__init__"); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_child_region), __pyx_ptype_14_region_filter_RegionBase, 1, "child_region", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":527 * * def __init__(self, RegionBase child_region): * self.child_region = child_region # <<<<<<<<<<<<<< * * */ __Pyx_INCREF(((PyObject *)__pyx_v_child_region)); __Pyx_GIVEREF(((PyObject *)__pyx_v_child_region)); __Pyx_GOTREF(((struct __pyx_obj_14_region_filter_Transform *)__pyx_v_self)->child_region); __Pyx_DECREF(((PyObject *)((struct __pyx_obj_14_region_filter_Transform *)__pyx_v_self)->child_region)); ((struct __pyx_obj_14_region_filter_Transform *)__pyx_v_self)->child_region = __pyx_v_child_region; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("_region_filter.Transform.__init__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":531 * * property child: * def __get__(self): # <<<<<<<<<<<<<< * return self.child_region * */ static PyObject *__pyx_pf_14_region_filter_9Transform_5child___get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pf_14_region_filter_9Transform_5child___get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannySetupContext("__get__"); /* "_region_filter.pyx":532 * property child: * def __get__(self): * return self.child_region # <<<<<<<<<<<<<< * * #def __del__(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)((struct __pyx_obj_14_region_filter_Transform *)__pyx_v_self)->child_region)); __pyx_r = ((PyObject *)((struct __pyx_obj_14_region_filter_Transform *)__pyx_v_self)->child_region); goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":538 * * * cdef int _transform(self, double x, double y, double *xp, double *yp): # <<<<<<<<<<<<<< * xp[0] = x * yp[0] = y */ static int __pyx_f_14_region_filter_9Transform__transform(struct __pyx_obj_14_region_filter_Transform *__pyx_v_self, double __pyx_v_x, double __pyx_v_y, double *__pyx_v_xp, double *__pyx_v_yp) { int __pyx_r; __Pyx_RefNannySetupContext("_transform"); /* "_region_filter.pyx":539 * * cdef int _transform(self, double x, double y, double *xp, double *yp): * xp[0] = x # <<<<<<<<<<<<<< * yp[0] = y * */ (__pyx_v_xp[0]) = __pyx_v_x; /* "_region_filter.pyx":540 * cdef int _transform(self, double x, double y, double *xp, double *yp): * xp[0] = x * yp[0] = y # <<<<<<<<<<<<<< * * cdef npy_bool _inside(self, double x, double y): */ (__pyx_v_yp[0]) = __pyx_v_y; __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":542 * yp[0] = y * * cdef npy_bool _inside(self, double x, double y): # <<<<<<<<<<<<<< * cdef double xp, yp * cdef npy_bool r */ static npy_bool __pyx_f_14_region_filter_9Transform__inside(struct __pyx_obj_14_region_filter_Transform *__pyx_v_self, double __pyx_v_x, double __pyx_v_y) { double __pyx_v_xp; double __pyx_v_yp; npy_bool __pyx_v_r; npy_bool __pyx_r; __Pyx_RefNannySetupContext("_inside"); /* "_region_filter.pyx":546 * cdef npy_bool r * * self._transform(x, y, &xp, &yp) # <<<<<<<<<<<<<< * r = self.child_region._inside(xp, yp) * */ ((struct __pyx_vtabstruct_14_region_filter_Transform *)__pyx_v_self->__pyx_base.__pyx_vtab)->_transform(__pyx_v_self, __pyx_v_x, __pyx_v_y, (&__pyx_v_xp), (&__pyx_v_yp)); /* "_region_filter.pyx":547 * * self._transform(x, y, &xp, &yp) * r = self.child_region._inside(xp, yp) # <<<<<<<<<<<<<< * * return r */ __pyx_v_r = ((struct __pyx_vtabstruct_14_region_filter_RegionBase *)__pyx_v_self->child_region->__pyx_vtab)->_inside(__pyx_v_self->child_region, __pyx_v_xp, __pyx_v_yp); /* "_region_filter.pyx":549 * r = self.child_region._inside(xp, yp) * * return r # <<<<<<<<<<<<<< * * */ __pyx_r = __pyx_v_r; goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":574 * cdef double origin_x, origin_y * * def __init__(self, RegionBase child_region, # <<<<<<<<<<<<<< * double degree, double origin_x, double origin_y): * cdef double theta */ static int __pyx_pf_14_region_filter_7Rotated___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pf_14_region_filter_7Rotated___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_child_region = 0; double __pyx_v_degree; double __pyx_v_origin_x; double __pyx_v_origin_y; double __pyx_v_theta; int __pyx_r; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__child_region,&__pyx_n_s__degree,&__pyx_n_s__origin_x,&__pyx_n_s__origin_y,0}; __Pyx_RefNannySetupContext("__init__"); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[4] = {0,0,0,0}; switch (PyTuple_GET_SIZE(__pyx_args)) { case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__child_region); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__degree); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__origin_x); if (likely(values[2])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__origin_y); if (likely(values[3])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)values[0]); __pyx_v_degree = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_degree == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_origin_x = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_origin_x == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_origin_y = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_origin_y == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { goto __pyx_L5_argtuple_error; } else { __pyx_v_child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)PyTuple_GET_ITEM(__pyx_args, 0)); __pyx_v_degree = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_degree == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_origin_x = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_origin_x == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_origin_y = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_origin_y == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.Rotated.__init__"); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_child_region), __pyx_ptype_14_region_filter_RegionBase, 1, "child_region", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":578 * cdef double theta * * Transform.__init__(self, child_region) # <<<<<<<<<<<<<< * * theta = degree / 180. * M_PI #3.1415926 */ __pyx_t_1 = PyObject_GetAttr(((PyObject *)((PyObject*)__pyx_ptype_14_region_filter_Transform)), __pyx_n_s____init__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_self); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self); __Pyx_GIVEREF(__pyx_v_self); __Pyx_INCREF(((PyObject *)__pyx_v_child_region)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_child_region)); __Pyx_GIVEREF(((PyObject *)__pyx_v_child_region)); __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "_region_filter.pyx":580 * Transform.__init__(self, child_region) * * theta = degree / 180. * M_PI #3.1415926 # <<<<<<<<<<<<<< * self.sin_theta = sin(theta) * self.cos_theta = cos(theta) */ __pyx_v_theta = ((__pyx_v_degree / 180.) * M_PI); /* "_region_filter.pyx":581 * * theta = degree / 180. * M_PI #3.1415926 * self.sin_theta = sin(theta) # <<<<<<<<<<<<<< * self.cos_theta = cos(theta) * */ ((struct __pyx_obj_14_region_filter_Rotated *)__pyx_v_self)->sin_theta = sin(__pyx_v_theta); /* "_region_filter.pyx":582 * theta = degree / 180. * M_PI #3.1415926 * self.sin_theta = sin(theta) * self.cos_theta = cos(theta) # <<<<<<<<<<<<<< * * self.origin_x = origin_x */ ((struct __pyx_obj_14_region_filter_Rotated *)__pyx_v_self)->cos_theta = cos(__pyx_v_theta); /* "_region_filter.pyx":584 * self.cos_theta = cos(theta) * * self.origin_x = origin_x # <<<<<<<<<<<<<< * self.origin_y = origin_y * */ ((struct __pyx_obj_14_region_filter_Rotated *)__pyx_v_self)->origin_x = __pyx_v_origin_x; /* "_region_filter.pyx":585 * * self.origin_x = origin_x * self.origin_y = origin_y # <<<<<<<<<<<<<< * * */ ((struct __pyx_obj_14_region_filter_Rotated *)__pyx_v_self)->origin_y = __pyx_v_origin_y; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("_region_filter.Rotated.__init__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":588 * * * cdef int _transform(self, double x, double y, double *xp, double *yp): # <<<<<<<<<<<<<< * cdef double x1, x2, y1, y2 * cdef double st, ct, ox, oy */ static int __pyx_f_14_region_filter_7Rotated__transform(struct __pyx_obj_14_region_filter_Rotated *__pyx_v_self, double __pyx_v_x, double __pyx_v_y, double *__pyx_v_xp, double *__pyx_v_yp) { double __pyx_v_x1; double __pyx_v_x2; double __pyx_v_y1; double __pyx_v_y2; double __pyx_v_st; double __pyx_v_ct; double __pyx_v_ox; double __pyx_v_oy; int __pyx_r; __Pyx_RefNannySetupContext("_transform"); /* "_region_filter.pyx":592 * cdef double st, ct, ox, oy * * st = self.sin_theta # <<<<<<<<<<<<<< * ct = self.cos_theta * ox = self.origin_x */ __pyx_v_st = __pyx_v_self->sin_theta; /* "_region_filter.pyx":593 * * st = self.sin_theta * ct = self.cos_theta # <<<<<<<<<<<<<< * ox = self.origin_x * oy = self.origin_y */ __pyx_v_ct = __pyx_v_self->cos_theta; /* "_region_filter.pyx":594 * st = self.sin_theta * ct = self.cos_theta * ox = self.origin_x # <<<<<<<<<<<<<< * oy = self.origin_y * */ __pyx_v_ox = __pyx_v_self->origin_x; /* "_region_filter.pyx":595 * ct = self.cos_theta * ox = self.origin_x * oy = self.origin_y # <<<<<<<<<<<<<< * * x1 = x - ox */ __pyx_v_oy = __pyx_v_self->origin_y; /* "_region_filter.pyx":597 * oy = self.origin_y * * x1 = x - ox # <<<<<<<<<<<<<< * y1 = y - oy * */ __pyx_v_x1 = (__pyx_v_x - __pyx_v_ox); /* "_region_filter.pyx":598 * * x1 = x - ox * y1 = y - oy # <<<<<<<<<<<<<< * * x2 = ct*x1 + st*y1 */ __pyx_v_y1 = (__pyx_v_y - __pyx_v_oy); /* "_region_filter.pyx":600 * y1 = y - oy * * x2 = ct*x1 + st*y1 # <<<<<<<<<<<<<< * y2 = -st*x1 + ct*y1 * */ __pyx_v_x2 = ((__pyx_v_ct * __pyx_v_x1) + (__pyx_v_st * __pyx_v_y1)); /* "_region_filter.pyx":601 * * x2 = ct*x1 + st*y1 * y2 = -st*x1 + ct*y1 # <<<<<<<<<<<<<< * * xp[0] = x2 + ox */ __pyx_v_y2 = (((-__pyx_v_st) * __pyx_v_x1) + (__pyx_v_ct * __pyx_v_y1)); /* "_region_filter.pyx":603 * y2 = -st*x1 + ct*y1 * * xp[0] = x2 + ox # <<<<<<<<<<<<<< * yp[0] = y2 + oy * */ (__pyx_v_xp[0]) = (__pyx_v_x2 + __pyx_v_ox); /* "_region_filter.pyx":604 * * xp[0] = x2 + ox * yp[0] = y2 + oy # <<<<<<<<<<<<<< * * */ (__pyx_v_yp[0]) = (__pyx_v_y2 + __pyx_v_oy); __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":618 * cdef double dy * * def __init__(self, RegionBase child_region, # <<<<<<<<<<<<<< * double dx, double dy): * */ static int __pyx_pf_14_region_filter_10Translated___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pf_14_region_filter_10Translated___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { struct __pyx_obj_14_region_filter_RegionBase *__pyx_v_child_region = 0; double __pyx_v_dx; double __pyx_v_dy; int __pyx_r; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__child_region,&__pyx_n_s__dx,&__pyx_n_s__dy,0}; __Pyx_RefNannySetupContext("__init__"); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[3] = {0,0,0}; switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__child_region); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dx); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 618; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dy); if (likely(values[2])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 618; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 618; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)values[0]); __pyx_v_dx = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_dx == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_dy = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_dy == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { __pyx_v_child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)PyTuple_GET_ITEM(__pyx_args, 0)); __pyx_v_dx = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_dx == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_dy = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_dy == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 618; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.Translated.__init__"); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_child_region), __pyx_ptype_14_region_filter_RegionBase, 1, "child_region", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 618; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":621 * double dx, double dy): * * Transform.__init__(self, child_region) # <<<<<<<<<<<<<< * * self.dx = dx */ __pyx_t_1 = PyObject_GetAttr(((PyObject *)((PyObject*)__pyx_ptype_14_region_filter_Transform)), __pyx_n_s____init__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_self); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self); __Pyx_GIVEREF(__pyx_v_self); __Pyx_INCREF(((PyObject *)__pyx_v_child_region)); PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_child_region)); __Pyx_GIVEREF(((PyObject *)__pyx_v_child_region)); __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "_region_filter.pyx":623 * Transform.__init__(self, child_region) * * self.dx = dx # <<<<<<<<<<<<<< * self.dy = dy * */ ((struct __pyx_obj_14_region_filter_Translated *)__pyx_v_self)->dx = __pyx_v_dx; /* "_region_filter.pyx":624 * * self.dx = dx * self.dy = dy # <<<<<<<<<<<<<< * * cdef int _transform(self, double x, double y, double *xp, double *yp): */ ((struct __pyx_obj_14_region_filter_Translated *)__pyx_v_self)->dy = __pyx_v_dy; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("_region_filter.Translated.__init__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":626 * self.dy = dy * * cdef int _transform(self, double x, double y, double *xp, double *yp): # <<<<<<<<<<<<<< * xp[0] = x - self.dx * yp[0] = y - self.dy */ static int __pyx_f_14_region_filter_10Translated__transform(struct __pyx_obj_14_region_filter_Translated *__pyx_v_self, double __pyx_v_x, double __pyx_v_y, double *__pyx_v_xp, double *__pyx_v_yp) { int __pyx_r; __Pyx_RefNannySetupContext("_transform"); /* "_region_filter.pyx":627 * * cdef int _transform(self, double x, double y, double *xp, double *yp): * xp[0] = x - self.dx # <<<<<<<<<<<<<< * yp[0] = y - self.dy * */ (__pyx_v_xp[0]) = (__pyx_v_x - __pyx_v_self->dx); /* "_region_filter.pyx":628 * cdef int _transform(self, double x, double y, double *xp, double *yp): * xp[0] = x - self.dx * yp[0] = y - self.dy # <<<<<<<<<<<<<< * * */ (__pyx_v_yp[0]) = (__pyx_v_y - __pyx_v_self->dy); __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":652 * * * cdef _set_v(self, double xc, double yc, double radius): # <<<<<<<<<<<<<< * self.xc = xc * self.yc = yc */ static PyObject *__pyx_f_14_region_filter_6Circle__set_v(struct __pyx_obj_14_region_filter_Circle *__pyx_v_self, double __pyx_v_xc, double __pyx_v_yc, double __pyx_v_radius) { PyObject *__pyx_r = NULL; __Pyx_RefNannySetupContext("_set_v"); /* "_region_filter.pyx":653 * * cdef _set_v(self, double xc, double yc, double radius): * self.xc = xc # <<<<<<<<<<<<<< * self.yc = yc * self.radius = radius */ __pyx_v_self->xc = __pyx_v_xc; /* "_region_filter.pyx":654 * cdef _set_v(self, double xc, double yc, double radius): * self.xc = xc * self.yc = yc # <<<<<<<<<<<<<< * self.radius = radius * self.radius2 = radius*radius */ __pyx_v_self->yc = __pyx_v_yc; /* "_region_filter.pyx":655 * self.xc = xc * self.yc = yc * self.radius = radius # <<<<<<<<<<<<<< * self.radius2 = radius*radius * */ __pyx_v_self->radius = __pyx_v_radius; /* "_region_filter.pyx":656 * self.yc = yc * self.radius = radius * self.radius2 = radius*radius # <<<<<<<<<<<<<< * * cdef _get_v(self): */ __pyx_v_self->radius2 = (__pyx_v_radius * __pyx_v_radius); __pyx_r = Py_None; __Pyx_INCREF(Py_None); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":658 * self.radius2 = radius*radius * * cdef _get_v(self): # <<<<<<<<<<<<<< * return (self.xc, self.yc, self.radius) * */ static PyObject *__pyx_f_14_region_filter_6Circle__get_v(struct __pyx_obj_14_region_filter_Circle *__pyx_v_self) { PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("_get_v"); /* "_region_filter.pyx":659 * * cdef _get_v(self): * return (self.xc, self.yc, self.radius) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->xc); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyFloat_FromDouble(__pyx_v_self->yc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyFloat_FromDouble(__pyx_v_self->radius); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 659; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_r = ((PyObject *)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("_region_filter.Circle._get_v"); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":662 * * * def __init__(self, double xc, double yc, double radius, # <<<<<<<<<<<<<< * RegionContext c=None): * """ */ static int __pyx_pf_14_region_filter_6Circle___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_14_region_filter_6Circle___init__[] = "\n "; struct wrapperbase __pyx_wrapperbase_14_region_filter_6Circle___init__; static int __pyx_pf_14_region_filter_6Circle___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { double __pyx_v_xc; double __pyx_v_yc; double __pyx_v_radius; struct __pyx_obj_14_region_filter_RegionContext *__pyx_v_c = 0; int __pyx_r; PyObject *__pyx_t_1 = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__xc,&__pyx_n_s__yc,&__pyx_n_s__radius,&__pyx_n_s__c,0}; __Pyx_RefNannySetupContext("__init__"); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[4] = {0,0,0,0}; /* "_region_filter.pyx":663 * * def __init__(self, double xc, double yc, double radius, * RegionContext c=None): # <<<<<<<<<<<<<< * """ * """ */ values[3] = (PyObject *)((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); switch (PyTuple_GET_SIZE(__pyx_args)) { case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__xc); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__yc); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__radius); if (likely(values[2])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__c); if (value) { values[3] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_xc = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_xc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_yc = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_yc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_radius = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_radius == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)values[3]); } else { __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); switch (PyTuple_GET_SIZE(__pyx_args)) { case 4: __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)PyTuple_GET_ITEM(__pyx_args, 3)); case 3: __pyx_v_radius = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_radius == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_yc = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_yc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_xc = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_xc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L3_error;} break; default: goto __pyx_L5_argtuple_error; } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.Circle.__init__"); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_c), __pyx_ptype_14_region_filter_RegionContext, 1, "c", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":668 * #if c: * # self.c = c * self.metric_set_origin(xc, yc, c) # <<<<<<<<<<<<<< * self._set_v(xc, yc, radius) * */ __pyx_t_1 = ((struct __pyx_vtabstruct_14_region_filter_Circle *)((struct __pyx_obj_14_region_filter_Circle *)__pyx_v_self)->__pyx_base.__pyx_vtab)->__pyx_base.metric_set_origin(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self), __pyx_v_xc, __pyx_v_yc, __pyx_v_c); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":669 * # self.c = c * self.metric_set_origin(xc, yc, c) * self._set_v(xc, yc, radius) # <<<<<<<<<<<<<< * * */ __pyx_t_1 = ((struct __pyx_vtabstruct_14_region_filter_Circle *)((struct __pyx_obj_14_region_filter_Circle *)__pyx_v_self)->__pyx_base.__pyx_vtab)->_set_v(((struct __pyx_obj_14_region_filter_Circle *)__pyx_v_self), __pyx_v_xc, __pyx_v_yc, __pyx_v_radius); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.Circle.__init__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":672 * * * cdef npy_bool _inside(self, double x, double y): # <<<<<<<<<<<<<< * cdef double dist2 * */ static npy_bool __pyx_f_14_region_filter_6Circle__inside(struct __pyx_obj_14_region_filter_Circle *__pyx_v_self, double __pyx_v_x, double __pyx_v_y) { double __pyx_v_dist2; npy_bool __pyx_r; __Pyx_RefNannySetupContext("_inside"); /* "_region_filter.pyx":675 * cdef double dist2 * * dist2 = ((x-self.xc)*self.m.g_x)**2 + ((y-self.yc)*self.m.g_y)**2 # <<<<<<<<<<<<<< * return (dist2 <= self.radius2) * */ __pyx_v_dist2 = (pow(((__pyx_v_x - __pyx_v_self->xc) * __pyx_v_self->__pyx_base.m.g_x), 2.0) + pow(((__pyx_v_y - __pyx_v_self->yc) * __pyx_v_self->__pyx_base.m.g_y), 2.0)); /* "_region_filter.pyx":676 * * dist2 = ((x-self.xc)*self.m.g_x)**2 + ((y-self.yc)*self.m.g_y)**2 * return (dist2 <= self.radius2) # <<<<<<<<<<<<<< * * def __repr__(self): */ __pyx_r = (__pyx_v_dist2 <= __pyx_v_self->radius2); goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":678 * return (dist2 <= self.radius2) * * def __repr__(self): # <<<<<<<<<<<<<< * return "Circle(%f, %f, %f)" % (self.xc, self.yc, self.radius) * */ static PyObject *__pyx_pf_14_region_filter_6Circle_1__repr__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pf_14_region_filter_6Circle_1__repr__(PyObject *__pyx_v_self) { PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("__repr__"); /* "_region_filter.pyx":679 * * def __repr__(self): * return "Circle(%f, %f, %f)" % (self.xc, self.yc, self.radius) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_14_region_filter_Circle *)__pyx_v_self)->xc); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyFloat_FromDouble(((struct __pyx_obj_14_region_filter_Circle *)__pyx_v_self)->yc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyFloat_FromDouble(((struct __pyx_obj_14_region_filter_Circle *)__pyx_v_self)->radius); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_r = ((PyObject *)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("_region_filter.Circle.__repr__"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":700 * * * def __init__(self, double xc, double yc, # <<<<<<<<<<<<<< * double radius_major, double radius_minor, * RegionContext c=None): */ static int __pyx_pf_14_region_filter_7Ellipse___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pf_14_region_filter_7Ellipse___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { double __pyx_v_xc; double __pyx_v_yc; double __pyx_v_radius_major; double __pyx_v_radius_minor; struct __pyx_obj_14_region_filter_RegionContext *__pyx_v_c = 0; int __pyx_r; PyObject *__pyx_t_1 = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__xc,&__pyx_n_s__yc,&__pyx_n_s__radius_major,&__pyx_n_s__radius_minor,&__pyx_n_s__c,0}; __Pyx_RefNannySetupContext("__init__"); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[5] = {0,0,0,0,0}; /* "_region_filter.pyx":702 * def __init__(self, double xc, double yc, * double radius_major, double radius_minor, * RegionContext c=None): # <<<<<<<<<<<<<< * * # check inside */ values[4] = (PyObject *)((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); switch (PyTuple_GET_SIZE(__pyx_args)) { case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__xc); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__yc); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__radius_major); if (likely(values[2])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__radius_minor); if (likely(values[3])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__c); if (value) { values[4] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_xc = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_xc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_yc = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_yc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_radius_major = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_radius_major == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_radius_minor = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_radius_minor == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)values[4]); } else { __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); switch (PyTuple_GET_SIZE(__pyx_args)) { case 5: __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)PyTuple_GET_ITEM(__pyx_args, 4)); case 4: __pyx_v_radius_minor = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_radius_minor == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_radius_major = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_radius_major == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_yc = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_yc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_xc = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_xc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L3_error;} break; default: goto __pyx_L5_argtuple_error; } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.Ellipse.__init__"); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_c), __pyx_ptype_14_region_filter_RegionContext, 1, "c", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":708 * # radius_minor**2*(x-xc)**2 + radius_major**2*(y-yc)**2 < (radius_major*radius_minor)**2 * * self.xc = xc # <<<<<<<<<<<<<< * self.yc = yc * self.radius_major = radius_major */ ((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->xc = __pyx_v_xc; /* "_region_filter.pyx":709 * * self.xc = xc * self.yc = yc # <<<<<<<<<<<<<< * self.radius_major = radius_major * self.radius_minor = radius_minor */ ((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->yc = __pyx_v_yc; /* "_region_filter.pyx":710 * self.xc = xc * self.yc = yc * self.radius_major = radius_major # <<<<<<<<<<<<<< * self.radius_minor = radius_minor * self.radius_major_2 = radius_major**2 */ ((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->radius_major = __pyx_v_radius_major; /* "_region_filter.pyx":711 * self.yc = yc * self.radius_major = radius_major * self.radius_minor = radius_minor # <<<<<<<<<<<<<< * self.radius_major_2 = radius_major**2 * self.radius_minor_2 = radius_minor**2 */ ((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->radius_minor = __pyx_v_radius_minor; /* "_region_filter.pyx":712 * self.radius_major = radius_major * self.radius_minor = radius_minor * self.radius_major_2 = radius_major**2 # <<<<<<<<<<<<<< * self.radius_minor_2 = radius_minor**2 * self.radius_major_2_radius_minor_2 = self.radius_major_2 * self.radius_minor_2 */ ((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->radius_major_2 = pow(__pyx_v_radius_major, 2.0); /* "_region_filter.pyx":713 * self.radius_minor = radius_minor * self.radius_major_2 = radius_major**2 * self.radius_minor_2 = radius_minor**2 # <<<<<<<<<<<<<< * self.radius_major_2_radius_minor_2 = self.radius_major_2 * self.radius_minor_2 * */ ((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->radius_minor_2 = pow(__pyx_v_radius_minor, 2.0); /* "_region_filter.pyx":714 * self.radius_major_2 = radius_major**2 * self.radius_minor_2 = radius_minor**2 * self.radius_major_2_radius_minor_2 = self.radius_major_2 * self.radius_minor_2 # <<<<<<<<<<<<<< * * self.metric_set_origin(xc, yc, c) */ ((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->radius_major_2_radius_minor_2 = (((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->radius_major_2 * ((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->radius_minor_2); /* "_region_filter.pyx":716 * self.radius_major_2_radius_minor_2 = self.radius_major_2 * self.radius_minor_2 * * self.metric_set_origin(xc, yc, c) # <<<<<<<<<<<<<< * #MetricInit(&(self.m), xc, yc) * */ __pyx_t_1 = ((struct __pyx_vtabstruct_14_region_filter_Ellipse *)((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->__pyx_base.__pyx_vtab)->__pyx_base.metric_set_origin(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self), __pyx_v_xc, __pyx_v_yc, __pyx_v_c); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.Ellipse.__init__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":720 * * * cdef npy_bool _inside(self, double x, double y): # <<<<<<<<<<<<<< * cdef double dist2 * */ static npy_bool __pyx_f_14_region_filter_7Ellipse__inside(struct __pyx_obj_14_region_filter_Ellipse *__pyx_v_self, double __pyx_v_x, double __pyx_v_y) { double __pyx_v_dist2; npy_bool __pyx_r; __Pyx_RefNannySetupContext("_inside"); /* "_region_filter.pyx":723 * cdef double dist2 * * dist2 = self.radius_minor_2*(x-self.xc)**2 + self.radius_major_2*(y-self.yc)**2 # <<<<<<<<<<<<<< * return (dist2 <= self.radius_major_2_radius_minor_2) * */ __pyx_v_dist2 = ((__pyx_v_self->radius_minor_2 * pow((__pyx_v_x - __pyx_v_self->xc), 2.0)) + (__pyx_v_self->radius_major_2 * pow((__pyx_v_y - __pyx_v_self->yc), 2.0))); /* "_region_filter.pyx":724 * * dist2 = self.radius_minor_2*(x-self.xc)**2 + self.radius_major_2*(y-self.yc)**2 * return (dist2 <= self.radius_major_2_radius_minor_2) # <<<<<<<<<<<<<< * * def __repr__(self): */ __pyx_r = (__pyx_v_dist2 <= __pyx_v_self->radius_major_2_radius_minor_2); goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":726 * return (dist2 <= self.radius_major_2_radius_minor_2) * * def __repr__(self): # <<<<<<<<<<<<<< * return "Ellipse(%f, %f, %f, %f)" % (self.xc, self.yc, self.radius_major, self.radius_minor) * */ static PyObject *__pyx_pf_14_region_filter_7Ellipse_1__repr__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pf_14_region_filter_7Ellipse_1__repr__(PyObject *__pyx_v_self) { PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__repr__"); /* "_region_filter.pyx":727 * * def __repr__(self): * return "Ellipse(%f, %f, %f, %f)" % (self.xc, self.yc, self.radius_major, self.radius_minor) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->xc); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyFloat_FromDouble(((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->yc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyFloat_FromDouble(((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->radius_major); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyFloat_FromDouble(((struct __pyx_obj_14_region_filter_Ellipse *)__pyx_v_self)->radius_minor); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_r = ((PyObject *)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("_region_filter.Ellipse.__repr__"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":744 * * * def __init__(self, double xc, double yc, double width, double height, # <<<<<<<<<<<<<< * RegionContext c=None): * cdef double halfwidth */ static int __pyx_pf_14_region_filter_3Box___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pf_14_region_filter_3Box___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { double __pyx_v_xc; double __pyx_v_yc; double __pyx_v_width; double __pyx_v_height; struct __pyx_obj_14_region_filter_RegionContext *__pyx_v_c = 0; double __pyx_v_halfwidth; double __pyx_v_halfheight; int __pyx_r; PyObject *__pyx_t_1 = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__xc,&__pyx_n_s__yc,&__pyx_n_s__width,&__pyx_n_s__height,&__pyx_n_s__c,0}; __Pyx_RefNannySetupContext("__init__"); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[5] = {0,0,0,0,0}; /* "_region_filter.pyx":745 * * def __init__(self, double xc, double yc, double width, double height, * RegionContext c=None): # <<<<<<<<<<<<<< * cdef double halfwidth * cdef double halfheight */ values[4] = (PyObject *)((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); switch (PyTuple_GET_SIZE(__pyx_args)) { case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__xc); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__yc); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__width); if (likely(values[2])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__height); if (likely(values[3])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__c); if (value) { values[4] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_xc = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_xc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_yc = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_yc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_width = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_width == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_height = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_height == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)values[4]); } else { __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); switch (PyTuple_GET_SIZE(__pyx_args)) { case 5: __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)PyTuple_GET_ITEM(__pyx_args, 4)); case 4: __pyx_v_height = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_height == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_width = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_width == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_yc = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_yc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_xc = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_xc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} break; default: goto __pyx_L5_argtuple_error; } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.Box.__init__"); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_c), __pyx_ptype_14_region_filter_RegionContext, 1, "c", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":749 * cdef double halfheight * * halfwidth = width*.5 # <<<<<<<<<<<<<< * halfheight = height*.5 * */ __pyx_v_halfwidth = (__pyx_v_width * .5); /* "_region_filter.pyx":750 * * halfwidth = width*.5 * halfheight = height*.5 # <<<<<<<<<<<<<< * * self.x1 = xc - halfwidth */ __pyx_v_halfheight = (__pyx_v_height * .5); /* "_region_filter.pyx":752 * halfheight = height*.5 * * self.x1 = xc - halfwidth # <<<<<<<<<<<<<< * self.x2 = xc + halfwidth * self.y1 = yc - halfheight */ ((struct __pyx_obj_14_region_filter_Box *)__pyx_v_self)->x1 = (__pyx_v_xc - __pyx_v_halfwidth); /* "_region_filter.pyx":753 * * self.x1 = xc - halfwidth * self.x2 = xc + halfwidth # <<<<<<<<<<<<<< * self.y1 = yc - halfheight * self.y2 = yc + halfheight */ ((struct __pyx_obj_14_region_filter_Box *)__pyx_v_self)->x2 = (__pyx_v_xc + __pyx_v_halfwidth); /* "_region_filter.pyx":754 * self.x1 = xc - halfwidth * self.x2 = xc + halfwidth * self.y1 = yc - halfheight # <<<<<<<<<<<<<< * self.y2 = yc + halfheight * */ ((struct __pyx_obj_14_region_filter_Box *)__pyx_v_self)->y1 = (__pyx_v_yc - __pyx_v_halfheight); /* "_region_filter.pyx":755 * self.x2 = xc + halfwidth * self.y1 = yc - halfheight * self.y2 = yc + halfheight # <<<<<<<<<<<<<< * * self.metric_set_origin(xc, yc, c) */ ((struct __pyx_obj_14_region_filter_Box *)__pyx_v_self)->y2 = (__pyx_v_yc + __pyx_v_halfheight); /* "_region_filter.pyx":757 * self.y2 = yc + halfheight * * self.metric_set_origin(xc, yc, c) # <<<<<<<<<<<<<< * #MetricInit(&(self.m), xc, yc) * */ __pyx_t_1 = ((struct __pyx_vtabstruct_14_region_filter_Box *)((struct __pyx_obj_14_region_filter_Box *)__pyx_v_self)->__pyx_base.__pyx_vtab)->__pyx_base.metric_set_origin(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self), __pyx_v_xc, __pyx_v_yc, __pyx_v_c); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 757; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.Box.__init__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":761 * * * cdef npy_bool _inside(self, double x, double y): # <<<<<<<<<<<<<< * return (self.x1 <= x) & (x <= self.x2) & (self.y1 <= y) & (y <= self.y2) * */ static npy_bool __pyx_f_14_region_filter_3Box__inside(struct __pyx_obj_14_region_filter_Box *__pyx_v_self, double __pyx_v_x, double __pyx_v_y) { npy_bool __pyx_r; __Pyx_RefNannySetupContext("_inside"); /* "_region_filter.pyx":762 * * cdef npy_bool _inside(self, double x, double y): * return (self.x1 <= x) & (x <= self.x2) & (self.y1 <= y) & (y <= self.y2) # <<<<<<<<<<<<<< * * */ __pyx_r = ((((__pyx_v_self->x1 <= __pyx_v_x) & (__pyx_v_x <= __pyx_v_self->x2)) & (__pyx_v_self->y1 <= __pyx_v_y)) & (__pyx_v_y <= __pyx_v_self->y2)); goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":784 * * * def __init__(self, x, y, # <<<<<<<<<<<<<< * RegionContext c=None): * self.xa = c_numpy.PyArray_CopyFromObject(x, c_numpy.NPY_DOUBLE, 1, 1) */ static int __pyx_pf_14_region_filter_7Polygon___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pf_14_region_filter_7Polygon___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_x = 0; PyObject *__pyx_v_y = 0; struct __pyx_obj_14_region_filter_RegionContext *__pyx_v_c = 0; int __pyx_r; PyObject *__pyx_t_1 = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__x,&__pyx_n_s__y,&__pyx_n_s__c,0}; __Pyx_RefNannySetupContext("__init__"); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); PyObject* values[3] = {0,0,0}; /* "_region_filter.pyx":785 * * def __init__(self, x, y, * RegionContext c=None): # <<<<<<<<<<<<<< * self.xa = c_numpy.PyArray_CopyFromObject(x, c_numpy.NPY_DOUBLE, 1, 1) * self.ya = c_numpy.PyArray_CopyFromObject(y, c_numpy.NPY_DOUBLE, 1, 1) */ values[2] = (PyObject *)((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__x); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__y); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__c); if (value) { values[2] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_x = values[0]; __pyx_v_y = values[1]; __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)values[2]); } else { __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)PyTuple_GET_ITEM(__pyx_args, 2)); case 2: __pyx_v_y = PyTuple_GET_ITEM(__pyx_args, 1); __pyx_v_x = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 784; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.Polygon.__init__"); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_c), __pyx_ptype_14_region_filter_RegionContext, 1, "c", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":786 * def __init__(self, x, y, * RegionContext c=None): * self.xa = c_numpy.PyArray_CopyFromObject(x, c_numpy.NPY_DOUBLE, 1, 1) # <<<<<<<<<<<<<< * self.ya = c_numpy.PyArray_CopyFromObject(y, c_numpy.NPY_DOUBLE, 1, 1) * */ __pyx_t_1 = PyArray_CopyFromObject(__pyx_v_x, NPY_DOUBLE, 1, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7c_numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 786; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->xa); __Pyx_DECREF(((PyObject *)((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->xa)); ((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->xa = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":787 * RegionContext c=None): * self.xa = c_numpy.PyArray_CopyFromObject(x, c_numpy.NPY_DOUBLE, 1, 1) * self.ya = c_numpy.PyArray_CopyFromObject(y, c_numpy.NPY_DOUBLE, 1, 1) # <<<<<<<<<<<<<< * * self.n = c_numpy.PyArray_SIZE(self.xa) */ __pyx_t_1 = PyArray_CopyFromObject(__pyx_v_y, NPY_DOUBLE, 1, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7c_numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->ya); __Pyx_DECREF(((PyObject *)((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->ya)); ((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->ya = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":789 * self.ya = c_numpy.PyArray_CopyFromObject(y, c_numpy.NPY_DOUBLE, 1, 1) * * self.n = c_numpy.PyArray_SIZE(self.xa) # <<<<<<<<<<<<<< * * self.x = c_numpy.PyArray_DATA(self.xa) */ __pyx_t_1 = ((PyObject *)((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->xa); __Pyx_INCREF(__pyx_t_1); ((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->n = PyArray_SIZE(((PyArrayObject *)__pyx_t_1)); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":791 * self.n = c_numpy.PyArray_SIZE(self.xa) * * self.x = c_numpy.PyArray_DATA(self.xa) # <<<<<<<<<<<<<< * self.y = c_numpy.PyArray_DATA(self.ya) * */ __pyx_t_1 = ((PyObject *)((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->xa); __Pyx_INCREF(__pyx_t_1); ((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->x = ((double *)PyArray_DATA(((PyArrayObject *)__pyx_t_1))); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":792 * * self.x = c_numpy.PyArray_DATA(self.xa) * self.y = c_numpy.PyArray_DATA(self.ya) # <<<<<<<<<<<<<< * * self.metric_set_origin(self.x[0], self.y[0], c) */ __pyx_t_1 = ((PyObject *)((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->ya); __Pyx_INCREF(__pyx_t_1); ((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->y = ((double *)PyArray_DATA(((PyArrayObject *)__pyx_t_1))); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":794 * self.y = c_numpy.PyArray_DATA(self.ya) * * self.metric_set_origin(self.x[0], self.y[0], c) # <<<<<<<<<<<<<< * #MetricInit(&(self.m), ) * */ __pyx_t_1 = ((struct __pyx_vtabstruct_14_region_filter_Polygon *)((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->__pyx_base.__pyx_vtab)->__pyx_base.metric_set_origin(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self), (((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->x[0]), (((struct __pyx_obj_14_region_filter_Polygon *)__pyx_v_self)->y[0]), __pyx_v_c); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.Polygon.__init__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":797 * #MetricInit(&(self.m), ) * * cdef npy_bool _inside(self, double x, double y): # <<<<<<<<<<<<<< * cdef int i, j * cdef npy_bool r */ static npy_bool __pyx_f_14_region_filter_7Polygon__inside(struct __pyx_obj_14_region_filter_Polygon *__pyx_v_self, double __pyx_v_x, double __pyx_v_y) { int __pyx_v_i; int __pyx_v_j; npy_bool __pyx_v_r; double *__pyx_v_xp; double *__pyx_v_yp; double __pyx_v__t; double __pyx_v_y_yp_i; double __pyx_v_y_yp_j; npy_bool __pyx_r; int __pyx_t_1; int __pyx_t_2; double __pyx_t_3; __Pyx_RefNannySetupContext("_inside"); /* "_region_filter.pyx":806 * * * j = self.n - 1 # <<<<<<<<<<<<<< * r = 0 * xp = self.x */ __pyx_v_j = (__pyx_v_self->n - 1); /* "_region_filter.pyx":807 * * j = self.n - 1 * r = 0 # <<<<<<<<<<<<<< * xp = self.x * yp = self.y */ __pyx_v_r = 0; /* "_region_filter.pyx":808 * j = self.n - 1 * r = 0 * xp = self.x # <<<<<<<<<<<<<< * yp = self.y * */ __pyx_v_xp = __pyx_v_self->x; /* "_region_filter.pyx":809 * r = 0 * xp = self.x * yp = self.y # <<<<<<<<<<<<<< * * */ __pyx_v_yp = __pyx_v_self->y; /* "_region_filter.pyx":822 * * #stable version, but would require more time * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< * y_yp_i = y - yp[i] * y_yp_j = y - yp[j] */ __pyx_t_1 = __pyx_v_self->n; for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { /* "_region_filter.pyx":823 * #stable version, but would require more time * for i from 0 <= i < self.n: * y_yp_i = y - yp[i] # <<<<<<<<<<<<<< * y_yp_j = y - yp[j] * */ __pyx_v_y_yp_i = (__pyx_v_y - (__pyx_v_yp[__pyx_v_i])); /* "_region_filter.pyx":824 * for i from 0 <= i < self.n: * y_yp_i = y - yp[i] * y_yp_j = y - yp[j] # <<<<<<<<<<<<<< * * if (y_yp_i == 0.) & (y_yp_j == 0.): # special case for horizontal line */ __pyx_v_y_yp_j = (__pyx_v_y - (__pyx_v_yp[__pyx_v_j])); /* "_region_filter.pyx":826 * y_yp_j = y - yp[j] * * if (y_yp_i == 0.) & (y_yp_j == 0.): # special case for horizontal line # <<<<<<<<<<<<<< * if (xp[i]-x)*(xp[j]-x) <= 0.: * return 1 */ __pyx_t_2 = ((__pyx_v_y_yp_i == 0.) & (__pyx_v_y_yp_j == 0.)); if (__pyx_t_2) { /* "_region_filter.pyx":827 * * if (y_yp_i == 0.) & (y_yp_j == 0.): # special case for horizontal line * if (xp[i]-x)*(xp[j]-x) <= 0.: # <<<<<<<<<<<<<< * return 1 * */ __pyx_t_2 = ((((__pyx_v_xp[__pyx_v_i]) - __pyx_v_x) * ((__pyx_v_xp[__pyx_v_j]) - __pyx_v_x)) <= 0.); if (__pyx_t_2) { /* "_region_filter.pyx":828 * if (y_yp_i == 0.) & (y_yp_j == 0.): # special case for horizontal line * if (xp[i]-x)*(xp[j]-x) <= 0.: * return 1 # <<<<<<<<<<<<<< * * if ((0<=y_yp_i) & (0>y_yp_j) | (0<=y_yp_j) & (0>y_yp_i)): */ __pyx_r = 1; goto __pyx_L0; goto __pyx_L6; } __pyx_L6:; goto __pyx_L5; } __pyx_L5:; /* "_region_filter.pyx":830 * return 1 * * if ((0<=y_yp_i) & (0>y_yp_j) | (0<=y_yp_j) & (0>y_yp_i)): # <<<<<<<<<<<<<< * _t = xp[i]+y_yp_i/(yp[j]-yp[i])*(xp[j]-xp[i]) * if _t == x: # return true immediately if point over the poly-edge */ __pyx_t_2 = (((0.0 <= __pyx_v_y_yp_i) & (0.0 > __pyx_v_y_yp_j)) | ((0.0 <= __pyx_v_y_yp_j) & (0.0 > __pyx_v_y_yp_i))); if (__pyx_t_2) { /* "_region_filter.pyx":831 * * if ((0<=y_yp_i) & (0>y_yp_j) | (0<=y_yp_j) & (0>y_yp_i)): * _t = xp[i]+y_yp_i/(yp[j]-yp[i])*(xp[j]-xp[i]) # <<<<<<<<<<<<<< * if _t == x: # return true immediately if point over the poly-edge * return 1 */ __pyx_t_3 = ((__pyx_v_yp[__pyx_v_j]) - (__pyx_v_yp[__pyx_v_i])); if (unlikely(__pyx_t_3 == 0)) { PyErr_Format(PyExc_ZeroDivisionError, "float division"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_v__t = ((__pyx_v_xp[__pyx_v_i]) + ((__pyx_v_y_yp_i / __pyx_t_3) * ((__pyx_v_xp[__pyx_v_j]) - (__pyx_v_xp[__pyx_v_i])))); /* "_region_filter.pyx":832 * if ((0<=y_yp_i) & (0>y_yp_j) | (0<=y_yp_j) & (0>y_yp_i)): * _t = xp[i]+y_yp_i/(yp[j]-yp[i])*(xp[j]-xp[i]) * if _t == x: # return true immediately if point over the poly-edge # <<<<<<<<<<<<<< * return 1 * # but above does not catch horizontal line */ __pyx_t_2 = (__pyx_v__t == __pyx_v_x); if (__pyx_t_2) { /* "_region_filter.pyx":833 * _t = xp[i]+y_yp_i/(yp[j]-yp[i])*(xp[j]-xp[i]) * if _t == x: # return true immediately if point over the poly-edge * return 1 # <<<<<<<<<<<<<< * # but above does not catch horizontal line * if (_t 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__c); if (value) { values[4] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_xc = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_xc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_yc = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_yc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_degree1 = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_degree1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_degree2 = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_degree2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)values[4]); } else { __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); switch (PyTuple_GET_SIZE(__pyx_args)) { case 5: __pyx_v_c = ((struct __pyx_obj_14_region_filter_RegionContext *)PyTuple_GET_ITEM(__pyx_args, 4)); case 4: __pyx_v_degree2 = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_degree2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_degree1 = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_degree1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_yc = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_yc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_xc = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_xc == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L3_error;} break; default: goto __pyx_L5_argtuple_error; } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_region_filter.AngleRange.__init__"); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_c), __pyx_ptype_14_region_filter_RegionContext, 1, "c", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_region_filter.pyx":864 * RegionContext c=None): * * self.xc = xc # <<<<<<<<<<<<<< * self.yc = yc * self.degree1 = degree1 */ ((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->xc = __pyx_v_xc; /* "_region_filter.pyx":865 * * self.xc = xc * self.yc = yc # <<<<<<<<<<<<<< * self.degree1 = degree1 * self.degree2 = degree2 */ ((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->yc = __pyx_v_yc; /* "_region_filter.pyx":866 * self.xc = xc * self.yc = yc * self.degree1 = degree1 # <<<<<<<<<<<<<< * self.degree2 = degree2 * */ ((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->degree1 = __pyx_v_degree1; /* "_region_filter.pyx":867 * self.yc = yc * self.degree1 = degree1 * self.degree2 = degree2 # <<<<<<<<<<<<<< * * # theta in radian */ ((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->degree2 = __pyx_v_degree2; /* "_region_filter.pyx":870 * * # theta in radian * self.radian1 = degree1/180.*M_PI#3.1415926 # <<<<<<<<<<<<<< * self.radian2 = self._fix_angle(degree2/180.*M_PI) * */ ((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->radian1 = ((__pyx_v_degree1 / 180.) * M_PI); /* "_region_filter.pyx":871 * # theta in radian * self.radian1 = degree1/180.*M_PI#3.1415926 * self.radian2 = self._fix_angle(degree2/180.*M_PI) # <<<<<<<<<<<<<< * * self.metric_set_origin(xc, yc, c) */ ((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->radian2 = ((struct __pyx_vtabstruct_14_region_filter_AngleRange *)((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->__pyx_base.__pyx_vtab)->_fix_angle(((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self), ((__pyx_v_degree2 / 180.) * M_PI)); /* "_region_filter.pyx":873 * self.radian2 = self._fix_angle(degree2/180.*M_PI) * * self.metric_set_origin(xc, yc, c) # <<<<<<<<<<<<<< * * */ __pyx_t_1 = ((struct __pyx_vtabstruct_14_region_filter_AngleRange *)((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->__pyx_base.__pyx_vtab)->__pyx_base.metric_set_origin(((struct __pyx_obj_14_region_filter_RegionBase *)__pyx_v_self), __pyx_v_xc, __pyx_v_yc, __pyx_v_c); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 873; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_region_filter.AngleRange.__init__"); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":876 * * * cdef double _fix_angle(self, double a): # <<<<<<<<<<<<<< * if a > self.radian1: * return self.radian1 + fmod((a-self.radian1), 2*M_PI) */ static double __pyx_f_14_region_filter_10AngleRange__fix_angle(struct __pyx_obj_14_region_filter_AngleRange *__pyx_v_self, double __pyx_v_a) { double __pyx_r; int __pyx_t_1; __Pyx_RefNannySetupContext("_fix_angle"); /* "_region_filter.pyx":877 * * cdef double _fix_angle(self, double a): * if a > self.radian1: # <<<<<<<<<<<<<< * return self.radian1 + fmod((a-self.radian1), 2*M_PI) * else: */ __pyx_t_1 = (__pyx_v_a > __pyx_v_self->radian1); if (__pyx_t_1) { /* "_region_filter.pyx":878 * cdef double _fix_angle(self, double a): * if a > self.radian1: * return self.radian1 + fmod((a-self.radian1), 2*M_PI) # <<<<<<<<<<<<<< * else: * return self.radian1 + 2.*M_PI - fmod((self.radian1-a), 2*M_PI) */ __pyx_r = (__pyx_v_self->radian1 + fmod((__pyx_v_a - __pyx_v_self->radian1), (2.0 * M_PI))); goto __pyx_L0; goto __pyx_L3; } /*else*/ { /* "_region_filter.pyx":880 * return self.radian1 + fmod((a-self.radian1), 2*M_PI) * else: * return self.radian1 + 2.*M_PI - fmod((self.radian1-a), 2*M_PI) # <<<<<<<<<<<<<< * * */ __pyx_r = ((__pyx_v_self->radian1 + (2. * M_PI)) - fmod((__pyx_v_self->radian1 - __pyx_v_a), (2.0 * M_PI))); goto __pyx_L0; } __pyx_L3:; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":883 * * * cdef npy_bool _inside(self, double x, double y): # <<<<<<<<<<<<<< * cdef double dx, dy, theta * */ static npy_bool __pyx_f_14_region_filter_10AngleRange__inside(struct __pyx_obj_14_region_filter_AngleRange *__pyx_v_self, double __pyx_v_x, double __pyx_v_y) { double __pyx_v_dx; double __pyx_v_dy; double __pyx_v_theta; npy_bool __pyx_r; __Pyx_RefNannySetupContext("_inside"); /* "_region_filter.pyx":886 * cdef double dx, dy, theta * * dx = x - self.xc # <<<<<<<<<<<<<< * dy = y - self.yc * */ __pyx_v_dx = (__pyx_v_x - __pyx_v_self->xc); /* "_region_filter.pyx":887 * * dx = x - self.xc * dy = y - self.yc # <<<<<<<<<<<<<< * * theta = atan2(dy, dx) */ __pyx_v_dy = (__pyx_v_y - __pyx_v_self->yc); /* "_region_filter.pyx":889 * dy = y - self.yc * * theta = atan2(dy, dx) # <<<<<<<<<<<<<< * * #if theta < self.radian1: */ __pyx_v_theta = atan2(__pyx_v_dy, __pyx_v_dx); /* "_region_filter.pyx":893 * #if theta < self.radian1: * # theta += 2.*M_PI * theta = self._fix_angle(theta) # <<<<<<<<<<<<<< * return (theta < self.radian2) * */ __pyx_v_theta = ((struct __pyx_vtabstruct_14_region_filter_AngleRange *)__pyx_v_self->__pyx_base.__pyx_vtab)->_fix_angle(__pyx_v_self, __pyx_v_theta); /* "_region_filter.pyx":894 * # theta += 2.*M_PI * theta = self._fix_angle(theta) * return (theta < self.radian2) # <<<<<<<<<<<<<< * * def __repr__(self): */ __pyx_r = (__pyx_v_theta < __pyx_v_self->radian2); goto __pyx_L0; __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "_region_filter.pyx":896 * return (theta < self.radian2) * * def __repr__(self): # <<<<<<<<<<<<<< * return "AngleRange(%f, %f, %f, %f)" % (self.xc, self.yc, self.degree1, self.degree2) */ static PyObject *__pyx_pf_14_region_filter_10AngleRange_1__repr__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pf_14_region_filter_10AngleRange_1__repr__(PyObject *__pyx_v_self) { PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; __Pyx_RefNannySetupContext("__repr__"); /* "_region_filter.pyx":897 * * def __repr__(self): * return "AngleRange(%f, %f, %f, %f)" % (self.xc, self.yc, self.degree1, self.degree2) # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyFloat_FromDouble(((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->xc); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 897; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyFloat_FromDouble(((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->yc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 897; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyFloat_FromDouble(((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->degree1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 897; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyFloat_FromDouble(((struct __pyx_obj_14_region_filter_AngleRange *)__pyx_v_self)->degree2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 897; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 897; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_12), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 897; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_r = ((PyObject *)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("_region_filter.AngleRange.__repr__"); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static struct __pyx_vtabstruct_14_region_filter_RegionContext __pyx_vtable_14_region_filter_RegionContext; static PyObject *__pyx_tp_new_14_region_filter_RegionContext(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_RegionContext *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_RegionContext *)o); p->__pyx_vtab = __pyx_vtabptr_14_region_filter_RegionContext; return o; } static void __pyx_tp_dealloc_14_region_filter_RegionContext(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } static PyMethodDef __pyx_methods_14_region_filter_RegionContext[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_RegionContext = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_RegionContext = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_RegionContext = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_RegionContext = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_RegionContext = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.RegionContext"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_RegionContext), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_RegionContext, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ &__pyx_tp_as_number_RegionContext, /*tp_as_number*/ &__pyx_tp_as_sequence_RegionContext, /*tp_as_sequence*/ &__pyx_tp_as_mapping_RegionContext, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_RegionContext, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_RegionContext, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_13RegionContext___init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_RegionContext, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_RegionBase __pyx_vtable_14_region_filter_RegionBase; static PyObject *__pyx_tp_new_14_region_filter_RegionBase(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_RegionBase *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_RegionBase *)o); p->__pyx_vtab = __pyx_vtabptr_14_region_filter_RegionBase; p->c = ((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_14_region_filter_RegionBase(PyObject *o) { struct __pyx_obj_14_region_filter_RegionBase *p = (struct __pyx_obj_14_region_filter_RegionBase *)o; Py_XDECREF(((PyObject *)p->c)); (*Py_TYPE(o)->tp_free)(o); } static int __pyx_tp_traverse_14_region_filter_RegionBase(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_14_region_filter_RegionBase *p = (struct __pyx_obj_14_region_filter_RegionBase *)o; if (p->c) { e = (*v)(((PyObject*)p->c), a); if (e) return e; } return 0; } static int __pyx_tp_clear_14_region_filter_RegionBase(PyObject *o) { struct __pyx_obj_14_region_filter_RegionBase *p = (struct __pyx_obj_14_region_filter_RegionBase *)o; PyObject* tmp; tmp = ((PyObject*)p->c); p->c = ((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyMethodDef __pyx_methods_14_region_filter_RegionBase[] = { {__Pyx_NAMESTR("set_context"), (PyCFunction)__pyx_pf_14_region_filter_10RegionBase_1set_context, METH_O, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("mask"), (PyCFunction)__pyx_pf_14_region_filter_10RegionBase_5mask, METH_O, __Pyx_DOCSTR(__pyx_doc_14_region_filter_10RegionBase_5mask)}, {__Pyx_NAMESTR("inside1"), (PyCFunction)__pyx_pf_14_region_filter_10RegionBase_6inside1, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14_region_filter_10RegionBase_6inside1)}, {__Pyx_NAMESTR("inside"), (PyCFunction)__pyx_pf_14_region_filter_10RegionBase_7inside, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("inside_xy"), (PyCFunction)__pyx_pf_14_region_filter_10RegionBase_8inside_xy, METH_O, __Pyx_DOCSTR(__pyx_doc_14_region_filter_10RegionBase_8inside_xy)}, {__Pyx_NAMESTR("inside_x_y"), (PyCFunction)__pyx_pf_14_region_filter_10RegionBase_9inside_x_y, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_14_region_filter_10RegionBase_9inside_x_y)}, {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_RegionBase = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ __pyx_pf_14_region_filter_10RegionBase_2__invert__, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ __pyx_pf_14_region_filter_10RegionBase_3__and__, /*nb_and*/ 0, /*nb_xor*/ __pyx_pf_14_region_filter_10RegionBase_4__or__, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_RegionBase = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_RegionBase = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_RegionBase = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_RegionBase = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.RegionBase"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_RegionBase), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_RegionBase, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ &__pyx_tp_as_number_RegionBase, /*tp_as_number*/ &__pyx_tp_as_sequence_RegionBase, /*tp_as_sequence*/ &__pyx_tp_as_mapping_RegionBase, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_RegionBase, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ __pyx_tp_traverse_14_region_filter_RegionBase, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_RegionBase, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_RegionBase, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_10RegionBase___init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_RegionBase, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_RegionNot __pyx_vtable_14_region_filter_RegionNot; static PyObject *__pyx_tp_new_14_region_filter_RegionNot(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_RegionNot *p; PyObject *o = __pyx_tp_new_14_region_filter_RegionBase(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_RegionNot *)o); p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_RegionNot; p->child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)Py_None); Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_14_region_filter_RegionNot(PyObject *o) { struct __pyx_obj_14_region_filter_RegionNot *p = (struct __pyx_obj_14_region_filter_RegionNot *)o; Py_XDECREF(((PyObject *)p->child_region)); __pyx_tp_dealloc_14_region_filter_RegionBase(o); } static int __pyx_tp_traverse_14_region_filter_RegionNot(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_14_region_filter_RegionNot *p = (struct __pyx_obj_14_region_filter_RegionNot *)o; e = __pyx_tp_traverse_14_region_filter_RegionBase(o, v, a); if (e) return e; if (p->child_region) { e = (*v)(((PyObject*)p->child_region), a); if (e) return e; } return 0; } static int __pyx_tp_clear_14_region_filter_RegionNot(PyObject *o) { struct __pyx_obj_14_region_filter_RegionNot *p = (struct __pyx_obj_14_region_filter_RegionNot *)o; PyObject* tmp; __pyx_tp_clear_14_region_filter_RegionBase(o); tmp = ((PyObject*)p->child_region); p->child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyMethodDef __pyx_methods_14_region_filter_RegionNot[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_RegionNot = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_RegionNot = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_RegionNot = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_RegionNot = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_RegionNot = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.RegionNot"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_RegionNot), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_RegionNot, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ &__pyx_tp_as_number_RegionNot, /*tp_as_number*/ &__pyx_tp_as_sequence_RegionNot, /*tp_as_sequence*/ &__pyx_tp_as_mapping_RegionNot, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_RegionNot, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("\n >>> r = RegionNot(r2)\n "), /*tp_doc*/ __pyx_tp_traverse_14_region_filter_RegionNot, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_RegionNot, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_RegionNot, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_9RegionNot___init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_RegionNot, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_RegionList __pyx_vtable_14_region_filter_RegionList; static PyObject *__pyx_tp_new_14_region_filter_RegionList(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_RegionList *p; PyObject *o = __pyx_tp_new_14_region_filter_RegionBase(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_RegionList *)o); p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_RegionList; p->child_regions = Py_None; Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_14_region_filter_RegionList(PyObject *o) { struct __pyx_obj_14_region_filter_RegionList *p = (struct __pyx_obj_14_region_filter_RegionList *)o; Py_XDECREF(p->child_regions); __pyx_tp_dealloc_14_region_filter_RegionBase(o); } static int __pyx_tp_traverse_14_region_filter_RegionList(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_14_region_filter_RegionList *p = (struct __pyx_obj_14_region_filter_RegionList *)o; e = __pyx_tp_traverse_14_region_filter_RegionBase(o, v, a); if (e) return e; if (p->child_regions) { e = (*v)(p->child_regions, a); if (e) return e; } return 0; } static int __pyx_tp_clear_14_region_filter_RegionList(PyObject *o) { struct __pyx_obj_14_region_filter_RegionList *p = (struct __pyx_obj_14_region_filter_RegionList *)o; PyObject* tmp; __pyx_tp_clear_14_region_filter_RegionBase(o); tmp = ((PyObject*)p->child_regions); p->child_regions = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyObject *__pyx_sq_item_14_region_filter_RegionList(PyObject *o, Py_ssize_t i) { PyObject *r; PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); Py_DECREF(x); return r; } static int __pyx_mp_ass_subscript_14_region_filter_RegionList(PyObject *o, PyObject *i, PyObject *v) { if (v) { return __pyx_pf_14_region_filter_10RegionList_4__setitem__(o, i, v); } else { return __pyx_pf_14_region_filter_10RegionList_5__delitem__(o, i); } } static PyMethodDef __pyx_methods_14_region_filter_RegionList[] = { {__Pyx_NAMESTR("_check_type_of_list"), (PyCFunction)__pyx_pf_14_region_filter_10RegionList__check_type_of_list, METH_O, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("asList"), (PyCFunction)__pyx_pf_14_region_filter_10RegionList_8asList, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_RegionList = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_RegionList = { __pyx_pf_14_region_filter_10RegionList_2__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ __pyx_sq_item_14_region_filter_RegionList, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ __pyx_pf_14_region_filter_10RegionList_6__contains__, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_RegionList = { __pyx_pf_14_region_filter_10RegionList_2__len__, /*mp_length*/ __pyx_pf_14_region_filter_10RegionList_3__getitem__, /*mp_subscript*/ __pyx_mp_ass_subscript_14_region_filter_RegionList, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_RegionList = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_RegionList = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.RegionList"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_RegionList), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_RegionList, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif __pyx_pf_14_region_filter_10RegionList_7__repr__, /*tp_repr*/ &__pyx_tp_as_number_RegionList, /*tp_as_number*/ &__pyx_tp_as_sequence_RegionList, /*tp_as_sequence*/ &__pyx_tp_as_mapping_RegionList, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_RegionList, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ __pyx_tp_traverse_14_region_filter_RegionList, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_RegionList, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_RegionList, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_10RegionList_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_RegionList, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_RegionOrList __pyx_vtable_14_region_filter_RegionOrList; static PyObject *__pyx_tp_new_14_region_filter_RegionOrList(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_RegionOrList *p; PyObject *o = __pyx_tp_new_14_region_filter_RegionList(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_RegionOrList *)o); p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_RegionOrList; return o; } static PyMethodDef __pyx_methods_14_region_filter_RegionOrList[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_RegionOrList = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_RegionOrList = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_RegionOrList = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_RegionOrList = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_RegionOrList = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.RegionOrList"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_RegionOrList), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_RegionList, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif __pyx_pf_14_region_filter_12RegionOrList___repr__, /*tp_repr*/ &__pyx_tp_as_number_RegionOrList, /*tp_as_number*/ &__pyx_tp_as_sequence_RegionOrList, /*tp_as_sequence*/ &__pyx_tp_as_mapping_RegionOrList, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_RegionOrList, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("\n >>> r = RegionOrList(r1, r2, r3, r4, ...)\n "), /*tp_doc*/ __pyx_tp_traverse_14_region_filter_RegionList, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_RegionList, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_RegionOrList, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_RegionOrList, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_RegionAndList __pyx_vtable_14_region_filter_RegionAndList; static PyObject *__pyx_tp_new_14_region_filter_RegionAndList(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_RegionAndList *p; PyObject *o = __pyx_tp_new_14_region_filter_RegionList(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_RegionAndList *)o); p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_RegionAndList; return o; } static PyMethodDef __pyx_methods_14_region_filter_RegionAndList[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_RegionAndList = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_RegionAndList = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_RegionAndList = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_RegionAndList = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_RegionAndList = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.RegionAndList"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_RegionAndList), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_RegionList, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif __pyx_pf_14_region_filter_13RegionAndList___repr__, /*tp_repr*/ &__pyx_tp_as_number_RegionAndList, /*tp_as_number*/ &__pyx_tp_as_sequence_RegionAndList, /*tp_as_sequence*/ &__pyx_tp_as_mapping_RegionAndList, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_RegionAndList, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("\n >>> r = RegionAndList(r1, r2, r3, r4, ...)\n "), /*tp_doc*/ __pyx_tp_traverse_14_region_filter_RegionList, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_RegionList, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_RegionAndList, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_RegionAndList, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_Transform __pyx_vtable_14_region_filter_Transform; static PyObject *__pyx_tp_new_14_region_filter_Transform(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_Transform *p; PyObject *o = __pyx_tp_new_14_region_filter_RegionBase(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_Transform *)o); p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_Transform; p->child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)Py_None); Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_14_region_filter_Transform(PyObject *o) { struct __pyx_obj_14_region_filter_Transform *p = (struct __pyx_obj_14_region_filter_Transform *)o; Py_XDECREF(((PyObject *)p->child_region)); __pyx_tp_dealloc_14_region_filter_RegionBase(o); } static int __pyx_tp_traverse_14_region_filter_Transform(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_14_region_filter_Transform *p = (struct __pyx_obj_14_region_filter_Transform *)o; e = __pyx_tp_traverse_14_region_filter_RegionBase(o, v, a); if (e) return e; if (p->child_region) { e = (*v)(((PyObject*)p->child_region), a); if (e) return e; } return 0; } static int __pyx_tp_clear_14_region_filter_Transform(PyObject *o) { struct __pyx_obj_14_region_filter_Transform *p = (struct __pyx_obj_14_region_filter_Transform *)o; PyObject* tmp; __pyx_tp_clear_14_region_filter_RegionBase(o); tmp = ((PyObject*)p->child_region); p->child_region = ((struct __pyx_obj_14_region_filter_RegionBase *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyObject *__pyx_getprop_14_region_filter_9Transform_child(PyObject *o, void *x) { return __pyx_pf_14_region_filter_9Transform_5child___get__(o); } static PyMethodDef __pyx_methods_14_region_filter_Transform[] = { {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets_14_region_filter_Transform[] = { {(char *)"child", __pyx_getprop_14_region_filter_9Transform_child, 0, 0, 0}, {0, 0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_Transform = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_Transform = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_Transform = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_Transform = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_Transform = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.Transform"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_Transform), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_Transform, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ &__pyx_tp_as_number_Transform, /*tp_as_number*/ &__pyx_tp_as_sequence_Transform, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Transform, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Transform, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ __pyx_tp_traverse_14_region_filter_Transform, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_Transform, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_Transform, /*tp_methods*/ 0, /*tp_members*/ __pyx_getsets_14_region_filter_Transform, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_9Transform___init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_Transform, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_Rotated __pyx_vtable_14_region_filter_Rotated; static PyObject *__pyx_tp_new_14_region_filter_Rotated(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_Rotated *p; PyObject *o = __pyx_tp_new_14_region_filter_Transform(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_Rotated *)o); p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_Rotated; return o; } static PyMethodDef __pyx_methods_14_region_filter_Rotated[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_Rotated = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_Rotated = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_Rotated = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_Rotated = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_Rotated = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.Rotated"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_Rotated), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_Transform, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ &__pyx_tp_as_number_Rotated, /*tp_as_number*/ &__pyx_tp_as_sequence_Rotated, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Rotated, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Rotated, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("\n Rotated\n\n >>> reg = Rotated(child_region, degree, origin_x, origin_y)\n\n\n Rotate the region by degree in anti-colockwise direction.\n "), /*tp_doc*/ __pyx_tp_traverse_14_region_filter_Transform, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_Transform, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_Rotated, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_7Rotated___init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_Rotated, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_Translated __pyx_vtable_14_region_filter_Translated; static PyObject *__pyx_tp_new_14_region_filter_Translated(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_Translated *p; PyObject *o = __pyx_tp_new_14_region_filter_Transform(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_Translated *)o); p->__pyx_base.__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_Translated; return o; } static PyMethodDef __pyx_methods_14_region_filter_Translated[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_Translated = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_Translated = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_Translated = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_Translated = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_Translated = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.Translated"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_Translated), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_Transform, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ &__pyx_tp_as_number_Translated, /*tp_as_number*/ &__pyx_tp_as_sequence_Translated, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Translated, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Translated, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("\n Translated region\n\n >>> Translate(child_region, dx, dy)\n "), /*tp_doc*/ __pyx_tp_traverse_14_region_filter_Transform, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_Transform, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_Translated, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_10Translated___init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_Translated, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_Circle __pyx_vtable_14_region_filter_Circle; static PyObject *__pyx_tp_new_14_region_filter_Circle(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_Circle *p; PyObject *o = __pyx_tp_new_14_region_filter_RegionBase(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_Circle *)o); p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_Circle; return o; } static PyMethodDef __pyx_methods_14_region_filter_Circle[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_Circle = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_Circle = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_Circle = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_Circle = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_Circle = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.Circle"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_Circle), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_RegionBase, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif __pyx_pf_14_region_filter_6Circle_1__repr__, /*tp_repr*/ &__pyx_tp_as_number_Circle, /*tp_as_number*/ &__pyx_tp_as_sequence_Circle, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Circle, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Circle, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("\n Circle\n\n >>> cir = Circle(xc, yc, radius, RegionContext c=None)\n\n "), /*tp_doc*/ __pyx_tp_traverse_14_region_filter_RegionBase, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_RegionBase, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_Circle, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_6Circle___init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_Circle, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_Ellipse __pyx_vtable_14_region_filter_Ellipse; static PyObject *__pyx_tp_new_14_region_filter_Ellipse(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_Ellipse *p; PyObject *o = __pyx_tp_new_14_region_filter_RegionBase(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_Ellipse *)o); p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_Ellipse; return o; } static PyMethodDef __pyx_methods_14_region_filter_Ellipse[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_Ellipse = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_Ellipse = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_Ellipse = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_Ellipse = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_Ellipse = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.Ellipse"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_Ellipse), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_RegionBase, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif __pyx_pf_14_region_filter_7Ellipse_1__repr__, /*tp_repr*/ &__pyx_tp_as_number_Ellipse, /*tp_as_number*/ &__pyx_tp_as_sequence_Ellipse, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Ellipse, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Ellipse, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("\n Ellipse\n\n >>> shape = Ellipse(xc, yc, radius_major, radius_minor)\n\n "), /*tp_doc*/ __pyx_tp_traverse_14_region_filter_RegionBase, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_RegionBase, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_Ellipse, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_7Ellipse___init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_Ellipse, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_Box __pyx_vtable_14_region_filter_Box; static PyObject *__pyx_tp_new_14_region_filter_Box(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_Box *p; PyObject *o = __pyx_tp_new_14_region_filter_RegionBase(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_Box *)o); p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_Box; return o; } static PyMethodDef __pyx_methods_14_region_filter_Box[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_Box = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_Box = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_Box = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_Box = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_Box = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.Box"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_Box), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_RegionBase, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ &__pyx_tp_as_number_Box, /*tp_as_number*/ &__pyx_tp_as_sequence_Box, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Box, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Box, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("\n Box\n\n >>> shape = Box(xc, yc, width, height)\n\n "), /*tp_doc*/ __pyx_tp_traverse_14_region_filter_RegionBase, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_RegionBase, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_Box, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_3Box___init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_Box, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_Polygon __pyx_vtable_14_region_filter_Polygon; static PyObject *__pyx_tp_new_14_region_filter_Polygon(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_Polygon *p; PyObject *o = __pyx_tp_new_14_region_filter_RegionBase(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_Polygon *)o); p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_Polygon; p->xa = ((PyArrayObject *)Py_None); Py_INCREF(Py_None); p->ya = ((PyArrayObject *)Py_None); Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_14_region_filter_Polygon(PyObject *o) { struct __pyx_obj_14_region_filter_Polygon *p = (struct __pyx_obj_14_region_filter_Polygon *)o; Py_XDECREF(((PyObject *)p->xa)); Py_XDECREF(((PyObject *)p->ya)); __pyx_tp_dealloc_14_region_filter_RegionBase(o); } static int __pyx_tp_traverse_14_region_filter_Polygon(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_14_region_filter_Polygon *p = (struct __pyx_obj_14_region_filter_Polygon *)o; e = __pyx_tp_traverse_14_region_filter_RegionBase(o, v, a); if (e) return e; if (p->xa) { e = (*v)(((PyObject*)p->xa), a); if (e) return e; } if (p->ya) { e = (*v)(((PyObject*)p->ya), a); if (e) return e; } return 0; } static int __pyx_tp_clear_14_region_filter_Polygon(PyObject *o) { struct __pyx_obj_14_region_filter_Polygon *p = (struct __pyx_obj_14_region_filter_Polygon *)o; PyObject* tmp; __pyx_tp_clear_14_region_filter_RegionBase(o); tmp = ((PyObject*)p->xa); p->xa = ((PyArrayObject *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->ya); p->ya = ((PyArrayObject *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyMethodDef __pyx_methods_14_region_filter_Polygon[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_Polygon = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_Polygon = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_Polygon = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_Polygon = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_Polygon = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.Polygon"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_Polygon), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_Polygon, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ &__pyx_tp_as_number_Polygon, /*tp_as_number*/ &__pyx_tp_as_sequence_Polygon, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Polygon, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Polygon, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("\n Polygon\n\n >>> shape = Polygon(x, y)\n\n x, y : list of floats\n "), /*tp_doc*/ __pyx_tp_traverse_14_region_filter_Polygon, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_Polygon, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_Polygon, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_7Polygon___init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_Polygon, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static struct __pyx_vtabstruct_14_region_filter_AngleRange __pyx_vtable_14_region_filter_AngleRange; static PyObject *__pyx_tp_new_14_region_filter_AngleRange(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_14_region_filter_AngleRange *p; PyObject *o = __pyx_tp_new_14_region_filter_RegionBase(t, a, k); if (!o) return 0; p = ((struct __pyx_obj_14_region_filter_AngleRange *)o); p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_14_region_filter_RegionBase*)__pyx_vtabptr_14_region_filter_AngleRange; return o; } static PyMethodDef __pyx_methods_14_region_filter_AngleRange[] = { {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_AngleRange = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ 0, /*nb_invert*/ 0, /*nb_lshift*/ 0, /*nb_rshift*/ 0, /*nb_and*/ 0, /*nb_xor*/ 0, /*nb_or*/ #if PY_MAJOR_VERSION < 3 0, /*nb_coerce*/ #endif 0, /*nb_int*/ #if PY_MAJOR_VERSION < 3 0, /*nb_long*/ #else 0, /*reserved*/ #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ #endif #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ 0, /*nb_inplace_lshift*/ 0, /*nb_inplace_rshift*/ 0, /*nb_inplace_and*/ 0, /*nb_inplace_xor*/ 0, /*nb_inplace_or*/ 0, /*nb_floor_divide*/ 0, /*nb_true_divide*/ 0, /*nb_inplace_floor_divide*/ 0, /*nb_inplace_true_divide*/ #if PY_VERSION_HEX >= 0x02050000 0, /*nb_index*/ #endif }; static PySequenceMethods __pyx_tp_as_sequence_AngleRange = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_AngleRange = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; static PyBufferProcs __pyx_tp_as_buffer_AngleRange = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getwritebuffer*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getsegcount*/ #endif #if PY_MAJOR_VERSION < 3 0, /*bf_getcharbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_getbuffer*/ #endif #if PY_VERSION_HEX >= 0x02060000 0, /*bf_releasebuffer*/ #endif }; static PyTypeObject __pyx_type_14_region_filter_AngleRange = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("_region_filter.AngleRange"), /*tp_name*/ sizeof(struct __pyx_obj_14_region_filter_AngleRange), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_14_region_filter_RegionBase, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif __pyx_pf_14_region_filter_10AngleRange_1__repr__, /*tp_repr*/ &__pyx_tp_as_number_AngleRange, /*tp_as_number*/ &__pyx_tp_as_sequence_AngleRange, /*tp_as_sequence*/ &__pyx_tp_as_mapping_AngleRange, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_AngleRange, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ __Pyx_DOCSTR("\n AngleRange\n\n >>> shape = Ellipse(xc, yc, degree1, degree2)\n\n "), /*tp_doc*/ __pyx_tp_traverse_14_region_filter_RegionBase, /*tp_traverse*/ __pyx_tp_clear_14_region_filter_RegionBase, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_14_region_filter_AngleRange, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pf_14_region_filter_10AngleRange___init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_14_region_filter_AngleRange, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ #endif }; static PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef __pyx_moduledef = { PyModuleDef_HEAD_INIT, __Pyx_NAMESTR("_region_filter"), 0, /* m_doc */ -1, /* m_size */ __pyx_methods /* m_methods */, NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 1}, {&__pyx_n_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 1}, {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0}, {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0}, {&__pyx_kp_u_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 1, 0, 0}, {&__pyx_kp_u_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 1, 0, 0}, {&__pyx_kp_u_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 1, 0, 0}, {&__pyx_kp_u_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 1, 0, 0}, {&__pyx_n_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 1}, {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0}, {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0}, {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0}, {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0}, {&__pyx_n_s__And, __pyx_k__And, sizeof(__pyx_k__And), 0, 0, 1, 1}, {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, {&__pyx_n_s__NotYetImplemented, __pyx_k__NotYetImplemented, sizeof(__pyx_k__NotYetImplemented), 0, 0, 1, 1}, {&__pyx_n_s__Or, __pyx_k__Or, sizeof(__pyx_k__Or), 0, 0, 1, 1}, {&__pyx_n_s__RegionAnd, __pyx_k__RegionAnd, sizeof(__pyx_k__RegionAnd), 0, 0, 1, 1}, {&__pyx_n_s__RegionOr, __pyx_k__RegionOr, sizeof(__pyx_k__RegionOr), 0, 0, 1, 1}, {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1}, {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, {&__pyx_n_s____init__, __pyx_k____init__, sizeof(__pyx_k____init__), 0, 0, 1, 1}, {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, {&__pyx_n_s___check_type_of_list, __pyx_k___check_type_of_list, sizeof(__pyx_k___check_type_of_list), 0, 0, 1, 1}, {&__pyx_n_s___fix_angle, __pyx_k___fix_angle, sizeof(__pyx_k___fix_angle), 0, 0, 1, 1}, {&__pyx_n_s___inside, __pyx_k___inside, sizeof(__pyx_k___inside), 0, 0, 1, 1}, {&__pyx_n_s___mask, __pyx_k___mask, sizeof(__pyx_k___mask), 0, 0, 1, 1}, {&__pyx_n_s___region_filter, __pyx_k___region_filter, sizeof(__pyx_k___region_filter), 0, 0, 1, 1}, {&__pyx_n_s___set_v, __pyx_k___set_v, sizeof(__pyx_k___set_v), 0, 0, 1, 1}, {&__pyx_n_s___transform, __pyx_k___transform, sizeof(__pyx_k___transform), 0, 0, 1, 1}, {&__pyx_n_s__asList, __pyx_k__asList, sizeof(__pyx_k__asList), 0, 0, 1, 1}, {&__pyx_n_s__c, __pyx_k__c, sizeof(__pyx_k__c), 0, 0, 1, 1}, {&__pyx_n_s__child_region, __pyx_k__child_region, sizeof(__pyx_k__child_region), 0, 0, 1, 1}, {&__pyx_n_s__child_regions, __pyx_k__child_regions, sizeof(__pyx_k__child_regions), 0, 0, 1, 1}, {&__pyx_n_s__cos_theta, __pyx_k__cos_theta, sizeof(__pyx_k__cos_theta), 0, 0, 1, 1}, {&__pyx_n_s__degree, __pyx_k__degree, sizeof(__pyx_k__degree), 0, 0, 1, 1}, {&__pyx_n_s__degree1, __pyx_k__degree1, sizeof(__pyx_k__degree1), 0, 0, 1, 1}, {&__pyx_n_s__degree2, __pyx_k__degree2, sizeof(__pyx_k__degree2), 0, 0, 1, 1}, {&__pyx_n_s__dimensions, __pyx_k__dimensions, sizeof(__pyx_k__dimensions), 0, 0, 1, 1}, {&__pyx_n_s__dx, __pyx_k__dx, sizeof(__pyx_k__dx), 0, 0, 1, 1}, {&__pyx_n_s__dy, __pyx_k__dy, sizeof(__pyx_k__dy), 0, 0, 1, 1}, {&__pyx_n_s__g_x, __pyx_k__g_x, sizeof(__pyx_k__g_x), 0, 0, 1, 1}, {&__pyx_n_s__g_y, __pyx_k__g_y, sizeof(__pyx_k__g_y), 0, 0, 1, 1}, {&__pyx_n_s__height, __pyx_k__height, sizeof(__pyx_k__height), 0, 0, 1, 1}, {&__pyx_n_s__inside_x_y, __pyx_k__inside_x_y, sizeof(__pyx_k__inside_x_y), 0, 0, 1, 1}, {&__pyx_n_s__inside_xy, __pyx_k__inside_xy, sizeof(__pyx_k__inside_xy), 0, 0, 1, 1}, {&__pyx_n_s__m, __pyx_k__m, sizeof(__pyx_k__m), 0, 0, 1, 1}, {&__pyx_n_s__metric_set_origin, __pyx_k__metric_set_origin, sizeof(__pyx_k__metric_set_origin), 0, 0, 1, 1}, {&__pyx_n_s__n, __pyx_k__n, sizeof(__pyx_k__n), 0, 0, 1, 1}, {&__pyx_n_s__nd, __pyx_k__nd, sizeof(__pyx_k__nd), 0, 0, 1, 1}, {&__pyx_n_s__origin_x, __pyx_k__origin_x, sizeof(__pyx_k__origin_x), 0, 0, 1, 1}, {&__pyx_n_s__origin_y, __pyx_k__origin_y, sizeof(__pyx_k__origin_y), 0, 0, 1, 1}, {&__pyx_n_s__radian1, __pyx_k__radian1, sizeof(__pyx_k__radian1), 0, 0, 1, 1}, {&__pyx_n_s__radian2, __pyx_k__radian2, sizeof(__pyx_k__radian2), 0, 0, 1, 1}, {&__pyx_n_s__radius, __pyx_k__radius, sizeof(__pyx_k__radius), 0, 0, 1, 1}, {&__pyx_n_s__radius2, __pyx_k__radius2, sizeof(__pyx_k__radius2), 0, 0, 1, 1}, {&__pyx_n_s__radius_major, __pyx_k__radius_major, sizeof(__pyx_k__radius_major), 0, 0, 1, 1}, {&__pyx_n_s__radius_major_2, __pyx_k__radius_major_2, sizeof(__pyx_k__radius_major_2), 0, 0, 1, 1}, {&__pyx_n_s__radius_minor, __pyx_k__radius_minor, sizeof(__pyx_k__radius_minor), 0, 0, 1, 1}, {&__pyx_n_s__radius_minor_2, __pyx_k__radius_minor_2, sizeof(__pyx_k__radius_minor_2), 0, 0, 1, 1}, {&__pyx_n_s__region1, __pyx_k__region1, sizeof(__pyx_k__region1), 0, 0, 1, 1}, {&__pyx_n_s__region2, __pyx_k__region2, sizeof(__pyx_k__region2), 0, 0, 1, 1}, {&__pyx_n_s__set_context, __pyx_k__set_context, sizeof(__pyx_k__set_context), 0, 0, 1, 1}, {&__pyx_n_s__set_update_func, __pyx_k__set_update_func, sizeof(__pyx_k__set_update_func), 0, 0, 1, 1}, {&__pyx_n_s__shape, __pyx_k__shape, sizeof(__pyx_k__shape), 0, 0, 1, 1}, {&__pyx_n_s__sin_theta, __pyx_k__sin_theta, sizeof(__pyx_k__sin_theta), 0, 0, 1, 1}, {&__pyx_n_s__update_metric, __pyx_k__update_metric, sizeof(__pyx_k__update_metric), 0, 0, 1, 1}, {&__pyx_n_s__width, __pyx_k__width, sizeof(__pyx_k__width), 0, 0, 1, 1}, {&__pyx_n_s__x, __pyx_k__x, sizeof(__pyx_k__x), 0, 0, 1, 1}, {&__pyx_n_s__x0, __pyx_k__x0, sizeof(__pyx_k__x0), 0, 0, 1, 1}, {&__pyx_n_s__x1, __pyx_k__x1, sizeof(__pyx_k__x1), 0, 0, 1, 1}, {&__pyx_n_s__x2, __pyx_k__x2, sizeof(__pyx_k__x2), 0, 0, 1, 1}, {&__pyx_n_s__xa, __pyx_k__xa, sizeof(__pyx_k__xa), 0, 0, 1, 1}, {&__pyx_n_s__xc, __pyx_k__xc, sizeof(__pyx_k__xc), 0, 0, 1, 1}, {&__pyx_n_s__y, __pyx_k__y, sizeof(__pyx_k__y), 0, 0, 1, 1}, {&__pyx_n_s__y0, __pyx_k__y0, sizeof(__pyx_k__y0), 0, 0, 1, 1}, {&__pyx_n_s__y1, __pyx_k__y1, sizeof(__pyx_k__y1), 0, 0, 1, 1}, {&__pyx_n_s__y2, __pyx_k__y2, sizeof(__pyx_k__y2), 0, 0, 1, 1}, {&__pyx_n_s__ya, __pyx_k__ya, sizeof(__pyx_k__ya), 0, 0, 1, 1}, {&__pyx_n_s__yc, __pyx_k__yc, sizeof(__pyx_k__yc), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_n_s__Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; } static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants"); /* "_region_filter.pyx":158 * shape = img_or_shape * else: * raise RegionFilterException("the inut needs to be a numpy 2-d array or a tuple of two integers") # <<<<<<<<<<<<<< * * if c_python.PySequence_Length(shape) != 2: */ __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_4)); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4)); /* "_region_filter.pyx":205 * return self.inside_xy(x) * else: * raise ValueError("input array has a wrong shape") # <<<<<<<<<<<<<< * else: * return self.inside_x_y(x, y) */ __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_7)); __Pyx_INCREF(((PyObject *)__pyx_kp_s_6)); PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_kp_s_6)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7)); __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; return 0; __pyx_L1_error:; return -1; } #if PY_MAJOR_VERSION < 3 PyMODINIT_FUNC init_region_filter(void); /*proto*/ PyMODINIT_FUNC init_region_filter(void) #else PyMODINIT_FUNC PyInit__region_filter(void); /*proto*/ PyMODINIT_FUNC PyInit__region_filter(void) #endif { PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; #if CYTHON_REFNANNY void* __pyx_refnanny = NULL; __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); if (!__Pyx_RefNanny) { PyErr_Clear(); __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); if (!__Pyx_RefNanny) Py_FatalError("failed to import 'refnanny' module"); } __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit__region_filter(void)", __LINE__, __FILE__); #endif __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #ifdef __pyx_binding_PyCFunctionType_USED if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif /*--- Library function declarations ---*/ /*--- Threads initialization code ---*/ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS #ifdef WITH_THREAD /* Python build with threading support? */ PyEval_InitThreads(); #endif #endif /*--- Module creation code ---*/ #if PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_region_filter"), __pyx_methods, 0, 0, PYTHON_API_VERSION); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #if PY_MAJOR_VERSION < 3 Py_INCREF(__pyx_m); #endif __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; /*--- Initialize various global constants etc. ---*/ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_module_is_main__region_filter) { if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; } /*--- Builtin init code ---*/ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Constants init code ---*/ if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Global init code ---*/ __pyx_v_14_region_filter_metric_wcs = ((struct __pyx_obj_14_region_filter_RegionContext *)Py_None); Py_INCREF(Py_None); /*--- Function export code ---*/ /*--- Type init code ---*/ __pyx_vtabptr_14_region_filter_RegionContext = &__pyx_vtable_14_region_filter_RegionContext; __pyx_vtable_14_region_filter_RegionContext.set_update_func = (PyObject *(*)(struct __pyx_obj_14_region_filter_RegionContext *, int (*)(struct __pyx_t_14_region_filter_Metric *)))__pyx_f_14_region_filter_13RegionContext_set_update_func; if (PyType_Ready(&__pyx_type_14_region_filter_RegionContext) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_RegionContext.tp_dict, __pyx_vtabptr_14_region_filter_RegionContext) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "RegionContext", (PyObject *)&__pyx_type_14_region_filter_RegionContext) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_RegionContext = &__pyx_type_14_region_filter_RegionContext; __pyx_vtabptr_14_region_filter_RegionBase = &__pyx_vtable_14_region_filter_RegionBase; __pyx_vtable_14_region_filter_RegionBase.update_metric = (PyObject *(*)(struct __pyx_obj_14_region_filter_RegionBase *))__pyx_f_14_region_filter_10RegionBase_update_metric; __pyx_vtable_14_region_filter_RegionBase.metric_set_origin = (PyObject *(*)(struct __pyx_obj_14_region_filter_RegionBase *, double, double, struct __pyx_obj_14_region_filter_RegionContext *))__pyx_f_14_region_filter_10RegionBase_metric_set_origin; __pyx_vtable_14_region_filter_RegionBase._inside = (npy_bool (*)(struct __pyx_obj_14_region_filter_RegionBase *, double, double))__pyx_f_14_region_filter_10RegionBase__inside; __pyx_vtable_14_region_filter_RegionBase._mask = (PyArrayObject *(*)(struct __pyx_obj_14_region_filter_RegionBase *, npy_intp, npy_intp))__pyx_f_14_region_filter_10RegionBase__mask; if (PyType_Ready(&__pyx_type_14_region_filter_RegionBase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_RegionBase.tp_dict, __pyx_vtabptr_14_region_filter_RegionBase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "RegionBase", (PyObject *)&__pyx_type_14_region_filter_RegionBase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_RegionBase = &__pyx_type_14_region_filter_RegionBase; __pyx_vtabptr_14_region_filter_RegionNot = &__pyx_vtable_14_region_filter_RegionNot; __pyx_vtable_14_region_filter_RegionNot.__pyx_base = *__pyx_vtabptr_14_region_filter_RegionBase; __pyx_vtable_14_region_filter_RegionNot.__pyx_base._inside = (npy_bool (*)(struct __pyx_obj_14_region_filter_RegionBase *, double, double))__pyx_f_14_region_filter_9RegionNot__inside; __pyx_type_14_region_filter_RegionNot.tp_base = __pyx_ptype_14_region_filter_RegionBase; if (PyType_Ready(&__pyx_type_14_region_filter_RegionNot) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_RegionNot.tp_dict, __pyx_vtabptr_14_region_filter_RegionNot) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "RegionNot", (PyObject *)&__pyx_type_14_region_filter_RegionNot) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_RegionNot = &__pyx_type_14_region_filter_RegionNot; __pyx_vtabptr_14_region_filter_RegionList = &__pyx_vtable_14_region_filter_RegionList; __pyx_vtable_14_region_filter_RegionList.__pyx_base = *__pyx_vtabptr_14_region_filter_RegionBase; __pyx_type_14_region_filter_RegionList.tp_base = __pyx_ptype_14_region_filter_RegionBase; if (PyType_Ready(&__pyx_type_14_region_filter_RegionList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_RegionList.tp_dict, __pyx_vtabptr_14_region_filter_RegionList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "RegionList", (PyObject *)&__pyx_type_14_region_filter_RegionList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_RegionList = &__pyx_type_14_region_filter_RegionList; __pyx_vtabptr_14_region_filter_RegionOrList = &__pyx_vtable_14_region_filter_RegionOrList; __pyx_vtable_14_region_filter_RegionOrList.__pyx_base = *__pyx_vtabptr_14_region_filter_RegionList; __pyx_vtable_14_region_filter_RegionOrList.__pyx_base.__pyx_base._inside = (npy_bool (*)(struct __pyx_obj_14_region_filter_RegionBase *, double, double))__pyx_f_14_region_filter_12RegionOrList__inside; __pyx_type_14_region_filter_RegionOrList.tp_base = __pyx_ptype_14_region_filter_RegionList; if (PyType_Ready(&__pyx_type_14_region_filter_RegionOrList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_RegionOrList.tp_dict, __pyx_vtabptr_14_region_filter_RegionOrList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "RegionOrList", (PyObject *)&__pyx_type_14_region_filter_RegionOrList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_RegionOrList = &__pyx_type_14_region_filter_RegionOrList; __pyx_vtabptr_14_region_filter_RegionAndList = &__pyx_vtable_14_region_filter_RegionAndList; __pyx_vtable_14_region_filter_RegionAndList.__pyx_base = *__pyx_vtabptr_14_region_filter_RegionList; __pyx_vtable_14_region_filter_RegionAndList.__pyx_base.__pyx_base._inside = (npy_bool (*)(struct __pyx_obj_14_region_filter_RegionBase *, double, double))__pyx_f_14_region_filter_13RegionAndList__inside; __pyx_type_14_region_filter_RegionAndList.tp_base = __pyx_ptype_14_region_filter_RegionList; if (PyType_Ready(&__pyx_type_14_region_filter_RegionAndList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_RegionAndList.tp_dict, __pyx_vtabptr_14_region_filter_RegionAndList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "RegionAndList", (PyObject *)&__pyx_type_14_region_filter_RegionAndList) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_RegionAndList = &__pyx_type_14_region_filter_RegionAndList; __pyx_vtabptr_14_region_filter_Transform = &__pyx_vtable_14_region_filter_Transform; __pyx_vtable_14_region_filter_Transform.__pyx_base = *__pyx_vtabptr_14_region_filter_RegionBase; __pyx_vtable_14_region_filter_Transform.__pyx_base._inside = (npy_bool (*)(struct __pyx_obj_14_region_filter_RegionBase *, double, double))__pyx_f_14_region_filter_9Transform__inside; __pyx_vtable_14_region_filter_Transform._transform = (int (*)(struct __pyx_obj_14_region_filter_Transform *, double, double, double *, double *))__pyx_f_14_region_filter_9Transform__transform; __pyx_type_14_region_filter_Transform.tp_base = __pyx_ptype_14_region_filter_RegionBase; if (PyType_Ready(&__pyx_type_14_region_filter_Transform) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_Transform.tp_dict, __pyx_vtabptr_14_region_filter_Transform) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Transform", (PyObject *)&__pyx_type_14_region_filter_Transform) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 523; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_Transform = &__pyx_type_14_region_filter_Transform; __pyx_vtabptr_14_region_filter_Rotated = &__pyx_vtable_14_region_filter_Rotated; __pyx_vtable_14_region_filter_Rotated.__pyx_base = *__pyx_vtabptr_14_region_filter_Transform; __pyx_vtable_14_region_filter_Rotated.__pyx_base._transform = (int (*)(struct __pyx_obj_14_region_filter_Transform *, double, double, double *, double *))__pyx_f_14_region_filter_7Rotated__transform; __pyx_type_14_region_filter_Rotated.tp_base = __pyx_ptype_14_region_filter_Transform; if (PyType_Ready(&__pyx_type_14_region_filter_Rotated) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_Rotated.tp_dict, __pyx_vtabptr_14_region_filter_Rotated) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Rotated", (PyObject *)&__pyx_type_14_region_filter_Rotated) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_Rotated = &__pyx_type_14_region_filter_Rotated; __pyx_vtabptr_14_region_filter_Translated = &__pyx_vtable_14_region_filter_Translated; __pyx_vtable_14_region_filter_Translated.__pyx_base = *__pyx_vtabptr_14_region_filter_Transform; __pyx_vtable_14_region_filter_Translated.__pyx_base._transform = (int (*)(struct __pyx_obj_14_region_filter_Transform *, double, double, double *, double *))__pyx_f_14_region_filter_10Translated__transform; __pyx_type_14_region_filter_Translated.tp_base = __pyx_ptype_14_region_filter_Transform; if (PyType_Ready(&__pyx_type_14_region_filter_Translated) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_Translated.tp_dict, __pyx_vtabptr_14_region_filter_Translated) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Translated", (PyObject *)&__pyx_type_14_region_filter_Translated) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 607; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_Translated = &__pyx_type_14_region_filter_Translated; __pyx_vtabptr_14_region_filter_Circle = &__pyx_vtable_14_region_filter_Circle; __pyx_vtable_14_region_filter_Circle.__pyx_base = *__pyx_vtabptr_14_region_filter_RegionBase; __pyx_vtable_14_region_filter_Circle.__pyx_base._inside = (npy_bool (*)(struct __pyx_obj_14_region_filter_RegionBase *, double, double))__pyx_f_14_region_filter_6Circle__inside; __pyx_vtable_14_region_filter_Circle._set_v = (PyObject *(*)(struct __pyx_obj_14_region_filter_Circle *, double, double, double))__pyx_f_14_region_filter_6Circle__set_v; __pyx_vtable_14_region_filter_Circle._get_v = (PyObject *(*)(struct __pyx_obj_14_region_filter_Circle *))__pyx_f_14_region_filter_6Circle__get_v; __pyx_type_14_region_filter_Circle.tp_base = __pyx_ptype_14_region_filter_RegionBase; if (PyType_Ready(&__pyx_type_14_region_filter_Circle) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} { PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_14_region_filter_Circle, "__init__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) { __pyx_wrapperbase_14_region_filter_6Circle___init__ = *((PyWrapperDescrObject *)wrapper)->d_base; __pyx_wrapperbase_14_region_filter_6Circle___init__.doc = __pyx_doc_14_region_filter_6Circle___init__; ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_14_region_filter_6Circle___init__; } } if (__Pyx_SetVtable(__pyx_type_14_region_filter_Circle.tp_dict, __pyx_vtabptr_14_region_filter_Circle) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Circle", (PyObject *)&__pyx_type_14_region_filter_Circle) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_Circle = &__pyx_type_14_region_filter_Circle; __pyx_vtabptr_14_region_filter_Ellipse = &__pyx_vtable_14_region_filter_Ellipse; __pyx_vtable_14_region_filter_Ellipse.__pyx_base = *__pyx_vtabptr_14_region_filter_RegionBase; __pyx_vtable_14_region_filter_Ellipse.__pyx_base._inside = (npy_bool (*)(struct __pyx_obj_14_region_filter_RegionBase *, double, double))__pyx_f_14_region_filter_7Ellipse__inside; __pyx_type_14_region_filter_Ellipse.tp_base = __pyx_ptype_14_region_filter_RegionBase; if (PyType_Ready(&__pyx_type_14_region_filter_Ellipse) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_Ellipse.tp_dict, __pyx_vtabptr_14_region_filter_Ellipse) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Ellipse", (PyObject *)&__pyx_type_14_region_filter_Ellipse) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_Ellipse = &__pyx_type_14_region_filter_Ellipse; __pyx_vtabptr_14_region_filter_Box = &__pyx_vtable_14_region_filter_Box; __pyx_vtable_14_region_filter_Box.__pyx_base = *__pyx_vtabptr_14_region_filter_RegionBase; __pyx_vtable_14_region_filter_Box.__pyx_base._inside = (npy_bool (*)(struct __pyx_obj_14_region_filter_RegionBase *, double, double))__pyx_f_14_region_filter_3Box__inside; __pyx_type_14_region_filter_Box.tp_base = __pyx_ptype_14_region_filter_RegionBase; if (PyType_Ready(&__pyx_type_14_region_filter_Box) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_Box.tp_dict, __pyx_vtabptr_14_region_filter_Box) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Box", (PyObject *)&__pyx_type_14_region_filter_Box) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_Box = &__pyx_type_14_region_filter_Box; __pyx_vtabptr_14_region_filter_Polygon = &__pyx_vtable_14_region_filter_Polygon; __pyx_vtable_14_region_filter_Polygon.__pyx_base = *__pyx_vtabptr_14_region_filter_RegionBase; __pyx_vtable_14_region_filter_Polygon.__pyx_base._inside = (npy_bool (*)(struct __pyx_obj_14_region_filter_RegionBase *, double, double))__pyx_f_14_region_filter_7Polygon__inside; __pyx_type_14_region_filter_Polygon.tp_base = __pyx_ptype_14_region_filter_RegionBase; if (PyType_Ready(&__pyx_type_14_region_filter_Polygon) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_Polygon.tp_dict, __pyx_vtabptr_14_region_filter_Polygon) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Polygon", (PyObject *)&__pyx_type_14_region_filter_Polygon) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_Polygon = &__pyx_type_14_region_filter_Polygon; __pyx_vtabptr_14_region_filter_AngleRange = &__pyx_vtable_14_region_filter_AngleRange; __pyx_vtable_14_region_filter_AngleRange.__pyx_base = *__pyx_vtabptr_14_region_filter_RegionBase; __pyx_vtable_14_region_filter_AngleRange.__pyx_base._inside = (npy_bool (*)(struct __pyx_obj_14_region_filter_RegionBase *, double, double))__pyx_f_14_region_filter_10AngleRange__inside; __pyx_vtable_14_region_filter_AngleRange._fix_angle = (double (*)(struct __pyx_obj_14_region_filter_AngleRange *, double))__pyx_f_14_region_filter_10AngleRange__fix_angle; __pyx_type_14_region_filter_AngleRange.tp_base = __pyx_ptype_14_region_filter_RegionBase; if (PyType_Ready(&__pyx_type_14_region_filter_AngleRange) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetVtable(__pyx_type_14_region_filter_AngleRange.tp_dict, __pyx_vtabptr_14_region_filter_AngleRange) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "AngleRange", (PyObject *)&__pyx_type_14_region_filter_AngleRange) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_14_region_filter_AngleRange = &__pyx_type_14_region_filter_AngleRange; /*--- Type import code ---*/ __pyx_ptype_7c_numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_7c_numpy_dtype)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_7c_numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_7c_numpy_ndarray)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_7c_numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_7c_numpy_flatiter)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_7c_numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_7c_numpy_broadcast)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Function import code ---*/ /*--- Execution code ---*/ /* "_region_filter.pyx":25 * * * c_numpy.import_array() # <<<<<<<<<<<<<< * #c_numpy.import_ufunc() * */ import_array(); /* "_region_filter.pyx":31 * * * class NotYetImplemented(Exception): # <<<<<<<<<<<<<< * pass * */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_builtin_Exception); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_Exception); __Pyx_GIVEREF(__pyx_builtin_Exception); __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__NotYetImplemented, __pyx_n_s___region_filter); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; if (PyObject_SetAttr(__pyx_m, __pyx_n_s__NotYetImplemented, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; /* "_region_filter.pyx":34 * pass * * class RegionFilterException(Exception): # <<<<<<<<<<<<<< * pass * */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_INCREF(__pyx_builtin_Exception); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_builtin_Exception); __Pyx_GIVEREF(__pyx_builtin_Exception); __pyx_t_2 = __Pyx_CreateClass(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_1), __pyx_n_s_2, __pyx_n_s___region_filter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; if (PyObject_SetAttr(__pyx_m, __pyx_n_s_2, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; /* "_region_filter.pyx":84 * * cdef RegionContext metric_wcs * metric_wcs = RegionContext() # <<<<<<<<<<<<<< * metric_wcs.set_update_func(_update_metric_wcs) * */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_14_region_filter_RegionContext)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_GOTREF(((PyObject *)__pyx_v_14_region_filter_metric_wcs)); __Pyx_DECREF(((PyObject *)__pyx_v_14_region_filter_metric_wcs)); __Pyx_GIVEREF(__pyx_t_1); __pyx_v_14_region_filter_metric_wcs = ((struct __pyx_obj_14_region_filter_RegionContext *)__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":85 * cdef RegionContext metric_wcs * metric_wcs = RegionContext() * metric_wcs.set_update_func(_update_metric_wcs) # <<<<<<<<<<<<<< * * */ __pyx_t_1 = ((struct __pyx_vtabstruct_14_region_filter_RegionContext *)__pyx_v_14_region_filter_metric_wcs->__pyx_vtab)->set_update_func(__pyx_v_14_region_filter_metric_wcs, __pyx_f_14_region_filter__update_metric_wcs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":89 * * * class BaseClassInitException(Exception): # <<<<<<<<<<<<<< * pass * */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_builtin_Exception); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_Exception); __Pyx_GIVEREF(__pyx_builtin_Exception); __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s_1, __pyx_n_s___region_filter); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; if (PyObject_SetAttr(__pyx_m, __pyx_n_s_1, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; /* "_region_filter.pyx":409 * * * def RegionAnd(RegionBase region1, RegionBase region2): # <<<<<<<<<<<<<< * """ * >>> r = RegionAnd(reg1, reg2) */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_14_region_filter_RegionAnd, NULL, __pyx_n_s___region_filter); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__RegionAnd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":426 * * * def RegionOr(RegionBase region1, RegionBase region2): # <<<<<<<<<<<<<< * """ * >>> r = RegionOr(reg1, reg2) */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_14_region_filter_1RegionOr, NULL, __pyx_n_s___region_filter); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__RegionOr, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_region_filter.pyx":2 * * cdef extern from "stdio.h": # <<<<<<<<<<<<<< * pass * */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_13), ((PyObject *)__pyx_kp_u_14)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_kp_u_15), ((PyObject *)__pyx_kp_u_16)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; /* "c_python.pxd":1 * # -*- Mode: Python -*- Not really, but close enough # <<<<<<<<<<<<<< * * # Expose as much of the Python C API as we need here */ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); if (__pyx_m) { __Pyx_AddTraceback("init _region_filter"); Py_DECREF(__pyx_m); __pyx_m = 0; } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init _region_filter"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); #if PY_MAJOR_VERSION < 3 return; #else return __pyx_m; #endif } /* Runtime support code */ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { PyObject *result; result = PyObject_GetAttr(dict, name); if (!result) PyErr_SetObject(PyExc_NameError, name); return result; } static void __Pyx_RaiseArgtupleInvalid( const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found) { Py_ssize_t num_expected; const char *number, *more_or_less; if (num_found < num_min) { num_expected = num_min; more_or_less = "at least"; } else { num_expected = num_max; more_or_less = "at most"; } if (exact) { more_or_less = "exactly"; } number = (num_expected == 1) ? "" : "s"; PyErr_Format(PyExc_TypeError, #if PY_VERSION_HEX < 0x02050000 "%s() takes %s %d positional argument%s (%d given)", #else "%s() takes %s %zd positional argument%s (%zd given)", #endif func_name, more_or_less, num_expected, number, num_found); } static CYTHON_INLINE int __Pyx_CheckKeywordStrings( PyObject *kwdict, const char* function_name, int kw_allowed) { PyObject* key = 0; Py_ssize_t pos = 0; while (PyDict_Next(kwdict, &pos, &key, 0)) { #if PY_MAJOR_VERSION < 3 if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) #else if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) #endif goto invalid_keyword_type; } if ((!kw_allowed) && unlikely(key)) goto invalid_keyword; return 1; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%s() keywords must be strings", function_name); return 0; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 "%s() got an unexpected keyword argument '%s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", function_name, key); #endif return 0; } static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); tmp_type = tstate->curexc_type; tmp_value = tstate->curexc_value; tmp_tb = tstate->curexc_traceback; tstate->curexc_type = type; tstate->curexc_value = value; tstate->curexc_traceback = tb; Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); } static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { PyThreadState *tstate = PyThreadState_GET(); *type = tstate->curexc_type; *value = tstate->curexc_value; *tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; } #if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { Py_XINCREF(type); Py_XINCREF(value); Py_XINCREF(tb); /* First, check the traceback argument, replacing None with NULL. */ if (tb == Py_None) { Py_DECREF(tb); tb = 0; } else if (tb != NULL && !PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "raise: arg 3 must be a traceback or None"); goto raise_error; } /* Next, replace a missing value with None */ if (value == NULL) { value = Py_None; Py_INCREF(value); } #if PY_VERSION_HEX < 0x02050000 if (!PyClass_Check(type)) #else if (!PyType_Check(type)) #endif { /* Raising an instance. The value should be a dummy. */ if (value != Py_None) { PyErr_SetString(PyExc_TypeError, "instance exception may not have a separate value"); goto raise_error; } /* Normalize to raise , */ Py_DECREF(value); value = type; #if PY_VERSION_HEX < 0x02050000 if (PyInstance_Check(type)) { type = (PyObject*) ((PyInstanceObject*)type)->in_class; Py_INCREF(type); } else { type = 0; PyErr_SetString(PyExc_TypeError, "raise: exception must be an old-style class or instance"); goto raise_error; } #else type = (PyObject*) Py_TYPE(type); Py_INCREF(type); if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { PyErr_SetString(PyExc_TypeError, "raise: exception class must be a subclass of BaseException"); goto raise_error; } #endif } __Pyx_ErrRestore(type, value, tb); return; raise_error: Py_XDECREF(value); Py_XDECREF(type); Py_XDECREF(tb); return; } #else /* Python 3+ */ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { if (tb == Py_None) { tb = 0; } else if (tb && !PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "raise: arg 3 must be a traceback or None"); goto bad; } if (value == Py_None) value = 0; if (PyExceptionInstance_Check(type)) { if (value) { PyErr_SetString(PyExc_TypeError, "instance exception may not have a separate value"); goto bad; } value = type; type = (PyObject*) Py_TYPE(value); } else if (!PyExceptionClass_Check(type)) { PyErr_SetString(PyExc_TypeError, "raise: exception class must be a subclass of BaseException"); goto bad; } PyErr_SetObject(type, value); if (tb) { PyThreadState *tstate = PyThreadState_GET(); PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { Py_INCREF(tb); tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } } bad: return; } #endif static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact) { if (!type) { PyErr_Format(PyExc_SystemError, "Missing type object"); return 0; } if (none_allowed && obj == Py_None) return 1; else if (exact) { if (Py_TYPE(obj) == type) return 1; } else { if (PyObject_TypeCheck(obj, type)) return 1; } PyErr_Format(PyExc_TypeError, "Argument '%s' has incorrect type (expected %s, got %s)", name, type->tp_name, Py_TYPE(obj)->tp_name); return 0; } static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { if (unlikely(!type)) { PyErr_Format(PyExc_SystemError, "Missing type object"); return 0; } if (likely(PyObject_TypeCheck(obj, type))) return 1; PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", Py_TYPE(obj)->tp_name, type->tp_name); return 0; } static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) { PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION >= 3 "%s() got multiple values for keyword argument '%U'", func_name, kw_name); #else "%s() got multiple values for keyword argument '%s'", func_name, PyString_AS_STRING(kw_name)); #endif } static int __Pyx_ParseOptionalKeywords( PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name) { PyObject *key = 0, *value = 0; Py_ssize_t pos = 0; PyObject*** name; PyObject*** first_kw_arg = argnames + num_pos_args; while (PyDict_Next(kwds, &pos, &key, &value)) { name = first_kw_arg; while (*name && (**name != key)) name++; if (*name) { values[name-argnames] = value; } else { #if PY_MAJOR_VERSION < 3 if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { #else if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) { #endif goto invalid_keyword_type; } else { for (name = first_kw_arg; *name; name++) { #if PY_MAJOR_VERSION >= 3 if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && PyUnicode_Compare(**name, key) == 0) break; #else if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && _PyString_Eq(**name, key)) break; #endif } if (*name) { values[name-argnames] = value; } else { /* unexpected keyword found */ for (name=argnames; name != first_kw_arg; name++) { if (**name == key) goto arg_passed_twice; #if PY_MAJOR_VERSION >= 3 if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; #else if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && _PyString_Eq(**name, key)) goto arg_passed_twice; #endif } if (kwds2) { if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; } else { goto invalid_keyword; } } } } } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, **name); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 "%s() got an unexpected keyword argument '%s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", function_name, key); #endif bad: return -1; } static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases) { PyObject *metaclass; /* Default metaclass */ #if PY_MAJOR_VERSION < 3 if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) { PyObject *base = PyTuple_GET_ITEM(bases, 0); metaclass = PyObject_GetAttrString(base, "__class__"); if (!metaclass) { PyErr_Clear(); metaclass = (PyObject*) Py_TYPE(base); } } else { metaclass = (PyObject *) &PyClass_Type; } #else if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) { PyObject *base = PyTuple_GET_ITEM(bases, 0); metaclass = (PyObject*) Py_TYPE(base); } else { metaclass = (PyObject *) &PyType_Type; } #endif Py_INCREF(metaclass); return metaclass; } static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, PyObject *modname) { PyObject *result; PyObject *metaclass; if (PyDict_SetItemString(dict, "__module__", modname) < 0) return NULL; /* Python2 __metaclass__ */ metaclass = PyDict_GetItemString(dict, "__metaclass__"); if (metaclass) { Py_INCREF(metaclass); } else { metaclass = __Pyx_FindPy2Metaclass(bases); } result = PyObject_CallFunctionObjArgs(metaclass, name, bases, dict, NULL); Py_DECREF(metaclass); return result; } static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_npy_bool(npy_bool val) { const npy_bool neg_one = (npy_bool)-1, const_zero = (npy_bool)0; const int is_unsigned = const_zero < neg_one; if ((sizeof(npy_bool) == sizeof(char)) || (sizeof(npy_bool) == sizeof(short))) { return PyInt_FromLong((long)val); } else if ((sizeof(npy_bool) == sizeof(int)) || (sizeof(npy_bool) == sizeof(long))) { if (is_unsigned) return PyLong_FromUnsignedLong((unsigned long)val); else return PyInt_FromLong((long)val); } else if (sizeof(npy_bool) == sizeof(PY_LONG_LONG)) { if (is_unsigned) return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val); else return PyLong_FromLongLong((PY_LONG_LONG)val); } else { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; return _PyLong_FromByteArray(bytes, sizeof(npy_bool), little, !is_unsigned); } } static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { const unsigned char neg_one = (unsigned char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned char" : "value too large to convert to unsigned char"); } return (unsigned char)-1; } return (unsigned char)val; } return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { const unsigned short neg_one = (unsigned short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned short" : "value too large to convert to unsigned short"); } return (unsigned short)-1; } return (unsigned short)val; } return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { const unsigned int neg_one = (unsigned int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(unsigned int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(unsigned int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to unsigned int" : "value too large to convert to unsigned int"); } return (unsigned int)-1; } return (unsigned int)val; } return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); } static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { const char neg_one = (char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to char" : "value too large to convert to char"); } return (char)-1; } return (char)val; } return (char)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { const short neg_one = (short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to short" : "value too large to convert to short"); } return (short)-1; } return (short)val; } return (short)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { const int neg_one = (int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to int" : "value too large to convert to int"); } return (int)-1; } return (int)val; } return (int)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { const signed char neg_one = (signed char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed char) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed char)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed char" : "value too large to convert to signed char"); } return (signed char)-1; } return (signed char)val; } return (signed char)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { const signed short neg_one = (signed short)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed short) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed short)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed short" : "value too large to convert to signed short"); } return (signed short)-1; } return (signed short)val; } return (signed short)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { const signed int neg_one = (signed int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(signed int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(signed int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to signed int" : "value too large to convert to signed int"); } return (signed int)-1; } return (signed int)val; } return (signed int)__Pyx_PyInt_AsSignedLong(x); } static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { const int neg_one = (int)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; if (sizeof(int) < sizeof(long)) { long val = __Pyx_PyInt_AsLong(x); if (unlikely(val != (long)(int)val)) { if (!unlikely(val == -1 && PyErr_Occurred())) { PyErr_SetString(PyExc_OverflowError, (is_unsigned && unlikely(val < 0)) ? "can't convert negative value to int" : "value too large to convert to int"); } return (int)-1; } return (int)val; } return (int)__Pyx_PyInt_AsLong(x); } static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { const unsigned long neg_one = (unsigned long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned long"); return (unsigned long)-1; } return (unsigned long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned long"); return (unsigned long)-1; } return PyLong_AsUnsignedLong(x); } else { return PyLong_AsLong(x); } } else { unsigned long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (unsigned long)-1; val = __Pyx_PyInt_AsUnsignedLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG)-1; } return (unsigned PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to unsigned PY_LONG_LONG"); return (unsigned PY_LONG_LONG)-1; } return PyLong_AsUnsignedLongLong(x); } else { return PyLong_AsLongLong(x); } } else { unsigned PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (unsigned PY_LONG_LONG)-1; val = __Pyx_PyInt_AsUnsignedLongLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { const long neg_one = (long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long)-1; } return (long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long)-1; } return PyLong_AsUnsignedLong(x); } else { return PyLong_AsLong(x); } } else { long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (long)-1; val = __Pyx_PyInt_AsLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to PY_LONG_LONG"); return (PY_LONG_LONG)-1; } return (PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to PY_LONG_LONG"); return (PY_LONG_LONG)-1; } return PyLong_AsUnsignedLongLong(x); } else { return PyLong_AsLongLong(x); } } else { PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (PY_LONG_LONG)-1; val = __Pyx_PyInt_AsLongLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { const signed long neg_one = (signed long)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed long"); return (signed long)-1; } return (signed long)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed long"); return (signed long)-1; } return PyLong_AsUnsignedLong(x); } else { return PyLong_AsLong(x); } } else { signed long val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (signed long)-1; val = __Pyx_PyInt_AsSignedLong(tmp); Py_DECREF(tmp); return val; } } static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_VERSION_HEX < 0x03000000 if (likely(PyInt_Check(x))) { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed PY_LONG_LONG"); return (signed PY_LONG_LONG)-1; } return (signed PY_LONG_LONG)val; } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, "can't convert negative value to signed PY_LONG_LONG"); return (signed PY_LONG_LONG)-1; } return PyLong_AsUnsignedLongLong(x); } else { return PyLong_AsLongLong(x); } } else { signed PY_LONG_LONG val; PyObject *tmp = __Pyx_PyNumber_Int(x); if (!tmp) return (signed PY_LONG_LONG)-1; val = __Pyx_PyInt_AsSignedLongLong(tmp); Py_DECREF(tmp); return val; } } static void __Pyx_WriteUnraisable(const char *name) { PyObject *old_exc, *old_val, *old_tb; PyObject *ctx; __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); #if PY_MAJOR_VERSION < 3 ctx = PyString_FromString(name); #else ctx = PyUnicode_FromString(name); #endif __Pyx_ErrRestore(old_exc, old_val, old_tb); if (!ctx) { PyErr_WriteUnraisable(Py_None); } else { PyErr_WriteUnraisable(ctx); Py_DECREF(ctx); } } static int __Pyx_SetVtable(PyObject *dict, void *vtable) { #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) PyObject *ob = PyCapsule_New(vtable, 0, 0); #else PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); #endif if (!ob) goto bad; if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0) goto bad; Py_DECREF(ob); return 0; bad: Py_XDECREF(ob); return -1; } #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size, int strict) { PyObject *py_module = 0; PyObject *result = 0; PyObject *py_name = 0; char warning[200]; py_module = __Pyx_ImportModule(module_name); if (!py_module) goto bad; #if PY_MAJOR_VERSION < 3 py_name = PyString_FromString(class_name); #else py_name = PyUnicode_FromString(class_name); #endif if (!py_name) goto bad; result = PyObject_GetAttr(py_module, py_name); Py_DECREF(py_name); py_name = 0; Py_DECREF(py_module); py_module = 0; if (!result) goto bad; if (!PyType_Check(result)) { PyErr_Format(PyExc_TypeError, "%s.%s is not a type object", module_name, class_name); goto bad; } if (!strict && ((PyTypeObject *)result)->tp_basicsize > size) { PyOS_snprintf(warning, sizeof(warning), "%s.%s size changed, may indicate binary incompatibility", module_name, class_name); #if PY_VERSION_HEX < 0x02050000 PyErr_Warn(NULL, warning); #else PyErr_WarnEx(NULL, warning, 0); #endif } else if (((PyTypeObject *)result)->tp_basicsize != size) { PyErr_Format(PyExc_ValueError, "%s.%s has the wrong size, try recompiling", module_name, class_name); goto bad; } return (PyTypeObject *)result; bad: Py_XDECREF(py_module); Py_XDECREF(result); return 0; } #endif #ifndef __PYX_HAVE_RT_ImportModule #define __PYX_HAVE_RT_ImportModule static PyObject *__Pyx_ImportModule(const char *name) { PyObject *py_name = 0; PyObject *py_module = 0; #if PY_MAJOR_VERSION < 3 py_name = PyString_FromString(name); #else py_name = PyUnicode_FromString(name); #endif if (!py_name) goto bad; py_module = PyImport_Import(py_name); Py_DECREF(py_name); return py_module; bad: Py_XDECREF(py_name); return 0; } #endif #include "compile.h" #include "frameobject.h" #include "traceback.h" static void __Pyx_AddTraceback(const char *funcname) { PyObject *py_srcfile = 0; PyObject *py_funcname = 0; PyObject *py_globals = 0; PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; #if PY_MAJOR_VERSION < 3 py_srcfile = PyString_FromString(__pyx_filename); #else py_srcfile = PyUnicode_FromString(__pyx_filename); #endif if (!py_srcfile) goto bad; if (__pyx_clineno) { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); #else py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); #endif } else { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromString(funcname); #else py_funcname = PyUnicode_FromString(funcname); #endif } if (!py_funcname) goto bad; py_globals = PyModule_GetDict(__pyx_m); if (!py_globals) goto bad; py_code = PyCode_New( 0, /*int argcount,*/ #if PY_MAJOR_VERSION >= 3 0, /*int kwonlyargcount,*/ #endif 0, /*int nlocals,*/ 0, /*int stacksize,*/ 0, /*int flags,*/ __pyx_empty_bytes, /*PyObject *code,*/ __pyx_empty_tuple, /*PyObject *consts,*/ __pyx_empty_tuple, /*PyObject *names,*/ __pyx_empty_tuple, /*PyObject *varnames,*/ __pyx_empty_tuple, /*PyObject *freevars,*/ __pyx_empty_tuple, /*PyObject *cellvars,*/ py_srcfile, /*PyObject *filename,*/ py_funcname, /*PyObject *name,*/ __pyx_lineno, /*int firstlineno,*/ __pyx_empty_bytes /*PyObject *lnotab*/ ); if (!py_code) goto bad; py_frame = PyFrame_New( PyThreadState_GET(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ py_globals, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; py_frame->f_lineno = __pyx_lineno; PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_srcfile); Py_XDECREF(py_funcname); Py_XDECREF(py_code); Py_XDECREF(py_frame); } static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); } else if (t->intern) { *t->p = PyString_InternFromString(t->s); } else { *t->p = PyString_FromStringAndSize(t->s, t->n - 1); } #else /* Python 3+ has unicode identifiers */ if (t->is_unicode | t->is_str) { if (t->intern) { *t->p = PyUnicode_InternFromString(t->s); } else if (t->encoding) { *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); } else { *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); } } else { *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); } #endif if (!*t->p) return -1; ++t; } return 0; } /* Type Conversion Functions */ static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { int is_true = x == Py_True; if (is_true | (x == Py_False) | (x == Py_None)) return is_true; else return PyObject_IsTrue(x); } static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { PyNumberMethods *m; const char *name = NULL; PyObject *res = NULL; #if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(x) || PyLong_Check(x)) #else if (PyLong_Check(x)) #endif return Py_INCREF(x), x; m = Py_TYPE(x)->tp_as_number; #if PY_VERSION_HEX < 0x03000000 if (m && m->nb_int) { name = "int"; res = PyNumber_Int(x); } else if (m && m->nb_long) { name = "long"; res = PyNumber_Long(x); } #else if (m && m->nb_int) { name = "int"; res = PyNumber_Long(x); } #endif if (res) { #if PY_VERSION_HEX < 0x03000000 if (!PyInt_Check(res) && !PyLong_Check(res)) { #else if (!PyLong_Check(res)) { #endif PyErr_Format(PyExc_TypeError, "__%s__ returned non-%s (type %.200s)", name, name, Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "an integer is required"); } return res; } static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { Py_ssize_t ival; PyObject* x = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); return ival; } static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { #if PY_VERSION_HEX < 0x02050000 if (ival <= LONG_MAX) return PyInt_FromLong((long)ival); else { unsigned char *bytes = (unsigned char *) &ival; int one = 1; int little = (int)*(unsigned char*)&one; return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); } #else return PyInt_FromSize_t(ival); #endif } static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { return (size_t)-1; } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { PyErr_SetString(PyExc_OverflowError, "value too large to convert to size_t"); return (size_t)-1; } return (size_t)val; } #endif /* Py_PYTHON_H */ pyregion-1.1.4/src/_region_filter.pyx0000644000175000017500000005461112255736553020121 0ustar jjleejjlee00000000000000 cdef extern from "stdio.h": pass cdef extern from "stdlib.h": pass # cdef extern from "geom2.h": # ctypedef struct Metric: # double g_x # double g_y # ctypedef struct RegionContext: # int (*init_metric)(Metric *m, double x0, double y0) # #cdef extern RegionContext metric_wcs cimport c_numpy from c_numpy cimport npy_bool cimport c_python c_numpy.import_array() #c_numpy.import_ufunc() ctypedef int Py_ssize_t class NotYetImplemented(Exception): pass class RegionFilterException(Exception): pass cdef struct Metric: double x0 double y0 double g_x double g_y cdef int MetricSetOrigin(Metric *m, double x0, double y0): m.x0 = x0 m.y0 = y0 #m.g_x = 1. #m.g_y = 1. cdef struct _RegionContext: int (*update_metric)(Metric *m) cdef class RegionContext: #cdef int (*init_metric)(Metric *m, double x0, double y0) cdef _RegionContext c def __init__(self): pass cdef set_update_func(self, int (*update_metric)(Metric *m)): self.c.update_metric = update_metric cdef int _update_metric_default(Metric *m): m.g_x = 1. m.g_y = 1. cdef int _update_metric_wcs(Metric *m): cdef double theta theta = m.y0/180.*3.1415926; m.g_x = cos(theta) m.g_y = 1. #cdef RegionContext metric_default #metric_default._set(_init_metric_default) cdef RegionContext metric_wcs metric_wcs = RegionContext() metric_wcs.set_update_func(_update_metric_wcs) class BaseClassInitException(Exception): pass cdef class RegionBase: #cdef double sin_theta #cdef double cos_theta cdef Metric m cdef RegionContext c #cdef __new__(self): # MetricInit(&(self.m), xc, yc) def __init__(self): #selc.c = metric_default #self.update_context(metric_default) #MetricInit(&(self.m), x0, y0) raise BaseClassInitException() cdef update_metric(self): if self.c: self.c.c.update_metric(&(self.m)) else: _update_metric_default(&(self.m)) def set_context(self, RegionContext cnt): self.c = cnt self.update_metric() cdef metric_set_origin(self, double xc, double yc, RegionContext cnt): MetricSetOrigin(&(self.m), xc, yc) if cnt: self.set_context(cnt) else: self.update_metric() def __invert__(self): return RegionNot(self) def __and__(self, RegionBase o): return RegionAnd(self, o) def __or__(self, RegionBase o): return RegionOr(self, o) cdef npy_bool _inside(self, double x, double y): return (0) def mask(self, img_or_shape): """ Create a mask ( a 2-d image whose pixel value is 1 if the pixel is inside the filter, otherwise 0). It takes a single argument which is numpy 2d array (or any python object with *shape* attribute) or a tuple of two integer representing the image shape. """ cdef int l, nx, ny if hasattr(img_or_shape, "shape"): shape = img_or_shape.shape elif c_python.PySequence_Check(img_or_shape): shape = img_or_shape else: raise RegionFilterException("the inut needs to be a numpy 2-d array or a tuple of two integers") if c_python.PySequence_Length(shape) != 2: raise RegionFilterException("shape of the input image must be 2d: %s is given" % (str(shape))) ny = c_python.PySequence_GetItem(shape, 0) nx = c_python.PySequence_GetItem(shape, 1) return self._mask(nx, ny) cdef c_numpy.ndarray _mask(self, c_numpy.npy_intp nx, c_numpy.npy_intp ny): cdef c_numpy.npy_intp ny_nx[2] cdef c_numpy.ndarray ra cdef npy_bool *rd cdef int iy, ix ny_nx[0] = ny ny_nx[1] = nx ra = c_numpy.PyArray_EMPTY(2, ny_nx, c_numpy.NPY_BOOL, 0) rd = c_numpy.PyArray_DATA(ra) for iy from 0 <= iy < ny: for ix from 0 <= ix < nx: #rd[iy*nx + ix] = self._inside(i, j) # altenatively more optimized #rd[0] = self._inside(ix+1, iy+1) # +1 for (1,1) based.. rd[0] = self._inside(ix, iy) rd = rd + 1 return ra def inside1(self, double x, double y): """ inside1(float, float) : returns True if the point (x,y) is inside the filter. """ return self._inside(x, y) def inside(self, x, y=None): if y is None: if len(x.shape) == 2 and x.shape[-1] == 2: return self.inside_xy(x) else: raise ValueError("input array has a wrong shape") else: return self.inside_x_y(x, y) def inside_xy(self, xy): """ inside(x, y) : given the numpy array of x and y, returns an array b of same shape, where b[i] = inside1(x[i], y[i]) """ cdef c_numpy.ndarray xya cdef c_numpy.ndarray ra cdef double *xyd cdef npy_bool *rd cdef int i cdef int n xya = c_numpy.PyArray_ContiguousFromAny(xy, c_numpy.NPY_DOUBLE, 1, 0) ra = c_numpy.PyArray_EMPTY(1, xya.dimensions, c_numpy.NPY_BOOL, 0) xyd = c_numpy.PyArray_DATA(xya) rd = c_numpy.PyArray_DATA(ra) n = xya.dimensions[0] # c_numpy.PyArray_SIZE(xya) / 2 #_inside_ptr = self._inside for i from 0 <= i < n: rd[i] = self._inside(xyd[2*i], xyd[2*i+1]) return ra def inside_x_y(self, x, y): """ inside(x, y) : given the numpy array of x and y, returns an array b of same shape, where b[i] = inside1(x[i], y[i]) """ cdef c_numpy.ndarray xa cdef c_numpy.ndarray ya cdef c_numpy.ndarray ra cdef double *xd cdef double *yd cdef npy_bool *rd cdef int i cdef int n #cdef c_numpy.npy_bool ((*_inside_ptr)(RegionBase, double ,double )) # FIX : check if two input has identical shape xa = c_numpy.PyArray_ContiguousFromAny(x, c_numpy.NPY_DOUBLE, 1, 0) ya = c_numpy.PyArray_ContiguousFromAny(y, c_numpy.NPY_DOUBLE, 1, 0) ra = c_numpy.PyArray_EMPTY(xa.nd, xa.dimensions, c_numpy.NPY_BOOL, 0) xd = c_numpy.PyArray_DATA(xa) yd = c_numpy.PyArray_DATA(ya) rd = c_numpy.PyArray_DATA(ra) n = c_numpy.PyArray_SIZE(xa) #_inside_ptr = self._inside for i from 0 <= i < n: #self._inside(xd[0], yd[0]) #rd[i] = _inside_ptr(self, xd[i], yd[i]) rd[i] = self._inside(xd[i], yd[i]) #rd[i] = _inside_ptr(self, xd[i], yd[i]) #print xd[i], yd[i], rd[i] return ra # def inside2(self, x, y): # cdef c_numpy.ndarray xa # cdef c_numpy.ndarray ya # cdef c_numpy.ndarray ra # cdef double *xd # cdef double *yd # cdef npy_bool *rd # cdef int i # cdef int ((*_inside_ptr)(RegionBase, double ,double )) # cdef int n # # This approach fails! # cobj = c_python.PyObject_GetAttrString(self, "__pyx_vtable__") # _inside_ptr = c_python.PyCObject_AsVoidPtr(cobj) # xa = c_numpy.PyArray_ContiguousFromAny(x, c_numpy.NPY_DOUBLE, 1, 0) # ya = c_numpy.PyArray_ContiguousFromAny(y, c_numpy.NPY_DOUBLE, 1, 0) # ra = c_numpy.PyArray_EMPTY(xa.nd, xa.dimensions, # c_numpy.NPY_BOOL, 0) # xd = c_numpy.PyArray_DATA(xa) # yd = c_numpy.PyArray_DATA(ya) # rd = c_numpy.PyArray_DATA(ra) # n = c_numpy.PyArray_SIZE(xa) # for i from 0 <= i < n: # #self._inside(xd[0], yd[0]) # #rd[i] = _inside_ptr(self, xd[i], yd[i]) # rd[i] = self._inside(xd[i], yd[i]) # return ra cdef class RegionNot(RegionBase): """ >>> r = RegionNot(r2) """ cdef RegionBase child_region def __init__(self, RegionBase child_region): self.child_region = child_region cdef npy_bool _inside(self, double x, double y): return not(self.child_region._inside(x, y)) cdef class RegionList(RegionBase): cdef object child_regions def _check_type_of_list(self, kl): for k in kl: if not isinstance(k, RegionBase): raise TypeError("All elements should be subclass of RegionBase type: %s" % k) def __init__(self, *kl): self._check_type_of_list(kl) self.child_regions = list(kl) def __len__(self): return len(self.child_regions) def __getitem__(self, Py_ssize_t x): return self.child_regions[x] def __setitem__(self, Py_ssize_t x, RegionBase y): self.child_regions[x] = y def __delitem__(self, Py_ssize_t x): del self.child_regions[x] # def __getslice__(self, Py_ssize_t i, Py_ssize_t j): # return self.__class__(*self.child_regions[i:j]) # def __setslice__(self, Py_ssize_t i, Py_ssize_t j, x): # self._check_type_of_list(x) # self.child_regions[i:j] = x # def __delslice__(self, Py_ssize_t i, Py_ssize_t j): # del self.child_regions[i:j] def __contains__(self, RegionBase x): return x in self.child_regions def __repr__(self): return repr(self.child_regions) def asList(self): return self.child_regions cdef class RegionOrList(RegionList): """ >>> r = RegionOrList(r1, r2, r3, r4, ...) """ cdef npy_bool _inside(self, double x, double y): cdef c_python.PyListObject *child_regions cdef int i, n child_regions = self.child_regions n = c_python.PyList_GET_SIZE(child_regions) for i from 0 <= i < n: if ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): return 1 return 0 def __repr__(self): return "Or"+repr(self.child_regions) cdef class RegionAndList(RegionList): """ >>> r = RegionAndList(r1, r2, r3, r4, ...) """ cdef npy_bool _inside(self, double x, double y): cdef c_python.PyListObject *child_regions cdef int i, n child_regions = self.child_regions n = c_python.PyList_GET_SIZE(child_regions) for i from 0 <= i < n: if not ( c_python.PyList_GET_ITEM(child_regions, i))._inside(x, y): return 0 return 1 def __repr__(self): return "And"+repr(self.child_regions) def RegionAnd(RegionBase region1, RegionBase region2): """ >>> r = RegionAnd(reg1, reg2) """ if isinstance(region1, RegionAndList): region1_list = region1.asList() else: region1_list = [region1] if isinstance(region2, RegionAndList): region2_list = region2.asList() else: region2_list = [region2] return RegionAndList(*(region1_list + region2_list)) def RegionOr(RegionBase region1, RegionBase region2): """ >>> r = RegionOr(reg1, reg2) """ if isinstance(region1, RegionOrList): region1_list = region1.asList() else: region1_list = [region1] if isinstance(region2, RegionOrList): region2_list = region2.asList() else: region2_list = [region2] return RegionOrList(*(region1_list + region2_list)) # cdef class RegionAnd_OLD(RegionBase): # cdef RegionBase child_region1 # cdef RegionBase child_region2 # def __init__(self, RegionBase child_region1, RegionBase child_region2): # self.child_region1 = child_region1 # self.child_region2 = child_region2 # cdef npy_bool _inside(self, double x, double y): # return (self.child_region1._inside(x, y)) & (self.child_region2._inside(x, y)) # cdef class RegionOr_OLD(RegionBase): # cdef RegionBase child_region1 # cdef RegionBase child_region2 # def __init__(self, RegionBase child_region1, RegionBase child_region2): # self.child_region1 = child_region1 # self.child_region2 = child_region2 # cdef npy_bool _inside(self, double x, double y): # return (self.child_region1._inside(x, y)) | (self.child_region2._inside(x, y)) # cdef class Transformed(RegionBase): # cdef double T11, T12, T21, T22 # cdef double TI11, TI12, TI21, TI22 # cdef double origin_x, origin_y # cdef RegionBase child_region # def __init__(self, # RegionBase child_region, # double T11, double T12, double T21, double T22, # double origin_x, double origin_y): # self.child_region = child_region # self.T11 = T11 # self.T12 = T12 # self.T21 = T21 # self.T22 = T22 # # calculate inverse transform! # self.TI11 = T11 # self.TI12 = T12 # self.TI21 = T21 # self.TI22 = T22 # self.origin_x = origin_x # self.origin_y = origin_y # cdef int _transform(self, double x, double y, double *xp, double *yp): # cdef double x1, x2, y1, y2 # x1 = x - self.origin_x # y1 = y - self.origin_y # # FIX IT! # x2 = x1 # y2 = y1 # xp[0] = x2 + self.origin_x # yp[0] = y2 + self.origin_y # cdef npy_bool _inside(self, double x, double y): # cdef double xp, yp # cdef npy_bool r # self._transform(x, y, &xp, &yp) # r = self.child_region._inside(xp, yp) # return r cdef class Transform(RegionBase): cdef RegionBase child_region def __init__(self, RegionBase child_region): self.child_region = child_region property child: def __get__(self): return self.child_region #def __del__(self): # del self.child_region cdef int _transform(self, double x, double y, double *xp, double *yp): xp[0] = x yp[0] = y cdef npy_bool _inside(self, double x, double y): cdef double xp, yp cdef npy_bool r self._transform(x, y, &xp, &yp) r = self.child_region._inside(xp, yp) return r cdef extern from "math.h": double sin(double) double cos(double) double atan2(double, double) double fmod(double, double) double M_PI cdef class Rotated(Transform): """ Rotated >>> reg = Rotated(child_region, degree, origin_x, origin_y) Rotate the region by degree in anti-colockwise direction. """ cdef double sin_theta cdef double cos_theta cdef double origin_x, origin_y def __init__(self, RegionBase child_region, double degree, double origin_x, double origin_y): cdef double theta Transform.__init__(self, child_region) theta = degree / 180. * M_PI #3.1415926 self.sin_theta = sin(theta) self.cos_theta = cos(theta) self.origin_x = origin_x self.origin_y = origin_y cdef int _transform(self, double x, double y, double *xp, double *yp): cdef double x1, x2, y1, y2 cdef double st, ct, ox, oy st = self.sin_theta ct = self.cos_theta ox = self.origin_x oy = self.origin_y x1 = x - ox y1 = y - oy x2 = ct*x1 + st*y1 y2 = -st*x1 + ct*y1 xp[0] = x2 + ox yp[0] = y2 + oy cdef class Translated(Transform): """ Translated region >>> Translate(child_region, dx, dy) """ # translated region cdef double dx cdef double dy def __init__(self, RegionBase child_region, double dx, double dy): Transform.__init__(self, child_region) self.dx = dx self.dy = dy cdef int _transform(self, double x, double y, double *xp, double *yp): xp[0] = x - self.dx yp[0] = y - self.dy # Basic Shapes cdef class Circle(RegionBase): """ Circle >>> cir = Circle(xc, yc, radius, RegionContext c=None) """ cdef double xc cdef double yc cdef double radius cdef double radius2 #cdef Metric m cdef _set_v(self, double xc, double yc, double radius): self.xc = xc self.yc = yc self.radius = radius self.radius2 = radius*radius cdef _get_v(self): return (self.xc, self.yc, self.radius) def __init__(self, double xc, double yc, double radius, RegionContext c=None): """ """ #if c: # self.c = c self.metric_set_origin(xc, yc, c) self._set_v(xc, yc, radius) cdef npy_bool _inside(self, double x, double y): cdef double dist2 dist2 = ((x-self.xc)*self.m.g_x)**2 + ((y-self.yc)*self.m.g_y)**2 return (dist2 <= self.radius2) def __repr__(self): return "Circle(%f, %f, %f)" % (self.xc, self.yc, self.radius) cdef class Ellipse(RegionBase): """ Ellipse >>> shape = Ellipse(xc, yc, radius_major, radius_minor) """ cdef double xc cdef double yc cdef double radius_major cdef double radius_major_2 cdef double radius_minor cdef double radius_minor_2 cdef double radius_major_2_radius_minor_2 def __init__(self, double xc, double yc, double radius_major, double radius_minor, RegionContext c=None): # check inside # (x-xc)**2/radius_major**2 + (y-yc)**2/radius_minor**2 < 1 # radius_minor**2*(x-xc)**2 + radius_major**2*(y-yc)**2 < (radius_major*radius_minor)**2 self.xc = xc self.yc = yc self.radius_major = radius_major self.radius_minor = radius_minor self.radius_major_2 = radius_major**2 self.radius_minor_2 = radius_minor**2 self.radius_major_2_radius_minor_2 = self.radius_major_2 * self.radius_minor_2 self.metric_set_origin(xc, yc, c) #MetricInit(&(self.m), xc, yc) cdef npy_bool _inside(self, double x, double y): cdef double dist2 dist2 = self.radius_minor_2*(x-self.xc)**2 + self.radius_major_2*(y-self.yc)**2 return (dist2 <= self.radius_major_2_radius_minor_2) def __repr__(self): return "Ellipse(%f, %f, %f, %f)" % (self.xc, self.yc, self.radius_major, self.radius_minor) cdef class Box(RegionBase): """ Box >>> shape = Box(xc, yc, width, height) """ cdef double x1 cdef double x2 cdef double y1 cdef double y2 def __init__(self, double xc, double yc, double width, double height, RegionContext c=None): cdef double halfwidth cdef double halfheight halfwidth = width*.5 halfheight = height*.5 self.x1 = xc - halfwidth self.x2 = xc + halfwidth self.y1 = yc - halfheight self.y2 = yc + halfheight self.metric_set_origin(xc, yc, c) #MetricInit(&(self.m), xc, yc) cdef npy_bool _inside(self, double x, double y): return (self.x1 <= x) & (x <= self.x2) & (self.y1 <= y) & (y <= self.y2) cdef class Polygon(RegionBase): """ Polygon >>> shape = Polygon(x, y) x, y : list of floats """ cdef c_numpy.ndarray xa cdef c_numpy.ndarray ya #cdef object xa #cdef object ya cdef double *x cdef double *y cdef int n def __init__(self, x, y, RegionContext c=None): self.xa = c_numpy.PyArray_CopyFromObject(x, c_numpy.NPY_DOUBLE, 1, 1) self.ya = c_numpy.PyArray_CopyFromObject(y, c_numpy.NPY_DOUBLE, 1, 1) self.n = c_numpy.PyArray_SIZE(self.xa) self.x = c_numpy.PyArray_DATA(self.xa) self.y = c_numpy.PyArray_DATA(self.ya) self.metric_set_origin(self.x[0], self.y[0], c) #MetricInit(&(self.m), ) cdef npy_bool _inside(self, double x, double y): cdef int i, j cdef npy_bool r cdef double *xp cdef double *yp cdef double _t cdef double y_yp_i, y_yp_j j = self.n - 1 r = 0 xp = self.x yp = self.y # aopted from "http://alienryderflex.com/polygon/" # When the point is on the edge, the behavior seems undefined... # for i from 0 <= i < self.n: # if ((yp[i]<=y) & (yp[j]>y) | (yp[j]<=y) & (yp[i]>y)): # _t = xp[i]+(y-yp[i])/(yp[j]-yp[i])*(xp[j]-xp[i]) # if (_ty_yp_j) | (0<=y_yp_j) & (0>y_yp_i)): _t = xp[i]+y_yp_i/(yp[j]-yp[i])*(xp[j]-xp[i]) if _t == x: # return true immediately if point over the poly-edge return 1 # but above does not catch horizontal line if (_t>> shape = Ellipse(xc, yc, degree1, degree2) """ cdef double xc cdef double yc cdef double degree1 cdef double degree2 cdef double radian1 cdef double radian2 def __init__(self, double xc, double yc, double degree1, double degree2, RegionContext c=None): self.xc = xc self.yc = yc self.degree1 = degree1 self.degree2 = degree2 # theta in radian self.radian1 = degree1/180.*M_PI#3.1415926 self.radian2 = self._fix_angle(degree2/180.*M_PI) self.metric_set_origin(xc, yc, c) cdef double _fix_angle(self, double a): if a > self.radian1: return self.radian1 + fmod((a-self.radian1), 2*M_PI) else: return self.radian1 + 2.*M_PI - fmod((self.radian1-a), 2*M_PI) cdef npy_bool _inside(self, double x, double y): cdef double dx, dy, theta dx = x - self.xc dy = y - self.yc theta = atan2(dy, dx) #if theta < self.radian1: # theta += 2.*M_PI theta = self._fix_angle(theta) return (theta < self.radian2) def __repr__(self): return "AngleRange(%f, %f, %f, %f)" % (self.xc, self.yc, self.degree1, self.degree2) pyregion-1.1.4/distribute_setup.py0000644000175000017500000003661512255736553017555 0ustar jjleejjlee00000000000000#!python """Bootstrap distribute installation If you want to use setuptools in your package's setup.py, just include this file in the same directory with it, and add this to the top of your setup.py:: from distribute_setup import use_setuptools use_setuptools() If you want to require a specific version of setuptools, set a download mirror, or use an alternate download directory, you can do so by supplying the appropriate options to ``use_setuptools()``. This file can also be run as a script to install or upgrade setuptools. """ import os import sys import time import fnmatch import tempfile import tarfile from distutils import log try: from site import USER_SITE except ImportError: USER_SITE = None try: import subprocess def _python_cmd(*args): args = (sys.executable,) + args return subprocess.call(args) == 0 except ImportError: # will be used for python 2.3 def _python_cmd(*args): args = (sys.executable,) + args # quoting arguments if windows if sys.platform == 'win32': def quote(arg): if ' ' in arg: return '"%s"' % arg return arg args = [quote(arg) for arg in args] return os.spawnl(os.P_WAIT, sys.executable, *args) == 0 DEFAULT_VERSION = "0.6.24" DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/" SETUPTOOLS_FAKED_VERSION = "0.6c11" SETUPTOOLS_PKG_INFO = """\ Metadata-Version: 1.0 Name: setuptools Version: %s Summary: xxxx Home-page: xxx Author: xxx Author-email: xxx License: xxx Description: xxx """ % SETUPTOOLS_FAKED_VERSION def _install(tarball): # extracting the tarball tmpdir = tempfile.mkdtemp() log.warn('Extracting in %s', tmpdir) old_wd = os.getcwd() try: os.chdir(tmpdir) tar = tarfile.open(tarball) _extractall(tar) tar.close() # going in the directory subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) os.chdir(subdir) log.warn('Now working in %s', subdir) # installing log.warn('Installing Distribute') if not _python_cmd('setup.py', 'install'): log.warn('Something went wrong during the installation.') log.warn('See the error message above.') finally: os.chdir(old_wd) def _build_egg(egg, tarball, to_dir): # extracting the tarball tmpdir = tempfile.mkdtemp() log.warn('Extracting in %s', tmpdir) old_wd = os.getcwd() try: os.chdir(tmpdir) tar = tarfile.open(tarball) _extractall(tar) tar.close() # going in the directory subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) os.chdir(subdir) log.warn('Now working in %s', subdir) # building an egg log.warn('Building a Distribute egg in %s', to_dir) _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir) finally: os.chdir(old_wd) # returning the result log.warn(egg) if not os.path.exists(egg): raise IOError('Could not build the egg.') def _do_download(version, download_base, to_dir, download_delay): egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg' % (version, sys.version_info[0], sys.version_info[1])) if not os.path.exists(egg): tarball = download_setuptools(version, download_base, to_dir, download_delay) _build_egg(egg, tarball, to_dir) sys.path.insert(0, egg) import setuptools setuptools.bootstrap_install_from = egg def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15, no_fake=True): # making sure we use the absolute path to_dir = os.path.abspath(to_dir) was_imported = 'pkg_resources' in sys.modules or \ 'setuptools' in sys.modules try: try: import pkg_resources if not hasattr(pkg_resources, '_distribute'): if not no_fake: _fake_setuptools() raise ImportError except ImportError: return _do_download(version, download_base, to_dir, download_delay) try: pkg_resources.require("distribute>="+version) return except pkg_resources.VersionConflict: e = sys.exc_info()[1] if was_imported: sys.stderr.write( "The required version of distribute (>=%s) is not available,\n" "and can't be installed while this script is running. Please\n" "install a more recent version first, using\n" "'easy_install -U distribute'." "\n\n(Currently using %r)\n" % (version, e.args[0])) sys.exit(2) else: del pkg_resources, sys.modules['pkg_resources'] # reload ok return _do_download(version, download_base, to_dir, download_delay) except pkg_resources.DistributionNotFound: return _do_download(version, download_base, to_dir, download_delay) finally: if not no_fake: _create_fake_setuptools_pkg_info(to_dir) def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, delay=15): """Download distribute from a specified location and return its filename `version` should be a valid distribute version number that is available as an egg for download under the `download_base` URL (which should end with a '/'). `to_dir` is the directory where the egg will be downloaded. `delay` is the number of seconds to pause before an actual download attempt. """ # making sure we use the absolute path to_dir = os.path.abspath(to_dir) try: from urllib.request import urlopen except ImportError: from urllib2 import urlopen tgz_name = "distribute-%s.tar.gz" % version url = download_base + tgz_name saveto = os.path.join(to_dir, tgz_name) src = dst = None if not os.path.exists(saveto): # Avoid repeated downloads try: log.warn("Downloading %s", url) src = urlopen(url) # Read/write all in one block, so we don't create a corrupt file # if the download is interrupted. data = src.read() dst = open(saveto, "wb") dst.write(data) finally: if src: src.close() if dst: dst.close() return os.path.realpath(saveto) def _no_sandbox(function): def __no_sandbox(*args, **kw): try: from setuptools.sandbox import DirectorySandbox if not hasattr(DirectorySandbox, '_old'): def violation(*args): pass DirectorySandbox._old = DirectorySandbox._violation DirectorySandbox._violation = violation patched = True else: patched = False except ImportError: patched = False try: return function(*args, **kw) finally: if patched: DirectorySandbox._violation = DirectorySandbox._old del DirectorySandbox._old return __no_sandbox def _patch_file(path, content): """Will backup the file then patch it""" existing_content = open(path).read() if existing_content == content: # already patched log.warn('Already patched.') return False log.warn('Patching...') _rename_path(path) f = open(path, 'w') try: f.write(content) finally: f.close() return True _patch_file = _no_sandbox(_patch_file) def _same_content(path, content): return open(path).read() == content def _rename_path(path): new_name = path + '.OLD.%s' % time.time() log.warn('Renaming %s into %s', path, new_name) os.rename(path, new_name) return new_name def _remove_flat_installation(placeholder): if not os.path.isdir(placeholder): log.warn('Unkown installation at %s', placeholder) return False found = False for file in os.listdir(placeholder): if fnmatch.fnmatch(file, 'setuptools*.egg-info'): found = True break if not found: log.warn('Could not locate setuptools*.egg-info') return log.warn('Removing elements out of the way...') pkg_info = os.path.join(placeholder, file) if os.path.isdir(pkg_info): patched = _patch_egg_dir(pkg_info) else: patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO) if not patched: log.warn('%s already patched.', pkg_info) return False # now let's move the files out of the way for element in ('setuptools', 'pkg_resources.py', 'site.py'): element = os.path.join(placeholder, element) if os.path.exists(element): _rename_path(element) else: log.warn('Could not find the %s element of the ' 'Setuptools distribution', element) return True _remove_flat_installation = _no_sandbox(_remove_flat_installation) def _after_install(dist): log.warn('After install bootstrap.') placeholder = dist.get_command_obj('install').install_purelib _create_fake_setuptools_pkg_info(placeholder) def _create_fake_setuptools_pkg_info(placeholder): if not placeholder or not os.path.exists(placeholder): log.warn('Could not find the install location') return pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1]) setuptools_file = 'setuptools-%s-py%s.egg-info' % \ (SETUPTOOLS_FAKED_VERSION, pyver) pkg_info = os.path.join(placeholder, setuptools_file) if os.path.exists(pkg_info): log.warn('%s already exists', pkg_info) return log.warn('Creating %s', pkg_info) f = open(pkg_info, 'w') try: f.write(SETUPTOOLS_PKG_INFO) finally: f.close() pth_file = os.path.join(placeholder, 'setuptools.pth') log.warn('Creating %s', pth_file) f = open(pth_file, 'w') try: f.write(os.path.join(os.curdir, setuptools_file)) finally: f.close() _create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info) def _patch_egg_dir(path): # let's check if it's already patched pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') if os.path.exists(pkg_info): if _same_content(pkg_info, SETUPTOOLS_PKG_INFO): log.warn('%s already patched.', pkg_info) return False _rename_path(path) os.mkdir(path) os.mkdir(os.path.join(path, 'EGG-INFO')) pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO') f = open(pkg_info, 'w') try: f.write(SETUPTOOLS_PKG_INFO) finally: f.close() return True _patch_egg_dir = _no_sandbox(_patch_egg_dir) def _before_install(): log.warn('Before install bootstrap.') _fake_setuptools() def _under_prefix(location): if 'install' not in sys.argv: return True args = sys.argv[sys.argv.index('install')+1:] for index, arg in enumerate(args): for option in ('--root', '--prefix'): if arg.startswith('%s=' % option): top_dir = arg.split('root=')[-1] return location.startswith(top_dir) elif arg == option: if len(args) > index: top_dir = args[index+1] return location.startswith(top_dir) if arg == '--user' and USER_SITE is not None: return location.startswith(USER_SITE) return True def _fake_setuptools(): log.warn('Scanning installed packages') try: import pkg_resources except ImportError: # we're cool log.warn('Setuptools or Distribute does not seem to be installed.') return ws = pkg_resources.working_set try: setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools', replacement=False)) except TypeError: # old distribute API setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools')) if setuptools_dist is None: log.warn('No setuptools distribution found') return # detecting if it was already faked setuptools_location = setuptools_dist.location log.warn('Setuptools installation detected at %s', setuptools_location) # if --root or --preix was provided, and if # setuptools is not located in them, we don't patch it if not _under_prefix(setuptools_location): log.warn('Not patching, --root or --prefix is installing Distribute' ' in another location') return # let's see if its an egg if not setuptools_location.endswith('.egg'): log.warn('Non-egg installation') res = _remove_flat_installation(setuptools_location) if not res: return else: log.warn('Egg installation') pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO') if (os.path.exists(pkg_info) and _same_content(pkg_info, SETUPTOOLS_PKG_INFO)): log.warn('Already patched.') return log.warn('Patching...') # let's create a fake egg replacing setuptools one res = _patch_egg_dir(setuptools_location) if not res: return log.warn('Patched done.') _relaunch() def _relaunch(): log.warn('Relaunching...') # we have to relaunch the process # pip marker to avoid a relaunch bug if sys.argv[:3] == ['-c', 'install', '--single-version-externally-managed']: sys.argv[0] = 'setup.py' args = [sys.executable] + sys.argv sys.exit(subprocess.call(args)) def _extractall(self, path=".", members=None): """Extract all members from the archive to the current working directory and set owner, modification time and permissions on directories afterwards. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by getmembers(). """ import copy import operator from tarfile import ExtractError directories = [] if members is None: members = self for tarinfo in members: if tarinfo.isdir(): # Extract directories with a safe mode. directories.append(tarinfo) tarinfo = copy.copy(tarinfo) tarinfo.mode = 448 # decimal for oct 0700 self.extract(tarinfo, path) # Reverse sort directories. if sys.version_info < (2, 4): def sorter(dir1, dir2): return cmp(dir1.name, dir2.name) directories.sort(sorter) directories.reverse() else: directories.sort(key=operator.attrgetter('name'), reverse=True) # Set correct owner, mtime and filemode on directories. for tarinfo in directories: dirpath = os.path.join(path, tarinfo.name) try: self.chown(tarinfo, dirpath) self.utime(tarinfo, dirpath) self.chmod(tarinfo, dirpath) except ExtractError: e = sys.exc_info()[1] if self.errorlevel > 1: raise else: self._dbg(1, "tarfile: %s" % e) def main(argv, version=DEFAULT_VERSION): """Install or upgrade setuptools and EasyInstall""" tarball = download_setuptools() _install(tarball) if __name__ == '__main__': main(sys.argv[1:]) pyregion-1.1.4/README0000644000175000017500000000123512255736553014453 0ustar jjleejjlee00000000000000pyregion ======== pyregion is a python module to parse ds9 region files. It also supports ciao region files. Homepage : http://leejjoon.github.com/pyregion/ pyregion is "easy_install"able. http://pypi.python.org/pypi/pyregion FEATURES -------- * ds9 and ciao region files. * (physical, wcs) coordinate conversion to the image coordinate. * convert regions to matplotlib patches. * convert regions to spatial filter (i.e., generate mask images) LICENSE ------- All files (see exception below) are under MIT License. See LICENSE. * "lib/kapteyn_celestial.py" is from the Kapteyn package (http://www.astro.rug.nl/software/kapteyn/). See LICENSE_kapteyn.txt. pyregion-1.1.4/MANIFEST.in0000644000175000017500000000027412255736553015333 0ustar jjleejjlee00000000000000recursive-include examples *.py *.reg include examples/*.header include src/_region_filter.c include src/_region_filter.pyx include LICENSE LICENSE_kapteyn.txt include distribute_setup.py pyregion-1.1.4/setup.cfg0000664000175000017500000000007312423134227015400 0ustar jjleejjlee00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 pyregion-1.1.4/examples/0000775000175000017500000000000012423134227015375 5ustar jjleejjlee00000000000000pyregion-1.1.4/examples/demo_region_filter01.py0000644000175000017500000000217312255736553021762 0ustar jjleejjlee00000000000000try: from astropy.io import fits as pyfits except ImportError: import pyfits from demo_helper import pyfits_card_fromstring 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 header = demo_header() # sample fits header shape = (header["NAXIS1"], header["NAXIS2"]) reg_name = "test.reg" r = pyregion.open(reg_name).as_imagecoord(header) m = r.get_mask(shape=shape) fig = plt.figure(1, figsize=(7,5)) ax = plt.subplot(121) plt.imshow(m, origin="lower") patch_list, text_list = r.get_mpl_patches_texts() for p in patch_list: ax.add_patch(p) for t in text_list: ax.add_artist(t) # another region reg_name = "test02.reg" r = pyregion.open(reg_name).as_imagecoord(header) m = r.get_mask(shape=shape) ax = plt.subplot(122) plt.imshow(m, origin="lower") patch_list, text_list = r.get_mpl_patches_texts() for p in patch_list: ax.add_patch(p) for t in text_list: ax.add_artist(t) plt.show() pyregion-1.1.4/examples/demo_print_region.py0000644000175000017500000000233212255736553021465 0ustar jjleejjlee00000000000000from pyregion import read_region, read_region_as_imagecoord import math try: from astropy.io import fits as pyfits except ImportError: import pyfits from demo_helper import pyfits_card_fromstring 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 def print_region(r): for i, l in enumerate(r): print("[region %d]" % (i+1)) print() print("%s; %s(%s)" % (l.coord_format, l.name, ", ".join([str(s) for s in l.coord_list]))) print(l.attr[0]) print(", ".join(["%s=%s" % (k, v.strip()) for k, v in list(l.attr[1].items())])) print() if __name__ == "__main__": print("** coordinate in FK5 **") print() region_name = "test01_print.reg" #region_name = "test_text.reg" #region_name = "test01.reg" r = read_region(open(region_name).read()) print_region(r) print() print() print("** coordinate in image **") print() header = test_header() r = read_region_as_imagecoord(open(region_name).read(), header) print_region(r) pyregion-1.1.4/examples/test_text.reg0000644000175000017500000000124512255736553020134 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 fk5 line(171.2398,-59.290221,171.17045,-59.241461) # line=1 1 width=2 # vector(171.15897,-59.260323,121.9732",291.286) vector=1 # text(171.08249,-59.263998) font="helvetica 14 normal" text={Region} line(171.12155,-59.236131,171.06222,-59.243213) # line=0 0 font="helvetica 14 normal" dash=1 # compass(171.09742,-59.292704,31.583948") compass=physical {N} {E} 1 1 font="helvetica 14 normal" dash=1 # ruler(171.25782,-59.237453,171.2087,-59.261266) ruler=physical physical pyregion-1.1.4/examples/test01_img.reg0000644000175000017500000000063312255736553020065 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 image -ellipse(750,853,46,21,317.01716) # width=3 background circle(964,945,37.6236) # color=cyan box(730.5,718,87,48,19.038396) # width=4 polygon(878.11234,811.88766,1003,861,973,688,878.11234,752.11234) pyregion-1.1.4/examples/test01_fk5_sexagecimal.reg0000644000175000017500000000101512255736553022333 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 fk5 -ellipse(11:24:37.960,-59:15:47.50,22.632",10.332",317.017) # width=3 background circle(11:24:24.230,-59:15:02.20,18.5108") # color=cyan box(11:24:39.213,-59:16:53.91,42.804",23.616",19.0384) # width=4 polygon(11:24:29.737,-59:16:07.72,11:24:21.723,-59:15:43.52,11:24:23.641,-59:17:08.64,11:24:29.736,-59:16:37.13) pyregion-1.1.4/examples/test01_gal.reg0000644000175000017500000000104712255736553020054 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 galactic -ellipse(+292:01:59.027,+01:45:33.389,22.632",10.332",297.784) # width=3 background circle(+292:00:04.651,+01:45:41.444,18.5108") # color=cyan box(+292:02:29.979,+01:44:33.837,42.804",23.616",359.806) # width=4 polygon(+292:01:06.152,+01:44:53.528,+292:00:00.146,+01:44:56.102,+292:00:42.141,+01:43:40.599,+292:01:15.844,+01:44:25.760) pyregion-1.1.4/examples/test_annuli_wcs.reg0000644000175000017500000000215412255736553021312 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 fk5 ellipse(171.10843,-59.253758,14.960585",10.087995",28.857918",19.459034",52.743907",35.565473",30) annulus(171.16832,-59.254719,28.11015",37.480176",46.850202",56.22023") panda(171.16861,-59.281915,338.334,648.034,4,19.15789",38.315779",2) epanda(171.11991,-59.281368,53.141616,122.03456,1,16.696805",23.231349",33.39361",46.462699",1,28.831146) || # epanda=(53.141616 122.03456 217.20636 259.80344 311.69855)(16.696805" 23.231349" 33.39361" 46.462699")(28.831146) epanda(171.11991,-59.281368,122.03456,217.20636,1,16.696805",23.231349",33.39361",46.462699",1,28.831146) || # epanda=ignore epanda(171.11991,-59.281368,217.20636,259.80344,1,16.696805",23.231349",33.39361",46.462699",1,28.831146) || # epanda=ignore epanda(171.11991,-59.281368,259.80344,311.69855,1,16.696805",23.231349",33.39361",46.462699",1,28.831146) # epanda=ignore bpanda(171.09611,-59.273707,0,360,4,14.267754",15.251754",28.535508",30.503508",1,0) pyregion-1.1.4/examples/ttt_region01.py0000664000175000017500000000205111711202666020266 0ustar jjleejjlee00000000000000import pyregion 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 if 1: region_list = ["test01_fk5_sexagecimal.reg", "test01_gal.reg", "test01_img.reg", "test01_ds9_physical.reg", "test01_fk5_degree.reg", "test01_mixed.reg", "test01_ciao.reg", "test01_ciao_physical.reg", ] h = demo_header() for region_file in region_list[1:2]: reg = pyregion.open(region_file) reg01 = reg.as_imagecoord(h) pyregion-1.1.4/examples/test01_ds9_physical.reg0000644000175000017500000000064312255736553021705 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: t1.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 physical -ellipse(4053.9922,4121.9905,46,21,317.017) circle(4267.9987,4214.0083,37.623659) box(4034.5013,3987.0067,87,48,19.0384) polygon(4182.1103,4080.8819,4307.0067,4129.9947,4276.9938,3957.01,4182.1053,4021.1054) pyregion-1.1.4/examples/demo_region01.py0000644000175000017500000000121112255736553020405 0ustar jjleejjlee00000000000000import matplotlib.pyplot as plt from demo_helper import show_region if 1: region_list = ["test01_fk5_sexagecimal.reg", "test01_gal.reg", "test01_img.reg", "test01_ds9_physical.reg", "test01_fk5_degree.reg", "test01_mixed.reg", "test01_ciao.reg", "test01_ciao_physical.reg", ] fig = plt.figure(1, figsize=(6,5)) fig.clf() ax_list = show_region(fig, region_list) for ax in ax_list: ax.set_xlim(596, 1075) ax.set_ylim(585, 1057) plt.draw() plt.show() pyregion-1.1.4/examples/test01_fk5.reg0000644000175000017500000000075312255736553020001 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 fk5 -ellipse(171.15816,-59.263193,22.632",10.332",317.01716) # width=3 background circle(171.10096,-59.250612,18.510811") # color=cyan box(171.16339,-59.281643,42.804",23.616",19.038396) # width=4 polygon(171.1239,-59.26881,171.09051,-59.262088,171.0985,-59.285735,171.1239,-59.27698) pyregion-1.1.4/examples/demo_region04.py0000644000175000017500000000077312255736553020424 0ustar jjleejjlee00000000000000try: from astropy.io import fits as pyfits except ImportError: import pyfits import matplotlib.pyplot as plt import pyregion import math if 1: reg_name = "test04_img.reg" ax = plt.subplot(111) ax.set_xlim(600, 1100) ax.set_ylim(600, 1100) ax.set_aspect(1) r = pyregion.open(reg_name) patch_list, text_list = r.get_mpl_patches_texts() for p in patch_list: ax.add_patch(p) for t in text_list: ax.add_artist(t) plt.draw() plt.show() pyregion-1.1.4/examples/test01.reg0000644000175000017500000000076012255736553017232 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 fk5 ## -ellipse(171.15816,-59.263193,22.632",10.332",317.01716) # width=3 background ascircle(171.10096,-59.250612,18.510811") # color=cyan box(171.16339,-59.281643,42.804",23.616",19.038396) # width=4 polygon(171.1239,-59.26881,171.09051,-59.262088,171.0985,-59.285735,171.1239,-59.27698) pyregion-1.1.4/examples/test.reg0000644000175000017500000000423012255736553017065 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: pspc_skyview.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 fk5 circle(305.66137,46.273027,286.45302") ellipse(305.2084,46.309061,240",600",15.433424) # color=black width=4 box(304.61491,46.299899,1032",552",28.9055) # color=white tag={Group 1} polygon(304.30761,46.142612,303.94162,46.140616,304.12265,46.314927,303.72947,46.178781,303.9453,45.887034,304.10869,45.854872,304.30963,45.889013) # color=red line(305.70423,45.962694,305.10953,45.946101) # line=0 0 dash=1 # vector(305.47681,45.437697,1448.972",63.434949) vector=1 # text(304.75479,45.939998) text={Text} annulus(304.01194,45.570957,216",506.2428",674.9904") # color=yellow ellipse(304.7357,45.626666,349.44527",196.03028",797.79697",447.54464",339.24891) # width=2 tag={Group 1} panda(305.48266,45.157674,0,151.26,2,398.8488",797.6976",1) # color=blue width=2 epanda(304.78308,45.140013,0,88.057145,1,193.49419",257.83216",504.22594",671.88407",1,8.11303) # epanda=(0 88.057145 228.1969 327.92448)(193.49419" 257.83216" 504.22594" 671.88407" 672.30125" 895.84543")(8.11303) color=cyan epanda(304.78308,45.140013,0,88.057145,1,504.22594",671.88407",672.30125",895.84543",1,8.11303) # epanda=ignore epanda(304.78308,45.140013,88.057145,228.1969,1,193.49419",257.83216",504.22594",671.88407",1,8.11303) # epanda=ignore epanda(304.78308,45.140013,88.057145,228.1969,1,504.22594",671.88407",672.30125",895.84543",1,8.11303) # epanda=ignore epanda(304.78308,45.140013,228.1969,327.92448,1,193.49419",257.83216",504.22594",671.88407",1,8.11303) # epanda=ignore epanda(304.78308,45.140013,228.1969,327.92448,1,504.22594",671.88407",672.30125",895.84543",1,8.11303) # epanda=ignore point(304.26232,45.252305) # point=circle point(304.0256,45.251053) # point=box color=magenta point(303.79815,45.262722) # point=diamond point(304.25414,45.105615) # point=cross point(304.04637,45.104528) # point=x point(304.25577,44.918982) # point=arrow point(304.02028,44.931056) # point=boxcircle bpanda(305.53095,44.934745,0,290,1,605.36378",294.48644",1371.1215",666.9984",1,342.545) # color=blue width=2 pyregion-1.1.4/examples/demo_region03.py0000664000175000017500000000303112341145563020402 0ustar jjleejjlee00000000000000try: from astropy.io import fits as pyfits except ImportError: import pyfits import matplotlib.pyplot as plt import pyregion import math 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 if 1: region_list = ["test_text.reg", "test_context.reg"] h = get_test_header() n = len(region_list) nx = int(math.ceil(n**.5)) ny = int(math.ceil(1.*n/nx)) fig = plt.figure(1, figsize=(7,5)) fig.clf() nrows_ncols = (ny, nx) grid= ImageGrid(fig, 111, nrows_ncols, ngrids=n, add_all=True, share_all=True, axes_class=(pywcsgrid2.Axes, dict(header=h))) ax = grid[0] ax.set_xlim(300, 1300) ax.set_ylim(300, 1300) ax.set_aspect(1) #plt.imshow(d, origin="lower", cmap=plt.cm.gray_r) from mpl_toolkits.axes_grid.anchored_artists import AnchoredText for ax, reg_name in zip(grid, region_list): r = pyregion.open(reg_name).as_imagecoord(h) patch_list, text_list = r.get_mpl_patches_texts() for p in patch_list: ax.add_patch(p) for t in text_list: ax.add_artist(t) atext = AnchoredText(reg_name.replace("_", r"\_"), loc=2) ax.add_artist(atext) plt.draw() plt.show() pyregion-1.1.4/examples/test01_print.reg0000644000175000017500000000052612255736553020446 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 fk5 circle(11:24:24.230,-59:15:02.20,18.5108") # color=cyan background box(11:24:39.213,-59:16:53.91,42.804",23.616",19.0384) # width=4 pyregion-1.1.4/examples/test.header0000644000175000017500000000116412255736553017543 0ustar jjleejjlee00000000000000SIMPLE = T / file does conform to FITS standard BITPIX = 16 / number of bits per data pixel NAXIS = 2 / number of data axes NAXIS1 = 1629 / length of data axis NAXIS2 = 1653 / length of data axis EXTEND = T / FITS dataset may contain extensions CTYPE1 = 'RA---TAN' CRVAL1 = 1.7114680010248E+02 CRPIX1 = 7.9250000000000E+02 CDELT1 = -1.3666666666667E-04 CUNIT1 = 'deg ' CTYPE2 = 'DEC--TAN' CRVAL2 = -5.9266678641361E+01 CRPIX2 = 8.2750000000000E+02 CDELT2 = 1.3666666666667E-04 CUNIT2 = 'deg 'pyregion-1.1.4/examples/test02.reg0000644000175000017500000000062412255736553017232 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: pspc_skyview.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 physical ellipse(82,167,36,75,346.95915) epanda(140,166,87.19363,195.80251,1,32.5,39.5,65,79,1,307.90041) -polygon(78.265142,201.73486,132,209,125,178,163.73486,116.26514,78.265142,116.26514) pyregion-1.1.4/examples/sample_fits01.header0000644000175000017500000000214012255736553021226 0ustar jjleejjlee00000000000000SIMPLE = T / file does conform to FITS standard BITPIX = 16 / number of bits per data pixel NAXIS = 2 / number of data axes NAXIS1 = 1629 / length of data axis NAXIS2 = 1653 / length of data axis EXTEND = T / FITS dataset may contain extensions EQUINOX = 2.0000000000000E+03 / default CTYPE1 = 'RA---TAN' CRVAL1 = 1.7114680010248E+02 CRPIX1 = 7.9250000000000E+02 CDELT1 = -1.3666666666667E-04 CUNIT1 = 'deg ' CTYPE2 = 'DEC--TAN' CRVAL2 = -5.9266678641361E+01 CRPIX2 = 8.2750000000000E+02 CDELT2 = 1.3666666666667E-04 CUNIT2 = 'deg ' CTYPE1P = 'X ' / sky coordinates CRVAL1P = 3.3045000000000E+03 CRPIX1P = 5.0000000000000E-01 CDELT1P = 1.0000000000000E+00 WCSTY1P = 'PHYSICAL' LTV1 = -3.3040000000000E+03 LTM1_1 = 1.0000000000000E+00 CTYPE2P = 'Y ' / sky coordinates CRVAL2P = 3.2695000000000E+03 CRPIX2P = 5.0000000000000E-01 CDELT2P = 1.0000000000000E+00 WCSTY2P = 'PHYSICAL' LTV2 = -3.2690000000000E+03 LTM2_2 = 1.0000000000000E+00 pyregion-1.1.4/examples/test01_mixed.reg0000644000175000017500000000103112255736553020410 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 fk5 -ellipse(171.15816,-59.263193,22.632",10.332",317.01716) # width=3 background galactic circle(+292:00:04.651,+01:45:41.444,18.5108") # color=cyan image box(730.5,718,87,48,19.038396) # width=4 galactic polygon(+292:01:06.152,+01:44:53.528,+292:00:00.146,+01:44:56.102,+292:00:42.141,+01:43:40.599,+292:01:15.844,+01:44:25.760) pyregion-1.1.4/examples/test01_fk5_degree.reg0000644000175000017500000000075312255736553021314 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 fk5 -ellipse(171.15816,-59.263193,22.632",10.332",317.01716) # width=3 background circle(171.10096,-59.250612,18.510811") # color=cyan box(171.16339,-59.281643,42.804",23.616",19.038396) # width=4 polygon(171.1239,-59.26881,171.09051,-59.262088,171.0985,-59.285735,171.1239,-59.27698) pyregion-1.1.4/examples/test_annuli_ciao.reg0000644000175000017500000000134012255736553021425 0ustar jjleejjlee00000000000000# Region file format: CIAO version 1.0 annulus(11:24:40.397,-59:15:16.99,0.468502',0.62467') annulus(11:24:40.397,-59:15:16.99,0.62467',0.780837') annulus(11:24:40.397,-59:15:16.99,0.780837',0.937004') pie(11:24:40.465,-59:16:54.89,0.319298',0.478947',338.334,415.759) pie(11:24:40.465,-59:16:54.89,0.319298',0.478947',55.759,133.184) pie(11:24:40.465,-59:16:54.89,0.319298',0.478947',133.184,210.609) pie(11:24:40.465,-59:16:54.89,0.319298',0.478947',210.609,288.034) pie(11:24:40.465,-59:16:54.89,0.478947',0.638596',338.334,415.759) pie(11:24:40.465,-59:16:54.89,0.478947',0.638596',55.759,133.184) pie(11:24:40.465,-59:16:54.89,0.478947',0.638596',133.184,210.609) pie(11:24:40.465,-59:16:54.89,0.478947',0.638596',210.609,288.034) pyregion-1.1.4/examples/test04_img.reg0000644000175000017500000000103712255736553020067 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: E3000-7000.b1.img.fl.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 image -ellipse(750,853,46,21,317.017) # width=3 text={Ellipse} background circle(964,945,37.6236) # color=cyan text={Circle} box(730.5,718,87,48,19.0384) # width=4 text={Rectangle} polygon(878.11237,811.88766,1003,861,973.00003,688,878.11237,752.11234) # text={Polygon} point(800, 960) # point=box color=black text={Point} pyregion-1.1.4/examples/demo_helper.py0000644000175000017500000000265012255736553020250 0ustar jjleejjlee00000000000000import matplotlib.pyplot as plt import pyregion 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() n = len(region_list) nx = int(math.ceil(n**.5)) ny = int(math.ceil(1.*n/nx)) nrows_ncols = (ny, nx) grid = [plt.subplot(ny, nx, i+1) for i in range(n)] for ax, reg_name in zip(grid, region_list): ax.set_aspect(1) r = pyregion.open(reg_name).as_imagecoord(h) patch_list, text_list = r.get_mpl_patches_texts() for p in patch_list: ax.add_patch(p) for t in text_list: ax.add_artist(t) if plt.rcParams["text.usetex"]: reg_name = reg_name.replace("_", r"\_") ax.set_title(reg_name, size=10) for t in ax.get_xticklabels() + ax.get_yticklabels(): t.set_visible(False) return grid pyregion-1.1.4/examples/test01_ciao_physical.reg0000644000175000017500000000037212255736553022120 0ustar jjleejjlee00000000000000# Region file format: CIAO version 1.0 -ellipse(4053.9922,4121.9905,46,21,317.017) circle(4267.9987,4214.0083,37.623659) rotbox(4034.5013,3987.0067,87,48,19.0384) polygon(4182.1103,4080.8819,4307.0067,4129.9947,4276.9938,3957.01,4182.1053,4021.1054) pyregion-1.1.4/examples/sample_fits02.header0000644000175000017500000000333212255736553021233 0ustar jjleejjlee00000000000000SIMPLE = T / Written by SkyView Thu Mar 19 00:15:05 GMT 2009 BITPIX = -64 / 4 byte floating point NAXIS = 2 / Two dimensional image NAXIS1 = 300 / Width of image NAXIS2 = 300 / Height of image CRVAL1 = 304.75 / Reference longitude CRVAL2 = 45.7 / Reference latitude RADESYS = 'FK5 ' / Coordinate system EQUINOX = 2000.0 / Epoch of the equinox CTYPE1 = 'RA---TAN' / Coordinates -- projection CTYPE2 = 'DEC--TAN' / Coordinates -- projection CRPIX1 = 150.5 / X reference pixel CRPIX2 = 150.5 / Y reference pixel CDELT1 = -0.006666666666667 / X scale CDELT2 = 0.006666666666666666 / Y scale COMMENT COMMENT SkyView Survey metadata COMMENT COMMENT Provenance: Observational data from NASA Goddard Space Flight C COMMENT enter, mosaicking of images done by SkyView. COMMENT Copyright: Public domain COMMENT Regime: X-ray COMMENT NSurvey: 1 COMMENT Frequency: 0.3 EHz (.1-2.4 keV) COMMENT Coverage: Isolated pointings in the sky. Total coverage < 14 COMMENT % COMMENT PixelScale: 15" COMMENT PixelUnits: cts/s/pixel COMMENT Resolution: 30" but variable across the field of view COMMENT Coordinates: Equatorial COMMENT Equinox: 2000 COMMENT Projection: Gnomonic COMMENT Epoch: 1991-1994 COMMENT Reference: ROSAT Mission Description and Data Products Guide, availa COMMENT ble thr ough the ROSAT Guest Observer Facility, NASA GSFC. COMMENT SkyView Rosat Survey Generation description. COMMENT COMMENT Survey specific cards COMMENT SURVEY = 'PSPC 2.0 Deg-Inten' pyregion-1.1.4/examples/demo_region02.py0000644000175000017500000000061312255736553020413 0ustar jjleejjlee00000000000000import matplotlib.pyplot as plt from demo_helper import show_region if 1: region_list = ["test_annuli.reg", "test_annuli_wcs.reg", "test_annuli_ciao.reg"] fig = plt.figure(1, figsize=(6,6)) fig.clf() ax_list = show_region(fig, region_list) for ax in ax_list: ax.set_xlim(596, 1075) ax.set_ylim(585, 1057) plt.draw() plt.show() pyregion-1.1.4/examples/test_annuli.reg0000644000175000017500000000176312255736553020443 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 image ellipse(936.01565,922.00132,30.407693,20.504055,58.654304,39.550882,107.20306,72.287547,30) annulus(712.00157,914.99658,57.134451,76.17922,95.223988,114.26876) panda(711,716,338.334,648.034,4,38.9388,77.8776,2) epanda(893,720,53.141616,122.03456,1,33.936596,47.21819,67.873192,94.43638,1,28.831146) || # epanda=(53.141616 122.03456 217.20636 259.80344 311.69855)(33.936596 47.21819 67.873192 94.43638)(28.831146) epanda(893,720,122.03456,217.20636,1,33.936596,47.21819,67.873192,94.43638,1,28.831146) || # epanda=ignore epanda(893,720,217.20636,259.80344,1,33.936596,47.21819,67.873192,94.43638,1,28.831146) || # epanda=ignore epanda(893,720,259.80344,311.69855,1,33.936596,47.21819,67.873192,94.43638,1,28.831146) # epanda=ignore bpanda(982.0005,775.9995,0,360,4,28.9995,30.9995,57.999,61.999,1,0) pyregion-1.1.4/examples/test_context.reg0000644000175000017500000000462712255736553020643 0ustar jjleejjlee00000000000000# Region file format: DS9 version 4.1 # Filename: test01.fits global color=green dashlist=8 3 width=1 font="helvetica 10 normal" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 image # composite(818,804,22.791484) || composite=1 color=red point(818,804) || # point=boxcircle # text(917.93183,1012.7012) || textangle=22.791484 font="times 12 normal" text={I} # text(1038.5994,726.09152) || textangle=22.791484 font="times 12 normal" text={II} # text(719.41413,591.67326) || textangle=22.791484 font="times 12 normal" text={III} # text(601.61767,880.81539) || textangle=22.791484 font="times 12 normal" text={IV} box(605.81608,905.40937,312.19512,39.02439,22.791484) || box(620.9621,869.4441,312.19512,39.02439,22.791484) || box(919.09424,1016.1681,39.02439,312.19512,22.791484) || box(1014.738,738.86864,312.19512,39.02439,22.791484) || box(1029.8552,702.89125,312.19512,39.02439,22.791484) || box(716.57467,592.13153,39.02439,312.19512,22.791484) || box(666.40018,761.54827,312.19512,39.02439,22.791484) || box(651.25415,797.51354,312.19512,39.02439,22.791484) || box(636.10813,833.47882,312.19512,39.02439,22.791484) || box(590.67005,941.37466,312.19512,39.02439,22.791484) || box(575.524,977.33995,312.19512,39.02439,22.791484) || box(560.37801,1013.3052,312.19512,39.02439,22.791484) || box(1075.2743,594.98745,312.19512,39.02439,22.791484) || box(1060.1571,630.96483,312.19512,39.02439,22.791484) || box(1044.9724,666.91387,312.19512,39.02439,22.791484) || box(999.55334,774.81768,312.19512,39.02439,22.791484) || box(984.43613,810.79506,312.19512,39.02439,22.791484) || box(969.25147,846.74409,312.19512,39.02439,22.791484) || box(1026.9902,1061.6062,39.02439,312.19512,22.791484) || box(991.04728,1046.4696,39.02439,312.19512,22.791484) || box(955.03709,1031.3047,39.02439,312.19512,22.791484) || box(883.15144,1001.0315,39.02439,312.19512,22.791484) || box(847.14118,985.86658,39.02439,312.19512,22.791484) || box(811.19838,970.72999,39.02439,312.19512,22.791484) || box(775.25558,955.59341,39.02439,312.19512,22.791484) || box(860.43576,652.71563,39.02439,312.19512,22.791484) || box(824.47049,637.56961,39.02439,312.19512,22.791484) || box(788.50521,622.42358,39.02439,312.19512,22.791484) || box(752.53995,607.27755,39.02439,312.19512,22.791484) || box(680.60939,576.9855,39.02439,312.19512,22.791484) || box(644.64412,561.83947,39.02439,312.19512,22.791484) || box(608.67884,546.69344,39.02439,312.19512,22.791484) pyregion-1.1.4/examples/test01_ciao.reg0000644000175000017500000000047212255736553020225 0ustar jjleejjlee00000000000000# Region file format: CIAO version 1.0 -ellipse(11:24:37.960,-59:15:47.50,0.3772',0.1722',317.017) circle(11:24:24.230,-59:15:02.20,0.308514') rotbox(11:24:39.213,-59:16:53.91,0.7134',0.3936',19.0384) polygon(11:24:29.737,-59:16:07.72,11:24:21.723,-59:15:43.52,11:24:23.641,-59:17:08.64,11:24:29.736,-59:16:37.13) pyregion-1.1.4/setup.py0000664000175000017500000000636212365063103015277 0ustar jjleejjlee00000000000000from setuptools import setup, Extension # check if cython or pyrex is available. pyrex_impls = 'Cython.Distutils.build_ext', 'Pyrex.Distutils.build_ext' for pyrex_impl in pyrex_impls: try: # from (pyrex_impl) import build_ext build_ext = __import__(pyrex_impl, fromlist=['build_ext']).build_ext break except: pass have_pyrex = 'build_ext' in globals() if have_pyrex: cmdclass = {'build_ext': build_ext} PYREX_SOURCE = "src/_region_filter.pyx" else: cmdclass = {} PYREX_SOURCE = "src/_region_filter.c" import sys import warnings # If you don't want to build filtering module (which requires a C # compiler), set it to False WITH_FILTER = True for line in open('lib/version.py').readlines(): if (line.startswith('__version__')): exec(line.strip()) def main(): if sys.version_info[0] >= 3: install_requires = ['pyparsing>=2.0.0'] elif sys.version_info[:2] >= (2, 6): # For Python 2.6 and 2.7, any version *except* 2.0.0 will work install_requires = ['pyparsing!=2.0.0'] else: # For Python < 2.6, a version before 2.0.0 is required install_requires = ['pyparsing<2.0.0'] ka = dict(name = "pyregion", version = __version__, description = "python parser for ds9 region files", author = "Jae-Joon Lee", author_email = "lee.j.joon@gmail.com", url="http://leejjoon.github.com/pyregion/", download_url="http://github.com/leejjoon/pyregion/downloads", license = "MIT", platforms = ["Linux","MacOS X"], packages = ['pyregion'], package_dir={'pyregion':'lib'}, install_requires = install_requires, use_2to3 = False, ) ka["classifiers"]=['Development Status :: 5 - Production/Stable', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: MIT License', 'Operating System :: MacOS :: MacOS X', 'Operating System :: POSIX :: Linux', 'Programming Language :: Cython', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Topic :: Scientific/Engineering :: Astronomy', ] if WITH_FILTER: try: import numpy except ImportError: warnings.warn("numpy must be installed to build the filtering module.") sys.exit(1) try: numpy_include = numpy.get_include() except AttributeError: numpy_include = numpy.get_numpy_include() if cmdclass: ka["cmdclass"] = cmdclass ka["ext_modules"] = [ Extension("pyregion._region_filter", [PYREX_SOURCE], include_dirs=['./src', numpy_include, ], libraries=[], ) ] setup(**ka) if __name__ == "__main__": main()