Skip to content

Commit eb89153

Browse files
authored
Legend offset new attribute (#2069)
* gfortran not needed any longer on mac * added offset attriubte * ok legend now works * added a bunch of tests, make sure line is drawn once only * got legend_2 to work * pep8ed and flake8ed * Update VCS_validation_functions.py * get text offset a bit smaller * huge bug in extension and levels setting, fixed now * updated correct json file to reflect new attributes * updated correct json file to reflect new attributes * apparently matplotlib cmaps need cycler * reverted update baselines to False and cleaned up styling * seems like sometimes activating fails, sticking th activation in a loop I suspects the fail is due to some concurency issue so repeating for a while should eventually work * adding clean-local to cmake
1 parent 54f2834 commit eb89153

16 files changed

+284
-151
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ before_install:
1010
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh; fi
1111
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update ; fi
1212
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then wget https://repo.continuum.io/miniconda/Miniconda-latest-MacOSX-x86_64.sh -O miniconda.sh; fi
13-
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then wget https://github.com/UV-CDAT/uvcdat/releases/download/v2.4.1/gfortran-4.9.2-Mac.tar.gz -O ~/gfortran-4.9.2-Mac.tar.gz ; pushd / ; sudo tar xzvf ~/gfortran-4.9.2-Mac.tar.gz ; pushd ; fi
1413
- export PATH="$HOME/miniconda/bin:$PATH"
1514
- bash miniconda.sh -b -p $HOME/miniconda
1615
- conda config --set always_yes yes --set changeps1 no
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Clean build directory:"@CMAKE_BINARY_DIR@
4+
cd @CMAKE_BINARY_DIR@
5+
rm -rf CMake* CTestTestfile.cmake DartConfiguration.tcl Makefile Testing/ cmake_install.cmake version CDAT-prefix

CMake/cdat_modules_extra/install_cdat_from_conda.bash.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
@CONDA@ create -y -n @CONDA_ENVIRONMENT_NAME@ -c @CONDA_CHANNEL_UVCDAT@ hdf5 libnetcdf lapack clapack ossuuid libcf esmf jasper g2clib yasm x264 ffmpeg cmor proj4>=4.9.2 vtk libcdms cdat_info flake8 requests numpy==1.9.2 matplotlib --show-channel-urls --copy
3+
@CONDA@ create -y -n @CONDA_ENVIRONMENT_NAME@ -c @CONDA_CHANNEL_UVCDAT@ hdf5 libnetcdf lapack clapack ossuuid libcf esmf jasper g2clib yasm x264 ffmpeg cmor proj4>=4.9.2 vtk libcdms cdat_info flake8 requests numpy==1.9.2 cycler matplotlib --show-channel-urls --copy
44

55
source @ACTIVATE@ @CONDA_ENVIRONMENT_NAME@
66
for pkg in testing cdtime regrid2 cdms2 esg DV3D vcs vcsaddons cdutil unidata xmgrace genutil Thermo WK distarray; do

CMake/cdat_modules_extra/runtest.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22
echo "ACTIVATING ENV:"@CONDA_ENVIRONMENT_NAME@
3-
source activate @CONDA_ENVIRONMENT_NAME@
3+
while [[ `which python` != *"@CONDA_ENVIRONMENT_NAME@"* ]]
4+
do
5+
source activate @CONDA_ENVIRONMENT_NAME@
6+
done
47
export DYLD_FALLBACK_LIBRARY_PATH=`python -c "import sys,os;print os.path.join(sys.prefix,'lib')"`
58
echo "Python:" `which python`
69
echo "Running: "$*

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,19 @@ configure_file(${cdat_CMAKE_SOURCE_DIR}/cdat_modules_extra/clean_cdat_from_conda
292292
${cdat_CMAKE_BINARY_DIR}/clean_cdat_from_conda.bash
293293
@ONLY
294294
)
295+
296+
configure_file(${cdat_CMAKE_SOURCE_DIR}/cdat_modules_extra/clean_local_build.bash.in
297+
${cdat_CMAKE_BINARY_DIR}/clean_local_build.bash
298+
@ONLY
299+
)
295300
add_subdirectory(testing)
296301

297302
# Clean conda env
298303
add_custom_target(clean-conda
299304
COMMAND ${cdat_CMAKE_BINARY_DIR}/clean_cdat_from_conda.bash
300305
)
306+
307+
# Clean local env
308+
add_custom_target(clean-local
309+
COMMAND ${cdat_CMAKE_BINARY_DIR}/clean_local_build.bash
310+
)

Packages/testing/regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def find_alternates(fname):
8383
return results
8484

8585
def check_result_image(fname, baselinefname=sys.argv[1], threshold=defaultThreshold,
86-
baseline=True, cleanup=True, update_baselines = False, suffix="_2"):
86+
baseline=True, cleanup=True, update_baselines = False, suffix="_1"):
8787
testImage = image_from_file(fname)
8888
if testImage is None:
8989
print "Testing image missing, test failed."

