[ncl-talk] How to get the regional data of SMAP L4 *(HDF5 format)

Dennis Shea shea at ucar.edu
Fri Dec 15 10:03:02 MST 2017


What Mary wrote is generally correct ... Specifically:
========================
You are trying to extract the region from your HDF5 data by using
coordinate subscripting.

*Coordinate subscripting can only be done on rectilinear data*, *which is
data represented by one-dimensional lat/lon arrays that are the same length
as their corresponding dimension.*

Your data is likely curvilinear, which means your data is represented by
two-dimensional lat/lon arrays. I say this because in your code it looks
like you are extracting 2D lat/lon arrays:

  lat2d    = f->cell_lat
  lon2d    = f->cell_lon
  nSmapLat = dimsizes(lat2d(:,0))
  nSmapLon = dimsizes(lon2d(0,:))
===========================
Generally, when people see two dimensional latitude & longitude arrays (
cell_lat[*][*] and cell_lon[*][*] ), the grid structure is *'almost*
*always*' curvilinear. However, I noted that the file is a *L4* file (
*SMAP_L4*). NASA Level-4 files are '*almost always*' on a 'nice' grid.

I used an undocumented and unsupported function of mine to test if the grid
is a rectilinear grid despite the two-dimensional latitude & longitude
arrays. The function returns *True* if it is rectilinear and *False*
otherwise.

%> ncl tst.smap_rectilinear.ncl


The grid is rectilinear. Hence, you can use the approach you originally
used. (It did need a few improvements :-) )

%> ncl smap_regional.ncl_YiLu

Yes ... there are a fe locations over the water but if you use a higher
resolution map that will not be the case.

Good luck

On Thu, Dec 14, 2017 at 9:21 AM, Mary Haley <haley at ucar.edu> wrote:

