X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



1259 Rate this article:
No rating

Code example to execute ENVItask in Python using Jupyter Notebook

 

Below is an example of the steps to be followed to call an ENVITask from Python Jupyter Notebook on Windows

Pre-requisite: ENVI+IDL needs to be installed and licensed on your machine

 

  • Configure the IDL-Python Bridge

https://www.l3harrisgeospatial.com/docs/python.html

 

  • Install and configure Jupyter Notebook

https://www.l3harrisgeospatial.com/docs/idl_kernel.html

 

  • Download envipy from the L3Harris Download & License Center and install it

https://harrisgeospatial.flexnetoperations.com

Installation instructions are available in the portal.

In case you instead installed envipyengine via pip, see note 2 at the end of the article

 

  • Start Jupyter Notebook and create a new IDL notebook: New > IDL Notebook

 

  • Test Jupyter Notebook and confirm it is working fine by calling an IDL and a Python command

For example run the commands below:

In [0]     print,'Hi, I am in IDL'
In [1]     >>>

print('Hi, I am in Python now')

 

Please find below a few hints about the usage of Jupyter Notebook and the IDL-Python bridge

https://www.l3harrisgeospatial.com/Support/Self-Help-Tools/Help-Articles/Help-Articles-Detail/ArtMID/10220/ArticleID/23903/A-few-hints-while-using-Jupyter-Notebook-and-IDL-Python-Bridge

 

 

  • Run the code below illustrating how to call the ExportRasterToTIFF Task
In [2]       >>>
print('import envi engine into python')
from envipyengine import Engine
print('load envi engine')
envi_engine = Engine('ENVI')
print('load the ENVI task to run')
task = envi_engine.task('ExportRasterToTIFF')
print('set task parameters using Python dictionnary')
input_raster = dict(url='C:\\Program Files\\Harris\\ENVI56\\data\\qb_boulder_msi',factory='URLRaster')
parameters = dict(INPUT_RASTER=input_raster,OUTPUT_RASTER_URI='C:\\TEMP\\qb_boulder_msi_output_tiff')
print('parameters')
print(parameters)
print('execute the task')
task.execute(parameters)
print('Task completed')

 

Notes:

- You must double the “\” in Windows OS paths to so they will be interpreted properly by Python.

- Input raster should be defined as a list or hash

- Input parameters have to be passed through a Python dictionary

 

Output

import envi engine into python
load envi engine
load the ENVI task to run
set task parameters using Python dictionnary
parameters
{'INPUT_RASTER': {'url': 'C:\\Program Files\\Harris\\ENVI56\\data\\qb_boulder_msi', 'factory': 'URLRaster'}, 'OUTPUT_RASTER_URI': 'C:\\TEMP\\qb_boulder_msi_output_tiff'}
execute the task
Task completed

And a qb_boulder_msi_output_tiff is created in C:\Temp.

 

Note 1: : ENVI does not allow you to overwrite an existing file. Thus, the file called C:\TEMP\qb_boulder_msi_output_tiff needs to be deleted prior to run the code a second time. Another option is to create a random string and to add it to the filename in Python using for example the commands below:

[...]

import random

digits = '123456789'

parameters = dict(INPUT_RASTER=input_raster,OUTPUT_RASTER_URI='C:\\TEMP\\qb_boulder_msi_output_tiff'+''.join(random.choice(digits) for i in range(8)))

[...]

 

Note 2: In case you installed envipyengine via pip, an additional configuration step needs to be added after importing envipyengine:

>>> 

print('import envi engine into python')

from envipyengine import Engine

print('envi engine configuration')

envipyengine.config.set('engine', 'C:\\Program Files\\Harris\\ENVI56\\IDL88\\bin\\bin.x86_64\\taskengine.exe')

[...]

You can check if envipyengine configuration is set-up correctly by looking at the below files:

C:\ProgramData\envipyengine\settings.cfg for all users of the system

C:\Users\<user>\AppData\Local\envipyengine\settings.cfg for a given user of the system

It should include the following lines

[envipyengine]

engine = C:\Program Files\Harris\ENVI56\IDL88\bin\bin.x86_64\taskengine.exe

[engine-environment]

 

Note 3: A log can be set-up to troubleshoot issues by adding the following lines:

[envipyengine]

engine = C:\Program Files\Harris\ENVI56\IDL88\bin\bin.x86_64\taskengine.exe

engine-args = --log=C:\_BERANGERE\temp\diagnostic.log

[engine-environment]

in the below files:

C:\ProgramData\envipyengine\settings.cfg for all users of the system

C:\Users\<user>\AppData\Local\envipyengine\settings.cfg for a given user of the system

 

 

 

 

----------------------

created by BC on 1/26/2021

Reviewed by BC (US) on 2/4/2022 & 8/15/22

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »