Spatial Modeler Discussions

Gain, exchange, and share knowledge, or discuss topics with other Hexagon Geospatial Product pioneers and experts to get the most out of Hexagon Geospatial products.
Showing results for 
Search instead for 
Do you mean 
Reply
Occasional Contributor
Posts: 8
Registered: ‎06-10-2019

Using Numpy memmap through python operator

Helllo,

 

I am currently trying to use numpy Memmap in a python file to process some data.

The python file works fine when I  run it through my IDLE interface.

However, when I try to read the same file through a python operator in a spatial model,

the processing seems to stop at the point when I try to use memmap.

I was wondering if there are any limitations in using numpy memmap through Spatial modeler

or ERDAS IMAGINE.

 

Any information is appreciated!

 

 

Emi

Staff
Posts: 14
Registered: ‎04-26-2018

Re: Using Numpy memmap through python operator

Is this possibly a Python version problem? If there is more than one Python version on your machine spatial models may be using a different version of the interpreter to run your script. It seems like a good first step to confirm the version of Python being used. The attached file (show_version.zip) contains a Python script called show_version.py which implents a Python function called showVersion(), to will display a dialog with the version of the Python interpreter.

 

Follow these steps:

 

  1. Unzip the attachment.
  2. Create an empty model.
  3. Drag in a Python Script operator.
  4. Double Click or Configure the operator and select the "show_version.py" file and click OK.
  5. Run the model.

This will display a dialog with the Python version string displayed.

 

Is this the same version that is shown from within your Python IDLE Interface? If they are different then I would ask if the Spatial Modeler python version is compatible with the version of memmap?

 

 

 

 

Occasional Contributor
Posts: 8
Registered: ‎06-10-2019

Re: Using Numpy memmap through python operator

Hi Brad,

 


Thank you for the python to check my version.

The Python versions seem to match although my IDLE interfaces showed some "on win32" comment in the end.
(Would this affect version differences in any way?)


IDLE Interface "Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)] on win32"

Python Operator output "Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)]"

If my versions are OK, what could be the next point I should consider?

 

Thank you

Emi

 

Staff
Posts: 14
Registered: ‎04-26-2018

Re: Using Numpy memmap through python operator

Can you please provide the details on the version of numpy that you are using? I don't seem to be able to locate a version that is compatible with Python 3.4.4. 

Staff
Posts: 14
Registered: ‎04-26-2018

Re: Using Numpy memmap through python operator

After finally getting numpy installed and working, I think I may have your answer.

 

A memmap is created using memmap(filename, ....). I followed an existing example that used a simple name like 'memmap.dat' as the filename and that did indeed work in my IDE (VisualStudio Code) but failed in Spatial Modeler. I then change the filename to a full path like 'C:\\data\\memmap\\memmap.dat' and the code worked in both environments and produced correct results. 

 

My theory is that when a simple filename with no path component is used the actual location is determined by the environment in which the script was run and in the case of the Spatial Modeler the environment is resulting in a default location which is write protected. 

 

By supplying a complete path a location with proper access right can be selected and the memmap() function call will succeed.

 

Hopefully this will get you past this snag.