Skip to content

Commit cd5cf9f

Browse files
committed
Merge pull request #1735 from UV-CDAT/issue_1734_non_contiguous_levs
Issue 1734 non contiguous levs
2 parents 5e022b7 + 62d47e1 commit cd5cf9f

File tree

6 files changed

+63
-116
lines changed

6 files changed

+63
-116
lines changed

Packages/vcs/Lib/vcsvtk/boxfillpipeline.py

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _updateContourLevelsAndColors(self):
4040
if self._gm.boxfill_type != "custom":
4141
self._updateContourLevelsAndColorsForBoxfill()
4242
else:
43-
self._updateContourLevelsAndColorsForCustomBoxfill()
43+
self._updateContourLevelsAndColorsGeneric()
4444

4545
if isinstance(self._contourLevels, numpy.ndarray):
4646
self._contourLevels = self._contourLevels.tolist()
@@ -93,40 +93,6 @@ def _updateContourLevelsAndColorsForBoxfill(self):
9393
# Use consecutive colors:
9494
self._contourColors = range(self._gm.color_1, self._gm.color_2 + 1)
9595

96-
def _updateContourLevelsAndColorsForCustomBoxfill(self):
97-
"""Set contour information for a custom boxfill."""
98-
self._contourLevels = self._gm.levels
99-
100-
if numpy.allclose(self._contourLevels[0], [0., 1.e20]) or \
101-
numpy.allclose(self._contourLevels, 1.e20):
102-
levs2 = vcs.mkscale(self._scalarRange[0],
103-
self._scalarRange[1])
104-
if len(levs2) == 1: # constant value ?
105-
levs2 = [levs2[0], levs2[0] + .00001]
106-
self._contourLevels = []
107-
if self._gm.ext_1:
108-
# user wants arrow at the end
109-
levs2[0] = -1.e20
110-
if self._gm.ext_2:
111-
# user wants arrow at the end
112-
levs2[-1] = 1.e20
113-
for i in range(len(levs2) - 1):
114-
self._contourLevels.append([levs2[i], levs2[i + 1]])
115-
else:
116-
if not isinstance(self._gm.levels[0], (list, tuple)):
117-
self._contourLevels = []
118-
levs2 = self._gm.levels
119-
if numpy.allclose(levs2[0], 1.e20):
120-
levs2[0] = 0
121-
for i in range(len(levs2) - 1):
122-
self._contourLevels.append([levs2[i], levs2[i + 1]])
123-
124-
# Contour colors:
125-
self._contourColors = self._gm.fillareacolors
126-
if self._contourColors is None:
127-
# TODO BUG levs2 may not be defined here...
128-
self._contourColors = vcs.getcolors(levs2, split=0)
129-
13096
def _createPolyDataFilter(self):
13197
"""Overrides baseclass implementation."""
13298
self._vtkPolyDataFilter = vtk.vtkDataSetSurfaceFilter()
@@ -346,7 +312,6 @@ def _plotInternalCustomBoxfill(self):
346312
geos = []
347313
wholeDataMin, wholeDataMax = vcs.minmax(self._originalData1)
348314
_colorMap = self.getColorMap()
349-
assert(style != 'solid' or len(tmpLevels) == 1)
350315
for i, l in enumerate(tmpLevels):
351316
# Ok here we are trying to group together levels can be, a join
352317
# will happen if: next set of levels continues where one left off

Packages/vcs/Lib/vcsvtk/isofillpipeline.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,7 @@ def _updateVTKDataSet(self):
3131
self._vtkDataSet.GetPointData().SetScalars(data)
3232

3333
def _updateContourLevelsAndColors(self):
34-
"""Overrides baseclass implementation."""
35-
# Contour values:
36-
self._contourLevels = self._gm.levels
37-
if numpy.allclose(self._contourLevels[0], [0., 1.e20]) or \
38-
numpy.allclose(self._contourLevels, 1.e20):
39-
levs2 = vcs.mkscale(self._scalarRange[0],
40-
self._scalarRange[1])
41-
if len(levs2) == 1: # constant value ?
42-
levs2 = [levs2[0], levs2[0] + .00001]
43-
self._contourLevels = []
44-
if self._gm.ext_1:
45-
# user wants arrow at the end
46-
levs2[0] = -1.e20
47-
if self._gm.ext_2:
48-
# user wants arrow at the end
49-
levs2[-1] = 1.e20
50-
for i in range(len(levs2) - 1):
51-
self._contourLevels.append([levs2[i], levs2[i + 1]])
52-
else:
53-
if not isinstance(self._gm.levels[0], (list, tuple)):
54-
self._contourLevels = []
55-
levs2 = self._gm.levels
56-
if numpy.allclose(levs2[0], 1.e20):
57-
levs2[0] = -1.e20
58-
for i in range(len(levs2) - 1):
59-
self._contourLevels.append([levs2[i], levs2[i + 1]])
60-
61-
if isinstance(self._contourLevels, numpy.ndarray):
62-
self._contourLevels = self._contourLevels.tolist()
63-
64-
# Figure out colors
65-
self._contourColors = self._gm.fillareacolors
66-
if self._contourColors == [1]:
67-
# TODO BUG It's possible that levs2 may not exist here...
68-
self._contourColors = vcs.getcolors(levs2, split=0)
69-
if isinstance(self._contourColors, (int, float)):
70-
self._contourColors = [self._contourColors]
34+
self._updateContourLevelsAndColorsGeneric()
7135

