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

Last change on this file since 21303 was 21303, checked in by bdef, 8 years ago

CHG: major cosmetic clean up we now ask shape (N,) rather than (N,1) also uniformised numpy imports

File size: 5.3 KB
RevLine 
[21303]1import numpy as np
[14260]2
[13411]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
[21253]15 # {{{ units
[14260]16 if options.exist('unit'):
17 if 'km' in options.getfieldvalue('unit','km'):
18 options.changefieldvalue('unit',10**-3)
[18012]19 elif '100km' in options.getfieldvalue('unit','100km'):
[14260]20 options.changefieldvalue('unit',10**-5)
[21253]21 # }}}
22 # {{{ density
[14260]23 if options.exist('density'):
24 density=options.getfieldvalue('density')
25 options.changefieldvalue('density',abs(ceil(density)))
[21253]26 # }}}
27 # {{{ show section
[14260]28 if options.exist('showsection'):
29 if 'on' in options.getfieldvalue('showsection','on'):
30 options.changefieldvalue('showsection',4)
[21253]31 # }}}
32 # {{{ smooth values
[14260]33 if options.exist('smooth'):
34 if 'on' in options.getfieldvalue('smooth','on'):
35 options.changefieldvalue('smooth',0)
[21253]36 # }}}
37 # {{{ contouronly values
[14260]38 if options.exist('contouronly'):
39 if 'on' in options.getfieldvalue('contouronly','on'):
40 options.changefieldvalue('contouronly',1)
[21253]41 # }}}
42 # {{{ colorbar
[14260]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)
[21253]48 # }}}
49 # {{{ text
[14260]50 if options.exist('text'):
[17856]51 # text values (coerce to list for consistent functionality)
52 textlist=[]
53 text=options.getfieldvalue('text','default text')
54 textlist.extend([text] if isinstance(text,str) else text)
55 numtext=len(textlist)
56 # text position
57 textpos=options.getfieldvalue('textposition',[0.5,0.5])
58 if not isinstance(textpos,list):
59 raise Exception('textposition should be passed as a list')
[21253]60 if any(isinstance(i,list) for i in textpos):
[19426]61 textx=[item[0] for item in textpos]
62 texty=[item[1] for item in textpos]
63 else:
64 textx=[textpos[0]]
65 texty=[textpos[1]]
[17856]66 if len(textx)!=numtext or len(texty)!=numtext:
67 raise Exception('textposition should contain one list of x,y vertices for every text instance')
68
69 # font size
[19435]70 if options.exist('textfontsize'):
71 textfontsize=options.getfieldvalue('textfontsize',12)
[17856]72 sizelist=[]
[19435]73 sizelist.extend(textsize if isinstance(textfontsize,list) else [textfontsize])
[14260]74 else:
[17856]75 sizelist=[12]
76 if len(sizelist)==1:
[21253]77 sizelist=np.tile(sizelist,numtext)
[14260]78
[17856]79 # font color
[14260]80 if options.exist('textcolor'):
[17856]81 textcolor=options.getfieldvalue('textcolor','k')
82 colorlist=[]
83 colorlist.extend(textcolor if isinstance(textcolor,list) else [textcolor])
[14260]84 else:
[17856]85 colorlist=['k']
86 if len(colorlist)==1:
[21253]87 colorlist=np.tile(colorlist,numtext)
[14260]88
[17856]89 # textweight
90 if options.exist('textweight'):
[19462]91 textweight=options.getfieldvalue('textweight')
[17856]92 weightlist=[]
[19462]93 weightlist.extend(textweight if isinstance(textweight,list) else [textweight])
[14260]94 else:
[17856]95 weightlist=['normal']
96 if len(weightlist)==1:
[21253]97 weightlist=np.tile(weightlist,numtext)
[14260]98
[17856]99 # text rotation
[14260]100 if options.exist('textrotation'):
[17856]101 textrotation=options.getfieldvalue('textrotation',0)
102 rotationlist=[]
103 rotationlist.extend(textrotation if isinstance(textrotation,list) else [textrotation])
[14260]104 else:
[17856]105 rotationlist=[0]
106 if len(rotationlist)==1:
[21253]107 rotationlist=np.tile(rotationlist,numtext)
[14260]108
[17856]109 options.changefieldvalue('text',textlist)
110 options.addfield('textx',textx)
111 options.addfield('texty',texty)
[19435]112 options.changefieldvalue('textfontsize',sizelist)
[17856]113 options.changefieldvalue('textcolor',colorlist)
114 options.changefieldvalue('textweight',weightlist)
115 options.changefieldvalue('textrotation',rotationlist)
[21253]116 # }}}
117 # {{{ expdisp
[18647]118 expdispvaluesarray=[]
119 expstylevaluesarray=[]
120 expstylevalues=[]
[14260]121 if options.exist('expstyle'):
[21253]122 expstylevalues=options.getfieldvalue('expstyle')
123 if type(expstylevalues)==str:
124 expstylevalues=[expstylevalues]
[14260]125 if options.exist('expdisp'):
126 expdispvalues=options.getfieldvalue('expdisp')
[21253]127 if type(expdispvalues)==str:
128 expdispvalues=[expdispvalues]
129 for i in np.arange(len(expdispvalues)):
[14260]130 expdispvaluesarray.append(expdispvalues[i])
[18647]131 if len(expstylevalues)>i:
[14260]132 expstylevaluesarray.append(expstylevalues[i])
133 else:
134 expstylevaluesarray.append('-k')
135 options.changefieldvalue('expstyle',expstylevaluesarray)
136 options.changefieldvalue('expdisp',expdispvaluesarray)
[21253]137 # }}}
138 # {{{ latlonnumbering
[14260]139 if options.exist('latlonclick'):
140 if 'on' in options.getfieldvalue('latlonclick','on'):
141 options.changefieldvalue('latlonclick',1)
[21253]142 # }}}
143 # {{{ northarrow
[14260]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])
[21253]150 # }}}
151 # {{{ scale ruler
[14260]152 if options.exist('scaleruler'):
[21283]153 if 'on' in options.getfieldvalue('scaleruler','off'):
[14260]154 Lx=max(md.mesh.x)-min(md.mesh.x)
155 Ly=max(md.mesh.y)-min(md.mesh.y)
[21283]156 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])
[21253]157 # }}}
158 # {{{ log scale
[14260]159 if options.exist('log'):
[21253]160 options.changefieldvalue('cutoff',np.log10(options.getfieldvalue('cutoff',1.5))/np.log10(options.getfieldvalue('log')))
161 # }}}
[13411]162 return options
Note: See TracBrowser for help on using the repository browser.