1 | import numpy as npy
|
---|
2 |
|
---|
3 | def checkplotoptions(md,options):
|
---|
4 | '''
|
---|
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 |
|
---|
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(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 | #text
|
---|
51 | if options.exist('text'):
|
---|
52 |
|
---|
53 | # text values (coerce to list for consistent functionality)
|
---|
54 | textlist=[]
|
---|
55 | text=options.getfieldvalue('text','default text')
|
---|
56 | textlist.extend([text] if isinstance(text,str) else text)
|
---|
57 | numtext=len(textlist)
|
---|
58 |
|
---|
59 | # text position
|
---|
60 | textpos=options.getfieldvalue('textposition',[0.5,0.5])
|
---|
61 | if not isinstance(textpos,list):
|
---|
62 | raise Exception('textposition should be passed as a list')
|
---|
63 | if any(isinstance(i,list) for i in textpos):
|
---|
64 | textx=[item[0] for item in textpos]
|
---|
65 | texty=[item[1] for item in textpos]
|
---|
66 | else:
|
---|
67 | textx=[textpos[0]]
|
---|
68 | texty=[textpos[1]]
|
---|
69 | if len(textx)!=numtext or len(texty)!=numtext:
|
---|
70 | raise Exception('textposition should contain one list of x,y vertices for every text instance')
|
---|
71 |
|
---|
72 | # font size
|
---|
73 | if options.exist('textsize'):
|
---|
74 | textsize=options.getfieldvalue('textsize',12)
|
---|
75 | sizelist=[]
|
---|
76 | sizelist.extend(textsize if isinstance(textsize,list) else [textsize])
|
---|
77 | else:
|
---|
78 | sizelist=[12]
|
---|
79 | if len(sizelist)==1:
|
---|
80 | sizelist=npy.tile(sizelist,numtext)
|
---|
81 |
|
---|
82 | # font color
|
---|
83 | if options.exist('textcolor'):
|
---|
84 | textcolor=options.getfieldvalue('textcolor','k')
|
---|
85 | colorlist=[]
|
---|
86 | colorlist.extend(textcolor if isinstance(textcolor,list) else [textcolor])
|
---|
87 | else:
|
---|
88 | colorlist=['k']
|
---|
89 | if len(colorlist)==1:
|
---|
90 | colorlist=npy.tile(colorlist,numtext)
|
---|
91 |
|
---|
92 | # textweight
|
---|
93 | if options.exist('textweight'):
|
---|
94 | textweightvalues=options.getfieldvalue('textweight')
|
---|
95 | weightlist=[]
|
---|
96 | weightlist.extend(textweight if isinstance(textwieght,list) else [textweight])
|
---|
97 | else:
|
---|
98 | weightlist=['normal']
|
---|
99 | if len(weightlist)==1:
|
---|
100 | weightlist=npy.tile(weightlist,numtext)
|
---|
101 |
|
---|
102 | # text rotation
|
---|
103 | if options.exist('textrotation'):
|
---|
104 | textrotation=options.getfieldvalue('textrotation',0)
|
---|
105 | rotationlist=[]
|
---|
106 | rotationlist.extend(textrotation if isinstance(textrotation,list) else [textrotation])
|
---|
107 | else:
|
---|
108 | rotationlist=[0]
|
---|
109 | if len(rotationlist)==1:
|
---|
110 | rotationlist=npy.tile(rotationlist,numtext)
|
---|
111 |
|
---|
112 | options.changefieldvalue('text',textlist)
|
---|
113 | options.addfield('textx',textx)
|
---|
114 | options.addfield('texty',texty)
|
---|
115 | options.changefieldvalue('textsize',sizelist)
|
---|
116 | options.changefieldvalue('textcolor',colorlist)
|
---|
117 | options.changefieldvalue('textweight',weightlist)
|
---|
118 | options.changefieldvalue('textrotation',rotationlist)
|
---|
119 |
|
---|
120 | #expdisp
|
---|
121 | expdispvaluesarray=[]
|
---|
122 | expstylevaluesarray=[]
|
---|
123 | expstylevalues=[]
|
---|
124 | if options.exist('expstyle'):
|
---|
125 | expstylevalues=options.getfieldvalue('expstyle')
|
---|
126 | if type(expstylevalues)==str:
|
---|
127 | expstylevalues=[expstylevalues]
|
---|
128 | if options.exist('expdisp'):
|
---|
129 | expdispvalues=options.getfieldvalue('expdisp')
|
---|
130 | if type(expdispvalues)==str:
|
---|
131 | expdispvalues=[expdispvalues]
|
---|
132 | for i in npy.arange(len(expdispvalues)):
|
---|
133 | expdispvaluesarray.append(expdispvalues[i])
|
---|
134 | if len(expstylevalues)>i:
|
---|
135 | expstylevaluesarray.append(expstylevalues[i])
|
---|
136 | else:
|
---|
137 | expstylevaluesarray.append('-k')
|
---|
138 |
|
---|
139 | options.changefieldvalue('expstyle',expstylevaluesarray)
|
---|
140 | options.changefieldvalue('expdisp',expdispvaluesarray)
|
---|
141 |
|
---|
142 | #latlonnumbering
|
---|
143 | if options.exist('latlonclick'):
|
---|
144 | if 'on' in options.getfieldvalue('latlonclick','on'):
|
---|
145 | options.changefieldvalue('latlonclick',1)
|
---|
146 |
|
---|
147 | #northarrow
|
---|
148 | if options.exist('northarrow'):
|
---|
149 | if 'on' in options.getfieldvalue('northarrow','on'):
|
---|
150 | #default values
|
---|
151 | Lx=max(md.mesh.x)-min(md.mesh.x)
|
---|
152 | Ly=max(md.mesh.y)-min(md.mesh.y)
|
---|
153 | 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])
|
---|
154 |
|
---|
155 | #scale ruler
|
---|
156 | if options.exist('scaleruler'):
|
---|
157 | if 'on' in options.exist('scaleruler','on'):
|
---|
158 | Lx=max(md.mesh.x)-min(md.mesh.x)
|
---|
159 | Ly=max(md.mesh.y)-min(md.mesh.y)
|
---|
160 | options.changefieldvalue('scaleruler',[min(md.mesh.x)+6./8.*Lx, min(md.mesh.y)+1./10.*Ly, 10**(ceil(log10(Lx)))/5, floor(Lx/100), 5])
|
---|
161 |
|
---|
162 | #log scale
|
---|
163 | if options.exist('log'):
|
---|
164 | if options.exist('clim'):
|
---|
165 | options.changefieldvalue('clim',log(options.getfieldvalue('clim'))/log(options.getfieldvalue('log')))
|
---|
166 | options.changefieldvalue('cutoff',log(options.getfieldvalue('cutoff',1.5))/log(options.getfieldvalue('log')))
|
---|
167 |
|
---|
168 | return options
|
---|