Packages/vcs/vcs/Plegend.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ class Pls(object):
9393
"_texttable",
9494
"_textorientation",
9595
"texttable",
96-
"textorientation"]
96+
"textorientation",
97+
"offset",
98+
"_offset",
99+
"arrow",
100+
"_arrow",
101+
]
97102

98103
def __init__(self, member):
99104
# def __init__(self, template, member=None):
@@ -115,6 +120,8 @@ def __init__(self, member):
115120
self.y1 = 0.129999995232
116121
self.x2 = 0.949999988079
117122
self.y2 = 0.159999996424
123+
self.offset = .01
124+
self.arrow = .05
118125

119126
##########################################################################
120127
# #
@@ -129,6 +136,8 @@ def __init__(self, member):
129136
line = VCS_validation_functions.line
130137
texttable = VCS_validation_functions.texttable
131138
textorientation = VCS_validation_functions.textorientation
139+
offset = VCS_validation_functions.offset
140+
arrow = VCS_validation_functions.arrow
132141

133142
##########################################################################
134143
# #
@@ -145,6 +154,7 @@ def list(self):
145154
print " line =", self.line
146155
print " texttable =", self.texttable
147156
print " textorientation =", self.textorientation
157+
print " offset =", self.offset
148158

149159

150160
##########################################################################

Packages/vcs/vcs/VCS_validation_functions.py

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ def checkListTuple(self, name, value):
716716
# Now make sure the items are either number or listofnumbers
717717
# for v in value:
718718
checkName(self, name, value)
719-
if isinstance(value, list) or isinstance(value, tuple):
719+
if isinstance(value, (list, tuple)):
720720
return list(value)
721721
else:
722722
checkedRaise(
@@ -1745,13 +1745,37 @@ def _setpriority(self, value):
17451745
priority = property(_getpriority, _setpriority)
17461746

17471747

1748-
def _getX1(self):
1748+
@property
1749+
def arrow(self):
1750+
"""length of extension arrows"""
1751+
return self._arrow
1752+
1753+
1754+
@arrow.setter
1755+
def arrow(self, value):
1756+
self._arrow = checkNumber(self, "arrow", value, 0., None)
1757+
1758+
1759+
@property
1760+
def offset(self):
1761+
"""offset position of legend labels from legend colorbar, in % of page (can be negative)"""
1762+
return self._offset
1763+
1764+
1765+
@offset.setter
1766+
def offset(self, value):
1767+
self._offset = checkNumber(self, "offset", value, -1., 1.)
1768+
1769+
1770+
@property
1771+
def x1(self):
1772+
"""x1 position in % of page"""
17491773
return self._x1
17501774

17511775

1752-
def _setX1(self, value):
1776+
@x1.setter
1777+
def x1(self, value):
17531778
self._x1 = checkNumber(self, "x1", value, 0., 1.)
1754-
x1 = property(_getX1, _setX1, "x1 position in % of page")
17551779

17561780

17571781
def _getX2(self):
@@ -1852,18 +1876,21 @@ def _setcolormap(self, value):
18521876
colormap = property(_getcolormap, _setcolormap)
18531877

18541878

1855-
def _getlevels(self):
1879+
@property
1880+
def levels(self):
1881+
"""Sets the levels on a graphic method, optionally turns on/off extensions arrows"""
18561882
return self._levels
18571883

18581884

1859-
def _setlevels(self, value):
1860-
if value == ([1.0000000200408773e+20, 1.0000000200408773e+20],):
1885+
@levels.setter
1886+
def levels(self, value):
1887+
value = list(checkListTuple(self, 'levels', value))
1888+
1889+
if len(value) == 2 and numpy.allclose(value, 1.e20):
18611890
self._levels = value
18621891
return
18631892

1864-
value = list(checkListTuple(self, 'levels', value))
1865-
1866-
# Now make sure the items are either number or listofnumbers
1893+
# Now make sure the items are either number or list of numbers
18671894
for v in value:
18681895
if isNumber(v):
18691896
continue
@@ -1891,17 +1918,23 @@ def _setlevels(self, value):
18911918
value[0], (list, tuple)) and len(value[0]) > 2:
18921919
value = list(value[0])
18931920

