source: trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py @ 922

Last change on this file since 922 was 920, checked in by aslmd, 12 years ago

UTIL PYTHON planetoplot_v2. Added options to pp.py. Added help to pp.py. Set warnings in case files cannot be written. Set warnings for bounds too tight. Corrected one possible bug when several plots in a row.

File size: 25.8 KB
Line 
1###############################################
2## PLANETOPLOT                               ##
3## --> PPPLOT                                ##
4###############################################
5## Author: Aymeric Spiga. 02-03/2013         ##
6###############################################
7# python built-in librairies
8import time as timelib
9# added librairies
10import numpy as np
11import matplotlib.pyplot as mpl
12from matplotlib.cm import get_cmap
13from mpl_toolkits.basemap import Basemap
14# personal librairies
15import ppcompute
16###############################################
17
18#################################
19# global variables and settings #
20#################################
21
22# matplotlib settings
23# http://matplotlib.org/users/customizing.html
24# -------------------------------
25mpl.rcParams['font.family'] = "serif"
26mpl.rcParams['axes.color_cycle'] = "r,g,b,k"
27mpl.rcParams['contour.negative_linestyle'] = "dashed"
28mpl.rcParams['verbose.level'] = "silent"
29mpl.rcParams['lines.linewidth'] = 1.5
30mpl.rcParams['lines.markersize'] = 10
31mpl.rcParams['xtick.major.pad'] = 10
32mpl.rcParams['ytick.major.pad'] = 10
33
34# global variables
35# -------------------------------
36# - where settings files are located
37#   (None means planetoplot_v2 in PYTHONPATH)
38whereset = None
39# - some good default settings.
40# (bounds)
41how_many_sigma = 3.0 
42# (contours)
43ccol = 'black'
44cline = 0.55
45# (vectors)
46widthvec = 0.002
47reducevec = 30.
48# (colorbar)
49zeorientation="vertical"
50zefrac = 0.05
51# (save figures)
52pad_inches_value=0.25
53###############################################
54
55##########################
56# executed when imported #
57##########################
58###########################################
59# we load user-defined automatic settings #
60###########################################
61# initialize the warning variable about file not present...
62files_not_present = ""
63# ... and the whereset variable
64whereset = ppcompute.findset(whereset)
65
66# - variable settings
67# -------------------------------
68zefile = "set_var.txt"
69vf = {} ; vc = {} ; vl = {}
70try: 
71    f = open(whereset+zefile, 'r')
72    for line in f:
73        if "#" in line: pass
74        else:
75            var, format, colorb, label = line.strip().split(';')
76            ind = var.strip() 
77            vf[ind] = format.strip()
78            vc[ind] = colorb.strip()
79            vl[ind] = label.strip()
80    f.close()
81except IOError: 
82    files_not_present = files_not_present + zefile + " "
83
84## - file settings
85## -------------------------------
86#zefile = "set_file.txt"
87#prefix_t = {} ; suffix_t = {} ; name_t = {} ; proj_t = {} ; vecx_t = {} ; vecy_t = {}
88#try:
89#    f = open(whereset+zefile, 'r')
90#    for line in f:
91#        if "#" in line: pass
92#        else:
93#            prefix, suffix, name, proj, vecx, vecy = line.strip().split(';')
94#            ind = name.strip()
95#            prefix_t[ind] = prefix.strip()
96#            suffix_t[ind] = suffix.strip()
97#            #name_t[ind] = name.strip()
98#            proj_t[ind] = proj.strip()
99#            vecx_t[ind] = vecx.strip()
100#            vecy_t[ind] = vecy.strip()
101#    f.close()
102#except IOError:
103#    files_not_present = files_not_present + zefile + " "
104
105# - multiplot settings
106# -------------------------------
107zefile = "set_multiplot.txt"
108subv_t = {} ; subh_t = {} ; wspace_t = {} ; hspace_t = {} ; font_t = {}
109try:
110    f = open(whereset+zefile, 'r')
111    for line in f:
112        if "#" in line: pass
113        else:
114            num, subv, subh, wspace, hspace, font = line.strip().split(';')
115            ind = int(num.strip())
116            subv_t[ind] = int(subv.strip())
117            subh_t[ind] = int(subh.strip())
118            wspace_t[ind] = float(wspace.strip())
119            hspace_t[ind] = float(hspace.strip())
120            font_t[ind] = float(font.strip())
121    f.close()
122except IOError:
123    files_not_present = files_not_present + zefile + " "
124
125# - background settings
126# -------------------------------
127zefile = "set_back.txt"
128back = {}
129try:
130    f = open(whereset+zefile, 'r')
131    for line in f:
132        if "#" in line: pass
133        else:
134            name, link = line.strip().split(';')
135            ind = name.strip() 
136            back[ind] = link.strip()
137    f.close()
138except IOError:
139    files_not_present = files_not_present + zefile + " "
140
141# - area settings
142# -------------------------------
143zefile = "set_area.txt"
144area = {}
145try:
146    f = open(whereset+zefile, 'r')
147    for line in f:
148        if "#" in line: pass
149        else:
150            name, wlat1, wlat2, wlon1, wlon2 = line.strip().split(';')
151            area[name.strip()] = [[float(wlon1.strip()),float(wlon2.strip())],\
152                                  [float(wlat1.strip()),float(wlat2.strip())]]
153    f.close()
154except IOError:
155    files_not_present = files_not_present + zefile + " "
156# A note to the user about missing files
157if files_not_present != "":
158    print "warning: files "+files_not_present+" not in "+whereset+" ; those presets will be missing"
159
160# TBD: should change vector color with colormaps
161#"gist_heat":    "white",\
162#"hot":          "white",\
163#"gray":         "red",\
164
165####################
166# useful functions #
167####################
168
169# a function to define subplot
170# ... user can change settings in set_multiplot.txt read above
171# -------------------------------
172def definesubplot(numplot, fig):
173    try: 
174        mpl.rcParams['font.size'] = font_t[numplot]
175    except: 
176        mpl.rcParams['font.size'] = 18
177    try: 
178        fig.subplots_adjust(wspace = wspace_t[numplot], hspace = hspace_t[numplot])
179        subv, subh = subv_t[numplot],subh_t[numplot]
180    except: 
181        print "!! WARNING !! no preset found from set_multiplot.txt, or this setting file was not found."
182        subv = 1 ; subh = numplot
183    return subv,subh
184
185# a function to calculate automatically bounds (or simply prescribe those)
186# -------------------------------
187def calculate_bounds(field,vmin=None,vmax=None):
188    # prescribed cases first
189    zevmin = vmin
190    zevmax = vmax
191    # computed cases
192    if zevmin is None or zevmax is None:
193       # select values
194       ind = np.where(field < 9e+35)
195       fieldcalc = field[ ind ] # field must be a numpy array
196       # calculate stdev and mean
197       dev = np.std(fieldcalc)*how_many_sigma
198       damean = ppcompute.mean(fieldcalc)
199       # fill min/max if needed
200       if vmin is None: zevmin = damean - dev
201       if vmax is None: zevmax = damean + dev
202       # special case: negative values with stddev while field is positive
203       if zevmin < 0. and ppcompute.min(fieldcalc) > 0.: zevmin = 0.
204    # check that bounds are not too tight given the field
205    amin = ppcompute.min(field)
206    amax = ppcompute.max(field)
207    cmin = 100.*np.abs((amin - zevmin)/amin)
208    cmax = 100.*np.abs((amax - zevmax)/amax)
209    if cmin > 150. or cmax > 150.:
210        print "!! WARNING !! Bounds are a bit too tight. Might need to reconsider those."
211        print "!! WARNING !! --> actual",amin,amax,"adopted",zevmin,zevmax
212    return zevmin, zevmax   
213    #### treat vmin = vmax for continuity
214    #if vmin == vmax:  zevmin = damean - dev ; zevmax = damean + dev
215
216# a function to solve the problem with blank bounds !
217# -------------------------------
218def bounds(what_I_plot,zevmin,zevmax,miss=9e+35):
219    small_enough = 1.e-7
220    if zevmin < 0: what_I_plot[ what_I_plot < zevmin*(1.-small_enough) ] = zevmin*(1.-small_enough)
221    else:          what_I_plot[ what_I_plot < zevmin*(1.+small_enough) ] = zevmin*(1.+small_enough)
222    what_I_plot[ what_I_plot > miss  ] = -miss
223    what_I_plot[ what_I_plot > zevmax ] = zevmax*(1.-small_enough)
224    return what_I_plot
225
226# a generic function to show (GUI) or save a plot (PNG,EPS,PDF,...)
227# -------------------------------
228def save(mode="gui",filename="plot",folder="./",includedate=True,res=150,custom=False):
229    # a few settings
230    possiblesave = ['eps','ps','svg','png','jpg','pdf'] 
231    # now the main instructions
232    if mode == "gui": 
233        mpl.show()
234    elif mode in possiblesave:
235        ## name of plot
236        name = folder+'/'+filename
237        if includedate:
238            for ttt in timelib.gmtime():
239                name = name + "_" + str(ttt)
240        name = name +"."+mode
241        ## save file
242        print "**** Saving file in "+mode+" format... Please wait."
243        if not custom:
244            # ... regular plots
245            mpl.savefig(name,dpi=res,pad_inches=pad_inches_value,bbox_inches='tight')
246        else:
247            # ... mapping mode, adapted space for labels etc...
248            mpl.savefig(name,dpi=res)
249    else:
250        print "!! ERROR !! File format not supported. Supported: ",possiblesave
251
252##################################
253# a generic class to make a plot #
254##################################
255class plot():
256
257    # print out a help string when help is invoked on the object
258    # -------------------------------
259    def __repr__(self):
260        whatprint = 'plot object. \"help(plot)\" for more information\n'
261        return whatprint
262
263    # default settings
264    # -- user can define settings by two methods.
265    # -- 1. yeah = plot2d(title="foo")
266    # -- 2. yeah = pp() ; yeah.title = "foo"
267    # -------------------------------
268    def __init__(self,\
269                 var=None,\
270                 field=None,\
271                 absc=None,\
272                 xlabel="",\
273                 ylabel="",\
274                 div=20,\
275                 logx=False,\
276                 logy=False,\
277                 swap=False,\
278                 swaplab=True,\
279                 invert=False,\
280                 xcoeff=1.,\
281                 ycoeff=1.,\
282                 title=""):
283        ## what could be defined by the user
284        self.var = var
285        self.field = field
286        self.absc = absc
287        self.xlabel = xlabel
288        self.ylabel = ylabel
289        self.title = title
290        self.div = div
291        self.logx = logx
292        self.logy = logy
293        self.swap = swap
294        self.swaplab = swaplab # NB: swaplab only used if swap=True
295        self.invert = invert
296        self.xcoeff = xcoeff
297        self.ycoeff = ycoeff
298        ## other useful arguments
299        ## ... not used here in ppplot but need to be attached to plot object
300        self.axisbg = "white"
301        self.superpose = False
302
303    # check
304    # -------------------------------
305    def check(self):
306        if self.field is None: print "!! ERROR !! Please define a field to be plotted" ; exit()
307
308    # define_from_var
309    # ... this uses settings in set_var.txt
310    # -------------------------------
311    def define_from_var(self):
312        if self.var is not None:
313         if self.var.upper() in vl.keys():
314          self.title = vl[self.var.upper()]
315
316    # make
317    # this is generic to all plots
318    # -------------------------------
319    def make(self):
320        self.check()
321        mpl.xlabel(self.xlabel)
322        mpl.ylabel(self.ylabel)
323        if self.swap:
324         if self.swaplab:
325           mpl.xlabel(self.ylabel)
326           mpl.ylabel(self.xlabel)
327        mpl.title(self.title)
328        # if masked array, set masked values to filled values (e.g. np.nan) for plotting purposes
329        if type(self.field).__name__ in 'MaskedArray':
330            self.field[self.field.mask] = self.field.fill_value
331
332################################
333# a subclass to make a 1D plot #
334################################
335class plot1d(plot):
336
337    # print out a help string when help is invoked on the object
338    # -------------------------------
339    def __repr__(self):
340        whatprint = 'plot1d object. \"help(plot1d)\" for more information\n'
341        return whatprint
342
343    # default settings
344    # -- user can define settings by two methods.
345    # -- 1. yeah = plot1d(title="foo")
346    # -- 2. yeah = pp() ; yeah.title = "foo"
347    # -------------------------------
348    def __init__(self,\
349                 lstyle='-',\
350                 color='b',\
351                 marker='x'):
352        ## get initialization from parent class
353        plot.__init__(self)
354        ## what could be defined by the user
355        self.lstyle = lstyle
356        self.color = color
357        self.marker = marker
358
359    # define_from_var
360    # ... this uses settings in set_var.txt
361    # -------------------------------
362    def define_from_var(self):
363        # get what is done in the parent class
364        plot.define_from_var(self)
365        # add specific stuff
366        if self.var is not None:
367         if self.var.upper() in vl.keys():
368          self.ylabel = vl[self.var.upper()]
369          self.title = ""
370
371    # make
372    # -------------------------------
373    def make(self):
374        # get what is done in the parent class
375        plot.make(self)
376        # add specific stuff
377        mpl.grid(color='grey')
378        if self.lstyle == "": self.lstyle = " " # to allow for no line at all with ""
379        # swapping if requested
380        if self.swap:  x = self.field ; y = self.absc
381        else:          x = self.absc ; y = self.field
382        # coefficients on axis
383        x=x*self.xcoeff ; y=y*self.ycoeff
384        # check axis
385        if x.size != y.size:
386            print "!! ERROR !! x and y sizes don't match on 1D plot.", x.size, y.size
387            exit()
388        # make the 1D plot
389        # either request linestyle or let matplotlib decide
390        if self.lstyle is not None and self.color is not None:
391            mpl.plot(x,y,self.color+self.lstyle,marker=self.marker)
392        else:
393            mpl.plot(x,y,marker=self.marker)
394        # make log axes and/or invert ordinate
395        # ... this must be after plot so that axis bounds are well-defined
396        # ... also inverting must be after making the thing logarithmic
397        if self.logx: mpl.semilogx()
398        if self.logy: mpl.semilogy()
399        if self.invert: ax = mpl.gca() ; ax.set_ylim(ax.get_ylim()[::-1])
400        ## TBD: set with .div the number of ticks
401        ## TBD: be able to control plot limits
402        #ticks = self.div + 1
403        #ax = mpl.gca()
404        #ax.get_xaxis().set_ticks(np.linspace(ppcompute.min(x),ppcompute.max(x),ticks/2+1))
405
406################################
407# a subclass to make a 2D plot #
408################################
409class plot2d(plot):
410
411    # print out a help string when help is invoked on the object
412    # -------------------------------
413    def __repr__(self):
414        whatprint = 'plot2d object. \"help(plot2d)\" for more information\n'
415        return whatprint
416
417    # default settings
418    # -- user can define settings by two methods.
419    # -- 1. yeah = plot2d(title="foo")
420    # -- 2. yeah = pp() ; yeah.title = "foo"
421    # -------------------------------
422    def __init__(self,\
423                 ordi=None,\
424                 mapmode=False,\
425                 proj="cyl",\
426                 back=None,\
427                 colorb="jet",\
428                 trans=1.0,\
429                 addvecx=None,\
430                 addvecy=None,\
431                 addcontour=None,\
432                 fmt="%.2e",\
433                 blon=None,\
434                 blat=None,\
435                 area=None,\
436                 vmin=None,\
437                 vmax=None,\
438                 colorvec="black"):
439        ## get initialization from parent class
440        plot.__init__(self)
441        ## what could be defined by the user
442        self.ordi = ordi
443        self.mapmode = mapmode
444        self.proj = proj
445        self.back = back
446        self.colorb = colorb
447        self.trans = trans
448        self.addvecx = addvecx
449        self.addvecy = addvecy
450        self.colorvec = colorvec
451        self.addcontour = addcontour
452        self.fmt = fmt
453        self.blon = blon ; self.blat = blat
454        self.area = area
455        self.vmin = vmin ; self.vmax = vmax
456
457    # define_from_var
458    # ... this uses settings in set_var.txt
459    # -------------------------------
460    def define_from_var(self):
461        # get what is done in the parent class
462        plot.define_from_var(self)
463        # add specific stuff
464        if self.var is not None:
465         if self.var.upper() in vl.keys():
466          self.colorb = vc[self.var.upper()]
467          self.fmt = vf[self.var.upper()]
468
469    # make
470    # -------------------------------
471    def make(self):
472        # get what is done in the parent class...
473        plot.make(self)
474        # ... then add specific stuff
475        ############################################################################################
476        ### PRE-SETTINGS
477        ############################################################################################
478        # transposing if necessary
479        shape = self.field.shape
480        if shape[0] != shape[1]:
481         if len(self.absc) == shape[0] and len(self.ordi) == shape[1]:
482            print "!! WARNING !! Transposing axes"
483            self.field = np.transpose(self.field)
484        # bound field
485        zevmin, zevmax = calculate_bounds(self.field,vmin=self.vmin,vmax=self.vmax)
486        what_I_plot = bounds(self.field,zevmin,zevmax)
487        # define contour field levels. define color palette
488        ticks = self.div + 1
489        zelevels = np.linspace(zevmin,zevmax,ticks)
490        palette = get_cmap(name=self.colorb)
491        # do the same thing for possible contourline entries
492        if self.addcontour is not None:
493            # if masked array, set masked values to filled values (e.g. np.nan) for plotting purposes
494            if type(self.addcontour).__name__ in 'MaskedArray':
495               self.addcontour[self.addcontour.mask] = self.addcontour.fill_value
496            zevminc, zevmaxc = calculate_bounds(self.addcontour)
497            what_I_contour = bounds(self.addcontour,zevminc,zevmaxc)
498            ticks = self.div + 1
499            zelevelsc = np.linspace(zevminc,zevmaxc,ticks)
500        ############################################################################################
501        ### MAIN PLOT
502        ### NB: contour lines are done before contour shades otherwise colorar error
503        ############################################################################################
504        if not self.mapmode:
505            ## A SIMPLE 2D PLOT
506            ###################
507            # swapping if requested
508            if self.swap:  x = self.ordi ; y = self.absc
509            else:          x = self.absc ; y = self.ordi
510            # coefficients on axis
511            x=x*self.xcoeff ; y=y*self.ycoeff
512            # make shaded and line contours
513            if self.addcontour is not None: 
514                mpl.contour(x, y, what_I_contour, \
515                            zelevelsc, colors = ccol, linewidths = cline)
516            mpl.contourf(x, y, \
517                         self.field, \
518                         zelevels, cmap=palette)
519            # make log axes and/or invert ordinate
520            if self.logx: mpl.semilogx()
521            if self.logy: mpl.semilogy()
522            if self.invert: ax = mpl.gca() ; ax.set_ylim(ax.get_ylim()[::-1])
523        else:
524            ## A 2D MAP USING PROJECTIONS (basemap)
525            #######################################
526            mpl.xlabel("") ; mpl.ylabel("")
527            # additional security in case self.proj is None here
528            # ... we set cylindrical projection (the simplest one)
529            if self.proj is None: self.proj = "cyl"
530            # get lon and lat in 2D version.
531            # (but first ensure we do have 2D coordinates)
532            if self.absc.ndim == 1:     [self.absc,self.ordi] = np.meshgrid(self.absc,self.ordi)
533            elif self.absc.ndim > 2:    print "!! ERROR !! lon and lat arrays must be 1D or 2D"
534            # get lat lon intervals and associated settings
535            wlon = [np.min(self.absc),np.max(self.absc)]
536            wlat = [np.min(self.ordi),np.max(self.ordi)]
537            # -- area presets are in set_area.txt
538            if self.area is not None:
539             if self.area in area.keys():
540                wlon, wlat = area[self.area]
541            # -- settings for meridians and parallels
542            steplon = abs(wlon[1]-wlon[0])/6.
543            steplat = abs(wlat[1]-wlat[0])/3.
544            mertab = np.r_[wlon[0]:wlon[1]:steplon] ; merlab = [0,0,0,1]
545            partab = np.r_[wlat[0]:wlat[1]:steplat] ; parlab = [1,0,0,0]
546            format = '%.1f'
547            # -- center of domain and bounding lats
548            lon_0 = 0.5*(wlon[0]+wlon[1])
549            lat_0 = 0.5*(wlat[0]+wlat[1])
550            # some tests, bug fixes, and good-looking settings
551            # ... cyl is good for global and regional
552            if self.proj == "cyl":
553                format = '%.0f'
554            # ... global projections
555            elif self.proj in ["ortho","moll","robin"]:
556                wlat[0] = None ; wlat[1] = None ; wlon[0] = None ; wlon[1] = None
557                steplon = 30. ; steplat = 30.
558                if self.proj == "robin": steplon = 60.
559                mertab = np.r_[-360.:360.:steplon]
560                partab = np.r_[-90.:90.:steplat]
561                if self.proj == "ortho": 
562                    merlab = [0,0,0,0] ; parlab = [0,0,0,0]
563                    # in ortho projection, blon and blat can be used to set map center
564                    if self.blon is not None: lon_0 = self.blon
565                    if self.blat is not None: lat_0 = self.blat
566                elif self.proj == "moll":
567                    merlab = [0,0,0,0]
568                format = '%.0f'
569            # ... regional projections
570            elif self.proj in ["lcc","laea","merc"]:
571                if self.proj in ["lcc","laea"] and wlat[0] == -wlat[1]: 
572                    print "!! ERROR !! with Lambert lat1 must be different than lat2" ; exit()
573                if wlat[0] < -80. and wlat[1] > 80.:
574                    print "!! ERROR !! set an area (not global)" ; exit()
575                format = '%.0f'
576            elif self.proj in ["npstere","spstere"]:
577                # in polar projections, blat gives the bounding lat
578                # if not set, set something reasonable
579                if self.blat is None:   self.blat = 60.
580                # help the user who forgets self.blat would better be negative in spstere
581                # (this actually serves for the default setting just above)
582                if self.proj == "spstere" and self.blat > 0: self.blat = -self.blat
583            # ... unsupported projections
584            else:
585                print "!! ERROR !! unsupported projection. supported: "+\
586                      "cyl, npstere, spstere, ortho, moll, robin, lcc, laea, merc"
587            # finally define projection
588            m = Basemap(projection=self.proj,\
589                        lat_0=lat_0,lon_0=lon_0,\
590                        boundinglat=self.blat,\
591                        llcrnrlat=wlat[0],urcrnrlat=wlat[1],\
592                        llcrnrlon=wlon[0],urcrnrlon=wlon[1])
593            # draw meridians and parallels
594            ft = int(mpl.rcParams['font.size']*3./4.)
595            m.drawmeridians(mertab,labels=merlab,color='grey',linewidth=0.75,fontsize=ft,fmt=format)
596            m.drawparallels(partab,labels=parlab,color='grey',linewidth=0.75,fontsize=ft,fmt=format)
597            # define background (see set_back.txt)
598            if self.back is not None:
599              if self.back in back.keys():
600                 print "**** info: loading a background, please wait.",self.back
601                 if back not in ["coast","sea"]:   m.warpimage(back[self.back],scale=0.75)
602                 elif back == "coast":             m.drawcoastlines()
603                 elif back == "sea":               m.drawlsmask(land_color='white',ocean_color='aqua')
604              else:
605                 print "!! ERROR !! requested background not defined. change name or fill in set_back.txt" ; exit()
606            # define x and y given the projection
607            x, y = m(self.absc, self.ordi)
608            # contour field. first line contour then shaded contour.
609            if self.addcontour is not None: 
610                m.contour(x, y, what_I_contour, \
611                            zelevelsc, colors = ccol, linewidths = cline)
612            m.contourf(x, y, what_I_plot, zelevels, cmap = palette, alpha = self.trans)
613        ############################################################################################
614        ### COLORBAR
615        ############################################################################################
616        if self.trans > 0.:
617            ## draw colorbar. settings are different with projections. or if not mapmode.
618            if not self.mapmode: orientation=zeorientation ; frac = 0.075 ; pad = 0.03
619            elif self.proj in ['moll']: orientation="horizontal" ; frac = 0.075 ; pad = 0.03
620            elif self.proj in ['cyl']: orientation="vertical" ; frac = 0.023 ; pad = 0.03
621            else: orientation = zeorientation ; frac = zefrac ; pad = 0.03
622            zelevpal = np.linspace(zevmin,zevmax,num=min([ticks/2+1,21]))
623            zecb = mpl.colorbar(fraction=frac,pad=pad,\
624                                format=self.fmt,orientation=orientation,\
625                                ticks=zelevpal,\
626                                extend='neither',spacing='proportional') 
627            if zeorientation == "horizontal": zecb.ax.set_xlabel(self.title) ; self.title = ""
628        ############################################################################################
629        ### VECTORS. must be after the colorbar. we could also leave possibility for streamlines.
630        ############################################################################################
631        ### not expecting NaN in self.addvecx and self.addvecy. masked arrays is just enough.
632        stride = 3
633        if self.addvecx is not None and self.addvecy is not None and self.mapmode:
634                ## for metwinds only ???
635                [vecx,vecy] = m.rotate_vector(self.addvecx,self.addvecy,self.absc,self.ordi) 
636                # reference vector is scaled
637                zescale = ppcompute.mean(np.sqrt(self.addvecx*self.addvecx+self.addvecy*self.addvecy))
638                # make vector field
639                q = m.quiver( x[::stride,::stride],y[::stride,::stride],\
640                              vecx[::stride,::stride],vecy[::stride,::stride],\
641                              angles='xy',color=self.colorvec,pivot='middle',\
642                              scale=zescale*reducevec,width=widthvec )
643                # make vector key. default is on upper left corner.
644                p = mpl.quiverkey(q,-0.03,1.08,\
645                                  zescale,str(int(zescale)),\
646                                  color='black',labelpos='S',labelsep = 0.07)
647        #### streamplot!!! avec basemap
Note: See TracBrowser for help on using the repository browser.