|
|
|
|
User Forums
Stay Connected
Your ENVI and IDL user communities provide a wealth of information. From industry specific threads to code suggestions and application examples, these forums will inspire ideas, answer questions, and keep you connected with the community.
If you need an immediate answer to your question, please contact Technical Support.
Note: You must login to participate in a forum.
 | |  |
 | |  |
 | |  |
 | |  |
 | |  |
 |
|
|
|
It's hard to understand exactly what is happening from your description, but it looks to me like your code ran successfully. You show the program returning to an IDL prompt, and no error message, which is the behavior I would expect if everything ran successfully. Have you checked to see whether the output image you specified in your code was created, and if so, whether it looks good?
- Peg |
|
|
|
 |  |
|
|
|
For Landsat 7 (Landsat 5 too), code will look something like this:
Code example
PRO LANDSAT_CALIBRATION_BATCHMODE
COMPILE_OPT IDL2
ENVI_BATCH_INIT
InputPath = 'c:\LANDSAT\'
ListFiles = FILE_SEARCH(InputPath, COUNT = ProductCount, '*MTL.txt', /FOLD_CASE, /TEST_READ, /FULLY_QUALIFY_PATH)
IF(ProductCount LE 0) THEN BEGIN
Print, 'There are no valid landsat metadata to be processed.'
RETURN
ENVI_BATCH_EXIT
ENDIF
FOR i=0, ProductCount-1 DO BEGIN
InputFile = ListFiles[i]
Filename = FILE_BASENAME(InputFile, '_MTL.txt', /FOLD_CASE)
Envi_open_data_file, InputFile, /landsat_metadata
fids = envi_get_file_ids()
IF (fids[0] EQ -1) THEN BEGIN
Print, 'There are no valid landsat metadata to be processed.'
RETURN
ENVI_BATCH_EXIT
ENDIF
FOR j = 0, n_elements(fids)-1 DO BEGIN
envi_file_query, fids[j], fname = fname, nb=nb
IF (nb EQ 6) OR (nb EQ 4) THEN BEGIN
image_fid=fids[j]
envi_file_query, image_fid, fname = fname_image, dims=dims_image, nb=nb_image
print, fname_image , ' nb: ', nb_image, ' fid: ', image_fid
ENDIF
ENDFOR
pos=lindgen(nb_image)
; Metadata parser
n = FILE_LINES(InputFile)
metadata = STRARR(1,n)
OPENR, unit, InputFile, /GET_LUN
READF, unit, metadata
FREE_LUN, unit
; Find position of sun_angle in metadata and read value
ind=WHERE(STRPOS(metadata,'SUN_ELEVATION') ge 0)
IF (ind NE [-1]) THEN BEGIN
searching_line = metadata[ind]
searching_line_data=strsplit(strcompress(searching_line, /remove_all),'=', /extract)
sun_elevation=float(searching_line_data[1])
sun_angel=90.0-sun_elevation
ENDIF
; Find position of date in metadata and read value
ind=WHERE(STRPOS(metadata,'ACQUISITION_DATE') ge 0)
IF (ind NE [-1]) THEN BEGIN
searching_line = metadata[ind]
searching_line_data=strsplit(strcompress(searching_line, /remove_all),'=', /extract)
date_line=searching_line_data[1]
date_array=fix(strsplit(strcompress(date_line, /remove_all),'-', /extract))
date=intarr(3)
date[0]=date_array[1]
date[1]=date_array[2]
date[2]=date_array[0]
print, date
ENDIF
; Determine Satellite
IF ((STRPOS(Filename,'L7')) NE -1) THEN BEGIN
sat=0
bands_present=[0,1,2,3,4,7]
ENDIF
IF ((STRPOS(Filename,'L5')) NE -1) THEN BEGIN
sat=1
bands_present=[0,1,2,3,4,6]
ENDIF
PRINT, 'sun elevation=', sun_elevation
PRINT, 'sat_ind=', sat
gain=fltarr(nb_image)
bias=fltarr(nb_image)
min_max_rad=WHERE(STRPOS(metadata,'MIN_MAX_RADIANCE') ge 0)
lmax_min=fltarr(min_max_rad[1]-min_max_rad[0]-1)
searching_line = metadata[min_max_rad[1]+ 2]
searching_line_data=strsplit(strcompress(searching_line, /remove_all),'=', /extract)
qcalmax=fix(searching_line_data[1])
searching_line = metadata[min_max_rad[1]+ 3]
searching_line_data=strsplit(strcompress(searching_line, /remove_all),'=', /extract)
qcalmin=fix(searching_line_data[1])
FOR b=0, n_elements(lmax_min)-1 DO BEGIN
searching_line = metadata[min_max_rad[0]+b+1]
searching_line_data=strsplit(strcompress(searching_line, /remove_all),'=', /extract)
lmax_min[b]=float(searching_line_data[1])
ENDFOR
IF (sat EQ 0) OR (sat EQ 1) THEN BEGIN
lmax_min=reform(lmax_min, 2, n_elements(lmax_min)/2, /overwrite)
gain[0]=(lmax_min[0,0]-lmax_min[1,0])/(qcalmax-qcalmin)
bias[0]=lmax_min[1,0]-((lmax_min[0,0]-lmax_min[1,0])/(qcalmax-qcalmin))*qcalmin
gain[1]=(lmax_min[0,1]-lmax_min[1,1])/(qcalmax-qcalmin)
bias[1]=lmax_min[1,1]-((lmax_min[0,1]-lmax_min[1,1])/(qcalmax-qcalmin))*qcalmin
gain[2]=(lmax_min[0,2]-lmax_min[1,2])/(qcalmax-qcalmin)
bias[2]=lmax_min[1,2]-((lmax_min[0,2]-lmax_min[1,2])/(qcalmax-qcalmin))*qcalmin
gain[3]=(lmax_min[0,3]-lmax_min[1,3])/(qcalmax-qcalmin)
bias[3]=lmax_min[1,3]-((lmax_min[0,3]-lmax_min[1,3])/(qcalmax-qcalmin))*qcalmin
gain[4]=(lmax_min[0,4]-lmax_min[1,4])/(qcalmax-qcalmin)
bias[4]=lmax_min[1,4]-((lmax_min[0,4]-lmax_min[1,4])/(qcalmax-qcalmin))*qcalmin
gain[5]=(lmax_min[0,6]-lmax_min[1,6])/(qcalmax-qcalmin)
bias[5]=lmax_min[1,6]-((lmax_min[0,6]-lmax_min[1,6])/(qcalmax-qcalmin))*qcalmin
ENDIF
print, qcalmax
print, gain
print, bias
ENVI_DOIT, 'TMCAL_DOIT', fid=image_fid, bands_present=bands_present, pos=pos, dims=dims_image, sat=sat, $
cal_type=1, sun_angle=sun_angel, out_name=InputPath+Filename, r_fid=r_fid, date=date, $
gain=gain, bias=bias
FOR index=0, n_elements(fids)-1 DO BEGIN
envi_file_mng, /remove, id=fids[index]
ENDFOR
ENDFOR
envi_batch_exit
END
|
I'm not sure how well TMCAL_DOIT works, but the description in the help causes serious though .
ENVI help
result=Input * GAIN + BIAS
gain = (lmax - lmin) / 255
bias = lmin |
This is correct only for QCALMAX=0.
Alex
|
|
|
|
 |  |
