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

Last change on this file since 18647 was 18647, checked in by cborstad, 10 years ago

BUG: fixed python indexing for expdisp

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