示例#1
0
def plot_s1a_example(fsize='small'):
    test_data.get_sentinel1a(fsize=fsize)
    #w = SARWind(test_data.sentinel1a[fsize])
    w = BayesianWind(test_data.sentinel1a[fsize])
    cc = w.get_corners()
    lonmin = np.int(np.floor(np.min(cc[0])*100))/100.
    lonmax = np.int(np.ceil(np.max(cc[0])*100))/100.
    latmin = np.int(np.floor(np.min(cc[1])*100))/100.
    latmax = np.int(np.ceil(np.max(cc[1])*100))/100.
    w.reproject( Domain(NSR().wkt, ext='-lle %s %s %s %s -ts %s %s' %(lonmin,
        latmin, lonmax, latmax, (lonmax-lonmin)*110., (latmax-latmin)*110.) ) )
    #u = w['U']
    #v = w['V']
    windspeed = w['bspeed_modcmod']
    winddir = w['bdir_modcmod']
    u = -windspeed*np.sin((180.0 - winddir)*np.pi/180.0)
    v = windspeed*np.cos((180.0 - winddir)*np.pi/180.0)
    nmap = Nansatmap(w, resolution='h')
    nmap.pcolormesh(np.hypot(u,v), vmax=18)
    nmap.add_colorbar(fontsize=8)
    nmap.quiver(u, v, step=20)#, scale=1, width=0.001)
    nmap.draw_continents()
    nmap.drawgrid()
    #nmap.drawmeridians(np.arange(lonmin, lonmax, 5), labels=[False, False,
    #    True, False])
    #nmap.drawparallels(np.arange(latmin, latmax, 3), labels=[True, False,
    #    False, False])

    # set size of the figure (inches)
    #nmap.fig.set_figheight(20)
    #nmap.fig.set_figwidth(15)

    # save figure to a PNG file
    nmap.draw_continents()
    #plt.suptitle(
    #    'High resolution\nwind speed and direction\nfrom Sentinel-1A and ' \
    #        'NCEP\n%s' %w.time_coverage_start.isoformat(),
    #    fontsize=8
    #)

    #nmap.fig.savefig('s1a_wind_%s.png'%fsize, dpi=150, bbox_inches='tight')
    nmap.fig.savefig('s1a_bwind_%s.png'%fsize, dpi=150, bbox_inches='tight')
示例#2
0
n.reproject(d)

w = Nansat(os.path.join(home,
        'conferences/ESABigData2014/demo_data/gfs20110222/gfs.t00z.master.grbf03'))

w.reproject(d)

L_560 = n['L_560']

L_560[L_560>90] = np.nan

u = w['U']

v = w['V']

nMap = Nansatmap(n, resolution='f')

nMap.pcolormesh(L_560, vmin=20, vmax=90)

nMap.quiver(u,v,quivectors=20)

nMap.add_colorbar()

nMap.drawgrid()

nMap.quiver(u,v,quivectors=20)

plt.suptitle('TOA radiance from MERIS image and wind direction, 2011.02.22')

nMap.save('20110222_L_560.png')
示例#3
0
    def save_wind_map_image(
        self,
        fileName,
        scale=None,
        numArrowsRange=10,
        landmask=True,
        colorbar=True,
        cbar_fontsize=6,
        drawgrid=True,
        title=None,
        title_fontsize=10,
        edgecolor=None,
        quiverScaleCriteria=None,
        tight=True,
        **kwargs
    ):

        pcolormeshArgs = {"vmin": 0, "vmax": 20}
        for iKey in pcolormeshArgs.keys():
            if iKey in kwargs.keys():
                pcolormeshArgs[iKey] = kwargs.pop(iKey)

        quiverArgs = {
            "X": None,
            "Y": None,
            "U": None,
            "label": None,
            "labelpos": "E",
            "coordinates": "figure",
            "fontproperties": None,
            "width": None,
        }
        popKeys = []
        for iKey in quiverArgs:
            if "quiver_" + iKey in kwargs.keys():
                quiverArgs[iKey] = kwargs.pop("quiver_" + iKey)
            else:
                popKeys.append(iKey)
        for key in popKeys:
            quiverArgs.pop(key)

        nMap = Nansatmap(self, resolution="l", figsize=(5, 8))

        # use wind direction "to" for calculating u and v
        winddirection = np.mod(self["winddirection"] + 180, 360)
        windspeed = self["windspeed"]
        windspeedPcolor = np.copy(windspeed)

        # if data has non-value (dark blue), replace to Nan
        if edgecolor is not None:
            # Replace the edge color (dark blue) to white
            windspeedPcolor[windspeedPcolor == edgecolor] = np.NaN
        # Put colormesh
        nMap.pcolormesh(windspeedPcolor, **pcolormeshArgs)

        # apply landmask to windspeeds
        windspeed = np.ma.masked_where(self.watermask()[1] == 2, windspeed)

        # specify the number of quiver
        quiPixelSpacing = int(np.round(windspeed.shape[1] / numArrowsRange))
        numQuiX = int(self.vrt.dataset.RasterXSize / quiPixelSpacing)
        numQuiY = int(self.vrt.dataset.RasterYSize / quiPixelSpacing)

        # compute maximum wind speed on the sea
        maxSpeed = max(windspeed[windspeed.mask == False])
        # compute a scale for quiver lenght
        scale = None
        if quiverScaleCriteria is not None:
            for iKey in quiverScaleCriteria.keys():
                if eval(iKey % maxSpeed):
                    scale = quiverScaleCriteria[iKey]

        # Draw quivers
        Ux = np.sin(np.radians(winddirection)) * windspeed
        Vx = np.cos(np.radians(winddirection)) * windspeed
        nMap.quiver(Ux, Vx, scale=scale, quivectors=(numQuiY, numQuiX), **quiverArgs)

        if colorbar:
            nMap.add_colorbar(fontsize=cbar_fontsize)

        if drawgrid:
            nMap.drawgrid()

        if title is not None:
            plt.title(title, fontsize=title_fontsize)

        if tight:
            nMap.fig.tight_layout()

        nMap.save(fileName, landmask=landmask, **kwargs)
