def plot2D(self, va, pt, en, lv, da, na): # INITIALISE self.fig = plt.figure() self.fig = self.figsize( 8, 8, self.fig) # Create a default figure size if not set by user self.bmap, x, y = self.basemap_setup() # Get indices for time, level, lats, lons # TIME time_idx = self.W.get_time_idx(pt) # LEVEL if lv == 2000: lv_idx = 0 lv = 'sfc' # For naming purposes else: print("Non-surface levels not supported yet.") raise Exception # LAT/LON lat_sl, lon_sl = self.get_limited_domain(da) # FETCH DATA PS = {'t': time_idx, 'lv': lv_idx, 'la': lat_sl, 'lo': lon_sl} data = self.W.get(va, PS) la_n = data.shape[-2] lo_n = data.shape[-1] # COLORBAR, CONTOURING try: clvs, cm = scales.get_cm(va, lv) except: self.bmap.contourf(x, y, data.reshape((la_n, lo_n))) else: self.bmap.contourf(x, y, data.reshape((la_n, lo_n)), clvs, cmap=cm) # LABELS, TITLES etc if self.C.plot_titles: title = utils.string_from_time('title', pt) plt.title(title) if self.C.plot_colorbar: plt.colorbar(orientation='horizontal') # SAVE FIGURE datestr = utils.string_from_time('output', pt) if not na: # Use default naming scheme na = (va, lv, datestr) else: # Come up with scheme... print("Coming soon: ability to create custom filenames") raise Exception self.fname = self.create_fname(na) # No da variable here self.save(self.fig, self.p2p, self.fname) self.fig.clf()
def plot2D(self,va,pt,en,lv,da,na): # INITIALISE self.fig = plt.figure() self.fig = self.figsize(8,8,self.fig) # Create a default figure size if not set by user self.bmap,x,y = self.basemap_setup() # Get indices for time, level, lats, lons # TIME time_idx = self.W.get_time_idx(pt) # LEVEL if lv == 2000: lv_idx = 0 lv = 'sfc' # For naming purposes else: print("Non-surface levels not supported yet.") raise Exception # LAT/LON lat_sl, lon_sl = self.get_limited_domain(da) # FETCH DATA PS = {'t': time_idx, 'lv': lv_idx, 'la': lat_sl, 'lo': lon_sl} data = self.W.get(va,PS) la_n = data.shape[-2] lo_n = data.shape[-1] # COLORBAR, CONTOURING try: clvs,cm = scales.get_cm(va,lv) except: self.bmap.contourf(x,y,data.reshape((la_n,lo_n))) else: self.bmap.contourf(x,y,data.reshape((la_n,lo_n)),clvs,cmap=cm) # LABELS, TITLES etc if self.C.plot_titles: title = utils.string_from_time('title',pt) plt.title(title) if self.C.plot_colorbar: plt.colorbar(orientation='horizontal') # SAVE FIGURE datestr = utils.string_from_time('output',pt) if not na: # Use default naming scheme na = (va,lv,datestr) else: # Come up with scheme... print("Coming soon: ability to create custom filenames") raise Exception self.fname = self.create_fname(na) # No da variable here self.save(self.fig,self.p2p,self.fname) self.fig.clf()
def plot_variable2D(self,va,pt,en,lv,p2p,na=0,da=0): """Plot a longitude--latitude cross-section (bird's-eye-view). Use Basemap to create geographical data ======== REQUIRED ======== va = variable(s) pt = plot time(s) nc = ensemble member(s) lv = level(s) p2p = path to plots ======== OPTIONAL ======== da = smaller domain area(s), needs dictionary || DEFAULT = 0 na = naming scheme for plot files || DEFAULT = get what you're given """ va = self.get_sequence(va) pt = self.get_sequence(pt,SoS=1) en = self.get_sequence(en) lv = self.get_sequence(lv) da = self.get_sequence(da) perms = self.make_iterator(va,pt,en,lv,da) # Find some way of looping over wrfout files first, avoiding need # to create new W instances # print("Beginning plotting of {0} figures.".format(len(list(perms)))) #pdb.set_trace() for x in perms: va,pt,en,lv,da = x W = WRFOut(en) # wrfout file class using path F = BirdsEye(self.C,W,p2p) # 2D figure class F.plot2D(va,pt,en,lv,da,na) # Plot/save figure pt_s = utils.string_from_time('title',pt) print("Plotting from file {0}: \n variable = {1}" " time = {2}, level = {3}, area = {4}.".format(en,va,pt_s,lv,da))
def string_from_time(self,usage,t,dom=0,strlen=0,conven=0): str = utils.string_from_time(usage=usage,t=t,dom=dom,strlen=strlen,conven=conven) return str