7236
def _createPolyDataFilter(self):
7337
"""Overrides baseclass implementation."""
@@ -102,7 +66,6 @@ def _plotInternal(self):
10266
x1, x2, y1, y2 = vcs.utils.getworldcoordinates(self._gm,
10367
self._data1.getAxis(-1),
10468
self._data1.getAxis(-2))
105-
assert(style != 'solid' or len(tmpLevels) == 1)
10669
for i, l in enumerate(tmpLevels):
10770
# Ok here we are trying to group together levels can be, a join
10871
# will happen if: next set of levels continues where one left off

Packages/vcs/Lib/vcsvtk/meshfillpipeline.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,7 @@ def _updateScalarData(self):
2323
self._data2 = self._originalData2
2424

2525
def _updateContourLevelsAndColors(self):
26-
"""Overrides baseclass implementation."""
27-
# Contour values:
28-
self._contourLevels = self._gm.levels
29-
if numpy.allclose(self._contourLevels[0], [0., 1.e20]) or \
30-
numpy.allclose(self._contourLevels, 1.e20):
31-
levs2 = vcs.mkscale(self._scalarRange[0], self._scalarRange[1])
32-
if len(levs2) == 1: # constant value ?
33-
levs2 = [levs2[0], levs2[0] + .00001]
34-
self._contourLevels = []
35-
if self._gm.ext_1:
36-
# user wants arrow at the end
37-
levs2[0] = -1.e20
38-
if self._gm.ext_2:
39-
# user wants arrow at the end
40-
levs2[-1] = 1.e20
41-
for i in range(len(levs2) - 1):
42-
self._contourLevels.append([levs2[i], levs2[i + 1]])
43-
else:
44-
if not isinstance(self._contourLevels[0], (list, tuple)):
45-
self._contourLevels = []
46-
levs2 = self._gm.levels
47-
if numpy.allclose(levs2[0], 1.e20):
48-
levs2[0] = -1.e20
49-
for i in range(len(levs2) - 1):
50-
self._contourLevels.append([levs2[i], levs2[i + 1]])
51-
52-
# Contour colors:
53-
self._contourColors = self._gm.fillareacolors
54-
if self._contourColors == [1]:
55-
# TODO BUG levs2 may be uninitialized here
56-
self._contourColors = vcs.getcolors(levs2, split=0)
57-
if isinstance(self._contourColors, (int, float)):
58-
self._contourColors = [self._contourColors]
59-
60-
if isinstance(self._contourLevels, numpy.ndarray):
61-
self._contourLevels = self._contourLevels.tolist()
26+
self._updateContourLevelsAndColorsGeneric()
6227

6328
def _createPolyDataFilter(self):
6429
"""Overrides baseclass implementation."""
@@ -94,7 +59,6 @@ def _plotInternal(self):
9459
self._vtkDataSetBounds[3])
9560
_colorMap = self.getColorMap()
9661
self._patternActors = []
97-
assert(style != 'solid' or len(tmpLevels) == 1)
9862
for i, l in enumerate(tmpLevels):
9963
# Ok here we are trying to group together levels can be, a join
10064
# will happen if: next set of levels contnues where one left off