1894-
if (value[0] < -9.9E19):
1921+
# We need to check for extensions
1922+
v = value[0]
1923+
if isinstance(v, (list, tuple)):
1924+
v = v[0]
1925+
if v < -9.9E19:
18951926
self._ext_1 = True
18961927
else:
18971928
self._ext_1 = False
18981929

1899-
if (value[-1] > 9.9E19):
1930+
v = value[-1]
1931+
if isinstance(v, (list, tuple)):
1932+
v = v[-1]
1933+
if v > 9.9E19:
19001934
self._ext_2 = True
19011935
else:
19021936
self._ext_2 = False
19031937
self._levels = list(value)
1904-
levels = property(_getlevels, _setlevels)
19051938

19061939

19071940
def _getlegend(self):
@@ -1964,7 +1997,7 @@ def add_level_ext_1(self, ext_value):
19641997
if ext_value == "n":
19651998
return self.levels
19661999

1967-
# We may need to add extnsion
2000+
# We may need to add extension
19682001
if isinstance(self.levels, (list, tuple)):
19692002
if isinstance(self.levels, tuple):
19702003
self.levels = list(self.levels)
@@ -2004,9 +2037,10 @@ def add_level_ext_2(self, ext_value):
20042037
if self.levels == [] or numpy.allclose(self.levels, 1.e20):
20052038
return self.levels # nothing to do
20062039
if ((ext_value == 'n') and self.ext_2): # remove extension
2007-
if isinstance(self.levels[0], list): # remove from tuple of lists
2040+
if isinstance(self.levels[-1], list): # remove from tuple of lists
20082041
if self.levels[-1][1] > 9.e19:
20092042
self.levels.pop(-1)
2043+
return
20102044
if isinstance(self.levels, (tuple, list)): # remove from list
20112045
ret_tup = []
20122046
for i in range(len(self.levels) - 1):
@@ -2033,32 +2067,36 @@ def add_level_ext_2(self, ext_value):
20332067
return self.levels
20342068

20352069

2036-
def _getext_1(self):
2070+
@property
2071+
def ext_1(self):
2072+
"""Turns on extensions arrows for values before the first level"""
20372073
return self._ext_1
20382074

20392075

2040-
def _setext_1(self, value):
2076+
@ext_1.setter
2077+
def ext_1(self, value):
20412078
do = checkExt(self, 'ext_1', value)
20422079
if do:
20432080
add_level_ext_1(self, 'y')
20442081
else:
20452082
add_level_ext_1(self, 'n')
20462083
self._ext_1 = do
2047-
ext_1 = property(_getext_1, _setext_1)
20482084

20492085

2050-
def _getext_2(self):
2086+
@property
2087+
def ext_2(self):
2088+
"""Turns on extensions arrows for values after the last level"""
20512089
return self._ext_2
20522090

20532091

2054-
def _setext_2(self, value):
2092+
@ext_2.setter
2093+
def ext_2(self, value):
20552094
do = checkExt(self, 'ext_2', value)
20562095
if do:
20572096
add_level_ext_2(self, 'y')
20582097
else:
20592098
add_level_ext_2(self, 'n')
20602099
self._ext_2 = do
2061-
ext_2 = property(_getext_2, _setext_2)
20622100

20632101

20642102
def _getwc(self):

0 commit comments

Comments
 (0)