3 # Copyright (C) 2006-2007 Antonio Ingargiola <tritemio@gmail.com>
5 # This file is part of Image Analyzer.
7 # Image Analyzer is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
13 from numpy
import array
, ones
, zeros
, sqrt
, ceil
, floor
14 from common
.img
import image2array
16 def arrayFromTiff(filename
):
18 Returns and array loading the data from the TIFF file 'filename'.
20 return image2array(Image
.open(filename
))
22 def arrayfromfile(file, xmin
=None, xmax
=None, debug
=False):
24 Load (and returns) an array fron an ASCII text file. 'file' is the opened
27 Optional 'xmin' and 'xmax' permit to load only a slice of colums (for
28 example excluding the fistr and the last).
31 if xmin
== None: start
= 0
34 if xmax
== None: end
= -1
40 if line
.strip() == '': continue
42 if end
== -1: row_data
= [float(s
) for s
in data
[start
:]]
43 else: row_data
= [float(s
) for s
in data
[start
:end
+1]]
44 if debug
: print i
, 'len:', len(row_data
)
45 list_of_rows
.append(row_data
)
48 m
= array(list_of_rows
)
51 def arrayFromZemax(zemaxfile
, xmin
=None, xmax
=None):
53 Returns an arry loading the data from a Zemax simulation file. Zemax
54 simulation file are ASCII file with a particular header and syntax. See the
55 code for more information.
59 for i
in xrange(n
): zemaxfile
.next()
61 for line
in zemaxfile
:
62 if line
.startswith('Detector Viewer listing'):
63 #skip_n_lines(19) ## 2003 Version
64 skip_n_lines(23) ## 2005 Version
65 ## TODO: Automatic file version handling
66 zm
= arrayfromfile(zemaxfile
)[:,1:]
67 elif line
.startswith('Illumination Surface Listing'):
69 zm
= arrayfromfile(zemaxfile
, xmin
=xmin
, xmax
=xmax
, debug
=True)
71 print 'arrayFromZemax(): Invalid file format.'