| 1 | import numpy as np
|
|---|
| 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 | # {{{ units
|
|---|
| 16 | if options.exist('unit'):
|
|---|
| 17 | if 'km' in options.getfieldvalue('unit','km'):
|
|---|
| 18 | options.changefieldvalue('unit',10**-3)
|
|---|
| 19 | elif '100km' in options.getfieldvalue('unit','100km'):
|
|---|
| 20 | options.changefieldvalue('unit',10**-5)
|
|---|
| 21 | # }}}
|
|---|
| 22 | # {{{ density
|
|---|
| 23 | if options.exist('density'):
|
|---|
| 24 | density=options.getfieldvalue('density')
|
|---|
| 25 | options.changefieldvalue('density',abs(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 | # {{{ text
|
|---|
| 50 | if options.exist('text'):
|
|---|
| 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')
|
|---|
| 60 | if any(isinstance(i,list) for i in textpos):
|
|---|
| 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]]
|
|---|
| 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
|
|---|
| 70 | if options.exist('textfontsize'):
|
|---|
| 71 | textfontsize=options.getfieldvalue('textfontsize',12)
|
|---|
| 72 | sizelist=[]
|
|---|
| 73 | sizelist.extend(textsize if isinstance(textfontsize,list) else [textfontsize])
|
|---|
| 74 | else:
|
|---|
| 75 | sizelist=[12]
|
|---|
| 76 | if len(sizelist)==1:
|
|---|
| 77 | sizelist=np.tile(sizelist,numtext)
|
|---|
| 78 |
|
|---|
| 79 | # font color
|
|---|
| 80 | if options.exist('textcolor'):
|
|---|
| 81 | textcolor=options.getfieldvalue('textcolor','k')
|
|---|
| 82 | colorlist=[]
|
|---|
| 83 | colorlist.extend(textcolor if isinstance(textcolor,list) else [textcolor])
|
|---|
| 84 | else:
|
|---|
| 85 | colorlist=['k']
|
|---|
| 86 | if len(colorlist)==1:
|
|---|
| 87 | colorlist=np.tile(colorlist,numtext)
|
|---|
| 88 |
|
|---|
| 89 | # textweight
|
|---|
| 90 | if options.exist('textweight'):
|
|---|
| 91 | textweight=options.getfieldvalue('textweight')
|
|---|
| 92 | weightlist=[]
|
|---|
| 93 | weightlist.extend(textweight if isinstance(textweight,list) else [textweight])
|
|---|
| 94 | else:
|
|---|
| 95 | weightlist=['normal']
|
|---|
| 96 | if len(weightlist)==1:
|
|---|
| 97 | weightlist=np.tile(weightlist,numtext)
|
|---|
| 98 |
|
|---|
| 99 | # text rotation
|
|---|
| 100 | if options.exist('textrotation'):
|
|---|
| 101 | textrotation=options.getfieldvalue('textrotation',0)
|
|---|
| 102 | rotationlist=[]
|
|---|
| 103 | rotationlist.extend(textrotation if isinstance(textrotation,list) else [textrotation])
|
|---|
| 104 | else:
|
|---|
| 105 | rotationlist=[0]
|
|---|
| 106 | if len(rotationlist)==1:
|
|---|
| 107 | rotationlist=np.tile(rotationlist,numtext)
|
|---|
| 108 |
|
|---|
| 109 | options.changefieldvalue('text',textlist)
|
|---|
| 110 | options.addfield('textx',textx)
|
|---|
| 111 | options.addfield('texty',texty)
|
|---|
| 112 | options.changefieldvalue('textfontsize',sizelist)
|
|---|
| 113 | options.changefieldvalue('textcolor',colorlist)
|
|---|
| 114 | options.changefieldvalue('textweight',weightlist)
|
|---|
| 115 | options.changefieldvalue('textrotation',rotationlist)
|
|---|
| 116 | # }}}
|
|---|
| 117 | # {{{ expdisp
|
|---|
| 118 | expdispvaluesarray=[]
|
|---|
| 119 | expstylevaluesarray=[]
|
|---|
| 120 | expstylevalues=[]
|
|---|
| 121 | if options.exist('expstyle'):
|
|---|
| 122 | expstylevalues=options.getfieldvalue('expstyle')
|
|---|
| 123 | if type(expstylevalues)==str:
|
|---|
| 124 | expstylevalues=[expstylevalues]
|
|---|
| 125 | if options.exist('expdisp'):
|
|---|
| 126 | expdispvalues=options.getfieldvalue('expdisp')
|
|---|
| 127 | if type(expdispvalues)==str:
|
|---|
| 128 | expdispvalues=[expdispvalues]
|
|---|
| 129 | for i in np.arange(len(expdispvalues)):
|
|---|
| 130 | expdispvaluesarray.append(expdispvalues[i])
|
|---|
| 131 | if len(expstylevalues)>i:
|
|---|
| 132 | expstylevaluesarray.append(expstylevalues[i])
|
|---|
| 133 | else:
|
|---|
| 134 | expstylevaluesarray.append('-k')
|
|---|
| 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.getfieldvalue('scaleruler','off'):
|
|---|
| 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**(np.ceil(np.log10(Lx)))/5, np.floor(Lx/100), 5])
|
|---|
| 157 | # }}}
|
|---|
| 158 | # {{{ log scale
|
|---|
| 159 | if options.exist('log'):
|
|---|
| 160 | options.changefieldvalue('cutoff',np.log10(options.getfieldvalue('cutoff',1.5))/np.log10(options.getfieldvalue('log')))
|
|---|
| 161 | # }}}
|
|---|
| 162 | return options
|
|---|