Packages/vcs/Lib/vcsvtk/pipeline2d.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,46 @@ def _updateFromGenGridDict(self, genGridDict):
9292
"""
9393
raise NotImplementedError("Missing override.")
9494

95+
def _updateContourLevelsAndColorsGeneric(self):
96+
# Contour values:
97+
self._contourLevels = self._gm.levels
98+
if numpy.allclose(self._contourLevels[0], [0., 1.e20]) or \
99+
numpy.allclose(self._contourLevels, 1.e20):
100+
levs2 = vcs.mkscale(self._scalarRange[0],
101+
self._scalarRange[1])
102+
if len(levs2) == 1: # constant value ?
103+
levs2 = [levs2[0], levs2[0] + .00001]
104+
self._contourLevels = []
105+
if self._gm.ext_1:
106+
# user wants arrow at the end
107+
levs2[0] = -1.e20
108+
if self._gm.ext_2:
109+
# user wants arrow at the end
110+
levs2[-1] = 1.e20
111+
for i in range(len(levs2) - 1):
112+
self._contourLevels.append([levs2[i], levs2[i + 1]])
113+
else:
114+
if not isinstance(self._gm.levels[0], (list, tuple)):
115+
self._contourLevels = []
116+
levs2 = self._gm.levels
117+
if numpy.allclose(levs2[0], 1.e20):
118+
levs2[0] = -1.e20
119+
for i in range(len(levs2) - 1):
120+
self._contourLevels.append([levs2[i], levs2[i + 1]])
121+
else:
122+
levs2 = self._gm.levels
123+
124+
if isinstance(self._contourLevels, numpy.ndarray):
125+
self._contourLevels = self._contourLevels.tolist()
126+
127+
# Figure out colors
128+
self._contourColors = self._gm.fillareacolors
129+
if self._contourColors == [1] or self._contourColors is None:
130+
# TODO BUG It's possible that levs2 may not exist here...
131+
self._contourColors = vcs.getcolors(levs2, split=0)
132+
if isinstance(self._contourColors, (int, float)):
133+
self._contourColors = [self._contourColors]
134+
95135
def _updateContourLevelsAndColors(self):
96136
"""This method prepares the _contourLevels and _contourColors variables.
97137
"""
@@ -201,8 +241,7 @@ def _prepContours(self):
201241
tmpIndices.append(I)
202242
tmpOpacities.append(O)
203243
C = [self._contourColors[i]]
204-
# L = self._contourLevels[i]
205-
L = [L[-1], l[1]]
244+
L = self._contourLevels[i]
206245
I = indices[i]
207246
O = opacities[i]
208247
tmpLevels.append(L)

testing/vcs/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,15 @@ cdat_add_test(vcs_test_taylor_2_quads
703703
)
704704
FOREACH(gm isofill boxfill meshfill)
705705
FOREACH(style solid pattern hatch)
706+
cdat_add_test(vcs_test_${gm}_${style}_fill_non-contig
707+
"${PYTHON_EXECUTABLE}"
708+
"${cdat_SOURCE_DIR}/testing/vcs/test_vcs_gms_patterns_hatches.py"
709+
--gm_type=${gm}
710+
--fill_style=${style}
711+
--non-contiguous
712+
"--source=${BASELINE_DIR}/test_vcs_${gm}_${style}_SH_-180_180_non-contig.png"
713+
"--threshold=45"
714+
)
706715
cdat_add_test(vcs_test_${gm}_${style}_fill
707716
"${PYTHON_EXECUTABLE}"
708717
"${cdat_SOURCE_DIR}/testing/vcs/test_vcs_gms_patterns_hatches.py"

testing/vcs/test_vcs_gms_patterns_hatches.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
p = argparse.ArgumentParser(description="Patterns/hatches testing code for vcs gms")
1414
p.add_argument("--source", dest="src", help="source image file")
15-
p.add_argument("--gm_type", dest="gm", help="gm to test")
15+
p.add_argument("--gm_type", dest="gm", help="gm to test", default="isofill")
1616
p.add_argument("--fill_style", dest="fill_style", help="Patterns/hatches fill style",
1717
default="pattern", type=str)
1818
p.add_argument("--show", dest="show", action="store_true", help="show plots on screen (no bg)", default=False)
@@ -23,7 +23,8 @@
2323
p.add_argument("--lon2", dest="lon2", default=180, type=float, help="Last Longitude")
2424
p.add_argument("--keep", dest="keep", action="store_true", help="Save image, even if baseline matches.")
2525
p.add_argument("--threshold", dest="threshold", type=int, default=checkimage.defaultThreshold,
26-
help="Threshold value for image differnces")
26+
help="Default threshold")
27+
p.add_argument("--non-contiguous", dest="contig", default=True, action="store_false", help="use non contiguous levels")
2728

2829
args = p.parse_args(sys.argv[1:])
2930

@@ -46,7 +47,11 @@
4647
p.type = ptype
4748
gm.projection = p
4849

49-
gm.levels = [220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320]
50+
if args.contig:
51+
gm.levels = [220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320]
52+
else:
53+
gm.levels = [[230,235],[240,245],[250,255],[260,265],[270,275],
54+
[280,285],[290,295],[300,305],[310,315],[320,325]]
5055
gm.fillareastyle = args.fill_style
5156
gm.fillareacolors = [242, 244, 237, 248, 250, 252, 44, 243, 139, 247]
5257
if args.fill_style == "hatch":
@@ -75,6 +80,8 @@
7580
if args.lon1 != args.lon2:
7681
xtra["longitude"] = (args.lon1, args.lon2)
7782
nm_xtra += "_%i_%i" % (args.lon1, args.lon2)
83+
if not args.contig:
84+
nm_xtra += "_non-contig"
7885

7986
xtra["time"] = slice(0, 1)
8087
xtra["squeeze"] = 1

0 commit comments

Comments
 (0)