New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colormap for difference or anomaly field needs adjustment #246

Open
lee1043 opened this Issue Sep 6, 2017 · 7 comments

Comments

Projects
None yet
2 participants
@lee1043

lee1043 commented Sep 6, 2017

When you see colorbar at range of [-10, 0] and [0, 10], you will see both colors are same. It looks like colors are somehow shifted by using 16, 240 range.

test

It is expected to have colorbar something like below. You will notify colors are contrasted at zero.

Below is a plotting code for above-most image.

import vcs, MV2, cdms2, cdutil

# Open sample file
f = cdms2.open('clt.nc')
d = f('clt',time=slice(0,1))

# Get anomaly field to have negative values
d_anom = MV2.subtract(d, cdutil.averager(d,axis='xy'))
d_anom.setAxis(0,d.getAxis(0))
d_anom.setAxis(1,d.getAxis(1))
d_anom.setAxis(2,d.getAxis(2))

# Plot
x = vcs.init()
iso = vcs.createisofill()

iso.levels = [-40, -30, -20, -10, 0, 10, 20, 30, 40]
#iso.levels = [-40, -30, -20, -10, 10, 20, 30, 40]  #### This does not work
iso.levels.insert(0,-1.e20)
iso.levels.append(1.e20)

iso.colormap = 'bl_to_darkred'
colors = vcs.getcolors(iso.levels,colors=range(16,240))
iso.fillareacolors = colors

x.plot(d_anom, iso)

x.png('test.png')
@doutriaux1

This comment has been minimized.

Member

doutriaux1 commented Sep 6, 2017

@lee1043 I think this is because by default getcolors splits the color range (0,255) in two halves and use the first half for negative values and the second half for positive values, as the result you're right the colors just before and just after zero are almost identical.

import vcs
>>> levels = [-40, -30, -20, -10, 0, 10, 20, 30, 40]
>>> print vcs.getcolors(levels)
[0, 42, 85, 127, 128, 170, 213, 255]

Note colors before and after 0 and 127 and 128. ALmost identical

I'll revise the algorithm, for now please use split=0 in your getcolor

>>> levels = [-40, -30, -20, -10, 0, 10, 20, 30, 40]
>>> print vcs.getcolors(levels,split=0)
[0, 36, 73, 109, 146, 182, 219, 255]

since you have as many colors on each side of the 0 it doesn't matter.

@doutriaux1 doutriaux1 self-assigned this Sep 6, 2017

@doutriaux1 doutriaux1 added this to the 3.0 milestone Sep 6, 2017

@lee1043

This comment has been minimized.

lee1043 commented Sep 6, 2017

@doutriaux1 Thanks for solution. Curious what split is for and how it work.

Also, above code does not work when I set levels as below, assign same color between -10 to 10.

iso.levels = [-40, -30, -20, -10, 10, 20, 30, 40]  #### This does not work

Returning error message is:

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    iso.fillareacolors = colors
  File "/export_backup/lee1043/anaconda2/envs/nightly-20170824-2/lib/python2.7/site-packages/vcs/__init__.py", line 56, in __setattr__
    super(bestMatch, self).__setattr__(a, v)
  File "/export_backup/lee1043/anaconda2/envs/nightly-20170824-2/lib/python2.7/site-packages/vcs/VCS_validation_functions.py", line 2123, in _setfillareacolors
    value)
  File "/export_backup/lee1043/anaconda2/envs/nightly-20170824-2/lib/python2.7/site-packages/vcs/VCS_validation_functions.py", line 778, in checkColorList
    NoneOk=True))
  File "/export_backup/lee1043/anaconda2/envs/nightly-20170824-2/lib/python2.7/site-packages/vcs/VCS_validation_functions.py", line 752, in checkColor
    maxelements=4)
  File "/export_backup/lee1043/anaconda2/envs/nightly-20170824-2/lib/python2.7/site-packages/vcs/VCS_validation_functions.py", line 242, in checkListOfNumbers
    checkNumber(self, name, v, minvalue=minvalue, maxvalue=maxvalue)
  File "/export_backup/lee1043/anaconda2/envs/nightly-20170824-2/lib/python2.7/site-packages/vcs/VCS_validation_functions.py", line 197, in checkNumber
    str(maxvalue))
  File "/export_backup/lee1043/anaconda2/envs/nightly-20170824-2/lib/python2.7/site-packages/vcs/VCS_validation_functions.py", line 59, in checkedRaise
    raise ex(err)
ValueError: fillareacolors_list_value values must be at most 100.0

Is there any constraints when I have 0 in levels? I checked this error does not happen when I use split=0 option.

@doutriaux1

This comment has been minimized.

Member

doutriaux1 commented Sep 6, 2017

@lee1043 what? Let me try this. It should work. Can you point me to your code?

@lee1043

This comment has been minimized.

lee1043 commented Sep 6, 2017

test

split=0 solved the color issue for now. Thanks to @doutriaux1 .

@lee1043

This comment has been minimized.

lee1043 commented Sep 6, 2017

@doutriaux1 Here is the code that returns error when level is not including 0 and split=0 is not being used.
test.py.txt

@doutriaux1

This comment has been minimized.

Member

doutriaux1 commented Sep 6, 2017

@lee1043 the test works for me. Which vcs are you using?

@lee1043

This comment has been minimized.

lee1043 commented Sep 6, 2017

@doutriaux1

$ conda list vcs

# packages in environment at /export_backup/lee1043/anaconda2/envs/nightly-20170824-2:
#
vcs                       2.10.2017.08.22.21.30.dc1c718e3800ffbe7028430b7d01789377b2b3b8  py27ha5a9922_0    uvcdat/label/nightly
vcsaddons                 2.10                     py27_0    uvcdat

@doutriaux1 doutriaux1 modified the milestones: 3.0, Next Release Mar 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment