Coverage for runmacs/spec/io/envifile.py : 68%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- # Filename: envifile.py
######################################################################### # # envifile.py - This file is part of the Munich Aerosol Cloud Scanner package. # # Copyright (C) 2013 Tobias Kölling # # runMACS is free software; you can redistribute it and/ # or modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # Spectral Python is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; if not, write to # # Free Software Foundation, Inc. # 59 Temple Place, Suite 330 # Boston, MA 02111-1307 # USA # ######################################################################### # # Send comments to: # Tobias Kölling, tobias.koelling@physik.uni-muenchen.de #
envifile ========
This modules loads general envifiles via mmap, to get good random access performance. """
""" Represents an bil, bip or bsq envi-file as numpy array.
Load a file, by passing the filename (without .hdr or .raw) to the constructor. After loading, the object behaves like a standary numpy array::
data = EnviFile('basefilename')
The dimensions are ordered as follows::
data[lines, samples, bands]
""" except KeyError: bands = 1 # to comply with spectral python, transpose to bip shape elif interleave == 'bip': shape = (lines, samples, bands) transpose = None elif interleave == 'bsq': shape = (bands, lines, samples) transpose = (1,2,0) else: raise ValueError('undefined interleave scheme "%s"'%interleave) except KeyError: headerskip = 0 else: fn = filename #obj.envi_fps = float(envi_header['fps']) else: obj = np.memmap.__new__(cls) # we are either view casting or creating from template, so copy additional infos # todo: check if it is wise to change dimensional information #self.envi_fps = getattr(obj, 'envi_fps', None)
""" compute average of cumulative EnviFile """ return stats[0,...]/stats.envi_cumulative
""" compute standard deviation of cumulative EnviFile """ return ((stats[1,...]/stats.envi_cumulative) - E(stats)**2)**.5
""" This class allows to read an ENVI file as raw bytes with some meta information, the idea is to provide a sequential an serializable interface to support parallel workers which look at the whole file. """ except KeyError: self.bands = 1 #self.fps = float(envi_header['fps']) else: self.datafile = open(filename) elif self.interleave == 'bip': self.lineshape = (self.samples, self.bands) raise ValueError('cannot read continous line from "%s" interleaving'%(self.interleave,)) raise IndexError('lineno %d is out of range (0 ... %d)'%(lineno, self.lines-1)) self.datafile.seek(lineno * self.linesize) self.datafile.close() |