[ncl-talk] set_dimension_query

Marston Johnston shejo284 at gmail.com
Tue Sep 19 03:03:49 MDT 2017


It tells you in the warning message, exactly what to do to remove the warning.

If you want to improve you coding skills, it would better to understand why the warning is occurring in the first place: dimension 0 and 1 of the variable you are passing has no names or the names do not match the variable on the lhs.

 

/M

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Marston S. Ward, PhD

Department of Earth Sciences

University of Gothenburg, Sweden

Email: marston.johnston at gu.se

SkypeID: marston.johnston 

Phone: +46-31-7864901 

Only the fruitful thing is true!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

 

From: ncl-talk <ncl-talk-bounces at ucar.edu> on behalf of Kunal Bali <kunal.bali9 at gmail.com>
Date: Tuesday, 19 September 2017 at 10:50
Cc: "ncl-talk at ucar.edu" <ncl-talk at ucar.edu>
Subject: Re: [ncl-talk] set_dimension_query

 

Thank you for providing this information. 

It's working. The script given below is now able to convert multiple files into .netcdf with the desired file name.  
However, on the same time, it also shows some warnings. But noted that, I am successfully creating the multiple files into the netcdf. I just need to know that how can I remove these warnings? 

warning:VarVarWrite: Dimension names for dimension number (0) don't match, assigning name of rhs dimension to lhs and overwriting coordinate variable, use "(/../)" if this change is not desired
warning:VarVarWrite: Dimension names for dimension number (1) don't match, assigning name of rhs dimension to lhs and overwriting coordinate variable, use "(/../)" if this change is not desired
warning:["Execute.c":8640]:Execute: Error occurred at or near line 22 in file netcdf2.ncl

 

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

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

        diri = "/Users/Pushp/Desktop/test/"   ; input directory
        fili  = systemfunc("cd "+diri+" ; ls MAIACTAOT.h00v02*hdf")
        nfili = dimsizes(fili)
        print("nfili="+nfili)

 
        dirnc = "/Users/Pushp/Desktop/test/"   ; output (netCDF) directory

        do nf=0,nfili-1
        pthi = diri+fili(nf)
        f    = addfile(pthi,"r")

        var  = short2flt(f->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&lon = lon

     
     filroot = str_get_cols(fili(nf), 0, 27)  ; eg: "MAIACTAOT.h00v02.20000570505"
     filnc    = filroot+".nc"
     pthnc  = dirnc + filnc 

     system("/bin/rm -f "+pthnc) 
     ncdf = addfile(pthnc,"c")  ; open new netCDF file

    
     end do    ; end 'nf' loop
        
   ;     system("/bin/rm -f simple2.nc") 
   ;     ncdf = addfile("simple2.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&lat = lat
;       ncdf->var&lon = lon
       ncdf->var = var

end


Kunal Bali

Research Scholar 

Radio & Atmospheric Science Division 

CSIR - National Physical Laboratory

New Delhi - 110012

India

 

 

 

 

 

On Mon, Sep 18, 2017 at 9:04 PM, Dennis Shea <shea at ucar.edu> wrote:

Loop over the files ...


 diri = "/media/Local Disk/NPL/MODIS_FPC/"   ; input directory

 fili  = systemfunc("cd "+diri +; ls MAIACTAOT.h00v02*hdf")

 nfili = dimsizes(fili)

 print("nfili="+nfili)

 dirnc = "/media/Local Disk/NPL/MODIS_FPC/"   ; output (netCDF) directory

 

 do nf=0,nfili-1

      pthi = diri+fili(nf)

      f      = addfile(pthi,"r")

      ....

     filroot = str_get_cols(fili(nf), 0, 27)  ; eg: "MAIACTAOT.h00v02.20000570505"

     filnc    = filroot+".nc"

     pthnc  = dirnc + filnc

     system("/bin/rm -f "+pthnc)  
     ncdf = addfile(pthnc,"c")  ; open new netCDF file

     ....


end do    ; end 'nf' loop


=====

If there is something you do not understand use some print statements.

Become familiar with the 'string' category. Look at all the functions.

   https://www.ncl.ucar.edu/Document/Functions/string.shtml

Please read the documentation for the function used above

   https://www.ncl.ucar.edu/Document/Functions/Built-in/str_get_cols.shtml

Good Luck

 

 

On Mon, Sep 18, 2017 at 6:11 AM, Kunal Bali <kunal.bali9 at gmail.com> wrote:

Thnks for the reply. 

 

that will change the name of only one file. isn't it. but what about the other files 

I have 365 files in one directory and I need to change all the file name one by one.


Kunal Bali

 

 

 

 

 

On Mon, Sep 18, 2017 at 5:14 PM, Dennis Shea <shea at ucar.edu> wrote:

Really? 

Change:
      system("/bin/rm -f simple.nc")  
      ncdf = addfile("simple.nc" ,"c") 

To:
      system("/bin/rm -f MAIACTAOT.h00v02.20000570505.nc")  
      ncdf = addfile("MAIACTAOT.h00v02.20000570505.nc" ,"c") 

 

 

On Mon, Sep 18, 2017 at 12:37 AM, Kunal Bali <kunal.bali9 at gmail.com> wrote:

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.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.h00v02.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.h00v02.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 

 

 


_______________________________________________
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 

 

 

 

 


_______________________________________________
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 

 

 


_______________________________________________
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

 

 

_______________________________________________ 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/20170919/55365ce0/attachment.html>


More information about the ncl-talk mailing list