[ncl-talk] set_dimension_query

Kunal Bali kunal.bali9 at gmail.com
Wed Sep 13 12:35:38 MDT 2017


For direct output as a netcdf format, I used the script given below. It
produced the netcdf file easily. But the netcdf file and original hdf file
both showing the different results. The data pattern is shifted. I mean it
may be related to the lat lon position. please see the attached file, you
will understand.  And please let me know which one is correct.

;----------------------------------------------------------------------

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

begin
;---Read data
        a = addfile("/media/Local
Disk/NPL/MODIS_FPC/MAIACTAOT.h00v02.20000570505.hdf","r")
        var  = short2flt(a->Optical_Depth_055(:,:))
            ;          short2flt(a[:]->noxfire)
        nlat = 1200
        nlon = 1200
        lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north")
        lon = lonGlobeFo(nlon, "lon", "longitude", "degrees_east")
        lat = lat(::-1)
        lon = (/ lon - 180. /)  ; subtract 180 from all values
        lon&lon = lon           ; update coordinates

        var!0 = "lat"    ; you can name these dimensions whatever you want..
        var!1 = "lon"
        var&lat = lat     ; but make sure you refer to the correct named
dimensions
        var&lon = lon

                 system("/bin/rm -f simple.nc")
             ncdf = addfile("simple.nc" ,"c")  ; open output netCDF file

    ;===================================================================
    ; create global attributes of the file (optional)
    ;===================================================================
       fAtt               = True            ; assign file attributes
       fAtt at title         = "NCL Simple Approach to netCDF Creation"
       fAtt at source_file   =  "original-file.nc"
       fAtt at Conventions   = "None"
       fAtt at creation_date = systemfunc ("date")
       fileattdef( ncdf, fAtt )            ; copy file attributes

    ;===================================================================
    ; make time an UNLIMITED dimension; recommended  for most applications
    ;===================================================================
       filedimdef(ncdf,"time",-1,True)
       ncdf->var = var

end




Kunal Bali






On Wed, Sep 13, 2017 at 11:27 PM, Kunal Bali <kunal.bali9 at gmail.com> wrote:

> No problem, I sorted out.
>
> Just changed short to float.
>
> Kunal Bali
> Research Scholar
> Radio & Atmospheric Science Division
> CSIR - National Physical Laboratory
> New Delhi - 110012
> India
>
>
>
>
>
> On Wed, Sep 13, 2017 at 11:24 PM, Kunal Bali <kunal.bali9 at gmail.com>
> wrote:
>
>> Thanks for providing this information.
>>
>> Also, I would like to mention that when I plot this data. The values are
>> not in the domain. I mean the real values lie in-between 0 to 1 but here it
>> is reaching to 400.
>>
>> So, how to correct the values?
>>
>> Description of the variable is
>>
>> short Optical_Depth_055(YDim=1200, XDim=1200);
>>   :long_name = "AOT at 0.55 micron";
>>   :scale_factor = 0.001; // double
>>   :add_offset = 0.0; // double
>>   :unit = "None";
>>   :_FillValue = -28672S; // short
>>   :valid_range = -100S, 5000S; // short
>>
>>
>>
>>
>> Kunal Bali
>>
>>
>>
>>
>>
>>
>> On Wed, Sep 13, 2017 at 10:28 PM, Adam Phillips <asphilli at ucar.edu>
>> wrote:
>>
>>> Hi Kunal,
>>> Yes, clicking on the output netCDF link from the Applications page:
>>> http://www.ncl.ucar.edu/Applications/o-netcdf.shtml
>>> I would recommend following the inefficient method #1. Unless you are
>>> writing a file with many large variables, the inefficient method works just
>>> fine.
>>> http://www.ncl.ucar.edu/Applications/method_1.shtml
>>> Good luck,
>>> Adam
>>>
>>> On Wed, Sep 13, 2017 at 10:25 AM, Kunal Bali <kunal.bali9 at gmail.com>
>>> wrote:
>>>
>>>> Thank you so much, it worked
>>>>
>>>> I want to know one more thing.
>>>> After rearranging the dimensions can we now convert (or write) this
>>>> arranged file into netcdf format?
>>>>
>>>>
>>>>
>>>> Kunal Bali
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Wed, Sep 13, 2017 at 8:55 PM, Adam Phillips <asphilli at ucar.edu>
>>>> wrote:
>>>>
>>>>> Hi Kunal,
>>>>> I think you just need to rearrange the order of your lines and tweak a
>>>>> couple of lines. As the error message states, lat is not defined in your
>>>>> 3rd line and you are referring to it as if it is.Try this:
>>>>> a = addfile("/media/Local Disk/NPL/MODIS_FPC/MAIACTAOT.h
>>>>> 00v02.20000570505.hdf","r")
>>>>> var  = a->Optical_Depth_055(:,:)
>>>>> nlat = 1200
>>>>> nlon = 1200
>>>>> lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north")
>>>>> lon = lonGlobeFo(nlon, "lon", "longitude", "degrees_east")
>>>>> lat = lat(::-1)
>>>>> lon = (/ lon - 180. /)  ; subtract 180 from all values
>>>>> lon&lon = lon           ; update coordinates
>>>>>
>>>>> var!0 = "lat"    ; you can name these dimensions whatever you want..
>>>>> var!1 = "lon"
>>>>> var&lat = lat     ; but make sure you refer to the correct named
>>>>> dimensions
>>>>> var&lat = lon
>>>>> ;var&XDim_grid1km = lat
>>>>> ;var&YDim_grid1km = lon
>>>>>
>>>>> If you have any further questions please respond to the ncl-talk email
>>>>> list.
>>>>> Adam
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Sep 13, 2017 at 8:38 AM, Kunal Bali <kunal.bali9 at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Dear NCL
>>>>>>
>>>>>> I have a file with the variable summary. The dimensions are in 2D.
>>>>>>
>>>>>> ncl 2>  printVarSummary(var)
>>>>>>
>>>>>> Variable: var
>>>>>> Type: short
>>>>>> Total Size: 2880000 bytes
>>>>>>             1440000 values
>>>>>> Number of Dimensions: 2
>>>>>> Dimensions and sizes:    [*YDim_grid1km | 1200] x [XDim_grid1km |
>>>>>> 1200]*
>>>>>> Coordinates:
>>>>>> Number Of Attributes: 7
>>>>>>   long_name :    AOT at 0.55 micron
>>>>>>   scale_factor :    0.001
>>>>>>   add_offset :       0
>>>>>>   unit :    None
>>>>>>   _FillValue :    -28672
>>>>>>   valid_range :    ( -100, 5000 )
>>>>>>   hdf_name :    Optical_Depth_055
>>>>>>
>>>>>>
>>>>>> I am trying to read the dimensions of this file as
>>>>>>
>>>>>> begin
>>>>>> ;---Read data
>>>>>>          a = addfile("/media/Local Disk/NPL/MODIS_FPC/MAIACTAOT.h
>>>>>> 00v02.20000570505.hdf","r")
>>>>>>
>>>>>>             var  = a->Optical_Depth_055(:,:)
>>>>>>
>>>>>>          var&XDim_grid1km = lat
>>>>>>          var&YDim_grid1km = lon
>>>>>>
>>>>>>         nlat = 1200
>>>>>>          nlon = 1200
>>>>>>             lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north")
>>>>>>         lon = lonGlobeFo(nlon, "lon", "longitude", "degrees_east")
>>>>>>             lat = lat(::-1)
>>>>>>             lon = (/ lon - 180. /)  ; subtract 180 from all values
>>>>>>             lon&lon = lon           ; update coordinates
>>>>>>
>>>>>>
>>>>>>         var!0 = "lat"
>>>>>>         var!1 = "lon"
>>>>>>
>>>>>>
>>>>>> But the error appeared as
>>>>>> *fatal:Variable (lat) is undefined*
>>>>>>
>>>>>>
>>>>>> So, could anyone please let me know that how to read dimension of
>>>>>> this file.
>>>>>>
>>>>>> Thank You
>>>>>>
>>>>>>
>>>>>> Regards
>>>>>> Kunal Bali
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> ncl-talk mailing list
>>>>>> ncl-talk at ucar.edu
>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Adam Phillips
>>>>> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
>>>>> www.cgd.ucar.edu/staff/asphilli/   303-497-1726 <(303)%20497-1726>
>>>>>
>>>>> <http://www.cgd.ucar.edu/staff/asphilli>
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> ncl-talk at ucar.edu
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
>>>
>>>
>>> --
>>> Adam Phillips
>>> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
>>> www.cgd.ucar.edu/staff/asphilli/   303-497-1726
>>>
>>> <http://www.cgd.ucar.edu/staff/asphilli>
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170914/d8c3b54e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: output_from_netcdf.png
Type: image/png
Size: 81222 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170914/d8c3b54e/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: output_from_hdf.png
Type: image/png
Size: 199153 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170914/d8c3b54e/attachment-0003.png>


More information about the ncl-talk mailing list