[Thread Prev][Thread Next][Index]

Re: [ferret_users] How to read WRF output and plot ?



This has also been asked in the GitHub issue. 

I have some ideas which I posted there and will add here.

I have looked into this some more. It seems that the format for wrf files is not consistent with the COARDS and CF netCDF standards used by PyFerret https://www.ncl.ucar.edu/Applications/wrfnetcdf.shtml

I expect that this problem will be resolved with updates that are in the code base but not yet in a PyFerret release. I do not know what the plans are for the next release.

However, I have a suggestion, which I'd like to add here. I will show it using a small example file, attached to this message. This is a file from a previous question, which I think shows the behavior that is seen in the wrf files. Its netCDF header looks like this:
netcdf sample_wrf { dimensions: Time = UNLIMITED ; // (13 currently) bottom_top = 2 ; south_north = 6 ; west_east = 7 ; variables: float FNM(Time, bottom_top) ; FNM:FieldType = 104 ; FNM:MemoryOrder = "Z " ; FNM:description = "upper weight for vertical stretching" ; FNM:units = "" ; FNM:stagger = "" ; float P(Time, bottom_top, south_north, west_east) ; P:FieldType = 104 ; P:MemoryOrder = "XYZ" ; P:description = "perturbation pressure" ; P:units = "Pa" ; P:stagger = "" ; // global attributes: :TITLE = "Grids as in WRF model" ; :history = "Downloaded orig file from link at https://www.riinu.me/2014/05/saving-subset/" ; }
The note you are seeing about axis coordinates suggests that PyFerret would use attributes on coordinate variables to determine the directions of the dimensions when it is defining grids. The file with coordinate variables would look like this, when listed using ncdump -c
netcdf sample_wrf { dimensions: Time = UNLIMITED ; // (13 currently) bottom_top = 2 ; south_north = 6 ; west_east = 7 ; variables: double Time(Time) ; Time:axis = "T" ; double bottom_top(bottom_top) ; bottom_top:axis = "Z" ; double south_north(south_north) ; south_north:axis = "Y" ; double west_east(west_east) ; west_east:axis = "X" ; float FNM(Time, bottom_top) ; FNM:FieldType = 104 ; FNM:MemoryOrder = "Z " ; FNM:description = "upper weight for vertical stretching" ; FNM:units = "" ; FNM:stagger = "" ; float P(Time, bottom_top, south_north, west_east) ; P:FieldType = 104 ; P:MemoryOrder = "XYZ" ; P:description = "perturbation pressure" ; P:units = "Pa" ; P:stagger = "" ; // global attributes: :TITLE = "Grids as in WRF model" ; :history = "Downloaded orig file from link at https://www.riinu.me/2014/05/saving-subset/" ; data: Time = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ; bottom_top = 1, 2 ; south_north = 1, 2, 3, 4, 5, 6 ; west_east = 1, 2, 3, 4, 5, 6, 7 ; }

We can create a new, separate netCDF file that contains the desired coordinate variables. Then use the netcdf utility ncks to add the coordinate variables to the wrf file.

Here is a Ferret script to write a dummy file with the desired "axis" attributes. The appropriate axis attributes are automatically written by modern Ferret and PyFerret.

! Define the coordinate axes, the dimension names and lengths from the wrf file. Keep ! the same upper-case and lower-case spellings as in the file. define axis/t=1:13:1 Time define axis/z=1:2:1 bottom_top define axis/y=1:6:1 south_north define axis/x=1:7:1 west_east ! Define variables on these axes to write to a new netCDF file. let/title=Time tcoord = t[gt=Time] let/title=bottom_top zcoord = z[gz=bottom_top] let/title=south_north ycoord = y[gy=south_north] let/title=west_east xcoord = x[gx=west_east] ! Write the dummy variables. We will get the coordinate axes from this file. cancel mode upcase save/clobber/file=wrf_axes.nc tcoord, zcoord, ycoord, xcoord
Now, use the Unix ncks utility to copy the coordinate variables into the wrf file. (make a copy of the file if you want to keep the original)
> ncks -A -h -v Time wrf_axes.nc sample_wrf.nc > ncks -A -h -v bottom_top wrf_axes.nc sample_wrf.nc > ncks -A -h -v south_north wrf_axes.nc sample_wrf.nc > ncks -A -h -v west_east wrf_axes.nc sample_wrf.nc
Now, sample_wrf.nc will open.


On 9/5/2021 3:37 AM, Jeevan Kumar wrote:

I have wrfout file at one time step and trying to open in ferret. but I am having error like this (below)

(```
base) jeevan@MacBook-Pro idojaros % pf
 	NOAA/PMEL TMAP
 	PyFerret v7.63 (optimized)
 	Darwin 19.6.0 - 10/13/20
 	 5-Sep-21 12:14     

yes? use wrfout_d01_2020-01-16_00:00_jk_E_G.nc
           *** NOTE:
           *** NOTE: Could not adjust grid for variable ZNU
 **ERROR: inconsistent data grids: File needs axis attributes on coordinate variables indicating correct directions
yes? sh d
     currently SET data sets:
yes? q

How can I solve this ?

Best Regards
Jeevan Kumar
https://www.linkedin.com/in/jeevan-kumar-bodaballa-193b7691/



Attachment: sample_wrf.nc
Description: Binary data


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement