File: enable_later_versions_of_matplotlib.patch

package info (click to toggle)
dicompyler 0.4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,896 kB
  • sloc: python: 5,332; makefile: 9
file content (66 lines) | stat: -rw-r--r-- 2,775 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Author: Andreas Tille <tille@debian.org>
Last-Update: Wed, 10 Sep 2014 23:21:42 +0200
Description: Try to port dicompyler to current version of matplotlib
 Patch is oriented at code found here:
   http://sources.debian.net/src/psychopy/1.79.00%2Bgit16-g30c9343.dfsg-1/psychopy/visual/helpers.py/#L41

--- a/dicompyler/dvhcalc.py
+++ b/dicompyler/dvhcalc.py
@@ -12,7 +12,11 @@ import logging
 logger = logging.getLogger('dicompyler.dvhcalc')
 import numpy as np
 import numpy.ma as ma
-import matplotlib.nxutils as nx
+import matplotlib
+if matplotlib.__version__ > '1.2':
+    from matplotlib.path import Path as mpl_Path
+else:
+    from matplotlib import nxutils as nx
 
 def get_dvh(structure, dose, limit=None, callback=None):
     """Get a calculated cumulative DVH along with the associated parameters."""
@@ -100,11 +104,17 @@ def calculate_dvh(structure, dose, limit
             else:
                 contour['inside'] = False
                 for point in contour['data']:
-                    if nx.pnpoly(point[0], point[1],
+                    if matplotlib.__version__ > '1.2':
+                        if mpl_Path(np.array(contours[largestIndex]['data'])).contains_point(point):
+                            contour['inside'] = True
+                            # Assume if one point is inside, all will be inside
+                            break
+                    else:
+                        if nx.pnpoly(point[0], point[1],
                                  np.array(contours[largestIndex]['data'])):
-                        contour['inside'] = True
-                        # Assume if one point is inside, all will be inside
-                        break
+                            contour['inside'] = True
+                            # Assume if one point is inside, all will be inside
+                            break
                 # If the contour is inside, subtract it from the total histogram
                 if contour['inside']:
                     hist -= h
@@ -161,7 +171,10 @@ def calculate_contour_areas(plane):
 def get_contour_mask(doselut, dosegridpoints, contour):
     """Get the mask for the contour with respect to the dose plane."""
 
-    grid = nx.points_inside_poly(dosegridpoints, contour)
+    if matplotlib.__version__ > '1.2':
+        grid = mpl_Path(contour).contains_points(dosegridpoints)
+    else:
+        grid = nx.points_inside_poly(dosegridpoints, contour)
     grid = grid.reshape((len(doselut[1]), len(doselut[0])))
 
     return grid
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@ from setuptools import setup, find_packa
 import sys
 
 requires = [
-    'matplotlib>=0.99, <=1.1.0',
+    'matplotlib>=0.99, <=2.0.0',
     'numpy>=1.2.1',
     'pillow>=2.5.1',
     'pydicom>=0.9.5, <=0.9.9']