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

Home » Public Forums » archive » How to build ASCII File
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
How to build ASCII File [message #56838] Tue, 20 November 2007 09:19 Go to next message
Marshad2 is currently offline  Marshad2
Messages: 15
Registered: July 2007
Junior Member
Hi Guys:

I tried to make ASCII file for Spectral Response Curves obtained at
ftp://asapdata.arc.nasa.gov/MASTER/srf/May_03/ however, it is not
working. Can someone give suggestions how to build ASCII file for
Spectral Response Curves.

Best Regards,

Arshad
Re: How to build ASCII File [message #56913 is a reply to message #56838] Wed, 21 November 2007 08:38 Go to previous messageGo to next message
Marshad2 is currently offline  Marshad2
Messages: 15
Registered: July 2007
Junior Member
On Nov 20, 6:42 pm, Paul van Delst <Paul.vanDe...@noaa.gov> wrote:
> Marsh...@gmu.edu wrote:
>> On Nov 20, 12:19 pm, Marsh...@gmu.edu wrote:
>>> Hi Guys:
>
>>> I tried to make ASCII file for Spectral Response Curves obtained atftp://asapdata.arc.nasa.gov/MASTER/srf/May_03/however, it is not
>>> working. Can someone give suggestions how to build ASCII file for
>>> Spectral Response Curves.
>
>>> Best Regards,
>
>>> Arshad
>
>> Yes, they are ASCII files containing two columns: one is set of
>> wavelengths, and the other the spectral response for that band at each
>> of those wavelengths. Each file has a different set of wavelengths.
>> What I want to do is take the data from different bands, and compile
>> them into one ASCII file, with one wavelength column that contains all
>> the wavelengths from any of the 50 spectral response files, and then
>> one column for each band, containing the spectral responses at each
>> wavelength in the wavelength column. Where a given file does'nt
>> include values for some wavelengths, those wavelengths will end with
>> values of zero for that band in the big ccompiled ASCII file. This is
>> the detail regarding which I need help.
>
> I can't imagine why you'd want to do that, but since I don't know anything about your
> application, off the top of my head I would say you should:
>
> 1) Read all the files through once to get the minimum and maximum wavelengths.
> 2) Select a suitable wavelength interval (I assume it's different for every
> file/channel)
> 3) Create master array to hold SRFs for all wavelengths (for your common grid),
> all channels.
> 4) Loop over input files i=1,N
> 4a) Read channel file #i
> 4b) Interpolate SRF data to your common grid
> 4c) Slot the result into your master array for the i'th channel
> 5) Output master array to file.
>
> cheers,
>
> paulv- Hide quoted text -
>
> - Show quoted text -

Thank you Paul. Let me try it.

Arshad
Re: How to build ASCII File [message #56923 is a reply to message #56838] Tue, 20 November 2007 15:42 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Marshad2@gmu.edu wrote:
> On Nov 20, 12:19 pm, Marsh...@gmu.edu wrote:
>> Hi Guys:
>>
>> I tried to make ASCII file for Spectral Response Curves obtained atftp://asapdata.arc.nasa.gov/MASTER/srf/May_03/however, it is not
>> working. Can someone give suggestions how to build ASCII file for
>> Spectral Response Curves.
>>
>> Best Regards,
>>
>> Arshad
>
> Yes, they are ASCII files containing two columns: one is set of
> wavelengths, and the other the spectral response for that band at each
> of those wavelengths. Each file has a different set of wavelengths.
> What I want to do is take the data from different bands, and compile
> them into one ASCII file, with one wavelength column that contains all
> the wavelengths from any of the 50 spectral response files, and then
> one column for each band, containing the spectral responses at each
> wavelength in the wavelength column. Where a given file does'nt
> include values for some wavelengths, those wavelengths will end with
> values of zero for that band in the big ccompiled ASCII file. This is
> the detail regarding which I need help.

I can't imagine why you'd want to do that, but since I don't know anything about your
application, off the top of my head I would say you should:


1) Read all the files through once to get the minimum and maximum wavelengths.
2) Select a suitable wavelength interval (I assume it's different for every
file/channel)
3) Create master array to hold SRFs for all wavelengths (for your common grid),
all channels.
4) Loop over input files i=1,N
4a) Read channel file #i
4b) Interpolate SRF data to your common grid
4c) Slot the result into your master array for the i'th channel
5) Output master array to file.

cheers,

