Closed donm closed 9 years ago
Looks like a great fix. One question... You define two local functions:
parent_getitem
(inside ImageArray.__getitem__
)fix_negative_indices
(inside SpyFile.__getitem__
)It appears that since these functions act as closures, they will be recompiled each time the corresponding __getitem__
method is called. Would it be more efficient instead to add them as pseudo-private methods to the corresponding classes? That is,
ImageArray._parent_getitem
SpyFile._fix_negative_indices
Yeah, absolutely. Those functions will potentially be called repeatedly, so I'm glad you caught that. Also, the parent_getitem
function could be simplified quite a bit due to other changes after it was written.
I added the changes doing a rebase, so if you refresh hopefully github will show you the new commits.
This fixes #32, and also fixes some SpyFile behavior and adds additional enhancements to ImageArray.
In particular, one change to ImageArray in this patch is that methods and numpy ufuncs always return a numpy ndarray instead of another ImageArray. This is because many times (always?) these results lost their association with the original image that gave the quality of being ImageArrays. For example, things like
image_array.diagonal()
,image_array.mean(axis=2)
, orimage_array[0, 0, :]
would previously return other ImageArrays. This doesn't make semantic sense, plus some attributes were wrong or were not set (nrows
,bands
, etc.). Returning an ndarray gets around these issues, and also makes the return type consistent with indexing andread_*
methods in SpyFile.