| 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 | if '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=[0,0]
|
|---|
| 118 | expstylevaluesarray=[0,0]
|
|---|
| 119 | expstylevalues=[0,0]
|
|---|
| 120 | if options.exist('expstyle'):
|
|---|
| 121 | expstylevalues=options.getfieldvalue('expstyle')
|
|---|
| 122 | if options.exist('expdisp'):
|
|---|
| 123 | expdispvalues=options.getfieldvalue('expdisp')
|
|---|
| 124 | for i in npy.arange(len(expdispvalues)):
|
|---|
| 125 | expdispvaluesarray.append(expdispvalues[i])
|
|---|
| 126 | if len(expstylevalues)>i+1:
|
|---|
| 127 | expstylevaluesarray.append(expstylevalues[i])
|
|---|
| 128 | else:
|
|---|
| 129 | expstylevaluesarray.append('-k')
|
|---|
| 130 |
|
|---|
| 131 | options.changefieldvalue('expstyle',expstylevaluesarray)
|
|---|
| 132 | options.changefieldvalue('expdisp',expdispvaluesarray)
|
|---|
| 133 |
|
|---|
| 134 | #latlonnumbering
|
|---|
| 135 | if options.exist('latlonclick'):
|
|---|
| 136 | if 'on' in options.getfieldvalue('latlonclick','on'):
|
|---|
| 137 | options.changefieldvalue('latlonclick',1)
|
|---|
| 138 |
|
|---|
| 139 | #northarrow
|
|---|
| 140 | if options.exist('northarrow'):
|
|---|
| 141 | if 'on' in options.getfieldvalue('northarrow','on'):
|
|---|
| 142 | #default values
|
|---|
| 143 | Lx=max(md.mesh.x)-min(md.mesh.x)
|
|---|
| 144 | Ly=max(md.mesh.y)-min(md.mesh.y)
|
|---|
| 145 | 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])
|
|---|
| 146 |
|
|---|
| 147 | #scale ruler
|
|---|
| 148 | if options.exist('scaleruler'):
|
|---|
| 149 | if 'on' in options.exist('scaleruler','on'):
|
|---|
| 150 | Lx=max(md.mesh.x)-min(md.mesh.x)
|
|---|
| 151 | Ly=max(md.mesh.y)-min(md.mesh.y)
|
|---|
| 152 | 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])
|
|---|
| 153 |
|
|---|
| 154 | #log scale
|
|---|
| 155 | if options.exist('log'):
|
|---|
| 156 | if options.exist('caxis'):
|
|---|
| 157 | options.changefieldvalue('caxis',log(options.getfieldvalue('caxis'))/log(options.getfieldvalue('log')))
|
|---|
| 158 | options.changefieldvalue('cutoff',log(options.getfieldvalue('cutoff',1.5))/log(options.getfieldvalue('log')))
|
|---|
| 159 |
|
|---|
| 160 | return options
|
|---|