Exemplo n.º 1
0
    def _vector2raster(self, d, var, tndx):
        """
        Postprocess a vector field into barbs (used for wind) and contains hacks for WRF staggered grids.

        :param d: the open netCDF file
        :param var: the name of the variable in var_wisdom
        :param tndx: the time index
        :return: the raster png as a StringIO, and the coordinates
        """
        # gather wisdom about the variable
        wisdom = get_wisdom(var)
        wisdom.update(self.wisdom_update.get(var, {}))
        native_unit = wisdom['native_unit']
        u_name, v_name = wisdom['components']
        lat, lon = wisdom['grid'](d)

        # extract variable
        uw, vw = get_wisdom(u_name), get_wisdom(v_name)
        uw.update(self.wisdom_update.get(u_name, {}))
        vw.update(self.wisdom_update.get(v_name, {}))
        u = uw['retrieve_as'](d, tndx)
        v = vw['retrieve_as'](d, tndx)

        if u.shape != lat.shape:
            raise PostprocError(
                "Variable %s size does not correspond to grid size: var %s grid %s."
                % (u_name, u.shape, u_lat.shape))

        if v.shape != lat.shape:
            raise PostprocError(
                "Variable %s size does not correspond to grid size." % v_name)

        # look at mins and maxes
        fa_min, fa_max = min(np.nanmin(u),
                             np.nanmin(v)), max(np.nanmax(u), np.nanmax(v))

        # determine if we will use the range in the variable or a fixed range
        scale = wisdom['scale']
        if scale != 'original':
            fa_min, fa_max = scale[0], scale[1]
            u[u < fa_min] = fa_min
            u[u > fa_max] = fa_max
            v[v < fa_min] = fa_min
            v[v > fa_max] = fa_max

        # create the raster & get coordinate bounds, HACK to get better quiver resolution
        s = 3
        raster_png_data, corner_coords = basemap_barbs_mercator(
            u[::s, ::s], v[::s, ::s], lat[::s, ::s], lon[::s, ::s])

        return raster_png_data, corner_coords
Exemplo n.º 2
0
    def _vector2raster(self, d, var, tndx):
        """
        Postprocess a vector field into barbs (used for wind) and contains hacks for WRF staggered grids.

        :param d: the open netCDF file
        :param var: the name of the variable in var_wisdom
        :param tndx: the time index
        :return: the raster png as a StringIO, and the coordinates
        """
        # gather wisdom about the variable
        wisdom = get_wisdom(var)
        wisdom.update(self.wisdom_update.get(var, {}))
        native_unit = wisdom['native_unit']
        u_name, v_name = wisdom['components']
        lat, lon = wisdom['grid'](d)

        # extract variable
        uw, vw = get_wisdom(u_name), get_wisdom(v_name)
        uw.update(self.wisdom_update.get(u_name, {}))
        vw.update(self.wisdom_update.get(v_name, {}))
        u = uw['retrieve_as'](d, tndx)
        v = vw['retrieve_as'](d, tndx)

        if u.shape != lat.shape:
            raise PostprocError("Variable %s size does not correspond to grid size: var %s grid %s." % (u_name, u.shape, u_lat.shape))
        
        if v.shape != lat.shape:
            raise PostprocError("Variable %s size does not correspond to grid size." % v_name)

        # look at mins and maxes
        fa_min,fa_max = min(np.nanmin(u), np.nanmin(v)),max(np.nanmax(u), np.nanmax(v))

        # determine if we will use the range in the variable or a fixed range
        scale = wisdom['scale']
        if scale != 'original':
            fa_min, fa_max = scale[0], scale[1]
            u[u < fa_min] = fa_min
            u[u > fa_max] = fa_max
            v[v < fa_min] = fa_min
            v[v > fa_max] = fa_max

        # create the raster & get coordinate bounds, HACK to get better quiver resolution
        s = 3
        raster_png_data,corner_coords = basemap_barbs_mercator(u[::s,::s],v[::s,::s],lat[::s,::s],lon[::s,::s])

        return raster_png_data, corner_coords
Exemplo n.º 3
0
def vector_field_to_raster(u, v, lats, lons, wisdom):
    """
    Postprocess a vector field into arrows (used for wind).
    
    :param u: the vector in the U direction
    :param v: the vector in the V direction
    :param lats: the latitudes
    :param lons: the longitudes
    :param wisdom: a configuration dictionary controlling the visualization
    :return: the raster png as a StringIO, and the coordinates
    """
    native_unit = wisdom['native_unit']

    if u.shape != lats.shape:
        raise PostprocError(
            "U field does not correspond to grid size: field %s grid %s." %
            (u.shape, lats.shape))

    if v.shape != lats.shape:
        raise PostprocError(
            "V field does not correspond to grid size: field %s grid %s." %
            (v.shape, lats.shape))

    # look at mins and maxes
    fa_min, fa_max = min(np.nanmin(u),
                         np.nanmin(v)), max(np.nanmax(u), np.nanmax(v))

    # determine if we will use the range in the variable or a fixed range
    scale = wisdom['scale']
    if scale != 'original':
        fa_min, fa_max = scale[0], scale[1]
        u[u < fa_min] = fa_min
        u[u > fa_max] = fa_max
        v[v < fa_min] = fa_min
        v[v > fa_max] = fa_max

    # create the raster & get coordinate bounds, HACK to get better quiver resolution
    s = 3
    raster_png_data, corner_coords = basemap_barbs_mercator(
        u[::s, ::s], v[::s, ::s], lats[::s, ::s], lons[::s, ::s])

    return raster_png_data, corner_coords
Exemplo n.º 4
0
def vector_field_to_raster(u, v, lats, lons, wisdom):
    """
    Postprocess a vector field into arrows (used for wind).
    
    :param u: the vector in the U direction
    :param v: the vector in the V direction
    :param lats: the latitudes
    :param lons: the longitudes
    :param wisdom: a configuration dictionary controlling the visualization
    :return: the raster png as a StringIO, and the coordinates
    """
    native_unit = wisdom['native_unit']

    if u.shape != lats.shape:
        raise PostprocError("U field does not correspond to grid size: field %s grid %s." % (u.shape, lats.shape))
    
    if v.shape != lats.shape:
        raise PostprocError("V field does not correspond to grid size: field %s grid %s." % (v.shape, lats.shape))

    # look at mins and maxes
    fa_min,fa_max = min(np.nanmin(u), np.nanmin(v)),max(np.nanmax(u), np.nanmax(v))

    # determine if we will use the range in the variable or a fixed range
    scale = wisdom['scale']
    if scale != 'original':
        fa_min, fa_max = scale[0], scale[1]
        u[u < fa_min] = fa_min
        u[u > fa_max] = fa_max
        v[v < fa_min] = fa_min
        v[v > fa_max] = fa_max

    # create the raster & get coordinate bounds, HACK to get better quiver resolution
    s = 3
    raster_png_data,corner_coords = basemap_barbs_mercator(u[::s,::s],v[::s,::s],lats[::s,::s],lons[::s,::s])

    return raster_png_data, corner_coords