Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

build-scientific-colors-cpt.sh 9.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  1. #!/usr/bin/env bash
  2. #
  3. # This script takes the downloaded zip content from
  4. # Crameri, Fabio. (2021, September 12). Scientific colour maps
  5. # (Version 7.0.1). Zenodo. https://doi.org/10.5281/zenodo.5501399
  6. # and converts the *.cpt files into proper GMT master
  7. # CPT files with correct attribution and hinge info
  8. # Run from the ScientificColourMapsV directory (V is version) after the
  9. # zip has downloaded and been expanded. But first you need to manually
  10. # update the /tmp/cpt.info entries below with one line per CPT subdir in the
  11. # downloaded directory. It will create a gmt subdirectory with all the CPTs.
  12. # You also need to edit gmt_cpt_masters.h after adding the CPTs to share/cpt
  13. #
  14. # Last setup and run for ScientificColourMaps7 on 20/09/2021 for GMT 6.3 (master)
  15. # Gave 51 CPTS: The same as prior release with minor changes for categorical cpts.
  16. #
  17. if [ $# -eq 0 ]; then
  18. cat <<- EOF >&2
  19. Usage: build-scientific-colors-cpt.sh <SCM-directory>
  20. Will create the GMT CPT versions of Crameri's scientific colour maps.
  21. Give the full path to the expanded zip file top directory, such as
  22. ~/Download/ScientificColourMaps7.
  23. Before running you must update this script with:
  24. 1. Any new CPT entries since the last release to /tmp/cpt.info
  25. 2. Flag those with a soft hinge as S and a hard hinge as H
  26. 3. Manually set the current version number/doi (see the zip PDF docs)
  27. Afterwards you must:
  28. 1. Update src/gmt_cpt_masters.h with any new entries (copy lines from /tmp/cpt_strings.txt)
  29. 2. Adding the CPTs to share/cpt (overwriting the previous versions)
  30. 3. Probably mess with doc/scripts/GMT_App_M*.sh for new layouts
  31. EOF
  32. exit 1
  33. fi
  34. DIR=$1
  35. VERSION=7.0.1
  36. cat << EOF > /tmp/cpt.info
  37. acton|Perceptually uniform sequential colormap, by Fabio Crameri [C=RGB]
  38. actonS|Perceptually uniform sequential categorical colormap, by Fabio Crameri [C=RGB]
  39. bam|Perceptually uniform bimodal colormap, light, by Fabio Crameri [C=RGB]
  40. bamO|Perceptually uniform bimodal cyclic colormap, light, by Fabio Crameri [C=RGB]
  41. bamako|Perceptually uniform, low-lightness gradient colormap by Fabio Crameri [C=RGB]
  42. bamakoS|Perceptually uniform, low-lightness gradient categorical colormap by Fabio Crameri [C=RGB]
  43. batlow|Perceptually uniform 'rainbow' colormap by Fabio Crameri [C=RGB]
  44. batlowK|Perceptually uniform 'rainbow' colormap with black ending by Fabio Crameri [C=RGB]
  45. batlowS|Perceptually uniform 'rainbow' categorical colormap by Fabio Crameri [C=RGB]
  46. batlowW|Perceptually uniform 'rainbow' colormap with white ending by Fabio Crameri [C=RGB]
  47. berlin|Perceptually uniform bimodal colormap, dark, by Fabio Crameri [S,C=RGB]
  48. bilbao|Perceptually uniform colormap by Fabio Crameri [C=RGB]
  49. bilbaoS|Perceptually uniform categorical colormap by Fabio Crameri [C=RGB]
  50. broc|Perceptually uniform bimodal colormap, light, by Fabio Crameri [S,C=RGB]
  51. brocO|Perceptually uniform bimodal cyclic colormap, light, by Fabio Crameri [C=RGB]
  52. buda|Perceptually uniform, low-lightness gradient colormap, by Fabio Crameri [C=RGB]
  53. budaS|Perceptually uniform, low-lightness gradient categorical colormap, by Fabio Crameri [C=RGB]
  54. bukavu|Perceptually uniform multi-sequential colormap by Fabio Crameri [H,C=RGB]
  55. cork|Perceptually uniform bimodal colormap, light, by Fabio Crameri [S,C=RGB]
  56. corkO|Perceptually uniform bimodal cyclic colormap, light, by Fabio Crameri [C=RGB]
  57. davos|Perceptually uniform colormap by Fabio Crameri [C=RGB]
  58. davosS|Perceptually uniform categorical colormap by Fabio Crameri [C=RGB]
  59. devon|Perceptually uniform sequential colormap, by Fabio Crameri [C=RGB]
  60. devonS|Perceptually uniform sequential categorical colormap, by Fabio Crameri [C=RGB]
  61. fes|Perceptually uniform multi-sequential colormap by Fabio Crameri [H,C=RGB]
  62. grayC|Perceptually uniform 'gray' colormap by Fabio Crameri [C=RGB]
  63. grayCS|Perceptually uniform 'gray' categorical colormap by Fabio Crameri [C=RGB]
  64. hawaii|Perceptually uniform lush colormap by Fabio Crameri [C=RGB]
  65. hawaiiS|Perceptually uniform lush categorical colormap by Fabio Crameri [C=RGB]
  66. imola|Perceptually uniform, low-lightness gradient colormap, by Fabio Crameri [C=RGB]
  67. imolaS|Perceptually uniform, low-lightness gradient categorical colormap, by Fabio Crameri [C=RGB]
  68. lajolla|Perceptually uniform colormap, without black or white, by Fabio Crameri [C=RGB]
  69. lajollaS|Perceptually uniform categorical colormap, without black or white, by Fabio Crameri [C=RGB]
  70. lapaz|Perceptually uniform 'rainbow' colormap by Fabio Crameri [C=RGB]
  71. lapazS|Perceptually uniform 'rainbow' categorical colormap by Fabio Crameri [C=RGB]
  72. lisbon|Perceptually uniform bimodal colormap, dark, by Fabio Crameri [S,C=RGB]
  73. nuuk|Perceptually uniform, low-lightness gradient colormap, by Fabio Crameri [C=RGB]
  74. nuukS|Perceptually uniform, low-lightness gradient categorical colormap, by Fabio Crameri [C=RGB]
  75. oleron|Perceptually uniform topography colormap, by Fabio Crameri [H,C=RGB]
  76. oslo|Perceptually uniform, B&W limits, by Fabio Crameri [C=RGB]
  77. osloS|Perceptually uniform, B&W limits, categorical colormap, by Fabio Crameri [C=RGB]
  78. roma|Perceptually uniform 'seis' colormap by Fabio Crameri [S,C=RGB]
  79. romaO|Perceptually uniform cyclic colormap by Fabio Crameri [C=RGB]
  80. tofino|Perceptually uniform bimodal colormap, dark, by Fabio Crameri [S,C=RGB]
  81. tokyo|Perceptually uniform colormap without black or white, by Fabio Crameri [C=RGB]
  82. tokyoS|Perceptually uniform categorical colormap without black or white, by Fabio Crameri [C=RGB]
  83. turku|Perceptually uniform colormap by Fabio Crameri [C=RGB]
  84. turkuS|Perceptually uniform categorical colormap by Fabio Crameri [C=RGB]
  85. vanimo|Perceptually uniform bimodal colormap, dark, by Fabio Crameri [C=RGB]
  86. vik|Perceptually uniform bimodal colormap, light, by Fabio Crameri [S,C=RGB]
  87. vikO|Perceptually uniform bimodal cyclic colormap, light, by Fabio Crameri [C=RGB]
  88. EOF
  89. here=`pwd`
  90. cd $DIR
  91. # Make formatted list of lines suitable for copying into gmt_cpt_masters.h
  92. awk -F'|' '{printf "\"%-10s : %s\",\n", $1, $2}' /tmp/cpt.info > /tmp/cpt_strings.txt
  93. # Make list of CPTs with a hinge of some soft since these need to insert a true z = 0 slice
  94. grep "\[H," /tmp/cpt.info | awk -F'|' '{print $1}' > /tmp/hinge.lis
  95. grep "\[S," /tmp/cpt.info | awk -F'|' '{print $1}' >> /tmp/hinge.lis
  96. rm -rf gmt_cpts
  97. mkdir gmt_cpts
  98. cat <<- EOF > /tmp/front
  99. #
  100. #----------------------------------------------------------
  101. # COLOR_MODEL = RGB
  102. EOF
  103. while read line; do
  104. cpt=`echo $line | awk -F'|' '{print $1}'`
  105. cat <<- EOF > gmt_cpts/$cpt.cpt
  106. #
  107. EOF
  108. echo $line | awk -F'|' '{printf "# %s\n", $2}' >> gmt_cpts/$cpt.cpt
  109. last_char=$(echo $cpt | awk '{print substr($1,length($1),1)}')
  110. if [ "X${last_char}" = "XS" ]; then
  111. tmp=$(echo $cpt | awk '{print substr($1,1, length($1)-1)}')
  112. cptdir=${tmp}/CategoricalPalettes
  113. else
  114. cptdir=${cpt}
  115. fi
  116. cat <<- EOF >> gmt_cpts/$cpt.cpt
  117. #
  118. # www.fabiocrameri.ch/visualisation
  119. #
  120. # License: MIT License
  121. # Copyright (c) 2021, Fabio Crameri.
  122. # Crameri, F., (2021). Scientific colour maps. Zenodo. https://zenodo.org/record/5501399
  123. # This is Scientific Colour Maps version $VERSION
  124. # Note: Original file converted to GMT version >= 5 CPT format.
  125. EOF
  126. #if [ "$cpt" = "broc" ] || [ "$cpt" = "cork" ] || [ "$cpt" = "vik" ] || [ "$cpt" = "lisbon" ] || [ "$cpt" = "tofino" ] || [ "$cpt" = "berlin" ] || [ "$cpt" = "oleron" ] ; then
  127. if [ $(echo $line | grep -c "\[H") -eq 1 ]; then
  128. hinge="HARD_HINGE"
  129. elif [ $(echo $line | grep -c "\[S") -eq 1 ]; then
  130. hinge="SOFT_HINGE"
  131. else
  132. hinge=""
  133. fi
  134. if [ "X${last_char}" = "XS" ]; then
  135. cat /tmp/front >> gmt_cpts/$cpt.cpt
  136. echo "#----------------------------------------------------------" >> gmt_cpts/$cpt.cpt
  137. egrep -v '^#|^F|^B|^N' $cptdir/$cpt.cpt | awk '{if (NR == 1) { printf "%d\t%s/%s/%s\n%d\t%s/%s/%s\n", 0, $2, $3, $4, 1, $6, $7, $8} else {printf "%d\t%s/%s/%s\n", NR+1, $6, $7, $8}}' > /tmp/tmp.cpt
  138. elif [ "X$hinge" = "X" ]; then
  139. cat /tmp/front >> gmt_cpts/$cpt.cpt
  140. if [ "X${last_char}" = "XO" ]; then
  141. echo "# CYCLIC" >> gmt_cpts/$cpt.cpt
  142. fi
  143. echo "#----------------------------------------------------------" >> gmt_cpts/$cpt.cpt
  144. egrep -v '^#|^F|^B|^N' $cptdir/$cpt.cpt | awk '{printf "%.6f\t%s/%s/%s\t%.6f\t%s/%s/%s\n", $1, $2, $3, $4, $5, $6, $7, $8}' > /tmp/tmp.cpt
  145. else
  146. echo "# Note: Range changed from 0-1 to -1/+1 to place hinge at zero." >> gmt_cpts/$cpt.cpt
  147. cat /tmp/front >> gmt_cpts/$cpt.cpt
  148. echo "# $hinge" >> gmt_cpts/$cpt.cpt
  149. echo "#----------------------------------------------------------" >> gmt_cpts/$cpt.cpt
  150. # Convert to -1/1 range
  151. egrep -v '^#|^F|^B|^N' $cptdir/$cpt.cpt | awk '{printf "%.6f\t%s/%s/%s\t%.6f\t%s/%s/%s\n", 2*($1-0.5), $2, $3, $4, 2*($5-0.5), $6, $7, $8}' > /tmp/tmp.cpt
  152. fi
  153. cat /tmp/tmp.cpt >> gmt_cpts/$cpt.cpt
  154. if [ "X${last_char}" = "XS" ] || [ "X${last_char}" = "XO" ]; then # Categorical or cyclical CPTS have no F or B, only NaN
  155. egrep '^N' $cptdir/$cpt.cpt | awk '{printf "%s\t%s/%s/%s\n", $1, $2, $3, $4}' >> gmt_cpts/$cpt.cpt
  156. else
  157. egrep '^F|^B|^N' $cptdir/$cpt.cpt | awk '{printf "%s\t%s/%s/%s\n", $1, $2, $3, $4}' >> gmt_cpts/$cpt.cpt
  158. fi
  159. done < /tmp/cpt.info
  160. # Fix the zero hinges
  161. while read cpt; do
  162. grep '^#' gmt_cpts/${cpt}.cpt > /tmp/${cpt}.cpt
  163. egrep -v '^#|B|N|F' gmt_cpts/${cpt}.cpt | awk '{if (NR == 127) {printf "%s\t%s\t0.0\t\t\t%s\n", $1, $2, $4} else if (NR == 129) {printf "0.0\t\t\t%s\t%s\t%s\n", $2, $3, $4} else if (NR != 128) { print $0}}' >> /tmp/${cpt}.cpt
  164. egrep '^B|^N|^F' gmt_cpts/${cpt}.cpt >> /tmp/${cpt}.cpt
  165. mv -f /tmp/${cpt}.cpt gmt_cpts
  166. done < /tmp/hinge.lis
  167. rm -f tmp
  168. cd $here
  169. echo "Folder with new cpts is $DIR/gmt_cpts"
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...