Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Lansat TM Calibration in ENVI batch mode

394 views
Skip to first unread message

katb

unread,
Dec 13, 2010, 2:02:58 AM12/13/10
to
Hi,

I am having problems using 'TMCAL_DOIT' in an ENVI batch script to
automate the calibration of reflectance data for many days of Landsat
TM data in GeoTIFF format. I wish to perform the calibration for
bands 1,2,3,4,5,7 for each of the days (many many days!).

In the ENVI GUI it's easy:

BasicTools>Preprocessing>CalibrationUtilities>LandsatCalibration ...
open the *_MTL.txt file

However, in batch script mode the TMCAL_DOIT function requires the sun
angle to be manually input as an argument. This information is
provided in deep within the metadata file for each scene and will be
different for each of my data days. Is there a way to do this without
manually reading the sun angle manually from the metadata file and
typing it in?? I'm sure i'm missing something here. I am using ENVI
4.7 and IDL 7.1.1.

The main components of the script I have currently is below:

; set filename
lan_dat = "L71091085_08520000803_MTL.txt"

; Open Landsat data
ENVI_OPEN_FILE, lan_dat, r_fid=fid

; Get file attributes
ENVI_FILE_QUERY, fid, ns=ns, nl=nl, nb=nb

dims = [-1, 0, ns-1, 0, nl-1]
pos = lindgen(nb)
bands_present = [1,2,3,4,5,7]
out_name = 'testimg'

; Perform the TM Calibration
ENVI_DOIT, 'TMCAL_DOIT', $
fid=fid, pos=pos, dims=dims, $
bands_present=bands_present, $
sat=4, cal_type=1, date=0, $
sun_angle=38.0, out_name=out_name, $
r_fid=r_fid

Thanks in advance for any help or suggestions.

Kat Bormann

jeanh

unread,
Dec 13, 2010, 10:00:19 AM12/13/10
to
On 13/12/2010 2:02 AM, katb wrote:
> Hi,

> However, in batch script mode the TMCAL_DOIT function requires the sun
> angle to be manually input as an argument.

well, a variable can do just fine...

This information is
> provided in deep within the metadata file for each scene and will be
> different for each of my data days. Is there a way to do this without
> manually reading the sun angle manually from the metadata file and
> typing it in?? I'm sure i'm missing something here. I am using ENVI
> 4.7 and IDL 7.1.1.

:-) computers are better suited for repetitive tasks..


> ; set filename
> lan_dat = "L71091085_08520000803_MTL.txt"
>
> ; Open Landsat data
> ENVI_OPEN_FILE, lan_dat, r_fid=fid

Does it work? I tried it and it fails... the file must be the data, not
the MTL header (i.e. you may have to process band by band)


> Thanks in advance for any help or suggestions.
> Kat Bormann

You could try the function ENVI_GET_HEADER_VALUE(rFID, "SUN_ELEVATION")
... though as I have opened the data file, this header is not linked to
the data and it therefore does not work. It probably could.

Now, extracting the sun angle is fairly simple.

function get_sun_angle(MTLfileName)
;Open the header file
openR, lun, MTLfileName, /get_lun

;prepare a string array, one line = one array element
data=strarr(file_lines(MTLfileName))

;read the file
readf, lun, data

;Find the line with the sun angle info
line = where(strpos(data, "SUN_ELEVATION") ne -1)

;Get the sun angle, as double (be sure everything is on 1 line only)
sunAngle = double(strmid(data[line], strpos(data[line], "=")+1,
strlen(data[line])-strpos(data[line], "=")+1))[0]

;return the value
return, sunAngle

end


Then you can do

; Perform the TM Calibration
ENVI_DOIT, 'TMCAL_DOIT', $
fid=fid, pos=pos, dims=dims, $
bands_present=bands_present, $
sat=4, cal_type=1, date=0, $

sun_angle=get_sun_angle(MTLfileName), out_name=out_name, $
r_fid=r_fid

Hope this help!
Jean

PS: you will have much more answers if you post on the newsgroup
comp.land.idl-pvwave

0 new messages