Plotting NOAA data...

vasilescu_anton@...9... wrote:

Hi Jeff,

This example is just awesome! I really appreciate the time you put into this but it's way way over my head... There are a couple issues I have especially that I just started using python and matplotlib a couple days ago. First, the direct reading of the grib file is great but I am not able to download Nio. The link they sent me to confirm the registration goes to a page that is not available...

Anton: I downloaded and installed it this morning and it worked fine. If you're having problems, I'd suggest emailing them - they are quite responsive.

Also, because I figured out the data I need and already have the scripts in place to extract the CSV files I would really like to keep it that way. Would it be possible to just show me how to get from the csv file to the plot?
  

It's a matter of reading the CSV files into 2D arrays (lons,lats,data). I don't have time right now to work that out for your data. Anyway, I think you'll be happier in the long run if you bite the bullet now and learn how to use PyNIO to read the data.

-Jeff

···

Thanks a lot!
Anton Vasilescu

Jeff Whitaker wrote:
  

antonv wrote:
    

Better yet, here is the file that I am using on my testing but keep in
mind
that it's a 33mb file:
http://downloads.75ive.com/enp.t18z.grib.grib2
  

Anton: I had already downloaded a file from the ftp site, so here's an example script:

import Nio
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
f = Nio.open_file('akw.t00z.grib.grib2')
print f.variables.keys()
lons = f.variables['lon_0'][:]
# flip latitudes so data goes S-->N
lats = f.variables['lat_0'][::-1]
times = f.variables['forecast_time0'][:]
datavar = f.variables['WWSWHGT_P0_L1_GLL0']
ntime = 10
data = datavar[ntime,::-1]
print f.variables['WWSWHGT_P0_L1_GLL0']
print data.min(), data.max()
m = Basemap(projection='cyl',llcrnrlat=lats[0],llcrnrlon=lons[0],\
            urcrnrlat=lats[-1],urcrnrlon=lons[-1],resolution='l')
x, y = m(*np.meshgrid(lons, lats))
levels = np.arange(0,9.1,0.5)
m.contourf(x,y,data,levels)
m.drawcoastlines()
m.fillcontinents()
m.drawparallels(np.arange(40,81,10),labels=[1,0,0,0])
m.drawmeridians(np.arange(150,241,10),labels=[0,0,0,1])
m.drawparallels(np.arange(40,81,10),labels=[1,0,0,0])
m.drawmeridians(np.arange(150,241,10),labels=[0,0,0,1])
plt.title(datavar.long_name+' %s hr fcst'%(times[ntime]),fontsize=12)
plt.colorbar(orientation='horizontal',shrink=0.9,format="%g")
plt.show()

The resulting plot is attached.

Note you will need the Basemap toolkit (available from the matplotlib download site). If you don't want to plot the coastlines, you can just use plt.contourf. You'll also need PyNIO (The Nio module for reading and writing supported data formats) to read the GRIB file.

The png produced by this script is attached.

Let me know if you have any questions.

-Jeff
    

antonv wrote:
  

Here is the link to the folder that has the grib files. They are updated
every 3 hours:
ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/wave/prod/

Any of the files there would have the same info only at different times
of
day.

------------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Quoted from: http://www.nabble.com/Plotting-NOAA-data…-tp21139727p21149409.html

Is there a PyNIO binary for windows as on their download page there are only
Linux, Mac or Solaris versions?

Jeff Whitaker wrote:

···

vasilescu_anton@...9... wrote:

Hi Jeff,

This example is just awesome! I really appreciate the time you put into
this but it's way way over my head... There are a couple issues I have
especially that I just started using python and matplotlib a couple days
ago. First, the direct reading of the grib file is great but I am not
able to download Nio. The link they sent me to confirm the registration
goes to a page that is not available...

Anton: I downloaded and installed it this morning and it worked fine.
If you're having problems, I'd suggest emailing them - they are quite
responsive.

Also, because I figured out the data I need and already have the scripts
in place to extract the CSV files I would really like to keep it that
way. Would it be possible to just show me how to get from the csv file to
the plot?
  

It's a matter of reading the CSV files into 2D arrays (lons,lats,data).
I don't have time right now to work that out for your data. Anyway, I
think you'll be happier in the long run if you bite the bullet now and
learn how to use PyNIO to read the data.

-Jeff

Thanks a lot!
Anton Vasilescu

Jeff Whitaker wrote:
  

antonv wrote:
    

Better yet, here is the file that I am using on my testing but keep in
mind
that it's a 33mb file:
http://downloads.75ive.com/enp.t18z.grib.grib2
  

Anton: I had already downloaded a file from the ftp site, so here's an
example script:

import Nio
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
f = Nio.open_file('akw.t00z.grib.grib2')
print f.variables.keys()
lons = f.variables['lon_0'][:]
# flip latitudes so data goes S-->N
lats = f.variables['lat_0'][::-1]
times = f.variables['forecast_time0'][:]
datavar = f.variables['WWSWHGT_P0_L1_GLL0']
ntime = 10
data = datavar[ntime,::-1]
print f.variables['WWSWHGT_P0_L1_GLL0']
print data.min(), data.max()
m = Basemap(projection='cyl',llcrnrlat=lats[0],llcrnrlon=lons[0],\
            urcrnrlat=lats[-1],urcrnrlon=lons[-1],resolution='l')
x, y = m(*np.meshgrid(lons, lats))
levels = np.arange(0,9.1,0.5)
m.contourf(x,y,data,levels)
m.drawcoastlines()
m.fillcontinents()
m.drawparallels(np.arange(40,81,10),labels=[1,0,0,0])
m.drawmeridians(np.arange(150,241,10),labels=[0,0,0,1])
m.drawparallels(np.arange(40,81,10),labels=[1,0,0,0])
m.drawmeridians(np.arange(150,241,10),labels=[0,0,0,1])
plt.title(datavar.long_name+' %s hr fcst'%(times[ntime]),fontsize=12)
plt.colorbar(orientation='horizontal',shrink=0.9,format="%g")
plt.show()

The resulting plot is attached.

Note you will need the Basemap toolkit (available from the matplotlib
download site). If you don't want to plot the coastlines, you can just
use plt.contourf. You'll also need PyNIO
(The Nio module for reading and writing supported data formats) to read the GRIB file.

The png produced by this script is attached.

Let me know if you have any questions.

-Jeff
    

antonv wrote:
  

Here is the link to the folder that has the grib files. They are
updated
every 3 hours:
ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/wave/prod/

Any of the files there would have the same info only at different
times
of
day.

------------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Quoted from:
http://www.nabble.com/Plotting-NOAA-data…-tp21139727p21149409.html

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://www.nabble.com/Plotting-NOAA-data…-tp21139727p21150608.html
Sent from the matplotlib - users mailing list archive at Nabble.com.