Skip to content

Commit

Permalink
Added new task + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Norman committed Jun 4, 2018
1 parent 320f4cb commit baa13ab
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ Several ENVI Tasks that wrap the ENVI doits for converting between color spaces.

See [./other/examples.md](./other/examples.md) for examples running each task from IDL.

- XTExecuteStatement: This task will execute any valid IDL statement and is intended for use in the ENVI Modeler where you can't execute any IDL command that you want. You will not get results back from running any functions or procedures. The intended use was, but is not limited to, being able to run different IDL procedures that might initialize your environment prior to task processing. Note that this tool **requires** that you have ENVI + IDL started for use.

- XTExtractNameFromRaster: Simple procedure that returns the name of a raster with special characters removed so that you could write a new file to disk. The special characters that get removed are ones that are not allowed in filepaths on computers and can appear in some use cases.

- XTCreateRasterPyramid: This will create a Pyramid file for a raster.

- XTFileSearch: This task searches a folder for files for easy processing in ENVI for the ENVI Modeler. It will throw an error if no files are found.

- XTQUACWithBadBandsList: This task lets you process a file with QUAC (atmospheric correction) that first subsets the data with information on bad bands. For the examples below, you must have the same number of bad band elements as there are bands in the raster that will be processed.

- XTSaveROITrainingStatistics: This task saves statistics that were extracted from a raster over regions of interest so that the information persists between ENVI+IDL sessions.

- XTRestoreROITrainingStatistics: This task saves statistics that were extracted from a raster over regions of interest so that the information persists between ENVI+IDL sessions.
Expand Down
20 changes: 19 additions & 1 deletion other/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ Task.INPUT_RASTER = Raster
Task.Execute
```

## XTExecuteStatement

This task will execute any valid IDL statement and is intended for use in the ENVI Modeler where you can't execute any IDL command that you want. You will not get results back from running any functions or procedures. The intended use was, but is not limited to, being able to run different IDL procedures that might initialize your environment prior to task processing. Note that this tool **requires** that you have ENVI + IDL started for use.

```idl
; Start the application
e = ENVI()
; Load our extra tasks
xtTasksInit
; Get the task from the catalog of ENVITasks
Task = ENVITask('XTExecuteStatement')
Task.STATEMENT = 'print, 5'
Task.Execute
```


## XTExtractNameFromRaster

As the task name implies, this tasks extracts the name property from a raster and removes all special characters (those not allowed in filepaths). Here is a short example:
Expand Down Expand Up @@ -255,4 +273,4 @@ DataColl.Add, ClassTask.OUTPUT_RASTER
View = e.GetView()
Layer = View.CreateLayer(Raster)
Layer2 = View.CreateLayer(ClassTask.OUTPUT_RASTER)
```
```
41 changes: 41 additions & 0 deletions other/executeStatement/xtexecutestatement.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
;h+
; Copyright (c) 2018, Harris Geospatial Solutions, Inc.
;
; Licensed under MIT, see LICENSE.txt for more details
;h-

;+
; :Description:
; Routine that allows users to execute any IDL
; statement in an ENVI task and the ENVI modeler.
;
; This task does not return anything while running.
;
;
;
; :Keywords:
; STATEMENT: in, required, type=string
; Specify an IDL statement that you want to execute
; as a task.
;
; :Author: Zachary Norman - GitHub: znorman-harris
;-
pro xtExecuteStatement,$
STATEMENT = statement
compile_opt idl2, hidden

;validate the input
if (statement eq !NULL) then begin
message, 'STATEMENT not specified, required!', LEVEL = -1
endif
if ~isa(statement, /STRING) then begin
message, 'STATEMENT specified, but is not a string!', LEVEL = -1
endif

;execute the line
if ~execute(statement) then begin
help, /LAST_MESSAGE
print
message, 'Error while executing statement!', LEVEL = -1
endif
end
63 changes: 63 additions & 0 deletions other/executeStatement/xtexecutestatement.spec.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
;h+
; Copyright (c) 2018, Harris Geospatial Solutions, Inc.
;
; Licensed under MIT, see LICENSE.txt for more details
;h-

;+
; :Description:
; Tests for the xtexecutestatement procedure and task.
;
; Running these tests requires additional code that
; is not a part of this repository.
;
; :Author: Zachary Norman - GitHub: znorman-harris
;-

;get the current directory
thisdir = file_dirname(routine_filepath())

;specify the task and PRO file
taskFile = thisdir + path_sep() + 'xtexecutestatement.task'
proFile = thisdir + path_sep() + 'xtexecutestatement.pro'

;start ENVI
e = envi(/HEADLESS)

;create a luna tester
l = luna(CONFIG_FILE = './../../idl.test.json')

;create a suite
s = l.suite('Test that our task file')

; amke sure the task exist
it = s.test('exists')

(it.expects(1)).toEqual, file_test(taskFile)

; make sure we have a valid task file
it = s.test('is a valid task file')

(it.expects(taskFile)).toBeAValidENVITask

;create a suite
s = l.suite('Test that we can')

;validate procedure
it = s.test('run as a procedure')

; run procedure
(it.expects('xtExecuteStatement')).toRunProcedure, $
STATEMENT = 'print, 5'

; validate our task
it = s.test('run as a task')

task = ENVITask(taskFile)
task.STATEMENT = 'print, 5'

(it.expects(task)).toExecuteENVITask

;generate a test summary
l.GenerateTestSummary
end
18 changes: 18 additions & 0 deletions other/executeStatement/xtexecutestatement.task
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "XTExecuteStatement",
"version": "5.3",
"baseClass": "ENVITaskFromProcedure",
"routine": "xtexecutestatement",
"displayName": "XT Execute Statement",
"description": "This task will execute any valid IDL statement. You will not get results back from running the code. The intended use was, but is not limited to, being able to run different IDL procedures that might initialize your environment prior to task processing. Note that this tool **requires** that you have ENVI + IDL started for use.",
"parameters": [
{
"name": "STATEMENT",
"displayName": "Statement",
"description": "Specify the IDL statement that you want to execute.",
"direction": "input",
"parameterType": "required",
"dataType": "string"
}
]
}
2 changes: 1 addition & 1 deletion other/quacWithBadBandsList/xtquacwithbadbandslist.pro
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ pro xtQuacWithBadBandsList,$

;clean up
subset.close
end
end

0 comments on commit baa13ab

Please sign in to comment.