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 
Return to the default flat view Create a new topic Submit Reply
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 previous 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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
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 17:48:26 PDT 2025

Total time taken to generate the page: 0.00442 seconds