09-18-2018 10:28 PM
I am trying to run a Python script from my spatial model in Erdas Imagine 2018 (16.5.0 build 852) but I keep getting the error:
"Error parsing Python script:
See session log for details."
I have both Python 3.4 32 and 64 bit installed.
It seems the particular file in the error doesn't exist, but there are some older temp files with a different set of numbers.
I can't actually find the in the session log either. Where does this live?
I can run Python from cmd line so could this be some sort of permissions issue and it can't write to the temp folder?
09-25-2018 09:28 AM
Try changing the ERDAS IMAGINE temporary file directory to something other than your system’s default $TEMP folder, which is currently set to “C:/Users/geogjo/AppData/Local/Temp”. First, go to C:/Users/geogjo/AppData/Local/Temp and delete all of the unnecessary files and folders from this directory. Create a new folder that will be used for the IMAGINE temporary file directory. If you have another local disk available it is advisable that you create the new temp folder there. For example, “D:\imagine_temp”. It is a good idea to keep your IMAGINE temporary file directory on a different local disk from where your input data is stored and where the output is being written to. Make sure that you have full read/write permissions for the IMAGINE temporary file directory. Open the IMAGINE Preference Editor and select the User Interface && Session category, then scroll about half way down to find the Temporary File Directory preference. Enter the location of your new temp folder and click Save, then close the Preference Editor and try running your spatial model again.
Hexagon Geospatial Support
02-20-2019 10:11 AM
I am also facing issue to run any python code in ERDAS Imagine Spatial Modeler.
I want to use an image to create NDVI using ERDAS Imagine Spatial Modeler funtion Python script.
provide "Error Parsing Python Script"
My code is working fine even in Python3.4 amd 64bit with all required libraries installed already.
To PY code for an image NDVI-
from osgeo import gdal
import numpy as np
from numpy import *
g = gdal.Open("fhmod1.tif")
red = g.ReadAsArray()
g = gdal.Open("fhmod2.tif")
nir = g.ReadAsArray()
red = array(red, dtype = float)
nir = array(nir, dtype = float)
check = np.logical_and ( red > 1, nir > 1 )
ndvi = np.where ( check, (nir - red ) / ( nir + red )*100, 0 )
geo = g.GetGeoTransform()
proj = g.GetProjection()
shape = red.shape
driver = gdal.GetDriverByName("GTiff")
dst_ds = driver.Create( "ndvi.tif", shape, shape, 1, gdal.GDT_Float32)
dst_ds.SetGeoTransform( geo )
dst_ds.SetProjection( proj )
dst_ds = None #END
Is it possible to run py code in spatial modeler to get raster output.
Thanks and Regards,
02-27-2019 01:04 PM
The ERDAS IMAGINE online help gives quite extensive documentation regarding the use of Spatial Modeler and Python. It describes how to access Spatial Modeler capabilites from within Python and conversly, how to access Python from the Spatial Modeler. The section includes numerous small examples to help get started. I would ask first if this section has been read and have the examples in the section been tried?
To find the help navigate to: Spatial Modeling > Spatial Model Editor > Spatial Model Operators Guide > Python Operators > Python Scripting in Spatial Modeler.
From the discussion it seems like the desired result here is to have the Spatial Model run a Python Script. This is specifically done using the Python operator in the spatial modeler. There is a section in the help called "Using a Python Script as an Operator". This section describes how to to configure the operator to use a specific Python Script.
In the given example of using Python to create an NVDI, I would however, have to ask, what is the purpose here? This is a very straight forward model in the Spatial Modeler. The Python version looks like it is limited to reading the entire file into memory and operating on it that way. The Spatial Modeler will work on the data in an incremental fashion, thus avoiding memory limit problems.
In general, the connection with Python is meant to bring the best of both environments together.