Commit 4bd86971 authored by David E. DeMarle's avatar David E. DeMarle

make show raster better

With NaN's for background and values no longer bound to 0..255
(i.e. We can rely on floating point textures from OpenGL now),
let's automatically scale and bias to get something visual.
parent f2454630
......@@ -3,6 +3,7 @@ import PIL.Image
import PIL.ImImagePlugin
import numpy as np
import zlib
import as ma
if len(sys.argv) < 2:
print "supply filename of a raster file"
......@@ -47,11 +48,16 @@ if ext == ".npz":
imageslice = np.multiply(np.subtract(imageslice, mm[0]), 255)
im = PIL.Image.fromarray(imageslice)
elif ext == ".Z":
with open(fname, mode='r') as file:
with open(fname, mode='rb') as file:
compresseddata =
flatarr = np.fromstring(zlib.decompress(compresseddata),
im = PIL.Image.fromarray(flatarr.reshape((zlib_width, zlib_height)))
flatarr = np.fromstring(zlib.decompress(compresseddata),
flatarr = ma.masked_invalid(flatarr)
mxval = flatarr.max()
mnval = flatarr.min();
print "MIN AND MAX ARE ", mnval, mxval
flatarr = flatarr.filled(0)*255/(mxval-mnval)+mnval #scale and bias into 0..255 for display
im = PIL.Image.fromarray(flatarr.reshape((zlib_width, zlib_height)))
im =
asnumpy = np.array(im, np.float32)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment