1 | import numpy as np
|
---|
2 |
|
---|
3 |
|
---|
4 | def checkplotoptions(md, options):
|
---|
5 | '''
|
---|
6 | CHECKPLOTOPTIONS - build a structure that holds all plot options
|
---|
7 |
|
---|
8 | Usage:
|
---|
9 | options = checkplotoptions(md, options)
|
---|
10 |
|
---|
11 | See also: PLOTMODEL
|
---|
12 |
|
---|
13 | NOTE: not fully implemented yet
|
---|
14 | '''
|
---|
15 |
|
---|
16 | # {{{ units
|
---|
17 | if options.exist('unit'):
|
---|
18 | if 'km' in options.getfieldvalue('unit', 'km'):
|
---|
19 | options.changefieldvalue('unit', 10**- 3)
|
---|
20 | elif '100km' in options.getfieldvalue('unit', '100km'):
|
---|
21 | options.changefieldvalue('unit', 10**- 5)
|
---|
22 | # }}}
|
---|
23 | # {{{ density
|
---|
24 | if options.exist('density'):
|
---|
25 | density = options.getfieldvalue('density')
|
---|
26 | options.changefieldvalue('density', abs(np.ceil(density)))
|
---|
27 | # }}}
|
---|
28 | # {{{ show section
|
---|
29 | if options.exist('showsection'):
|
---|
30 | if 'on' in options.getfieldvalue('showsection', 'on'):
|
---|
31 | options.changefieldvalue('showsection', 4)
|
---|
32 | # }}}
|
---|
33 | # {{{ smooth values
|
---|
34 | if options.exist('smooth'):
|
---|
35 | if 'on' in options.getfieldvalue('smooth', 'on'):
|
---|
36 | options.changefieldvalue('smooth', 0)
|
---|
37 | # }}}
|
---|
38 | # {{{ contouronly values
|
---|
39 | if options.exist('contouronly'):
|
---|
40 | if 'on' in options.getfieldvalue('contouronly', 'on'):
|
---|
41 | options.changefieldvalue('contouronly', 1)
|
---|
42 | # }}}
|
---|
43 | # {{{ colorbar
|
---|
44 | if options.exist('colorbar'):
|
---|
45 | if 'on' in options.getfieldvalue('colorbar', 'on'):
|
---|
46 | options.changefieldvalue('colorbar', 1)
|
---|
47 | elif 'off' in options.getfieldvalue('colorbar', 'off'):
|
---|
48 | options.changefieldvalue('colorbar', 0)
|
---|
49 | # }}}
|
---|
50 | # {{{ layer
|
---|
51 | if options.exist('layer'):
|
---|
52 | if options.getfieldvalue('layer') == 0:
|
---|
53 | raise Exception('Due to Matlab history first layer is numbered 1')
|
---|
54 | if options.getfieldvalue('layer') == md.mesh.numberoflayers - 1:
|
---|
55 | print('WARNING : you are plotting layer {}, surface is layer{}.'.format(md.mesh.numberoflayers - 1, md.mesh.numberoflayers))
|
---|
56 | # }}}
|
---|
57 | # {{{ text
|
---|
58 | if options.exist('text'):
|
---|
59 | # text values (coerce to list for consistent functionality)
|
---|
60 | textlist = []
|
---|
61 | text = options.getfieldvalue('text', 'default text')
|
---|
62 | textlist.extend([text] if isinstance(text, str) else text)
|
---|
63 | numtext = len(textlist)
|
---|
64 | # text position
|
---|
65 | textpos = options.getfieldvalue('textposition', [0.5, 0.5])
|
---|
66 | if not isinstance(textpos, list):
|
---|
67 | raise Exception('textposition should be passed as a list')
|
---|
68 | if any(isinstance(i, list) for i in textpos):
|
---|
69 | textx = [item[0] for item in textpos]
|
---|
70 | texty = [item[1] for item in textpos]
|
---|
71 | else:
|
---|
72 | textx = [textpos[0]]
|
---|
73 | texty = [textpos[1]]
|
---|
74 | if len(textx) != numtext or len(texty) != numtext:
|
---|
75 | raise Exception('textposition should contain one list of x, y vertices for every text instance')
|
---|
76 |
|
---|
77 | # font size
|
---|
78 | if options.exist('textfontsize'):
|
---|
79 | textfontsize = options.getfieldvalue('textfontsize', 12)
|
---|
80 | sizelist = []
|
---|
81 | sizelist.extend(textfontsize if isinstance(textfontsize, list) else [textfontsize])
|
---|
82 | else:
|
---|
83 | sizelist = [12]
|
---|
84 | if len(sizelist) == 1:
|
---|
85 | sizelist = np.tile(sizelist, numtext)
|
---|
86 |
|
---|
87 | # font color
|
---|
88 | if options.exist('textcolor'):
|
---|
89 | textcolor = options.getfieldvalue('textcolor', 'k')
|
---|
90 | colorlist = []
|
---|
91 | colorlist.extend(textcolor if isinstance(textcolor, list) else [textcolor])
|
---|
92 | else:
|
---|
93 | colorlist = ['k']
|
---|
94 | if len(colorlist) == 1:
|
---|
95 | colorlist = np.tile(colorlist, numtext)
|
---|
96 |
|
---|
97 | # textweight
|
---|
98 | if options.exist('textweight'):
|
---|
99 | textweight = options.getfieldvalue('textweight')
|
---|
100 | weightlist = []
|
---|
101 | weightlist.extend(textweight if isinstance(textweight, list) else [textweight])
|
---|
102 | else:
|
---|
103 | weightlist = ['normal']
|
---|
104 | if len(weightlist) == 1:
|
---|
105 | weightlist = np.tile(weightlist, numtext)
|
---|
106 |
|
---|
107 | # text rotation
|
---|
108 | if options.exist('textrotation'):
|
---|
109 | textrotation = options.getfieldvalue('textrotation', 0)
|
---|
110 | rotationlist = []
|
---|
111 | rotationlist.extend(textrotation if isinstance(textrotation, list) else [textrotation])
|
---|
112 | else:
|
---|
113 | rotationlist = [0]
|
---|
114 | if len(rotationlist) == 1:
|
---|
115 | rotationlist = np.tile(rotationlist, numtext)
|
---|
116 |
|
---|
117 | options.changefieldvalue('text', textlist)
|
---|
118 | options.addfield('textx', textx)
|
---|
119 | options.addfield('texty', texty)
|
---|
120 | options.changefieldvalue('textfontsize', sizelist)
|
---|
121 | options.changefieldvalue('textcolor', colorlist)
|
---|
122 | options.changefieldvalue('textweight', weightlist)
|
---|
123 | options.changefieldvalue('textrotation', rotationlist)
|
---|
124 | # }}}
|
---|
125 | # {{{ expdisp
|
---|
126 | expdispvaluesarray = []
|
---|
127 | expstylevaluesarray = []
|
---|
128 | expstylevalues = []
|
---|
129 | if options.exist('expstyle'):
|
---|
130 | expstylevalues = options.getfieldvalue('expstyle')
|
---|
131 | if type(expstylevalues) == str:
|
---|
132 | expstylevalues = [expstylevalues]
|
---|
133 | if options.exist('expdisp'):
|
---|
134 | expdispvalues = options.getfieldvalue('expdisp')
|
---|
135 | if type(expdispvalues) == str:
|
---|
136 | expdispvalues = [expdispvalues]
|
---|
137 | for i in np.arange(len(expdispvalues)):
|
---|
138 | expdispvaluesarray.append(expdispvalues[i])
|
---|
139 | if len(expstylevalues) > i:
|
---|
140 | expstylevaluesarray.append(expstylevalues[i])
|
---|
141 | else:
|
---|
142 | expstylevaluesarray.append(' - k')
|
---|
143 | options.changefieldvalue('expstyle', expstylevaluesarray)
|
---|
144 | options.changefieldvalue('expdisp', expdispvaluesarray)
|
---|
145 | # }}}
|
---|
146 | # {{{ latlonnumbering
|
---|
147 | if options.exist('latlonclick'):
|
---|
148 | if 'on' in options.getfieldvalue('latlonclick', 'on'):
|
---|
149 | options.changefieldvalue('latlonclick', 1)
|
---|
150 | # }}}
|
---|
151 | # {{{ northarrow
|
---|
152 | if options.exist('northarrow'):
|
---|
153 | if 'on' in options.getfieldvalue('northarrow', 'on'):
|
---|
154 | #default values
|
---|
155 | Lx = max(md.mesh.x) - min(md.mesh.x)
|
---|
156 | Ly = max(md.mesh.y) - min(md.mesh.y)
|
---|
157 | options.changefieldvalue('northarrow', [min(md.mesh.x) + 1. / 6. * Lx, min(md.mesh.y) + 5. / 6. * Ly, 1. / 15. * Ly, 0.25, 1. / 250. * Ly])
|
---|
158 | # }}}
|
---|
159 | # {{{ scale ruler
|
---|
160 | if options.exist('scaleruler'):
|
---|
161 | if 'on' in options.getfieldvalue('scaleruler', 'off'):
|
---|
162 | Lx = max(md.mesh.x) - min(md.mesh.x)
|
---|
163 | Ly = max(md.mesh.y) - min(md.mesh.y)
|
---|
164 | options.changefieldvalue('scaleruler', [min(md.mesh.x) + 6. / 8. * Lx, min(md.mesh.y) + 1. / 10. * Ly, 10**(np.ceil(np.log10(Lx))) / 5, np.floor(Lx / 100), 5])
|
---|
165 | # }}}
|
---|
166 | # {{{ log scale
|
---|
167 | if options.exist('log'):
|
---|
168 | options.changefieldvalue('cutoff', np.log10(options.getfieldvalue('cutoff', 1.5)) / np.log10(options.getfieldvalue('log')))
|
---|
169 | # }}}
|
---|
170 | return options
|
---|