|
|
|
TMCAL_DOIT has been re-written to pass the metadata file directly to the routine so that you no longer need to parse the metadata file. It can now be called using something as simple as:
envi_doit, 'tmcal_doit', fid=fid, pos=pos, dims=dims, cal_type=1, out_name='tm_refl.dat', /use_metadata
Note that you don’t need to pass in any gain/bias/date/sat/sun_angle or bands_present and you can use pos if you want to calibrate a spectral subset.
We have a patch that can be applied to ENVI 4.8 that will allow for you to use the new routine. If you are interested, please contact Technical Support directly. |
|
|
|
 |  |
|
|
|
If you have multiple "MTL.txt" files the code provided by Alex will not work well.
If you replace (almost at the end):
FOR index=0, n_elements(fids)-1 DO BEGIN
envi_file_mng, /remove, id=fids[index]
ENDFOR
with:
fids=envi_get_file_ids()
FOR index=0, n_elements(fids)-1 DO BEGIN
envi_file_mng, /remove, id=fids[index]
ENDFOR
that will solve the problem (works for me). Otherwise, youll be always using the first file. Regardless this small "bug", the code works perfectly (thank you Alex for your code, was exactly what I was looking for!)
Im also not sure if you have to use the sun elevation raw value, or you have to convert it to sun angle (like Alexs code does)... Im always confused about it. It seems to me that when you do it manually (through the ENVIs menu), ENVI uses the sun elevation value; Am I correct?
Álvaro. |
|
|
|
 |  |
|
|
|
Yes, the SUN_ANGLE keyword is for the solar elevation angle, which is the angle of the sun above the horizon, extending from 0 degrees to 180 degrees. I think 0 to <90 degrees is when it's over the eastern horizon, and >90 to 180 degrees is when it's over the western horizon. So, 90 degrees is straight overhead.
- Peg |
|
|
|
|  |
 | |  |
 | |  |
 | |  |
|
|
|
|
|
|
|