示例#4
0
    def save_wind_map_image(self,
                            fileName,
                            scale=None,
                            numArrowsRange=10,
                            landmask=True,
                            colorbar=True,
                            cbar_fontsize=6,
                            drawgrid=True,
                            title=None,
                            title_fontsize=10,
                            edgecolor=None,
                            quiverScaleCriteria=None,
                            tight=True,
                            **kwargs):

        pcolormeshArgs = {'vmin': 0, 'vmax': 20}
        for iKey in pcolormeshArgs.keys():
            if iKey in kwargs.keys():
                pcolormeshArgs[iKey] = kwargs.pop(iKey)

        quiverArgs = {
            'X': None,
            'Y': None,
            'U': None,
            'label': None,
            'labelpos': 'E',
            'coordinates': 'figure',
            'fontproperties': None,
            'width': None
        }
        popKeys = []
        for iKey in quiverArgs:
            if 'quiver_' + iKey in kwargs.keys():
                quiverArgs[iKey] = kwargs.pop('quiver_' + iKey)
            else:
                popKeys.append(iKey)
        for key in popKeys:
            quiverArgs.pop(key)

        nMap = Nansatmap(self, resolution='l', figsize=(5, 8))

        # use wind direction "to" for calculating u and v
        winddirection = np.mod(self['winddirection'] + 180, 360)
        windspeed = self['windspeed']
        windspeedPcolor = np.copy(windspeed)

        # if data has non-value (dark blue), replace to Nan
        if edgecolor is not None:
            # Replace the edge color (dark blue) to white
            windspeedPcolor[windspeedPcolor == edgecolor] = np.NaN
        # Put colormesh
        nMap.pcolormesh(windspeedPcolor, **pcolormeshArgs)

        # apply landmask to windspeeds
        windspeed = np.ma.masked_where(
            self.watermask(tps=True)[1] == 2, windspeed)

        # specify the number of quiver
        quiPixelSpacing = int(np.round(windspeed.shape[1] / numArrowsRange))
        numQuiX = int(self.vrt.dataset.RasterXSize / quiPixelSpacing)
        numQuiY = int(self.vrt.dataset.RasterYSize / quiPixelSpacing)

        # compute maximum wind speed on the sea
        maxSpeed = max(windspeed[windspeed.mask == False])
        # compute a scale for quiver lenght
        scale = None
        if quiverScaleCriteria is not None:
            for iKey in quiverScaleCriteria.keys():
                if eval(iKey % maxSpeed):
                    scale = quiverScaleCriteria[iKey]

        # Draw quivers
        Ux = np.sin(np.radians(winddirection)) * windspeed
        Vx = np.cos(np.radians(winddirection)) * windspeed
        nMap.quiver(Ux,
                    Vx,
                    scale=scale,
                    quivectors=(numQuiY, numQuiX),
                    **quiverArgs)

        if colorbar:
            nMap.add_colorbar(fontsize=cbar_fontsize)

        if drawgrid:
            nMap.drawgrid()

        if title is not None:
            plt.title(title, fontsize=title_fontsize)

        if tight:
            nMap.fig.tight_layout()

        nMap.save(fileName, landmask=landmask, **kwargs)