[ncl-talk] set_dimension_query
Kunal Bali
kunal.bali9 at gmail.com
Mon Sep 18 00:37:08 MDT 2017
Thanks, it worked.
one more question is that.
I used the code (given below). So it gives simple.nc name as an output file.
ncdf = addfile("simple.nc" ,"c")
If I want to keep the original file name with the output file name then
what should I do?
I mean the original file name is MAIACTAOT.h00v02.20003660700.hdf
Now I want to create my netcdf file name as MAIACTAOT.h00v02.20003660700.nc
NOT simple.nc.
I can not simply write simple.nc file name because I have many files.
e.g I have one directory having 365 .hdf file. So I need to convert all the
hdf file to netcdf file at once with the same name of original file names.
I hope you have got my query.
please let me know that too.
Thank You
Kunal Bali
On Thu, Sep 14, 2017 at 9:09 PM, Adam Phillips <asphilli at ucar.edu> wrote:
> Hi Kunal,
> It looks to me like your latitudes are flipped. You are setting up and
> assigning your coordinate lat/lon variables in this coding:
>
> 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
>
> Assuming I'm right on your latitudes being the issue, one of the following
> two modifications should work:
> Delete this line:
> lat = lat(::-1)
>
> If the above doesn't fix it, try this:
> Change this:
> lat = lat(::-1)
> to this:
> lat = lat(::-1)
> lat&lat = lat
>
> If you continue to have issues please respond to ncl-talk.
> Adam
>
> On Wed, Sep 13, 2017 at 12:35 PM, Kunal Bali <kunal.bali9 at gmail.com>
> wrote:
>
>>
>> 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.h
>> 00v02.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 <(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/20170918/f3207842/attachment.html>
More information about the ncl-talk
mailing list