[Image-SIG] How do i import text file which has NaNs ?

Christopher Barker Chris.Barker at noaa.gov
Wed Dec 5 18:37:55 CET 2007

> The ASCII file has NaNs or NoData in them.

> I am not able to read the file into python since it is not able to 
> recognize NaN.

> */[jv] I’m not sure this is applicable, but have you looked at the numpy 
> extension package which has support for NaN?/*

numpy does support NaN, and it's an excellent choice for this kind of 
data anyway. It's also easy to turn a numpy array into a PIL image.

However, I'm not sure it supports NaN text literals, and, if it does, 
it's probably not platform independent, as it uses the system library 

I would check out numpy, but you may have to write the file scanning 
code yourself, and translate the NaN.

An example might help us get other ideas. For instance, what is the 
ascii representation of NaN? "NaN", or something else?

What system are you running on? For instance, on OS-X (Python 2.5, 
compiled with gcc4.0.1), this works:

 >>> float("NaN")

But I don't think that works on the stock Windows Python. However, there 
may be another literal that does. Try:

 >>> import numpy as N
 >>> str(N.nan)

and it might tell you the literal on your system.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the Image-SIG mailing list