paulv
Re: How to build ASCII File [message #56929 is a reply to message #56838] Tue, 20 November 2007 13:47 Go to previous messageGo to next message
Marshad2 is currently offline  Marshad2
Messages: 15
Registered: July 2007
Junior Member
On Nov 20, 12:19 pm, Marsh...@gmu.edu wrote:
> Hi Guys:
>
> I tried to make ASCII file for Spectral Response Curves obtained atftp://asapdata.arc.nasa.gov/MASTER/srf/May_03/however, it is not
> working. Can someone give suggestions how to build ASCII file for
> Spectral Response Curves.
>
> Best Regards,
>
> Arshad

Yes, they are ASCII files containing two columns: one is set of
wavelengths, and the other the spectral response for that band at each
of those wavelengths. Each file has a different set of wavelengths.
What I want to do is take the data from different bands, and compile
them into one ASCII file, with one wavelength column that contains all
the wavelengths from any of the 50 spectral response files, and then
one column for each band, containing the spectral responses at each
wavelength in the wavelength column. Where a given file does'nt
include values for some wavelengths, those wavelengths will end with
values of zero for that band in the big ccompiled ASCII file. This is
the detail regarding which I need help.

Regards,
Re: How to build ASCII File [message #56972 is a reply to message #56838] Sat, 24 November 2007 08:33 Go to previous messageGo to next message
devin.white is currently offline  devin.white
Messages: 50
Registered: March 2007
Member
I see what you're trying to do, but there's definitely an easier way
to go about it. You're attempting to create a binary ENVI Spectral
Library file that contains the spectral response curves for MASTER's
first 25 channels (VNIR and SWIR) from the individual SRF ASCII
files. Because of how ENVI Spectral Library files are constructed, an
entry for a particular channel must contain response values for the
entire wavelength range of the 25 channels, combined--even if the
recorded values for a channel (in a single SRF file) fall over a much
smaller range. As a result, you have to provide "filler" values of 0
to compensate. Because each SRF file covers a different range and
contains a variable number of entries, getting everything into one
ENVI Spectral Library file is a bit challenging. The program below
will build the library for you, as long as all of the individual SRF
files and the associated header file (*.ph) are in the same folder on
your computer. It makes liberal use of array and structure
concatenation, subscripting, and the WHERE function to build the
library. SORT is used in a few places to ensure that all response
values end up in the right locations. The program is provided as is.

pro create_master_spectral_reponse_sli
compile_opt idl2

header_file = dialog_pickfile(title='Select Spectral Response Header
File', filter='*.ph', $
get_path=header_path)
if header_file eq '' then return
out_name = dialog_pickfile(title='Select Output Library Name',
path=header_path)
if out_name eq '' then return

spec_search = file_search(header_path, '*.c*', count=spec_count)
if spec_count ne 50 then begin
ok = dialog_message('You must have all 50 MASTER spectral response
curve files to proceed', $
/error)
return
endif

;Sort response files from lowest to highest band
spec_sort = sort(spec_search)
spec_search = spec_search[spec_sort]

envi_read_cols, header_file, parameters

band_nums = lindgen(25)+1
band_names = replicate('Band',25) + ' ' + strtrim(string(band_nums),
2)

;Read in spectral response files and create
;structure array to hold all returned info
spec_struct = {sensor_type:'MASTER'}
wl_array = dblarr(1)
for i=0,24 do begin
envi_read_cols, spec_search[i], spec_data
spec_struct = create_struct(spec_struct, band_names[i], spec_data)
wl_array = [wl_array, reform(transpose(spec_data[0,*]))]
endfor

wl_array = wl_array[1:*]
wl_array = wl_array[sort(wl_array)]
num_measure = n_elements(wl_array)

openw, lun, out_name, /get_lun

;Write out band-specific spectral response library entries
for j=1,25 do begin
cur_wl = (spec_struct.(j))[0,*]
sort_cur = sort(cur_wl)
num_cur = n_elements(cur_wl)
where_cur = where(wl_array eq cur_wl[sort_cur[0]], where_count)
response = reform((spec_struct.(j))[1,sort_cur])
response_array = dblarr(num_measure)
response_array[where_cur[0]:(where_cur[0]+num_cur-1)] = response
writeu, lun, response_array
endfor

free_lun, lun

file_type=envi_file_type('ENVI Spectral Library')
envi_setup_head, fname=out_name, data_type=5, file_type=file_type, $
interleave=0, nb=1, ns=num_measure, $
nl=25, wl=wl_array, /write, /open, r_fid=lib_fid, $
wavelength_unit=0, spec_names=band_names

end



On Nov 20, 12:19 pm, Marsh...@gmu.edu wrote:
> Hi Guys:
>
> I tried to make ASCII file for Spectral Response Curves obtained atftp://asapdata.arc.nasa.gov/MASTER/srf/May_03/however, it is not
> working. Can someone give suggestions how to build ASCII file for
> Spectral Response Curves.
>
> Best Regards,
>
> Arshad
Re: How to build ASCII File [message #57031 is a reply to message #56972] Wed, 28 November 2007 13:37 Go to previous message
Marshad2 is currently offline  Marshad2
Messages: 15
Registered: July 2007
Junior Member
On Nov 24, 11:33 am, "devin.wh...@gmail.com" <devin.wh...@gmail.com>
wrote:
> I see what you're trying to do, but there's definitely an easier way
> to go about it. You're attempting to create a binary ENVI Spectral
> Library file that contains the spectral response curves for MASTER's
> first 25 channels (VNIR and SWIR) from the individual SRF ASCII
> files. Because of how ENVI Spectral Library files are constructed, an
> entry for a particular channel must contain response values for the
> entire wavelength range of the 25 channels, combined--even if the
> recorded values for a channel (in a single SRF file) fall over a much
> smaller range. As a result, you have to provide "filler" values of 0
> to compensate. Because each SRF file covers a different range and
> contains a variable number of entries, getting everything into one
> ENVI Spectral Library file is a bit challenging. The program below
> will build the library for you, as long as all of the individual SRF
> files and the associated header file (*.ph) are in the same folder on
> your computer. It makes liberal use of array and structure
> concatenation, subscripting, and the WHERE function to build the
> library. SORT is used in a few places to ensure that all response
> values end up in the right locations. The program is provided as is.
>
> pro create_master_spectral_reponse_sli
> compile_opt idl2
>
> header_file = dialog_pickfile(title='Select Spectral Response Header
> File', filter='*.ph', $
> get_path=header_path)
> if header_file eq '' then return
> out_name = dialog_pickfile(title='Select Output Library Name',
> path=header_path)
> if out_name eq '' then return
>
> spec_search = file_search(header_path, '*.c*', count=spec_count)
> if spec_count ne 50 then begin
> ok = dialog_message('You must have all 50 MASTER spectral response
> curve files to proceed', $
> /error)
> return
> endif
>
> ;Sort response files from lowest to highest band
> spec_sort = sort(spec_search)
> spec_search = spec_search[spec_sort]
>
> envi_read_cols, header_file, parameters
>
> band_nums = lindgen(25)+1
> band_names = replicate('Band',25) + ' ' + strtrim(string(band_nums),
> 2)
>
> ;Read in spectral response files and create
> ;structure array to hold all returned info
> spec_struct = {sensor_type:'MASTER'}
> wl_array = dblarr(1)
> for i=0,24 do begin
> envi_read_cols, spec_search[i], spec_data
> spec_struct = create_struct(spec_struct, band_names[i], spec_data)
> wl_array = [wl_array, reform(transpose(spec_data[0,*]))]
> endfor
>
> wl_array = wl_array[1:*]
> wl_array = wl_array[sort(wl_array)]
> num_measure = n_elements(wl_array)
>
> openw, lun, out_name, /get_lun
>
> ;Write out band-specific spectral response library entries
> for j=1,25 do begin
> cur_wl = (spec_struct.(j))[0,*]
> sort_cur = sort(cur_wl)
> num_cur = n_elements(cur_wl)
> where_cur = where(wl_array eq cur_wl[sort_cur[0]], where_count)
> response = reform((spec_struct.(j))[1,sort_cur])
> response_array = dblarr(num_measure)
> response_array[where_cur[0]:(where_cur[0]+num_cur-1)] = response
> writeu, lun, response_array
> endfor
>
> free_lun, lun
>
> file_type=envi_file_type('ENVI Spectral Library')
> envi_setup_head, fname=out_name, data_type=5, file_type=file_type, $
> interleave=0, nb=1, ns=num_measure, $
> nl=25, wl=wl_array, /write, /open, r_fid=lib_fid, $
> wavelength_unit=0, spec_names=band_names
>
> end
>
> On Nov 20, 12:19 pm, Marsh...@gmu.edu wrote:
>
>
>
>> Hi Guys:
>
>> I tried to make ASCII file for Spectral Response Curves obtained atftp://asapdata.arc.nasa.gov/MASTER/srf/May_03/however, it is not
>> working. Can someone give suggestions how to build ASCII file for
>> Spectral Response Curves.
>
>> Best Regards,
>
>> Arshad- Hide quoted text -
>
> - Show quoted text -

Thank You, Devin White. I really appreciate your respose.

Arshad
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: combine histograms
Next Topic: Re: combine histograms

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

Current Time: Wed Oct 08 15:21:46 PDT 2025

Total time taken to generate the page: 0.00397 seconds