import mikeio
from io import StringIO
PFS - Palette
Create a palette file for use with Mike Zero based on a matplotlib colormap
Start with a simple palette skeleton
= """
text [PALETTE_FILE]
[MIKEZero_Palette_Definition]
Palette_Title = 'Palette'
Palette_Type = 0
Locked = false
Topmost_Value = false
Nice_Value = true
RGB_Delete_Color = 255, 255, 255
RGB_Color_Value = 122, 209, 81
RGB_Color_Value = 253, 231, 37
EndSect // MIKEZero_Palette_Definition
EndSect // PALETTE_FILE
"""
= mikeio.read_pfs(StringIO(text), unique_keywords=False) pfs
from matplotlib import cm
cm.viridis
viridis
under
bad
over
import math
import numpy as np
= np.linspace(0,1, 16)
vals = [[math.floor(255*x) for x in cm.viridis(val)[:3]] for val in vals]
rgbs
rgbs
[[68, 1, 84],
[72, 25, 107],
[70, 47, 124],
[64, 67, 135],
[56, 86, 139],
[48, 103, 141],
[41, 120, 142],
[35, 136, 141],
[30, 152, 138],
[34, 167, 132],
[53, 183, 120],
[83, 197, 103],
[121, 209, 81],
[165, 218, 53],
[210, 225, 27],
[253, 231, 36]]
= rgbs pfs.PALETTE_FILE.MIKEZero_Palette_Definition.RGB_Color_Value
"viridis.pal") pfs.write(
!cat viridis.pal
// Created : 2022-11-10 18:13:12
// By : MIKE IO
// Version : 1.2.2
[PALETTE_FILE]
[MIKEZero_Palette_Definition]
Palette_Title = 'Palette'
Palette_Type = 0
Locked = false
Topmost_Value = false
Nice_Value = true
RGB_Delete_Color = 255, 255, 255
RGB_Color_Value = 68, 1, 84
RGB_Color_Value = 72, 25, 107
RGB_Color_Value = 70, 47, 124
RGB_Color_Value = 64, 67, 135
RGB_Color_Value = 56, 86, 139
RGB_Color_Value = 48, 103, 141
RGB_Color_Value = 41, 120, 142
RGB_Color_Value = 35, 136, 141
RGB_Color_Value = 30, 152, 138
RGB_Color_Value = 34, 167, 132
RGB_Color_Value = 53, 183, 120
RGB_Color_Value = 83, 197, 103
RGB_Color_Value = 121, 209, 81
RGB_Color_Value = 165, 218, 53
RGB_Color_Value = 210, 225, 27
RGB_Color_Value = 253, 231, 36
EndSect // MIKEZero_Palette_Definition
EndSect // PALETTE_FILE