comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » save multiple bands in one file in IDL ENVI
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
save multiple bands in one file in IDL ENVI [message #93094] Tue, 26 April 2016 10:03 Go to next message
Karalis Sotiris is currently offline  Karalis Sotiris
Messages: 4
Registered: April 2016
Junior Member
Dear listers
I am a novice in IDL so my question might be trivial. I have a multiple band file, and what i want to do is perform calculations with each band separately (for example, b1*10 or b2/2, not b1+b2) and then save the processed bands in one new (multiple band) file. I've been trying to use the ENVI DOIT routines. According to the manuals either ENVI LAYER STACKING DOIT or CF DOIT can accomplish what i want, but the examples don't really help me understand and adopt to my situation. Anybody has a clue? Thank you very much.
Re: save multiple bands in one file in IDL ENVI [message #93099 is a reply to message #93094] Wed, 27 April 2016 20:27 Go to previous messageGo to next message
zacharyanorman is currently offline  zacharyanorman
Messages: 17
Registered: July 2015
Junior Member
I would actually use the new ENVI API which is a lot more straight forward (to me at least). You can do something like the following. You can copy/paste this into IDL and it should run if you are on the latest version and if you installed in the default installation location. Just note that if you are working with larger files then the amount of RAM on your machine might be a limiting factor. In that case, you will need to use tile iterators in ENVI.

Another thing to note is that the interleave of your raster is very important. Interleave is basically the raster dimensions which represent rows, columns, and bands. For the example below, we are band sequential (BSQ) which is [ncolumns, nrows, nbands]. I usually stick with BSQ because it is easy to work with and can be faster to use locally with custom tile iterators (5-6 times faster). I can share some code to convert file interleave if that is something you are interested in.

Hope this helps!


;start ENVI
e = envi(/current)
;the above line returns !NULL if ENVI hasn't started
;so, in that case, we start ENVI
if (e eq !NULL) then e = envi(/headless)

; Open the first input file
file = Filepath('qb_boulder_msi', ROOT_DIR=e.Root_Dir, $
SUBDIRECTORY=['data'])
msiRaster = e.OpenRaster(file)

;get the data
dat = msiRaster.GetData()

;check what the data type of dat is
;shoud see it is uint
help, dat

;pre-allocate an array with the same type as dat
;you can find what type the data is by looking up the typecode
;be careful here because IDL does automatic type promotion (i.e integers
; are promoted to floats) which doubles output file size
newDat = make_array(msiRaster.NCOLUMNS, msiRaster.NROWS, 2, TYPE=dat.typecode)

;do some band math
;fill first band of output
newDat[*,*,0] = dat[*,*,3] - dat[*,*,2]
;fill second band of output
newDat[*,*,0] = dat[*,*,2] + dat[*,*,0]

;create a new ENVIRaster
;first, specify the file output location
newRaster_uri = e.GetTemporaryFilename()
print, 'Output raster URI : "' + newRaster_uri + '"'
newraster = ENVIRaster(newDat, URI = newRaster_uri , SPATIALREF = msiRaster .SPATIALREF)

;save the output raster
newRaster.save

;make sure we close both rasters so IDL doesn't have locks on the files
newRaster.close
msiRaster.close
Re: save multiple bands in one file in IDL ENVI [message #93104 is a reply to message #93099] Thu, 28 April 2016 03:07 Go to previous messageGo to next message
Karalis Sotiris is currently offline  Karalis Sotiris
Messages: 4
Registered: April 2016
Junior Member
Thank you Zachary. It worked just fine. I have a couple of questions more if you can help me:

1. How do i save in .tiff format (it saves in .dat)
2. How do i invoke tile operations, and lastly
3. What if i want to do this for tons of files

You see, when you begin with a new language without a tutor you don't know where to turn. So, i began with classic IDL introductions, then i read that if you want 'to include ENVI functionality' you can turn to ENVI DOIT routines (probably for those working in Remote Sensing), and then you have this 'object oriented' version of IDL-ENVI, which looks very straight forward, like you say. What to choose? By the way, can you suggest any 'getting started' tutorial, or some other reference (book or other) on this new ENVI API?

Thank you again for your help! Much appreciated.
Re: save multiple bands in one file in IDL ENVI [message #93106 is a reply to message #93094] Thu, 28 April 2016 06:45 Go to previous messageGo to next message
Karalis Sotiris is currently offline  Karalis Sotiris
Messages: 4
Registered: April 2016
Junior Member
Zachary, not to waste your time i think i found the answers to all of my last questions in http://www.harrisgeospatial.com/docs/programmingguideintrodu ction.html
this introduction seems very good with plenty of examples.
Thanks for putting me in track!
Re: save multiple bands in one file in IDL ENVI [message #93116 is a reply to message #93106] Thu, 28 April 2016 21:33 Go to previous messageGo to next message
zacharyanorman is currently offline  zacharyanorman
Messages: 17
Registered: July 2015
Junior Member
Glad you found it! It can be tricky learning a new programming language, but there are plenty of examples in the documentation center for the ENVI API. The most helpful thing to find out how to use different ENVI objects in idl is to use the "help" procedure in IDL on them and search for the object name. For example:

IDL> e = envi(/headless)
ENVI> ;specify parameters at the top of procedures
ENVI> file = Filepath('qb_boulder_msi', ROOT_DIR=e.Root_Dir, $
ENVI> SUBDIRECTORY=['data'])
ENVI>
ENVI> raster = e.openraster(file)
ENVI> help, raster
RASTER ENVIRASTER <41479>


If you then search online for "ENVIRASTER" you should get all of the methods and lots of examples for how to use them on harrisgeospatial.com.

Also, here is a help article that I wrote (I actually work at Harris - used to be Exelis VIS) with an example using a tile iterator in the new API for doing band math.

http://www.harrisgeospatial.com/Support/HelpArticlesDetail/T abId/219/ArtMID/900/ArticleID/14531/An-example-of-performing -band-math-with-the-new-ENVI-API.aspx

Let me know if you have any other questions!
Re: save multiple bands in one file in IDL ENVI [message #93126 is a reply to message #93094] Fri, 29 April 2016 12:12 Go to previous messageGo to next message
Karalis Sotiris is currently offline  Karalis Sotiris
Messages: 4
Registered: April 2016
Junior Member
Do you have any hint, suggestion or code for cloud masks in MODIS09 images?
Re: save multiple bands in one file in IDL ENVI [message #93145 is a reply to message #93126] Mon, 02 May 2016 13:56 Go to previous messageGo to next message
zacharyanorman is currently offline  zacharyanorman
Messages: 17
Registered: July 2015
Junior Member
There is a new mask for removing clouds from Landsat imagery, but you might be able to look at the references cited on the following link and develop a band math expression to detect clouds. Here is the link:

https://www.harrisgeospatial.com/docs/envicalculatecloudmask usingfmask.html
Re: save multiple bands in one file in IDL ENVI [message #94217 is a reply to message #93145] Mon, 27 February 2017 23:46 Go to previous message
carlphilip.ortiz is currently offline  carlphilip.ortiz
Messages: 1
Registered: February 2017
Junior Member
Hi! I have difficulties saving each band to ASCII in ENVI. Is there a way i can use to save each band at the same time automatically? I'll send you a screenshot about my problem through mail if you can help me. Thank you! It really takes so much time saving each band one by one. Thank you again!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: print data in colunms
Next Topic: IDL Stat analysis- ANOVA licening

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:56:41 PDT 2025

Total time taken to generate the page: 0.00489 seconds