> Dear Yi Lu,
>
> You are trying to extract the region from your HDF5 data by using
> coordinate subscripting.
>
> Coordinate subscripting can only be done on rectilinear data, which is
> data represented by one-dimensional lat/lon arrays that are the same length
> as their corresponding dimension.
>
> Your data is likely curvilinear, which means your data is represented by
> two-dimensional lat/lon arrays. I say this because in your code it looks
> like you are extracting 2D lat/lon arrays:
>
>   lat2d    = f->cell_lat
>   lon2d    = f->cell_lon
>   nSmapLat = dimsizes(lat2d(:,0))
>   nSmapLon = dimsizes(lon2d(0,:))
>
> Given this information, you cannot use coordinate subscripting to
> subscript your data.  Instead, you either need to use the function
> *getind_latlon2d* or *region_ind* to get the indexes of the area of
> interest.  For example:
>
>   lat_reg  = (/minLatBoundary,maxLatBoundary/)
>   lon_reg  = (/minLonBoundary,maxLonBoundary/)
>   ij       = getind_latlon2d(lat2d,lon2d,lat_reg,lon_reg)
>   sm_regional = sm(ij(0,0):ij(1,0),ij(0,1):ij(1,1))
>
> Before plotting, you need to subset your lat2d / lon2d arrays using the
> same indexing:
>
>  res at sfXArray = lon2d(ij(0,0):ij(1,0),ij(0,1):ij(1,1))
>  res at sfYArray = lat2d(ij(0,0):ij(1,0),ij(0,1):ij(1,1))
>
> Please see our "Subsetting / extracting data based on lat / lon values"
> example page:
>
> http://www.ncl.ucar.edu/Applications/latlon_subset.shtml
>
> and in particular, look at examples latlon_subset_2.ncl and
> latlon_subset_3.ncl, which show the difference between getind_latlon2d and
> region_ind.
>
> Also, to better understand the different types of data (rectilinear,
> curvilinear, unstructured) and how to plot them, see:
>
> http://www.ncl.ucar.edu/Applications/plot_data_on_map.shtml
>
> Good luck,
>
> --Mary
>
>
> On Wed, Dec 13, 2017 at 7:05 PM, 易路 <dg1225033 at smail.nju.edu.cn> wrote:
>
>> Hi, all
>> Sorry to disturb you for technical help.
>>
>> I am trying to extract the regional data from the soil product SMAP L4
>> which is stored in the format of HDF5. I wrote the ncl script taking
>> referecnce to the example listed on the web of
>> http://www.ncl.ucar.edu/Applications/HDF.shtml. But the extracted data
>> were not in the demond region. So would you please help me to find the
>> faults in my ncl script?  The main part of this script is as follow, and
>> the detail information can be downloaded from the accessory.
>> ********main part of the script *********
>>  nFiles  = dimsizes(iFiles)
>>   f       = addfile(iFiles(0), "r")
>>   lat2d     = f->cell_lat
>>   lon2d     = f->cell_lon
>>
>>  nSmapLat = dimsizes(lat2d(:,0))
>>  nSmapLon = dimsizes(lon2d(0,:))
>>  minSmapLat = min(lat2d)
>>  maxSmapLat = max(lat2d)
>>  minSmapLon = min(lon2d)
>>  maxSmapLon = max(lon2d)
>>
>>  lat=fspan(minSmapLat, maxSmapLat, nSmapLat)
>>     lat!0="lat"
>>     lat&lat=lat
>>     lat at units="degrees_north"
>>     lat at long_name="Latitude"
>>  lon=fspan(minSmapLon,maxSmapLon, nSmapLon)
>>     lon!0="lon"
>>     lon&lon=lon
>>     lon at units="degrees_east"
>>     lon at long_name="Longitude"
>>
>>   lat2d!0="lat"
>>   lat2d!1="lon"
>>   lat2d&lon=lon
>>   lat2d&lat=lat
>>
>>   lon2d!0="lat"
>>   lon2d!1="lon"
>>   lon2d&lon=lon
>>   lon2d&lat=lat
>>
>>   minLatBoundary  = 25
>>   maxLatBoundary  = 35
>>   minLonBoundary  = 110
>>   maxLonBoundary  = 120
>>
>>   sm   = f->sm_rootzone
>>   printVarSummary(sm)
>>   sm!0="lat"
>>   sm!1="lon"
>>   sm&lon=lon
>>   sm&lat=lat
>>   printVarSummary(sm)
>>
>>   sm_regional = sm({minLatBoundary:maxLatBoundary},{minLonBoundary:
>> maxLonBoundary})
>> ***********************************
>>
>> Thanks a lot for your precious attentions and time!
>>
>> Yi Lu
>>
>>
>>
>>
>>
>> 易路
>>
>> 南大邮件系统/学生/博士生/12级博士生
>>
>> 南京市汉口路22号
>>
>> ------------------------------
>> *从腾讯企业邮箱发来的超大附件*
>>
>> <http://exmail.qq.com/cgi-bin/ftnExs_download?k=523465623d8c4a92182f6ffe1038075719575c5a030c065706190304015b1d51000c504f0e0e55561b075257010c0452050d070051381e65657924326874043a65793a0547506f57060550520f0905310605565207086f334007555107670055181a4b4c5f0d3058&t=exs_ftn_download&code=64eb780e&s=email>
>> SMAP_L4_SM_gph_20150815T013000_Vv3030_001.h5
>> <http://exmail.qq.com/cgi-bin/ftnExs_download?k=523465623d8c4a92182f6ffe1038075719575c5a030c065706190304015b1d51000c504f0e0e55561b075257010c0452050d070051381e65657924326874043a65793a0547506f57060550520f0905310605565207086f334007555107670055181a4b4c5f0d3058&t=exs_ftn_download&code=64eb780e&s=email>
>> (136.33M, 2018年01月12日 11:27 到期)
>> 进入下载页面
>> <http://exmail.qq.com/cgi-bin/ftnExs_download?k=523465623d8c4a92182f6ffe1038075719575c5a030c065706190304015b1d51000c504f0e0e55561b075257010c0452050d070051381e65657924326874043a65793a0547506f57060550520f0905310605565207086f334007555107670055181a4b4c5f0d3058&t=exs_ftn_download&code=64eb780e&s=email>
>>http://exmail.qq.com/cgi-bin/ftnExs_download?k=523465
>> 623d8c4a92182f6ffe1038075719575c5a030c065706190304015b1d5100
>> 0c504f0e0e55561b075257010c0452050d070051381e6565792432687404
>> 3a65793a0547506f57060550520f0905310605565207086f334007555107
>> 670055181a4b4c5f0d3058&t=exs_ftn_download&code=64eb780e&s=email
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171215/a0d2ac85/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst.smap_rectilinear.ncl
Type: application/octet-stream
Size: 3167 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171215/a0d2ac85/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smap_single_picture_YiLu.png
Type: image/png
Size: 130529 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171215/a0d2ac85/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smap_regional.ncl_YiLu
Type: application/octet-stream
Size: 3874 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171215/a0d2ac85/attachment-0001.obj>


More information about the ncl-talk mailing list