source: issm/trunk-jpl/src/m/plot/checkplotoptions.py@ 26358

Last change on this file since 26358 was 26358, checked in by jdquinn, 4 years ago

CHG: Completed MATLAB -> Python updates for SE; archive updates now that GMSH can be used on macOS and Linux; various minor bug fixes; formatting; cleanup

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