I have some .bsq
files with corresponding header files (.hdr
). I want to open and edit them in Python, using the spectral
(SPy) module.
Since I need to edit the files from within a Python Toolbox in ArcMap (that is, a single Python script which uses the Python installation that comes with ArcMap), I decided to copy the GitHub repository of the SPy module and import it as
import sys
sys.path.append("/path/to/module")
import spatial as spy
in order to be able to run the toolbox on any computer without having to install pip or other software. (I intend to just copy the Toolbox and the module folder, or, in a later step, create a single Python script comprising the Toolbox as well as the SPy-module code.)
I opened some .bsq
-file and tried to subsequently edit it as memmap
, following this example.
First, I opened the image as spectral.io.bsqfile.BsqFile
:
path = "/path/to/image_header.hdr"
img = spy.open_image(path)
I am able to apply various methods to img
(such as: view metadata, read bands as array, etc), hence, I assume there were no issues with the path or the image file. I can also read single bands with memmap = True
:
mem_band = img.read_band(0, use_memmap = True)
Reading a single band results in an array of shape (lines, samples)
with dtype: float64
and where lines and sample correspond to the respective values in the .hdr
file.
However, trying to apply the .open_memmap()
method to the BsqFile
instance as follows:
mem = img.open_memmap(writable = True)
results in the following error:
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File
"/path/to/module/spectral/io/spyfile.py", line 809, in open_memmap dst_inter))
File "/path/to/lib/site-packages/numpy/core/fromnumeric.py", line 536, in transpose
return _wrapit(a, 'transpose', axes)
File "/path/to/lib/site-packages/numpy/core/fromnumeric.py", line 45, in _wrapit
result = getattr(asattr(obj), method)(*args, **kwds)
ValueError: axes don't match array
Is this due to some incompatibilities between the numpy
version that comes with the ArcMap-Python-Installation which I am required to use (numpy version 1.9.2)? Or are there other issues with the code or set-up?
- Python version: 2.7.10
- numpy version: 1.9.2
- spectral version: 0.23.1
Edit
With the given Python version, spectral.envi.create_image()
cannot create images of the given size due to an OverflowError
. Potentially, this older Python version does not handle large numbers "correctly"?
Using another Python installation, the .open_memmap()
method worked without issues.