0

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.

Manuel Popp
  • 1,003
  • 1
  • 10
  • 33
  • I'm a bit confused by the question because it looks like you successfully used `open_memmap`, then you state you received an error. Can you include the command you executed along with the error message? – bogatron Jan 03 '23 at 21:19
  • @bogatron The error occurred when using ```open_memmap```. I edited the post and hope it is more clear now – Manuel Popp Jan 03 '23 at 21:35
  • What is `img.shape`? – bogatron Jan 03 '23 at 21:42
  • @bogatron ```img.shape``` gives ```(3805, 3940, 493)``` (the product of these is, by the way, larger than ```sys.maxint``` which results in an ```OverflowError``` when trying to use ```envi.create_image()``` from ```spectral``` for an image of these dimensions. Maybe the error is related to image size?) – Manuel Popp Jan 03 '23 at 21:46
  • 1
    You heard that python2 was [sunsetted](https://www.python.org/doc/sunset-python-2) three years ago, right? On 2020-01-01? – J_H Jan 03 '23 at 21:48
  • @J_H I am aware of that. However, I am supposed to work with some ArcMap installation which comes with a Python installation that cannot be upgraded independently from ArcMap. – Manuel Popp Jan 03 '23 at 21:54

0 Answers0