Log In | Users | Register
Edit | Attach | New | Raw | Diff | Print | | Tools
You are here: Data » DocTools » ToolsVis » VisNCL » VisNCLFirstSteps

First Steps

This page is a 9 step/5 minute tutorial illustrating an interactive NCL session. It does not make use of the COSMO library and is intended solely to give a new user an impression of how NCL can be used interactively to make a simple contour plot.

Step 1: First, let's start NCL...

olifu@buin1:~[151]> ncl
 Copyright (C) 1995-2007 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 5.0.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
ncl 0> 

Step 2: Now, let's open an operational COSMO-2 run. In the example below, you will need to adapt the file name to match a current run. Don't forget to add the .grb extension to the file name, event if the file does not have it. This extension tells NCL that you are opening a grib file.

ncl 0> f=addfile("/opr/osm/traj/LATEST_RUN/09010500_857/lm_coarse/lfff00000000.grb","r")
ncl 1>

Step 3: Let's look at the contents of the file. NCL maps the grib file into a COSMO.NetCDF-like data structure with dimensions, variables and attributes.

ncl 1> print(f)

Variable: f
(0)
filename:       lfff00000000
path:   /opr/osm/traj/LATEST_RUN/09010500_857/lm_coarse/lfff00000000
   file global attributes:
   dimensions:
      g10_x_0 = 338
      g10_y_1 = 393
      lv_HYBY2 = 60
      g10_x_3 = 338
      g10_y_4 = 393
      g10_x_5 = 338
      g10_y_6 = 393
      lv_HYBL7 = 61
      ncl_scalar = 1
      lv_DBLY9 = 2
      lv_HYBL10 = 60
      lv_DBLL11 = 9
      lv_DBLL12 = 8
   variables:
      float P_GDS10_SFC ( g10_x_0, g10_y_1 )
         center :       Zurich
         long_name :    pressure
         units :        Pa
         _FillValue :   -999
         coordinates :  g10_lat_0 g10_lon_1
         level_indicator :      1
         gds_grid_type :        10
         parameter_table_version :      2
         parameter_number :     1
         forecast_time :        0
         forecast_time_units :  hours
         initial_time : 01/05/2009 (00:00)

...

ncl 2>

Step 4: Now let's load a variable from the file into a NCL variable. Note that NCL automagically maps corresponding 2-dimensional grib records into a 3-dimensional field. Here, we will load the pressure...

ncl 2> p=f->P_GDS10_HYBY

Step 5: Now let's inspect the contents of the variable. NCL variables have values but also dimensions and attributes. In order to inspect the dimensions and attributes you can use the printVarSummary command. If you also want to inspect the values, use the print command.

ncl 3> printVarSummary(p)


Variable: p
Type: float
Total Size: 31880160 bytes
            7970040 values
Number of Dimensions: 3
Dimensions and sizes:   [lv_HYBY2 | 60] x [g10_x_0 | 338] x [g10_y_1 | 393]
Coordinates: 
Number Of Attributes: 12
  center :      Zurich
  long_name :   pressure
  units :       Pa
  _FillValue :  -999
  coordinates : g10_lat_0 g10_lon_1
  level_indicator :     110
  gds_grid_type :       10
  parameter_table_version :     2
  parameter_number :    1
  forecast_time :       0
  forecast_time_units : hours
  initial_time :        01/05/2009 (00:00)
ncl 4> 

Step 6: As a next step, we would like to make a plot of the pressure field. In order to do that, we first need to load some libraries which facilitate plotting for us.

ncl 4> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
ncl 5> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

Step 7: That's done. Now we need to open a graphics port. A graphics port can be anything, such as a X11 window (x11), a PostScript file (ps), a PDF file (pdf) or a NCAR graphics meta file. Normally, you will use x11 for debugging and pdf or ps for production.

ncl 6> wks = gsn_open_wks("x11","pressure")

Step 8: Now we can make a contour plot of the pressure on the lowest model level. Note that indices in NCL are zero-based and that the COSMO model numbers model levels inversely with height. Thus, index 59 corresponds to the lowest model level if we have a total of 60 model levels. After issuing the following command, a plot should appear. Click inside the plot window with your mouse to continue...

ncl 7> plot = gsn_csm_contour(wks,p(59,:,:),False)

X11_pressure.png

Step 9: As a last step, we want to exit the interactive NCL session.

ncl 8> exit

Note that you can put all of the above commands into a scripts file (test.ncl) and execute ncl with the script file as an argument in order to achieve the same results non-interactively.

NCL is much more than the few lines you have typed above. The NCL Gallery will give you a hint of the myriad of plots that NCL can produce for you. And now have fun exploring the possibilities of NCL!!!

-- OliverFuhrer - 28 Jan 2009

Attach
png
version 1 uploaded by OliverFuhrer on 27 Jan 2009 - 10:04
spacer
This site is managed by the Center for Climate Systems Modeling (C2SM).
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems? Send feedback!