Re: Open MYD09GQ.A2006060.h25v06.005.2008075213332.hdf using a NCL script

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed Dec 12 2012 - 08:47:20 MST

THX for ftp-ing the file.

NASA data creators append a .hdf file extension. These files
are read via standard HDF software interfaces. There is a separate
suite of interfaces for HDF-EOS files. To make a long story short,
often to get *all* the information, you (NCL) must open the
same file twice: once with the .hdf extension and, again, with the
manually added .hdfeos or .he2 extensions. (.hdfeos and .he2
mean the same thing.) NCL will add Climate and Forecast Convention
information (eg: units, long_name, ...) to the variables.

I suggest that hdf files always be looked at via ncl_filedump initially

The Ydim argument is from the .hdfeos extension.

As noted earlier by Dave Brown

"You have commented out the part from the template code about reading
the file with the .he2 extension."

; he2_file = addfile("MYD09A1.A2007273.h03v07.005.2007285103507.hdf.he2",
"r") ; Read file for the second time to efficiently obtain lat and lon.

Try, uncommenting that statement.

=================================

%> ncl_filedump MYD09GQ.A2006060.h25v06.005.2008075213332.hdf | less

yields

Variable: f
Type: file
filename: MYD09GQ.A2006060.h25v06.005.2008075213332
path: MYD09GQ.A2006060.h25v06.005.2008075213332.hdf
    file global attributes:
       HDFEOSVersion : HDFEOS_V2.9 <=== NOTE HDFEOS
       StructMetadata_0 : GROUP=SwathStructure
END_GROUP=SwathStructure
GROUP=GridStructure
         GROUP=GRID_1
                 GridName="MODIS_Grid_2D"
                 XDim=4800
                 YDim=4800
[SNIP]

%> ncl_filedump MYD09GQ.A2006060.h25v06.005.2008075213332.hdf.he2 | less

yields

Variable: f
Type: file
filename: MYD09GQ.A2006060.h25v06.005.2008075213332.hdf
path: MYD09GQ.A2006060.h25v06.005.2008075213332.hdf
    file global attributes:
    dimensions:
       YDim_MODIS_Grid_2D = 4800
       XDim_MODIS_Grid_2D = 4800
    variables:
       double GridLat_MODIS_Grid_2D ( YDim_MODIS_Grid_2D,
XDim_MODIS_Grid_2D )
          projection : Sinusoidal
          corners : ( 29.99895833063933, 29.99895833063933,
20.00104166486752, 20.00104166486752 )
          long_name : latitude
          units : degrees_north

On 12/11/12 9:05 AM, Filippo Locci wrote:
> Hi,
> using examples from http://www.hdfeos.org/zoo/index_openLPDAAC_Examples.php
> and modifing a script to open a MYD09GQ file but an error occurs:
> fatal:["Execute.c":5773]:variable (YDim) is not in file (eos_file)
>
> My script:
>
> ;This example code illustrates how to access and visualize LP_DAAC_MYD Grid
> file in NCL.
> ;If you have any questions, suggestions, comments on this example, please
> use the HDF-EOS Forum (http://hdfeos.org/forums).
> ;If you would like to see an example of any other NASA HDF/HDF-EOS data
> product that is not listed in the HDF-EOS Comprehensive Examples page (
> http://hdfeos.org/zoo),
> ;feel free to contact us at eoshelp@hdfgroup.org or post it at the HDF-EOS
> Forum (http://hdfeos.org/forums).
>
> load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> ; This is an example of a 2-D grid file data field.
> ; It is assumed users know how to obtain information such as _FillValue
> from HDFView.
> ; For information about HDFView, visit
> http://www.hdfgroup.org/hdf-java-html/hdfview/.
>
> begin
>
> eos_file=addfile("MYD09GQ.A2006060.h25v06.005.2008075213332.hdf", "r") ;
> Read file.
> ; he2_file = addfile("MYD09A1.A2007273.h03v07.005.2007285103507.hdf.he2",
> "r") ; Read file for the second time to efficiently obtain lat and lon.
>
> ; List available fields and attributes.
> print(eos_file)
>
> ; read data field
> data_raw = eos_file->sur_refl_b01_1
>
> ; print(data_raw)
>
> ; Apply scale factor according to the field attribute
> ; correct_data_value = (raw_data_value - offset) * scale_factor
> data = (data_raw - data_raw@add_offset) * data_raw@scale_factor
>
> data@_FillValue = (data_raw@_FillValue - data_raw@add_offset) *
> data_raw@scale_factor
>
> data@long_name = data_raw@long_name
> data@units = data_raw@units
>
> ; Associate longitude and latitude
> ; data@lat2d=he2_file->GridLat_MOD_Grid_500m_Surface_Reflectance
> ; data@lon2d=he2_file->GridLon_MOD_Grid_500m_Surface_Reflectance
>
>
> lat=eos_file->YDim ; associate longitude and latitude
> lon=eos_file->XDim ;
> lat@_FillValue=-999.0
> lon@_FillValue=-999.0
>
>
> data@lat2d=lat
> data@lon2d=lon
>
>
> xwks=gsn_open_wks("pdf","MYD09GQ.A2006060.h25v06.005.2008075213332.hdf_sur_refl.ncl")
> ; open workstation
>
> res=True ; plot mods desired
> res@cnFillOn=True ; enable contour fill
> res@gsnMaximize=True; make plot large
> res@gsnPaperOrientation = "portrait" ; force portrait orientation
> res@cnLinesOn=False ; turn off contour lines
> res@cnLineLabelsOn = False; turn off contour line labels
> res@gsnSpreadColors = True ; use the entire color spectrum
> res@cnFillMode = "RasterFill" ; faster
> res@lbOrientation ="vertical" ;vertical labels
> res@cnMissingValFillPattern = 0 ; missing value pattern is set to
> "SolidFill"
> res@cnMissingValFillColor = 0; white color for missing values
>
> ; the following 5 sentences are used to create a zoomed image
> res@mpLimitMode = "LatLon"
> res@mpMinLatF = min(data@lat2d) ; Set limits of map, based on the min/max
> of the dataset latitude/longitude
> res@mpMaxLatF = max(data@lat2d) ;
> res@mpMinLonF = min(data@lon2d) ;
> res@mpMaxLonF = max(data@lon2d) ;
>
> gsn_define_colormap(xwks,"BlAqGrYeOrReVi200") ; choose colormap
> res@tiMainString = "MYD09GQ.A2006060.h25v06.005.2008075213332.hdf" ;
> create title
> res@gsnLeftString = "Field name: " + data@long_name
> res@gsnRightString = "Units: " + data@units
>
> plot=gsn_csm_contour_map_ce(xwks,data,res) ; create plot
>
> ; cleaning up used resources
> delete(plot)
> delete(res)
> delete(xwks)
> delete(data)
> delete(data_raw)
> delete(eos_file)
> ; delete(he2_file)
>
> end
>
> I haven't a file where I could read the geolocation. It's possible to read
> this file via HDF viewer but
> I'm not able to open this file via an NCL script.
> Please, give me a suggestion.
> Thank you
> F
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Dec 13 00:47:46 2012

This archive was generated by hypermail 2.1.8 : Wed Dec 12 2012 - 19:07:01 MST