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

Home » Public Forums » archive » Re: reading multiple HDF files
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
Re: reading multiple HDF files [message #61322] Tue, 15 July 2008 10:50 Go to next message
Juggernaut is currently offline  Juggernaut
Messages: 83
Registered: June 2008
Member
On Jul 15, 11:05 am, David Fanning <n...@dfanning.com> wrote:
> julia.waltersp...@gmail.com writes:
>> In the meantime I did the file_search and read in file by file with a
>> for-loop. But I guess this solution does not append the "newly" read
>> Variable to the other ones so that I can do a plot of a time series..?
>
> You will probably have to do that yourself. :-)
>
> But, I imagine this array can get pretty big. I think I would
> write the files to disk, then read them back in using
> the associated variable method (ASSOC) when you need them.
>
> OpenW, outlun, 'mybigfile.dat', /Get_Lun
> FOR thisFile = 0, count-1 DO BEGIN
> thisImage = HDF_READ(files[thisFile], ....)
> WriteU, outlun, thisImage
> ENDFOR
> Free_Lun, outlun
>
> Then, later:
>
> OpenR, lun, 'mybigfile.dat', /Get_Lun
> imageStack = Assoc(lun, IntArr(xsize, ysize))
>
> To display the 4th image:
>
> TV, imageStack[3]
>
> Or, whatever else you want to do with them.
>
> If you want them all, of course:
>
> stack = IntArr(xsize, ysize, count)
> OpenR, lun, 'mybigfile.dat', /Get_Lun
> ReadU, lun, stack
> Free_Lun, lun
>
> Of course, your images might not be integer arrays, and
> I have no idea what size these are, etc., etc. Use this
> code at your discretion. :-)
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

If you want to compare these in a plot you'll probably need to
normalize your time series as this could be different for them all
although I don't know if MODIS has a 0 start of collect time or a zulu
start of collect time, etc...
Re: reading multiple HDF files [message #61324 is a reply to message #61322] Tue, 15 July 2008 08:05 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
julia.walterspiel@gmail.com writes:

> In the meantime I did the file_search and read in file by file with a
> for-loop. But I guess this solution does not append the "newly" read
> Variable to the other ones so that I can do a plot of a time series..?

You will probably have to do that yourself. :-)

But, I imagine this array can get pretty big. I think I would
write the files to disk, then read them back in using
the associated variable method (ASSOC) when you need them.

OpenW, outlun, 'mybigfile.dat', /Get_Lun
FOR thisFile = 0, count-1 DO BEGIN
thisImage = HDF_READ(files[thisFile], ....)
WriteU, outlun, thisImage
ENDFOR
Free_Lun, outlun


Then, later:

OpenR, lun, 'mybigfile.dat', /Get_Lun
imageStack = Assoc(lun, IntArr(xsize, ysize))

To display the 4th image:

TV, imageStack[3]

Or, whatever else you want to do with them.

If you want them all, of course:

stack = IntArr(xsize, ysize, count)
OpenR, lun, 'mybigfile.dat', /Get_Lun
ReadU, lun, stack
Free_Lun, lun

Of course, your images might not be integer arrays, and
I have no idea what size these are, etc., etc. Use this
code at your discretion. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: reading multiple HDF files [message #61327 is a reply to message #61324] Tue, 15 July 2008 07:51 Go to previous messageGo to next message
julia.walterspiel is currently offline  julia.walterspiel
Messages: 35
Registered: July 2008
Member
great, thanks guys! I'll try this, too.
In the meantime I did the file_search and read in file by file with a
for-loop. But I guess this solution does not append the "newly" read
Variable to the other ones so that I can do a plot of a time series..?
@david: yeah, lucky me it didnt take me too long to figure out what I
needed to change on your hdf_read program so that it works with my
variables :) (i used the filename = read_hdf() at the IDL command line
to check for the SDS variable names)
Re: reading multiple HDF files [message #61332 is a reply to message #61327] Tue, 15 July 2008 06:41 Go to previous messageGo to next message
Juggernaut is currently offline  Juggernaut
Messages: 83
Registered: June 2008
Member
On Jul 15, 7:41 am, julia.waltersp...@gmail.com wrote:
> Hi!
> I'm a newbie to IDL (I used to program in MATLAB but the place i work
> at only has IDL licences) and i need to get some things here done
> asap.
> I've been struggling with reading HDF files from MODIS for quiet some
> time now and I def need some good input!
> Here's the thing:
>
> I downloaded a bunch (hundrets) of MODIS data (e.g. MOD_06, Cloud
> product, daily data, years 2000-2008) in HDF format from which I need
> to extract the SDS "Cloud_Fraction" and plot it as a time series for a
> specific geographical region (Switzerland). I managed to read the
> files with the program hdf_read by David fanning and I have a vague
> idea what to do in order to read in multiple hdf files (I guess this
> is done with a FOR loop).
>
> HOWEVER: I simply cannot imagine how it is possible to link single
> SDS' (e.g. "Cloud_Fraction") from multiple hdf files, and I don't even
> wanna think about displaying them as a time series or on a map of a
> geographic region.
>
> Can anybody give me some good hints? anything would be greatly
> appreciated!!!
> many many thanks
> Julia

