Revision: 4508
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4508&view=rev
Author: jswhit
Date: 2007-11-29 13:15:23 -0800 (Thu, 29 Nov 2007)
Log Message:
-----------
include NetCDFFile in basemap.py, so docstring is included for web page.
Modified Paths:
--------------
trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/__init__.py
trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
Modified: trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/__init__.py
===================================================================
--- trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/__init__.py
2007-11-29 20:16:48 UTC (rev 4507)
+++ trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/__init__.py
2007-11-29 21:15:23 UTC (rev 4508)
@@ -1,3 +1,2 @@
from basemap import __doc__, __version__
from basemap import *
-from pupynere import NetCDFFile
Modified: trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
===================================================================
--- trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
2007-11-29 20:16:48 UTC (rev 4507)
+++ trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
2007-11-29 21:15:23 UTC (rev 4508)
@@ -14,7 +14,7 @@
from numpy import linspace, squeeze, ma
from matplotlib.cbook import is_scalar, dedent
from shapelib import ShapeFile
-import _geos
+import _geos, pupynere
# basemap data files now installed in lib/matplotlib/toolkits/basemap/data
basemap_datadir = os.sep.join([os.path.dirname(__file__), 'data'])
@@ -2762,3 +2762,47 @@
raise ValueError, 'width and/or height too large for this projection,
try smaller values'
else:
return corners
+
+has_pynio = True
+try:
+ from PyNGL import nio
+except ImportError:
+ has_pynio = False
+
+def NetCDFFile(file, maskandscale=True):
+ """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 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 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.
+ Data read from OPenDAP and NetCDF version 3 datasets will
+ automatically be converted to masked arrays if the variable has either
+ a 'missing_value' or '_FillValue' attribute, and some data points
+ are equal to the value specified by that attribute. In addition,
+ variables stored as integers that have the 'scale_factor' and
+ 'add_offset' attribute will automatically be rescaled to floats when
+ read. If PyNIO is used, neither of the automatic conversions will
+ be performed. To suppress these automatic conversions, set the
+ maskandscale keyword to False.
+ """
+ if file.startswith('http'):
+ return pupynere._RemoteFile(file,maskandscale)
+ else:
+ # 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 = pupynere._LocalFile(file,maskandscale)
+ 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 = pupynere._LocalFile(file,maskandscale)
+ return f
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins