def hview(self, vname, time=-1, k=20, fmt='%i', cff=None, unit='g', cblabel=None, levels=None, step=3, scale=5, method='pcolor'): """ 2015-11-08 ベクトルに対応させるために ax_heatmap と ax_vecmap を追加 """ print '{}, time={}, k={}, fmt={},'.format(vname, time, k, fmt), if cff is None: cff = romspy.unit2cff(vname, unit) if levels is None: levels = romspy.levels(vname, unit) if cblabel is None: cblabel = vname print 'cff={}'.format(cff) if vname == 'velocity': var = self.nc.variables['u'] else: var = self.nc.variables[vname] if var.ndim > 2: t, dtime = self.get_time(time) if vname == 'velocity': self.add_quiver(vname, t, k, cff, step, scale) else: if 'pcolor' in method: self.add_pcolor(vname, t, k, cff, levels, cblabel, fmt) if 'contour' in method: self.add_contour(vname, t, k, cff, levels, cblabel, fmt) if 'fill' in method: self.add_contourf(vname, t, k, cff, levels, cblabel, fmt) # basemap if self.mapfile is not None: romspy.basemap(self.mapfile) # finalize if var.ndim == 2: plt.title('Model domein & bathymetry') elif ('avg' in self.ncfile) or ('dia' in self.ncfile): time_string = datetime.datetime.strftime(dtime, '%Y-%m') plt.title('Average ({})'.format(time_string)) else: plt.title(datetime.datetime.strftime(dtime, '%Y-%m-%d %H:%M:%S')) return plt.gca()
def hview(self, vname, **kw): """ 2015-11-08 ベクトルに対応させるために ax_heatmap と ax_vecmap を追加 """ time = kw.pop('time', -1) k = kw.pop('k', 20) cff = kw.pop('cff', None) method = kw.pop('method', 'pcolor') unit = kw.pop('unit', 'g') levels = kw.pop('levels', None) if cff is None: cff = romspy.unit2cff(vname, unit) if levels is None: levels = romspy.levels(vname, unit) print 'cff={}'.format(cff) if vname == 'velocity': var = self.nc.variables['u'] else: var = self.nc.variables[vname] if var.ndim > 2: t, dtime = self.get_time(time) if vname == 'velocity': self.add_quiver(vname, t, k, **kw) elif method == 'limit': self.add_pcolor_limit(vname, t, k, **kw) else: if 'rbf' in method: self.add_contourf_rbf(vname, t, k, cff, levels, **kw) if 'pcolor' in method: self.add_pcolor(vname, t, k, cff, levels, **kw) if 'contour' in method: self.add_contour(vname, t, k, cff, levels, **kw) if 'fill' in method: self.add_contourf(vname, t, k, cff, levels, **kw) if self.mapfile is not None: romspy.basemap(self.mapfile) if k == 20: plt.text(135.25, 34.25, 'surface layer') elif k == 1: plt.text(135.25, 34.25, 'bottom layer') if var.ndim == 2: plt.title('Model domein & bathymetry') elif ('avg' in self.ncfile) or ('dia' in self.ncfile): time_string = datetime.datetime.strftime(dtime,'%Y-%m') plt.title('Average ({})'.format(time_string)) else: plt.title(datetime.datetime.strftime(dtime,'%Y-%m-%d %H:%M:%S')) return plt.gca()
def hview(self, vname, time=-1, k=20, fmt='%i', cff=None, unit='g', cblabel=None, levels=None, step=3, scale=5, method='pcolor'): """ 2015-11-08 ベクトルに対応させるために ax_heatmap と ax_vecmap を追加 """ print '{}, time={}, k={}, fmt={},'.format(vname, time, k, fmt), if cff is None: cff = romspy.unit2cff(vname, unit) if levels is None: levels = romspy.levels(vname, unit) if cblabel is None: cblabel = vname print 'cff={}'.format(cff) if vname == 'velocity': var = self.nc.variables['u'] else: var = self.nc.variables[vname] if var.ndim > 2: t, dtime = self.get_time(time) if vname == 'velocity': self.add_quiver(vname, t, k, cff, step, scale) else: if 'pcolor' in method: self.add_pcolor(vname, t, k, cff, levels, cblabel, fmt) if 'contour' in method: self.add_contour(vname, t, k, cff, levels, cblabel, fmt) if 'fill' in method: self.add_contourf(vname, t, k, cff, levels, cblabel, fmt) # basemap if self.mapfile is not None: romspy.basemap(self.mapfile) # print layer if k == 20: plt.text(135.25, 34.25, 'surface layer') elif k == 1: plt.text(135.25, 34.25, 'bottom layer') # finalize if var.ndim == 2: plt.title('Model domein & bathymetry') elif ('avg' in self.ncfile) or ('dia' in self.ncfile): time_string = datetime.datetime.strftime(dtime,'%Y-%m') plt.title('Average ({})'.format(time_string)) else: plt.title(datetime.datetime.strftime(dtime,'%Y-%m-%d %H:%M:%S')) return plt.gca()
def add_contourf(self, vname, t, k, cff, levels, cblabel, fmt): """ コンタープロットのaxを返す関数 2015-11-08 作成 """ X, Y = self.get_xy('contour') var = self.nc.variables[vname] if var.ndim == 4: var2d = var[t,k-1,:,:] * cff elif var.ndim == 3: var2d = var[t,:,:] * cff else: var2d = var[:,:] * cff if levels is None: levels = romspy.levels(vname) ax = plt.gca() if levels is not None: F = ax.contourf(X, Y, var2d, levels, extend='both') else: F = ax.contourf(X, Y, var2d, extend='both') CB = plt.colorbar(F) CB.ax.set_ylabel(cblabel) return F
def add_contour(self, vname, t, k, cff, levels, cblabel, fmt): """ コンタープロットのaxを返す関数 2015-11-08 作成 """ X, Y = self.get_xy('contour') var = self.nc.variables[vname] if var.ndim == 4: var2d = var[t,k-1,:,:] * cff elif var.ndim == 3: var2d = var[t,:,:] * cff else: var2d = var[:,:] * cff if levels is None: levels = romspy.levels(vname) ax = plt.gca() if levels is not None: C = ax.contour(X, Y, var2d, levels, colors='w') else: C = ax.contour(X, Y, var2d, colors='w') if fmt is not 'off': C.clabel(fmt=fmt, colors='k') # ,fontsize=9) return C
def add_pcolor(self, vname, t, k, cff, levels, cblabel, fmt): """ コンタープロットのaxを返す関数 2015-11-08 作成 """ X, Y = self.get_xy('pcolor') var = self.nc.variables[vname] if var.ndim == 4: var2d = var[t,k-1,:,:] * cff elif var.ndim == 3: var2d = var[t,:,:] * cff else: var2d = var[:,:] * cff if levels is None: levels = romspy.levels(vname) ax = plt.gca() if levels is not None: P = ax.pcolor(X, Y, var2d, vmin=levels[0], vmax=levels[-1]) else: P = ax.pcolor(X, Y, var2d) cbar = plt.colorbar(P) cbar.ax.set_ylabel(cblabel) return P
def add_contourf(self, vname, t, k, cff, levels, cblabel, fmt): """ コンタープロットのaxを返す関数 2015-11-08 作成 """ X, Y = self.get_xy('contour') var = self.nc.variables[vname] if var.ndim == 4: var2d = var[t, k - 1, :, :] * cff elif var.ndim == 3: var2d = var[t, :, :] * cff else: var2d = var[:, :] * cff if levels is None: levels = romspy.levels(vname) ax = plt.gca() if levels is not None: F = ax.contourf(X, Y, var2d, levels, extend='both') else: F = ax.contourf(X, Y, var2d, extend='both') CB = plt.colorbar(F) CB.ax.set_ylabel(cblabel) return F
def add_contour(self, vname, t, k, cff, levels, cblabel, fmt): """ コンタープロットのaxを返す関数 2015-11-08 作成 """ X, Y = self.get_xy('contour') var = self.nc.variables[vname] if var.ndim == 4: var2d = var[t, k - 1, :, :] * cff elif var.ndim == 3: var2d = var[t, :, :] * cff else: var2d = var[:, :] * cff if levels is None: levels = romspy.levels(vname) ax = plt.gca() if levels is not None: C = ax.contour(X, Y, var2d, levels, colors='w') else: C = ax.contour(X, Y, var2d, colors='w') if fmt is not 'off': C.clabel(fmt=fmt, colors='k') # ,fontsize=9) return C
def add_pcolor(self, vname, t, k, cff, levels, cblabel, fmt): """ コンタープロットのaxを返す関数 2015-11-08 作成 """ X, Y = self.get_xy('pcolor') var = self.nc.variables[vname] if var.ndim == 4: var2d = var[t, k - 1, :, :] * cff elif var.ndim == 3: var2d = var[t, :, :] * cff else: var2d = var[:, :] * cff if levels is None: levels = romspy.levels(vname) ax = plt.gca() if levels is not None: P = ax.pcolor(X, Y, var2d, vmin=levels[0], vmax=levels[-1]) else: P = ax.pcolor(X, Y, var2d) cbar = plt.colorbar(P) cbar.ax.set_ylabel(cblabel) return P
def pickup_line(nc, vname, line, time, method='idw', unit='g', cff=None, levels=None, grdfile=None, fmt='%2.1f', cblabel=None, pmethod='contourf'): if cff is None: cff = romspy.unit2cff(vname, unit) if type(time) == int: t = time time = netCDF4.num2date(nc.variables['ocean_time'][t], romspy.JST) elif type(time) == datetime.datetime: time2 = netCDF4.date2num(time, romspy.JST) time3 = nc.variables['ocean_time'][:] t = np.where(time3==time2)[0][0] else: print 'ERROR: your time type =',type(time) if cblabel is None: cblabel = vname print '\n',time, t cs_r = nc.variables['Cs_r'][:] var = np.zeros([len(line),len(cs_r)]) depth = np.zeros([len(line),len(cs_r)]) dist = np.zeros([len(line),len(cs_r)]) for s, l in enumerate(line): lon = l[0] lat = l[1] v = pickup(nc, vname, lon, lat, method, grdfile=grdfile) var[s,:] = v[t,:] h = pickup(nc, 'h', lon, lat, 'idw', grdfile=grdfile) try: zeta = pickup(nc, 'zeta', lon, lat, 'idw', grdfile=grdfile) depth[s,:] = (h + zeta[t]) * cs_r[:] except: depth[s,:] = (h + 1.0) * cs_r[:] if s == 0: dist[s,:] = 0 else: back = line[s-1] fore = line[s] dist[s,:] = dist[s-1,:] + vincenty(back, fore).meters #fig, ax = plt.subplots(figsize=[6,3]) ax = plt.gca() origin = 'upper' #origin = 'lower' if levels is None: levels = romspy.levels(vname, unit=unit) if pmethod == 'contourf': CF = ax.contourf(dist/1000, depth, var*cff, extend='both', origin=origin, levels=levels) plt.clabel(CF, fmt=fmt, colors='k') CB = plt.colorbar(CF) CB.ax.set_ylabel(cblabel) elif pmethod == 'contour': C = ax.contour(dist/1000, depth, var*cff, colors='w', origin=origin, levels=levels) plt.clabel(C, fmt=fmt, colors='k') elif pmethod == 'pcolor': CF = ax.pcolor(dist/1000, depth, var*cff, vmin=levels[0], vmax=levels[-1]) CB = plt.colorbar(CF) CB.ax.set_ylabel(cblabel) ax.plot(dist[:,0]/1000, depth[:,0], 'k-') ax.set_xlabel('distance(km)') ax.set_ylabel('depth(m)') ax.set_title(datetime.datetime.strftime(time, '%Y-%m-%d %H:%M:%S')) ax.set_xlabel('distance(km)') ax.set_ylabel('depth(m)') ax.set_title(datetime.datetime.strftime(time, '%Y-%m-%d %H:%M:%S')) return ax
def pickup_line(nc, vname, line, time, method='idw', unit='g', cff=None, levels=None, grdfile=None, fmt='%2.1f', cblabel=None, pmethod='contourf'): if cff is None: cff = romspy.unit2cff(vname, unit) if type(time) == int: t = time time = netCDF4.num2date(nc.variables['ocean_time'][t], romspy.JST) elif type(time) == datetime.datetime: time2 = netCDF4.date2num(time, romspy.JST) time3 = nc.variables['ocean_time'][:] t = np.where(time3 == time2)[0][0] else: print 'ERROR: your time type =', type(time) if cblabel is None: cblabel = vname print '\n', time, t cs_r = nc.variables['Cs_r'][:] var = np.zeros([len(line), len(cs_r)]) depth = np.zeros([len(line), len(cs_r)]) dist = np.zeros([len(line), len(cs_r)]) for s, l in enumerate(line): lon = l[0] lat = l[1] v = pickup(nc, vname, lon, lat, method, grdfile=grdfile) var[s, :] = v[t, :] h = pickup(nc, 'h', lon, lat, 'idw', grdfile=grdfile) try: zeta = pickup(nc, 'zeta', lon, lat, 'idw', grdfile=grdfile) depth[s, :] = (h + zeta[t]) * cs_r[:] except: depth[s, :] = (h + 1.0) * cs_r[:] if s == 0: dist[s, :] = 0 else: back = line[s - 1] fore = line[s] dist[s, :] = dist[s - 1, :] + vincenty(back, fore).meters #fig, ax = plt.subplots(figsize=[6,3]) ax = plt.gca() origin = 'upper' #origin = 'lower' if levels is None: levels = romspy.levels(vname, unit=unit) if pmethod == 'contourf': CF = ax.contourf(dist / 1000, depth, var * cff, extend='both', origin=origin, levels=levels) plt.clabel(CF, fmt=fmt, colors='k') CB = plt.colorbar(CF) CB.ax.set_ylabel(cblabel) elif pmethod == 'contour': C = ax.contour(dist / 1000, depth, var * cff, colors='w', origin=origin, levels=levels) plt.clabel(C, fmt=fmt, colors='k') elif pmethod == 'pcolor': CF = ax.pcolor(dist / 1000, depth, var * cff, vmin=levels[0], vmax=levels[-1]) CB = plt.colorbar(CF) CB.ax.set_ylabel(cblabel) ax.plot(dist[:, 0] / 1000, depth[:, 0], 'k-') ax.set_xlabel('distance(km)') ax.set_ylabel('depth(m)') ax.set_title(datetime.datetime.strftime(time, '%Y-%m-%d %H:%M:%S')) ax.set_xlabel('distance(km)') ax.set_ylabel('depth(m)') ax.set_title(datetime.datetime.strftime(time, '%Y-%m-%d %H:%M:%S')) return ax