[24213] | 1 | import numpy as np
|
---|
[14260] | 2 |
|
---|
[13411] | 3 |
|
---|
[24213] | 4 | def checkplotoptions(md, options):
|
---|
[26358] | 5 | """CHECKPLOTOPTIONS - build a structure that holds all plot options
|
---|
[13411] | 6 |
|
---|
[26358] | 7 | Usage:
|
---|
| 8 | options = checkplotoptions(md, options)
|
---|
[13411] | 9 |
|
---|
[26358] | 10 | See also: PLOTMODEL
|
---|
[13411] | 11 |
|
---|
[26358] | 12 | NOTE: not fully implemented yet
|
---|
| 13 | """
|
---|
[17856] | 14 |
|
---|
[24213] | 15 | # {{{ units
|
---|
| 16 | if options.exist('unit'):
|
---|
| 17 | if 'km' in options.getfieldvalue('unit', 'km'):
|
---|
[26358] | 18 | options.changefieldvalue('unit', pow(10, -3))
|
---|
[24213] | 19 | elif '100km' in options.getfieldvalue('unit', '100km'):
|
---|
[26358] | 20 | options.changefieldvalue('unit', pow(10, -5))
|
---|
[24213] | 21 | # }}}
|
---|
| 22 | # {{{ density
|
---|
| 23 | if options.exist('density'):
|
---|
| 24 | density = options.getfieldvalue('density')
|
---|
| 25 | options.changefieldvalue('density', abs(np.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 | # {{{ layer
|
---|
| 50 | if options.exist('layer'):
|
---|
| 51 | if options.getfieldvalue('layer') == 0:
|
---|
| 52 | raise Exception('Due to Matlab history first layer is numbered 1')
|
---|
| 53 | if options.getfieldvalue('layer') == md.mesh.numberoflayers - 1:
|
---|
| 54 | print('WARNING : you are plotting layer {}, surface is layer{}.'.format(md.mesh.numberoflayers - 1, md.mesh.numberoflayers))
|
---|
| 55 | # }}}
|
---|
| 56 | # {{{ text
|
---|
| 57 | if options.exist('text'):
|
---|
| 58 | # text values (coerce to list for consistent functionality)
|
---|
| 59 | textlist = []
|
---|
| 60 | text = options.getfieldvalue('text', 'default text')
|
---|
| 61 | textlist.extend([text] if isinstance(text, str) else text)
|
---|
| 62 | numtext = len(textlist)
|
---|
[26358] | 63 | # text position
|
---|
[24213] | 64 | textpos = options.getfieldvalue('textposition', [0.5, 0.5])
|
---|
| 65 | if not isinstance(textpos, list):
|
---|
| 66 | raise Exception('textposition should be passed as a list')
|
---|
| 67 | if any(isinstance(i, list) for i in textpos):
|
---|
| 68 | textx = [item[0] for item in textpos]
|
---|
| 69 | texty = [item[1] for item in textpos]
|
---|
| 70 | else:
|
---|
| 71 | textx = [textpos[0]]
|
---|
| 72 | texty = [textpos[1]]
|
---|
| 73 | if len(textx) != numtext or len(texty) != numtext:
|
---|
| 74 | raise Exception('textposition should contain one list of x, y vertices for every text instance')
|
---|
[14260] | 75 |
|
---|
[26358] | 76 | # font size
|
---|
[24213] | 77 | if options.exist('textfontsize'):
|
---|
| 78 | textfontsize = options.getfieldvalue('textfontsize', 12)
|
---|
| 79 | sizelist = []
|
---|
| 80 | sizelist.extend(textfontsize if isinstance(textfontsize, list) else [textfontsize])
|
---|
| 81 | else:
|
---|
| 82 | sizelist = [12]
|
---|
| 83 | if len(sizelist) == 1:
|
---|
| 84 | sizelist = np.tile(sizelist, numtext)
|
---|
[14260] | 85 |
|
---|
[26358] | 86 | # font color
|
---|
[24213] | 87 | if options.exist('textcolor'):
|
---|
| 88 | textcolor = options.getfieldvalue('textcolor', 'k')
|
---|
| 89 | colorlist = []
|
---|
| 90 | colorlist.extend(textcolor if isinstance(textcolor, list) else [textcolor])
|
---|
| 91 | else:
|
---|
| 92 | colorlist = ['k']
|
---|
| 93 | if len(colorlist) == 1:
|
---|
| 94 | colorlist = np.tile(colorlist, numtext)
|
---|
[14260] | 95 |
|
---|
[26358] | 96 | # textweight
|
---|
[24213] | 97 | if options.exist('textweight'):
|
---|
| 98 | textweight = options.getfieldvalue('textweight')
|
---|
| 99 | weightlist = []
|
---|
| 100 | weightlist.extend(textweight if isinstance(textweight, list) else [textweight])
|
---|
| 101 | else:
|
---|
| 102 | weightlist = ['normal']
|
---|
| 103 | if len(weightlist) == 1:
|
---|
| 104 | weightlist = np.tile(weightlist, numtext)
|
---|
[14260] | 105 |
|
---|
[26358] | 106 | # text rotation
|
---|
[24213] | 107 | if options.exist('textrotation'):
|
---|
| 108 | textrotation = options.getfieldvalue('textrotation', 0)
|
---|
| 109 | rotationlist = []
|
---|
| 110 | rotationlist.extend(textrotation if isinstance(textrotation, list) else [textrotation])
|
---|
| 111 | else:
|
---|
| 112 | rotationlist = [0]
|
---|
| 113 | if len(rotationlist) == 1:
|
---|
| 114 | rotationlist = np.tile(rotationlist, numtext)
|
---|
| 115 |
|
---|
| 116 | options.changefieldvalue('text', textlist)
|
---|
| 117 | options.addfield('textx', textx)
|
---|
| 118 | options.addfield('texty', texty)
|
---|
| 119 | options.changefieldvalue('textfontsize', sizelist)
|
---|
| 120 | options.changefieldvalue('textcolor', colorlist)
|
---|
| 121 | options.changefieldvalue('textweight', weightlist)
|
---|
| 122 | options.changefieldvalue('textrotation', rotationlist)
|
---|
| 123 | # }}}
|
---|
| 124 | # {{{ expdisp
|
---|
| 125 | expdispvaluesarray = []
|
---|
| 126 | expstylevaluesarray = []
|
---|
| 127 | expstylevalues = []
|
---|
| 128 | if options.exist('expstyle'):
|
---|
| 129 | expstylevalues = options.getfieldvalue('expstyle')
|
---|
| 130 | if type(expstylevalues) == str:
|
---|
| 131 | expstylevalues = [expstylevalues]
|
---|
| 132 | if options.exist('expdisp'):
|
---|
| 133 | expdispvalues = options.getfieldvalue('expdisp')
|
---|
| 134 | if type(expdispvalues) == str:
|
---|
| 135 | expdispvalues = [expdispvalues]
|
---|
| 136 | for i in np.arange(len(expdispvalues)):
|
---|
| 137 | expdispvaluesarray.append(expdispvalues[i])
|
---|
| 138 | if len(expstylevalues) > i:
|
---|
| 139 | expstylevaluesarray.append(expstylevalues[i])
|
---|
| 140 | else:
|
---|
| 141 | expstylevaluesarray.append(' - k')
|
---|
| 142 | options.changefieldvalue('expstyle', expstylevaluesarray)
|
---|
| 143 | options.changefieldvalue('expdisp', expdispvaluesarray)
|
---|
| 144 | # }}}
|
---|
| 145 | # {{{ latlonnumbering
|
---|
| 146 | if options.exist('latlonclick'):
|
---|
| 147 | if 'on' in options.getfieldvalue('latlonclick', 'on'):
|
---|
| 148 | options.changefieldvalue('latlonclick', 1)
|
---|
| 149 | # }}}
|
---|
| 150 | # {{{ northarrow
|
---|
| 151 | if options.exist('northarrow'):
|
---|
| 152 | if 'on' in options.getfieldvalue('northarrow', 'on'):
|
---|
[26358] | 153 | # default values
|
---|
[24213] | 154 | Lx = max(md.mesh.x) - min(md.mesh.x)
|
---|
| 155 | Ly = max(md.mesh.y) - min(md.mesh.y)
|
---|
| 156 | 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])
|
---|
| 157 | # }}}
|
---|
| 158 | # {{{ scale ruler
|
---|
| 159 | if options.exist('scaleruler'):
|
---|
| 160 | if 'on' in options.getfieldvalue('scaleruler', 'off'):
|
---|
| 161 | Lx = max(md.mesh.x) - min(md.mesh.x)
|
---|
| 162 | Ly = max(md.mesh.y) - min(md.mesh.y)
|
---|
| 163 | 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])
|
---|
| 164 | # }}}
|
---|
| 165 | # {{{ log scale
|
---|
| 166 | if options.exist('log'):
|
---|
| 167 | options.changefieldvalue('cutoff', np.log10(options.getfieldvalue('cutoff', 1.5)) / np.log10(options.getfieldvalue('log')))
|
---|
| 168 | # }}}
|
---|
| 169 | return options
|
---|