Also...as for the loop you can simply do a file_search() routine (just
run a help inquiry on it for syntax) and find all
hdf files in a certain directory. You can use the 'count' variable it
uses to determine the loop size and then use the hdf reader
stuff I mentioned above to plot the data against each other using
'oplot' to plot over successive plots.
Hope this helps a bit.
Re: reading multiple HDF files [message #61333 is a reply to message #61332] Tue, 15 July 2008 06:41 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Juggernaut writes:

> You should check out Liam Gumley's hdf_sd_varread and hdf_sd_vardir.
> Then you can do something like...
>
> varnames = hdf_sd_vardir(hdfid)
>
> index = hdf_sd_nametoindex(hdfid, varnames[i]) ;- 'i' is whichever
> index of varnames your Cloud_Fraction is
>
> varid = hdf_sd_select(hdfid, index)
>
> hdf_sd_getdata, varid, data ;- Your cloud_fraction data will be
> stored in 'data' for you to use
>
> hdf_sd_endaccess, varid

Yes, I second this. The program HDFRead you found on my web page
is *not* designed to read any HDF file, but just the one created
with HDFWrite. You can use the HDF_BROWSER if you have to, to
learn the name of your cloud_fraction variable, then use Liam's
routines to read the data you need from your files.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: reading multiple HDF files [message #61334 is a reply to message #61333] Tue, 15 July 2008 06:36 Go to previous messageGo to next message
Juggernaut is currently offline  Juggernaut
Messages: 83
Registered: June 2008
Member
On Jul 15, 7:41 am, julia.waltersp...@gmail.com wrote:
> Hi!
> I'm a newbie to IDL (I used to program in MATLAB but the place i work
> at only has IDL licences) and i need to get some things here done
> asap.
> I've been struggling with reading HDF files from MODIS for quiet some
> time now and I def need some good input!
> Here's the thing:
>
> I downloaded a bunch (hundrets) of MODIS data (e.g. MOD_06, Cloud
> product, daily data, years 2000-2008) in HDF format from which I need
> to extract the SDS "Cloud_Fraction" and plot it as a time series for a
> specific geographical region (Switzerland). I managed to read the
> files with the program hdf_read by David fanning and I have a vague
> idea what to do in order to read in multiple hdf files (I guess this
> is done with a FOR loop).
>
> HOWEVER: I simply cannot imagine how it is possible to link single
> SDS' (e.g. "Cloud_Fraction") from multiple hdf files, and I don't even
> wanna think about displaying them as a time series or on a map of a
> geographic region.
>
> Can anybody give me some good hints? anything would be greatly
> appreciated!!!
> many many thanks
> Julia

You should check out Liam Gumley's hdf_sd_varread and hdf_sd_vardir.
Then you can do something like...

varnames = hdf_sd_vardir(hdfid)

index = hdf_sd_nametoindex(hdfid, varnames[i]) ;- 'i' is whichever
index of varnames your Cloud_Fraction is

varid = hdf_sd_select(hdfid, index)

hdf_sd_getdata, varid, data ;- Your cloud_fraction data will be
stored in 'data' for you to use

hdf_sd_endaccess, varid
Re: reading multiple HDF files [message #61414 is a reply to message #61322] Tue, 15 July 2008 13:37 Go to previous message
bulrushmower is currently offline  bulrushmower
Messages: 19
Registered: February 2008
Junior Member
On Jul 15, 12:50 pm, Juggernaut <juggernau...@gmail.com> wrote:
> On Jul 15, 11:05 am, David Fanning <n...@dfanning.com> wrote:
>
>
>
>
>
>> julia.waltersp...@gmail.com writes:
>>> In the meantime I did the file_search and read in file by file with a
>>> for-loop. But I guess this solution does not append the "newly" read
>>> Variable to the other ones so that I can do a plot of a time series..?
>
>> You will probably have to do that yourself. :-)
>
>> But, I imagine this array can get pretty big. I think I would
>> write the files to disk, then read them back in using
>> the associated variable method (ASSOC) when you need them.
>
>>    OpenW, outlun, 'mybigfile.dat', /Get_Lun
>>    FOR thisFile = 0, count-1 DO BEGIN
>>         thisImage = HDF_READ(files[thisFile], ....)
>>        WriteU, outlun, thisImage
>>    ENDFOR
>>    Free_Lun, outlun
>
>> Then, later:
>
>>     OpenR, lun, 'mybigfile.dat', /Get_Lun
>>     imageStack = Assoc(lun, IntArr(xsize, ysize))
>
>> To display the 4th image:
>
>>     TV, imageStack[3]
>
>> Or, whatever else you want to do with them.
>
>> If you want them all, of course:
>
>>     stack = IntArr(xsize, ysize, count)
>>     OpenR, lun, 'mybigfile.dat', /Get_Lun
>>     ReadU, lun, stack
>>     Free_Lun, lun
>
>> Of course, your images might not be integer arrays, and
>> I have no idea what size these are, etc., etc. Use this
>> code at your discretion. :-)
>
>> Cheers,
>
>> David
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> If you want to compare these in a plot you'll probably need to
> normalize your time series as this could be different for them all
> although I don't know if MODIS has a 0 start of collect time or a zulu
> start of collect time, etc...- Hide quoted text -
>
> - Show quoted text -

Try this link
http://groups.google.com/group/comp.lang.idl-pvwave/browse_t hread/thread/cae923b1cd9c393b/da2b8712b63af341?hl=en&lnk =gst&q=HDF#da2b8712b63af341
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Where O Where Di My Pointer Go?
Next Topic: IDLWave opens new frame on error/stop

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

Current Time: Wed Oct 08 13:42:52 PDT 2025

Total time taken to generate the page: 0.00622 seconds