US-GHG-Center / veda-config-ghg

Veda config for GHG
https://ghg-demo.netlify.app
Other
3 stars 15 forks source link

Accommodate custom color maps for EPA datasets #203

Closed j08lue closed 8 months ago

j08lue commented 9 months ago

Requested color ramp:

my_cmap = colors.LinearSegmentedColormap.from_list(name='my_cmap',colors=['#6F4C9B', '#6059A9', '#5568B8', '#4E79C5', '#4D8AC6',
'#4E96BC', '#549EB3', '#59A5A9', '#60AB9E', '#69B190',
'#77B77D', '#8CBC68', '#A6BE54', '#BEBC48', '#D1B541',
'#DDAA3C', '#E49C39', '#E78C35', '#E67932', '#E4632D',
'#DF4828', '#DA2222', '#B8221E', '#95211B', '#721E17',
'#521A13'],N=3000)
my_cmap._init()

slopen = 200
alphas_slope = np.abs(np.linspace(0, 1.0, slopen))
alphas_stable = np.ones(3003-slopen)
alphas = np.concatenate((alphas_slope, alphas_stable))
my_cmap._lut[:,-1] = alphas
my_cmap.set_under('white', alpha=0)

1) If possible, please plot 'zeros' in the dataset as opaque colors (this will result in no transparent grid cells). 2) Please plot all data layers (both individual sources and aggregate layers) on the same color ramp, with MINIMUM set to zero and the MAXIMUM set to 2x10^12 molec/cm2/s.

Acceptance criteria

j08lue commented 9 months ago

Tagged you here, @slesaad and @siddharth0248, but please consult Dashboard folks when you pick this up.

slesaad commented 9 months ago

Hey @j08lue, we couldn't find a way to implement this colormap. We looked at different options with the colormap query parameter.

  1. Discrete colormap - one color for one value - obviously won't work since the values are not discrete
  2. Interval colormap - one color or range of values - won't work either
  3. Linear colormap - I think this is what we're looking for but it looks like it needs a color each for values 0-255, however, that big of dictionary exceeds the limit of maximum URL length. But also I don't think I fully understand how to use this. Since the value of the file range from 0-500 for example, do we rescale this to 0-255 and then send those value (if the max url length limit didn't exist)?

Might need some help implementing this if it is even possible currently! 😅

j08lue commented 9 months ago

Maybe @vincentsarago can shed light on what is possible?

Perhaps this is not possible via URL (client) parameters but with a custom colormap we register in rio-tiler or something?

Please document here what you have tried, @slesaad, which will make it easier to reproduce and find alternatives.

vincentsarago commented 9 months ago

see https://developmentseed.org/titiler/examples/code/tiler_with_custom_colormap/

But also I don't think I fully understand how to use this. Since the value of the file range from 0-500 for example, do we rescale this to 0-255 and then send those value (if the max url length limit didn't exist)?

@slesaad, yes you need to rescale the values from 0 to 255 (using rescale=0,500).

Jeanne-le-Roux commented 8 months ago

Just a note that Erin would still like us to implement this custom color ramp, but wants to make sure that the zero values are white.

slesaad commented 8 months ago

Tested the new colormap from the above pr ^. It looks mostly good to me.

total-agriculture, year 2018 (left custom colormap in the dashboard, right official paper) image

j08lue commented 8 months ago

Awesome, that is very convincing, @slesaad! 😄