Exemple #1
0
    def shading(self, varname, ax=None, t=None, thkth=None,
                azimuth=315, altitude=0, **kwargs):

        # extract data
        x, y, z = self._extract_xyz(varname, t, thkth=thkth)
        w = (3*x[0]-x[1])/2
        e = (3*x[-1]-x[-2])/2
        n = (3*y[0]-y[1])/2
        s = (3*y[-1]-y[-2])/2

        # convert to rad from the x-axis
        azimuth = (90-azimuth)*np.pi / 180.
        altitude = altitude*np.pi / 180.

        # compute cartesian coords of the illumination direction
        x0 = np.cos(azimuth) * np.cos(altitude)
        y0 = np.sin(azimuth) * np.cos(altitude)
        z0 = np.sin(altitude)
        z0 = 0.0  # remove shades from horizontal surfaces

        # compute hillshade (dot product of normal and light direction vectors)
        dx = x[1] - x[0]
        dy = y[1] - y[0]
        u, v = np.gradient(z, dx, dy)
        shade = (z0 - u*x0 - v*y0) / (1 + u**2 + v**2)**(0.5)

        # plot shadows only (white transparency is not possible)
        ax = _get_map_axes(ax)
        return ax.imshow((shade > 0)*shade,
                         cmap=kwargs.pop('cmap', default_cmaps.get('shading')),
                         norm=kwargs.pop('norm', default_norms.get('shading')),
                         extent=kwargs.pop('extent', (w, e, n, s)),
                         **kwargs)
Exemple #2
0
 def contourf(self, varname, ax=None, t=None, thkth=None, **kwargs):
     ax = _get_map_axes(ax)
     x, y, z = self._extract_xyz(varname, t, thkth=thkth)
     cs = ax.contourf(x[:], y[:], z,
                      cmap=kwargs.pop('cmap', default_cmaps.get(varname)),
                      norm=kwargs.pop('norm', default_norms.get(varname)),
                      **kwargs)
     return cs
Exemple #3
0
 def quiver(self, varname, ax=None, t=None, thkth=None, **kwargs):
     ax = _get_map_axes(ax)
     x, y, u, v, c = self._extract_xyuvc(varname, t, thkth=thkth)
     scale = kwargs.pop('scale', 100)
     u = np.sign(u)*np.log(1+np.abs(u)/scale)
     v = np.sign(v)*np.log(1+np.abs(v)/scale)
     return ax.quiver(x, y, u, v, c, scale=scale,
                      cmap=kwargs.pop('cmap', default_cmaps.get(
                         'c'+varname.lstrip('vel'))),
                      norm=kwargs.pop('norm', default_norms.get(
                         'c'+varname.lstrip('vel'))),
                      **kwargs)
Exemple #4
0
 def streamplot(self, varname, ax=None, t=None, thkth=None, **kwargs):
     ax = _get_map_axes(ax)
     x, y, u, v, c = self._extract_xyuvc(varname, t, thkth=thkth)
     return ax.streamplot(x, y, u, v,
                          density=kwargs.pop('density',
                                             (1.0, 1.0*len(y)/len(x))),
                          color=kwargs.pop('color', c),
                          cmap=kwargs.pop('cmap', default_cmaps.get(
                             'c'+varname.lstrip('vel'))),
                          norm=kwargs.pop('norm', default_norms.get(
                             'c'+varname.lstrip('vel'))),
                          **kwargs)
Exemple #5
0
 def imshow(self, varname, ax=None, t=None, thkth=None, **kwargs):
     ax = _get_map_axes(ax)
     x, y, z = self._extract_xyz(varname, t, thkth=thkth)
     w = (3*x[0]-x[1])/2
     e = (3*x[-1]-x[-2])/2
     n = (3*y[0]-y[1])/2
     s = (3*y[-1]-y[-2])/2
     im = ax.imshow(z,
                    cmap=kwargs.pop('cmap', default_cmaps.get(varname)),
                    norm=kwargs.pop('norm', default_norms.get(varname)),
                    interpolation=kwargs.pop('interpolation', 'nearest'),
                    origin=kwargs.pop('origin', 'lower'),
                    extent=kwargs.pop('extent', (w, e, n, s)),
                    **kwargs)
     return im
Exemple #6
0
 def streamplot(self, varname, ax=None, t=None, thkth=None, velth=None,
                **kwargs):
     ax = _get_map_axes(ax)
     x, y, u, v, c = self._extract_xyuvc(varname, t, thkth=thkth)
     if velth is not None:
         slow = c < velth
         u = np.ma.masked_where(slow, u)
         v = np.ma.masked_where(slow, v)
     u[u.mask] = np.nan  # bug in cartopy streamplot?
     v[v.mask] = np.nan  # bug in cartopy streamplot?
     return ax.streamplot(x, y, u, v,
                          density=kwargs.pop('density',
                                             (1.0, 1.0*len(y)/len(x))),
                          color=kwargs.pop('color', c),
                          cmap=kwargs.pop('cmap', default_cmaps.get(
                             'c'+varname.lstrip('vel'))),
                          norm=kwargs.pop('norm', default_norms.get(
                             'c'+varname.lstrip('vel'))),
                          **kwargs)