Accessing Predefined ColorScales in Python

Help
2014-06-28
2016-09-02
  • David Monarchi

    David Monarchi - 2014-06-28

    Hello -

    I am trying to access the predefined color scale Rainbow. I know that it is based on the Rainbow.png, but I can't figure out how to reference it. The specific code is
    dataSet = tlp.getDefaultPluginParameters("Color Mapping")
    dataSet["colorScale"] = ???

    I can build my own color scale, but would like to use some of the existing ones (Rainbow at the moment).

    Any advice or pointers to a reference would be appreciated.

    Thank you.

    Best,
    David

     
  • Adam Miller

    Adam Miller - 2014-06-28

    Every declared plugin parameter comes with a type and a description. I'm pretty sure that you can store a tlp.ColorScale in there;

    help(tlp.DataSet) returned this useful tidbit.

    class DataSet(sip.wrapper)
    | This class is used to store a set of parameters to transmit to a Tulip algorithm.
    | Below is an exhaustive list of data types that can be stored in a Tulip data set:
    |
    | * boolean
    | * integer
    | * float
    | * string
    | * :class:tlp.Coord
    | * :class:tlp.Color
    | * :class:tlp.Size
    | * :class:tlp.DataSet
    | * :class:tlp.ColorScale
    | * :class:tlp.StringCollection
    | * :class:tlp.BooleanProperty
    | * :class:tlp.ColorProperty
    | * :class:tlp.DoubleProperty
    | * :class:tlp.IntegerProperty
    | * :class:tlp.LayoutProperty
    | * :class:tlp.SizeProperty
    | * :class:tlp.StringProperty
    | * :class:tlp.PropertyInterface

     
  • David Monarchi

    David Monarchi - 2014-06-28

    Thanks, Adam. I don't have any problem constructing a DataSet and creating a ColorScale. My problem is referencing what I believe is a predefined colorScale, one that is named Rainbow in the GUI. I hoped that there was a constant defined for the color scale in the same way that there are predefined color constants such as tlp.Color.Amaranth or tlp.Color.Bronze.

    I've tried to find a place in the code that defines such a constant, but without luck. The only reference in the documentation I've found is a reference to Rainbow.png. That file is located at Tulip-4.5.0\share\tulip\bitmaps\colorscales. I suspect that it is used to construct the color scale, but I cannot find a method that takes an image as input to create the color scale. However, there is a way in the GUI to do that in the Color Mapping plugin.

    I have found the code for the Color Mapping plugin at http://fossies.org/linux/misc/tulip-4.5.0_src.tar.gz/tulip/plugins/colors/ColorMapping.cpp, but what I'm really looking for is the popup labeled "Color scale creation". In that popup there is a button to "Import from image", and I suspect that the code behind that button is what I want. However the reference above doesn't include that code.

    Any suggestions or insights would be greatly appreciated.

    Thank you.

    David

     
  • David Monarchi

    David Monarchi - 2016-08-23

    Hello -

    I am still trying to find a solution to this question, although now with version 4.9. :-)

    The color scale that I would like to use programmatically is RdYlGn_10_from_ColorBrewer.org.png. I know where the png file is located (C:\Program Files\Tulip-4.9.0\share\tulip\bitmaps\colorscales), but I don't know how to reference it in setting up the parameter values for the color plugin.

    When I print out the default plugin parameters for the Color Mapping plugin, I get the following:
    {'target': 'nodes', 'colorScale': <_tulip.ColorScale object at 0x0000000020D0E438>, 'maximum value': 0.0, 'input property': <Double property="" viewMetric="">, 'minimum value': 0.0, 'result': <Color property="" viewColor="">, 'override maximum value': False, 'override minimum value': False, 'type': 'linear'}.

    I understand how to enter all of the other values in the dictionary (e.g., viewMetric) for the input property), but I don't know how to translate <_tulip.ColorScale object at 0x0000000020D0E438> into a reference I can use.

    I would greatly appreciate any guidance or references any one could provide. :-)

    Thank you.

    David

     
  • Benjamin

    Benjamin - 2016-08-24

    Dear David,

    Here is a quick hack while we find a way to give a simpler access.
    In the attach .py file you can find all the definitions of all color brewer scales.
    I added you also the basic loading of color scales and with gradient interpolation - although contrary to Brewer's recommendations (the script includes printing for you to see the differences)

    In you case, you can then do:

    from tulip_colorbrewer import *
    RdYlGn_10_from_RGB = tlp.ColorScale([tlp.Color(c[0], c[1], c[2]) for c in colorbrewer['RdYlGn'][10]])
    
    #or also, given the attached loading at the bottom of the script
    
    RdYlGn_10 = tlp.brewerscales['RdYlGn'][10]
    RdYlGn_10_grad = tlp.gradient_brewerscales['RdYlGn'][10]
    

    and use it in you color mapping plugin, as your convenience

    I hope this helps !

     
  • David Monarchi

    David Monarchi - 2016-08-24

    Thank you, Benjamin. Very, very much appreciated! And I also greatly appreciate the speed of the reply. :-)

    Is there a possibility that at some point in the future the predefined scales might be accessible via constants in the same way that tlp.Color.Red is now?

    Regardless, thank you again. :-)

    David

     
  • Benjamin

    Benjamin - 2016-08-24

    Thank you David! This is exactly the sort of feedbacks we need to improve Tulip.
    Indeed it makes a lot of sense, not limited to the ColorBrewer schemes, but to any other color scales we could include as .png.
    I openned a ticket for your request. Thanks again!

     
  • Benjamin

    Benjamin - 2016-08-24

    (and David, our bad, I see your previous request on that matter went through without any of us responding - it was an exceptionnally busy period for the lab, all our apologies again).

     
  • Antoine Lambert

    Antoine Lambert - 2016-09-01

    Dear David and Benjamin,

    Just to let you know that I began to work on improving the handling of color scales trough Python for the next Tulip release. Been a while since I wanted to implement those features for the Python bindings but I am more focused on the development of Tulip 5 (https://github.com/tulip5/tulip) right now (which will bring a much efficient rendering engine written in OpenGL ES, a revamped GUI but also a javascript version of Tulip developed using emscripten and WebGL).

    As requested by David, it will be possible to easily retrieve the Tulip predefined color scales through a Python helper class. That class will be located in the tulipgui module as Qt is required to load the registered color scales (we use QImage and QSettings class under the hood). It will also be possible to register new color scales from Python for further reuse. Last but not least, the direct use of the tlp.ColorScale will be deprecated to use a more Pythonic way to create them : either by using a dictionnary or a list. For instance, to define a color scale going from blue to green to red, it will be sufficient to write [tlp.Color.Blue, tlp.Color.Green, tlp.Color.Red] or {0: tlp.Color.Blue, 0.5: tlp.Color.Green, 1.0: tlp.Color.Red}. I have almost finished to implement those features, still the documentation to write. I will commit those changes in the Tulip trunk soon.

    Cheers,

    Antoine

     
    • brenoust

      brenoust - 2016-09-02

      Hi Antoine,

      Thanks a lot for the great update!
      Looking forward to move to Tulip 5 =)

      Cheers,

      --
      Benjamin

      On 2 September 2016 at 06:11, Antoine Lambert anlambert@users.sf.net
      wrote:

      Dear David and Benjamin,

      Just to let you know that I began to work on improving the handling of
      color scales trough Python for the next Tulip release. Been a while since I
      wanted to implement those features for the Python bindings but I am more
      focused on the development of Tulip 5 (https://github.com/tulip5/tulip)
      right now (which will bring a much efficient rendering engine written in
      OpenGL ES, a revamped GUI but also a javascript version of Tulip developed
      using emscripten and WebGL).

      As requested by David, it will be possible to easily retrieve the Tulip
      predefined color scales through a Python helper class. That class will be
      located in the tulipgui module as Qt is required to load the registered
      color scales (we use QImage and QSettings class under the hood). It will
      also be possible to register new color scales from Python for further
      reuse. Last but not least, the direct use of the tlp.ColorScale will be
      deprecated to use a more Pythonic way to create them : either by using a
      dictionnary or a list. For instance, to define a color scale going from
      blue to green to red, it will be sufficient to write [tlp.Color.Blue,
      tlp.Color.Green, tlp.Color.Red]
      or {0: tlp.Color.Blue, 0.5:
      tlp.Color.Green, 1.0: tlp.Color.Red}. I have almost finished to implement
      those features, still the documentation to write. I will commit those
      changes in the Tulip trunk soon.

      Cheers,

      Antoine

      Accessing Predefined ColorScales in Python
      https://sourceforge.net/p/auber/discussion/206283/thread/950786e1/?limit=25#3634


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/auber/discussion/206283/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

Log in to post a comment.