[PYTHON IMAGE-SIG] [PREANNOUNCEMENT] netCDF reader for the matrix and image extensions
Fredrik Lundh
fredrik_lundh@ivab.se
Thu, 25 Jul 1996 11:51:01 +0200
Just a little teaser ;-)
I've pulled together a netCDF reader that doesn't need any C library:
data = NetCdfDataFile.open("dataset.cdf")
# list variables
print "variables:", data.keys()
# global attributes
print "global attributes:", data.attr.keys()
# dump all variables in the file
for i in data.keys():
var = data[i]
print i, data.type, data.shape
print "- data:", var[:]
if var.attr:
print "- local attributes:", var.attr.keys()
It currently sports a slightly different interface compared to Bill
Noon's, but they can probably be unified. And of course, to create or
modify netCDF files, you need to use the real library.
- The above module can be used with the Numerical extension to load
data as multidimensional arrays for further processing.
var = data["foo"]
foo = Numeric.array(var) # 1-dimensional
foo.reshape(var.shape) # make n-dimensional
- It can also be used with the next version of PIL 0.2 in order to
load image data from netCDF files (PIL still supports 8-bit data only,
but you can use scale/offset to fit other data into the 0..255 range).
# foo must be a 2-dimensional variable
var = data["foo"]
im = Image.new("L", var.shape)
im.putdata(var, scale, offset)
im.save("output.jpg")
I plan to release this with PIL 0.2. Comments and flames are welcome.
/F
=================
IMAGE-SIG - SIG on Image Processing with Python
send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org
=================