[14260] | 1 | import numpy as npy
|
---|
| 2 |
|
---|
[13411] | 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 |
|
---|
[14260] | 15 |
|
---|
| 16 | #units
|
---|
| 17 | if options.exist('unit'):
|
---|
| 18 | if 'km' in options.getfieldvalue('unit','km'):
|
---|
| 19 | options.changefieldvalue('unit',10**-3)
|
---|
[18012] | 20 | elif '100km' in options.getfieldvalue('unit','100km'):
|
---|
[14260] | 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 |
|
---|
[17856] | 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)
|
---|
[14260] | 58 |
|
---|
[17856] | 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')
|
---|
[19426] | 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]]
|
---|
[17856] | 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
|
---|
[19435] | 73 | if options.exist('textfontsize'):
|
---|
| 74 | textfontsize=options.getfieldvalue('textfontsize',12)
|
---|
[17856] | 75 | sizelist=[]
|
---|
[19435] | 76 | sizelist.extend(textsize if isinstance(textfontsize,list) else [textfontsize])
|
---|
[14260] | 77 | else:
|
---|
[17856] | 78 | sizelist=[12]
|
---|
| 79 | if len(sizelist)==1:
|
---|
| 80 | sizelist=npy.tile(sizelist,numtext)
|
---|
[14260] | 81 |
|
---|
[17856] | 82 | # font color
|
---|
[14260] | 83 | if options.exist('textcolor'):
|
---|
[17856] | 84 | textcolor=options.getfieldvalue('textcolor','k')
|
---|
| 85 | colorlist=[]
|
---|
| 86 | colorlist.extend(textcolor if isinstance(textcolor,list) else [textcolor])
|
---|
[14260] | 87 | else:
|
---|
[17856] | 88 | colorlist=['k']
|
---|
| 89 | if len(colorlist)==1:
|
---|
| 90 | colorlist=npy.tile(colorlist,numtext)
|
---|
[14260] | 91 |
|
---|
[17856] | 92 | # textweight
|
---|
| 93 | if options.exist('textweight'):
|
---|
| 94 | textweightvalues=options.getfieldvalue('textweight')
|
---|
| 95 | weightlist=[]
|
---|
| 96 | weightlist.extend(textweight if isinstance(textwieght,list) else [textweight])
|
---|
[14260] | 97 | else:
|
---|
[17856] | 98 | weightlist=['normal']
|
---|
| 99 | if len(weightlist)==1:
|
---|
| 100 | weightlist=npy.tile(weightlist,numtext)
|
---|
[14260] | 101 |
|
---|
[17856] | 102 | # text rotation
|
---|
[14260] | 103 | if options.exist('textrotation'):
|
---|
[17856] | 104 | textrotation=options.getfieldvalue('textrotation',0)
|
---|
| 105 | rotationlist=[]
|
---|
| 106 | rotationlist.extend(textrotation if isinstance(textrotation,list) else [textrotation])
|
---|
[14260] | 107 | else:
|
---|
[17856] | 108 | rotationlist=[0]
|
---|
| 109 | if len(rotationlist)==1:
|
---|
| 110 | rotationlist=npy.tile(rotationlist,numtext)
|
---|
[14260] | 111 |
|
---|
[17856] | 112 | options.changefieldvalue('text',textlist)
|
---|
| 113 | options.addfield('textx',textx)
|
---|
| 114 | options.addfield('texty',texty)
|
---|
[19435] | 115 | options.changefieldvalue('textfontsize',sizelist)
|
---|
[17856] | 116 | options.changefieldvalue('textcolor',colorlist)
|
---|
| 117 | options.changefieldvalue('textweight',weightlist)
|
---|
| 118 | options.changefieldvalue('textrotation',rotationlist)
|
---|
[14260] | 119 |
|
---|
| 120 | #expdisp
|
---|
[18647] | 121 | expdispvaluesarray=[]
|
---|
| 122 | expstylevaluesarray=[]
|
---|
| 123 | expstylevalues=[]
|
---|
[14260] | 124 | if options.exist('expstyle'):
|
---|
[18647] | 125 | expstylevalues=options.getfieldvalue('expstyle')
|
---|
| 126 | if type(expstylevalues)==str:
|
---|
| 127 | expstylevalues=[expstylevalues]
|
---|
[14260] | 128 | if options.exist('expdisp'):
|
---|
| 129 | expdispvalues=options.getfieldvalue('expdisp')
|
---|
[18647] | 130 | if type(expdispvalues)==str:
|
---|
| 131 | expdispvalues=[expdispvalues]
|
---|
[14260] | 132 | for i in npy.arange(len(expdispvalues)):
|
---|
| 133 | expdispvaluesarray.append(expdispvalues[i])
|
---|
[18647] | 134 | if len(expstylevalues)>i:
|
---|
[14260] | 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'):
|
---|
[18647] | 164 | if options.exist('clim'):
|
---|
| 165 | options.changefieldvalue('clim',log(options.getfieldvalue('clim'))/log(options.getfieldvalue('log')))
|
---|
[14260] | 166 | options.changefieldvalue('cutoff',log(options.getfieldvalue('cutoff',1.5))/log(options.getfieldvalue('log')))
|
---|
| 167 |
|
---|
[13411] | 168 | return options
|
---|