Revision: 4468
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4468&view=rev
Author:   jswhit
Date:     2007-11-27 09:34:20 -0800 (Tue, 27 Nov 2007)

Log Message:
-----------
use PyNIO to read data if the pure python NetCDF reader fails
(PyNIO can read GRIB1+2, HDF4, NetCDF4 and HDFEOS2).

Modified Paths:
--------------
    trunk/toolkits/basemap/examples/plotprecip.py
    trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/pupynere.py

Modified: trunk/toolkits/basemap/examples/plotprecip.py
===================================================================
--- trunk/toolkits/basemap/examples/plotprecip.py       2007-11-27 17:07:38 UTC 
(rev 4467)
+++ trunk/toolkits/basemap/examples/plotprecip.py       2007-11-27 17:34:20 UTC 
(rev 4468)
@@ -13,7 +13,6 @@
 # data from http://www.srh.noaa.gov/rfcshare/precip_analysis_new.php
 prcpvar = nc.variables['amountofprecip']
 data = 0.01*prcpvar[:]
-data = pylab.clip(data,0,10000)
 latcorners = nc.variables['lat'][:]
 loncorners = -nc.variables['lon'][:]
 plottitle = prcpvar.long_name+' for period ending '+prcpvar.dateofdata

Modified: trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/pupynere.py
===================================================================
--- trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/pupynere.py  
2007-11-27 17:07:38 UTC (rev 4467)
+++ trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/pupynere.py  
2007-11-27 17:34:20 UTC (rev 4468)
@@ -36,6 +36,11 @@
 from dap.client import open as open_remote
 from dap.dtypes import ArrayType, GridType, typemap
 
+has_pynio = True
+try:
+    from PyNGL import nio
+except ImportError:
+    has_pynio = False
 
 ABSENT       = '\x00' * 8
 ZERO         = '\x00' * 4
@@ -54,14 +59,31 @@
 def NetCDFFile(file):
     """NetCDF File reader.  API is the same as Scientific.IO.NetCDF.
     If 'file' is a URL that starts with 'http', it is assumed
-    to be a remote OPenDAP dataest, and the python dap client is used
+    to be a remote OPenDAP dataset, and the python dap client is used
     to retrieve the data. Only the OPenDAP Array and Grid data
     types are recognized.  If file does not start with 'http', it
-    is assumed to be a local NetCDF file."""
+    is assumed to be a local file.  If possible, the file will be read 
+    with a pure python NetCDF reader, otherwise PyNIO 
+    (http://www.pyngl.ucar.edu/Nio.shtml) will be used (if it is installed).
+    PyNIO supports NetCDF version 4, GRIB1, GRIB2, HDF4 and HDFEOS2 files.
+    """
     if file.startswith('http'):
         return _RemoteFile(file)
     else:
-        return _LocalFile(file)
+        # use pynio if it is installed and the file cannot
+        # be read with the pure python netCDF reader.  This allows
+        # netCDF version 4, GRIB1, GRIB2, HDF4 and HDFEOS files
+        # to be read.
+        if has_pynio:
+            try:
+                f = _LocalFile(file)
+            except:
+                f = nio.open_file(file)
+        # otherwise, use the pupynere netCDF 3 pure python reader.
+        # (will fail if file is not a netCDF version 3 file).
+        else:
+            f = _LocalFile(file)
+        return f
  
 def _maskandscale(var,datout):
     if hasattr(var, 'missing_value') and (datout == var.missing_value).any():


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to