ubarsc / rios

A raster processing layer on top of GDAL
https://www.rioshome.org
GNU General Public License v3.0
15 stars 8 forks source link

add addRamp() function to colortable module #30

Closed gillins closed 3 years ago

gillins commented 3 years ago

Seems users might want to add their own color tables...

ping: @petescarth

>>> from rios import colortable
>>> colortable.addRamp('bob', '0 100 200', '10 20 30', '99 101 89')
>>> colortable.genTable(10, 'bob')
array([[  0,  22,  44,  66,  88, 111, 133, 155, 177, 200],
       [ 10,  12,  14,  16,  18,  21,  23,  25,  27,  30],
       [ 99,  99,  99, 100, 100,  99,  97,  94,  91,  89],
       [255, 255, 255, 255, 255, 255, 255, 255, 255, 255]], dtype=uint8)
gillins commented 3 years ago

No - it's a carryover from TuiView where the different types of ramps are grouped separately in the GUI. Probably not ideal here, but I'm keen to keep this as close to the TuiView version to make life easier. The code to create the Python code for ramp is actually part of TuiView...

I'm happy to leave this in so anyone reading the code can easily tell what type of ramp is which.

neilflood commented 3 years ago

re: 'type' - no worries, sounds fair.

gillins commented 3 years ago

Just for future reference, the TuiView script that takes the .csv file from https://colorbrewer2.org and creates some Python code is https://github.com/ubarsc/tuiview/blob/master/colorbrewer2py.py. There is a request for a citation which (I think) I have done by having it attached to each ramp in the code. This script is a bit basic and creates dictionaries based on the format of this .csv.

At some stage the viridis family was also added (https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html) which doesn't seem to have a citation requirement.

I'd also note the TuiView implementation has the ability to read supplementary color ramps provided by the user from a file if the TUIVIEW_EXTRA_RAMP env var is set. I don't think RIOS needs to have this because of the user script can call the function added in this PR.

I suspect this all could have been done in a more tidy fashion, happy to take suggestions.