Re: HDF_SD_ADDDATA problem [message #59923] |
Tue, 22 April 2008 13:57  |
UV_Catastrophe
Messages: 1 Registered: April 2008
|
Junior Member |
|
|
On Apr 21, 7:24 pm, adfra...@utas.edu.au wrote:
> Dear Everyone,
>
> I'm having trouble writing to an HDF file using HDF_SD_ADDDATA, but
> let me set the scene quickly first.
>
> I'm using a multispectral satellite imagery dataset in its native L1B
> (HDF-EOS, it's MODIS for those who care!) format. When ordering the
> data, one has the option to channel subset the data to reduce size.
>
> I've written IDL programs to cloud mask the data, which involves
> manipulating an SDS within the HDF. My programs all work fine using
> the full, un-subsetted data, but whenever I try them on the subsetted
> HDFs, they fall over with this error.
>
> ------------------------------------------------------------ -----------
> % HDF_SD_ADDDATA: Unable to write the specified HDF-SD slice.
> % Execution halted at: HDFEDITSDS 28 /array/work/adfraser/
> MODIS
> images/18_4_08 processing of winter2 data/output/HDFeditSDS.pro
> % $MAIN$
> ------------------------------------------------------------ -----------
>
> Here is the code which I've been using to write successfully to the
> unsubsetted data but unsuccessfully to the subsetted data:
>
> ------------------------------------------------------------ ------------
> PRO HDFeditSDS, filename, sdsname, newdata
>
> sdfileid=hdf_sd_start(filename, /rdwr)
>
> ; Find the index of the "Gridded Data" SDS.
> index = HDF_SD_NAMETOINDEX(sdFileID, sdsname)
>
> ; Select the Gridded Data SDS.
> thisSdsID = HDF_SD_SELECT(sdFileID, index)
>
> HDF_SD_AddData, thisSdsID, newdata
>
> hdf_sd_end, sdfileid
>
> END
> ------------------------------------------------------------ -------------
>
> I've checked all the obvously stupid things (file access permissions
> are identical, and the SDS name exists within the HDF). I'm at a loss,
> please help!
>
> Cheers,
> Alex.
>
> Alex Fraser
> Ph.D. candidate
> University of Tasmania
> Antarctic Climate and Ecosystems Cooperative Research Centre
> Sandy Bay Campus
> Tasmania 7001
Hi Alex,
As Mary Jo pointed out, before calling HDF_SD_END, you should insert
the following command: "HDF_SD_ENDACCESS, sdfileid". However, as she
said, that doesn't explain why your code was working for unsubsetted
data.
Could you provide a little more information about the data that you're
working with? Specifically:
- Have you tried running your code with various different data
subsets? (You probably have, but it doesn't hurt to ask.)
- When you channel subset the data, which bands are you keeping?
- Out of curiosity, why aren't you just using the pre-masked data? (I
believe that the website can provide you with data that has already
been cloud masked.)
Ben Ripman
MODIS IOT
|
|
|
|
Re: HDF_SD_ADDDATA problem [message #59939 is a reply to message #59938] |
Tue, 22 April 2008 07:23   |
brodzik@nsidc.org
Messages: 7 Registered: July 2005
|
Junior Member |
|
|
On Apr 21, 5:24 pm, adfra...@utas.edu.au wrote:
> Dear Everyone,
>
> I'm having trouble writing to an HDF file using HDF_SD_ADDDATA, but
> let me set the scene quickly first.
>
> I'm using a multispectral satellite imagery dataset in its native L1B
> (HDF-EOS, it's MODIS for those who care!) format. When ordering the
> data, one has the option to channel subset the data to reduce size.
>
> I've written IDL programs to cloud mask the data, which involves
> manipulating an SDS within the HDF. My programs all work fine using
> the full, un-subsetted data, but whenever I try them on the subsetted
> HDFs, they fall over with this error.
>
> ------------------------------------------------------------ -----------
> % HDF_SD_ADDDATA: Unable to write the specified HDF-SD slice.
> % Execution halted at: HDFEDITSDS 28 /array/work/adfraser/
> MODIS
> images/18_4_08 processing of winter2 data/output/HDFeditSDS.pro
> % $MAIN$
> ------------------------------------------------------------ -----------
>
> Here is the code which I've been using to write successfully to the
> unsubsetted data but unsuccessfully to the subsetted data:
>
> ------------------------------------------------------------ ------------
> PRO HDFeditSDS, filename, sdsname, newdata
>
> sdfileid=hdf_sd_start(filename, /rdwr)
>
> ; Find the index of the "Gridded Data" SDS.
> index = HDF_SD_NAMETOINDEX(sdFileID, sdsname)
>
> ; Select the Gridded Data SDS.
> thisSdsID = HDF_SD_SELECT(sdFileID, index)
>
> HDF_SD_AddData, thisSdsID, newdata
>
> hdf_sd_end, sdfileid
>
> END
> ------------------------------------------------------------ -------------
>
> I've checked all the obvously stupid things (file access permissions
> are identical, and the SDS name exists within the HDF). I'm at a loss,
> please help!
>
> Cheers,
> Alex.
>
> Alex Fraser
> Ph.D. candidate
> University of Tasmania
> Antarctic Climate and Ecosystems Cooperative Research Centre
> Sandy Bay Campus
> Tasmania 7001
Alex,
I have also been working with MODIS HDF data lately, and sympathize
with your troubles.
The workings of HDF routines are very murky to me. As a result, my
behavior reduces to superstitious little rules like these. Makes me
understand how ignorance during the Middle Ages led people to do all
kinds of crazy things.
My wacky rules are:
a) always check return codes--they often behave in strange ways when
the object interface gets confused
b) always bracket an hdf_sd_select call with an hdf_sd_endaccess, (I
think you're missing an hdf_sd_endaccess in your sample, but that
doesn't explain why it works for unsubsetted data but not subsetted)
c) likewise with hdf_sd_start and hdf_sd_end
and, finally, after I recently added a new SD to a MODIS tile using
the HDF_SD interface, I learned that I really needed to use the EOS_GD
interface, so the new SD was really part of the HDF-EOS grid object
and other software (the MODIS reprojection tool) was only looking in
the grid object, and was ignoring any other SDs in the file. Just an
aside, but it might affect whatever you're doing downstream.
Ohmygosh, I never thought it would happen to me, but I'm speaking HDF-
bot...need to go get some Listerine.
Good luck,
Mary Jo
|
|
|
Re: HDF_SD_ADDDATA problem [message #59985 is a reply to message #59923] |
Wed, 23 April 2008 19:23  |
adfraser
Messages: 9 Registered: April 2008
|
Junior Member |
|
|
Thanks, Ben.
Yep, I added the endaccess call, but still no luck.
The data I'm working with are LAADS-subsetted L1B 1km-resolution MODIS
data, obtained from ladsweb.nascom.nasa.gov
I'm using bands 31 and 32. I've tried it with many subsetted files
(even from different batches), but the same result occurs.
I'm not performing the channel subsetting myself, they are ordered as
subsetted files "from the factory" (at laads).
To answer your curiosity, I'm performing some important polar-specific
fine-tuning of the cloud masks before application.
Thanks again!
Alex.
|
|
|
Re: HDF_SD_ADDDATA problem [message #59987 is a reply to message #59938] |
Wed, 23 April 2008 19:18  |
adfraser
Messages: 9 Registered: April 2008
|
Junior Member |
|
|
The types and dimensions both match, however the code I've posted
(top) still works regardless of whether the dimensions match.
HDF_SDS_ADDDATA is nice like that (when it works!).
|
|
|
Re: HDF_SD_ADDDATA problem [message #59988 is a reply to message #59939] |
Wed, 23 April 2008 19:17  |
adfraser
Messages: 9 Registered: April 2008
|
Junior Member |
|
|
Thanks a lot, Mary Jo, for your comments and suggestions.
I recently added the endaccess call, but unsurprisingly there was no
chance to my problems!
I haven't checked out the return codes, that might provide some
insight, hopefully!
Also, I hadn't used the EOS_GD interface before, I must check that out
one day. It looks interesting, is a part of the IDL standard
distribution?
HDF-bot: I know the feeling!
Thanks again, Alex.
|
|
|