Re: contour plots lat/lon arrays

From: Dennis Shea (shea AT cgd.ucar.edu)
Date: Thu Apr 21 2005 - 10:15:28 MDT

  • Next message: Mary Haley: "Re: Drawing grid-lines for Lambert Conformal Grid"

    The issue is meta data.

    NCL variables can be simple value only.
    However, in general NCL variables are structures
    or data objects. The variables can contain
    values and, possibly, additional information
    such as attributes and coordinate variables ... ie: meta data.

    When reading from a supported format [nc, grb, hdf]
    it imports the structure. This is different from
    fortran/C/C++/IDL/Matlab/.. where the user must
    read these indivudually. NCL does all this work for you.

    NCL allows users to access/create/change these
    using syntax [@, !, &]. NCL functions can query
    variables [eg: isatt, iscoord, ...]. Think
    "tell me about yourself". then the function/procedure
    can act appropriately.

    The gsn_csm* suite of plot interfaces is "aware"
    of COARDS/CSM/CF netCDF meta data conventions.

    Thus, when you call use

        plot = gsn_csm_contour_map_ce(wks, x , res)
        
    it queries the variable "x" for attribues [eg: long_name
    and units] and checks for coordinate variable associated
    with "x". These coordinate variables are expected to conform
    to those of, say, the COARDS convention. Specifically,
    the coordinate variables are expected to have units
    as specified Unidata's udunits. eg: the coordinate
    variables are expected to have something like
    "degrees_east", "degrees_north"

    Also, note that NCL does not pass meta data to a variable
    on the left hand side of the = when doing
    any type of operation on the right hand side.

    Thus,

          diff = A-B
          
    diff has no meta data. [ try: printVarSummary(diff) ]

    If u do want meta data a simple 'trick' is the following

          diff = A ; no operation so values and meta data are passed
          diff = A-B ; only differences are assigned to diff
                         ; meta data associated with diff is retained
          diff@long_name = "Diff: A-B" ; cahnge this attribute
          printVarSummary(diff)
          
    In your case:
          LH_diff = LH(0,:,:) ; create new array with meta
          LH_diff = LH(0,:,:) - LHOI(0,:,:) ; overwrite with differences
                                                ; meta data unaffected
          LH_diff@long_name = "..."
          printVarSummary(LH_Diff)
          
     
    > wks = create "fluxWork" psWorkstationClass defaultapp
    > "wkPSFileName" : "./lhcompare.ps"
    > end create

    I suggest that the above be replaced with the more conventional
          wks = gsn_open_wks("ps" ,"lhcompare") ; ps,pdf,x11,ncgm,eps
          
    D

    >
    >Hello,
    >
    >I am using gsn_csm_contour_map_ce to create contour plots. I am reading
    >in variables from a netcdf file from running CAM3.1. If I just read in
    >some variables and plot them using gsn_csm_contour_map_ce, everything
    >works fine, however I need to difference some variables that I am
    >reading in. After I subtract the variables and store their difference
    >in a new variable and attempt to plot that, I get the following error
    >messages:
    >-----------------------------------------------------
    >(0) check_for_y_lat_coord: Warning: Data either does not contain a
    >valid latitude coordinate array or doesn't contain one at all.
    >(0) A valid latitude coordinate array should have a 'units'
    >attribute equal to one of the following values:
    >(0) 'degrees_north' 'degrees-north' 'degree_north' 'degrees
    >north' 'degrees_N' 'Degrees_north' 'degree_N' 'degreeN' 'degreesN'
    >(0) check_for_lon_coord: Warning: Data either does not contain a
    >valid longitude coordinate array or doesn't contain one at all.
    >(0) A valid longitude coordinate array should have a 'units'
    >attribute equal to one of the following values:
    >(0) 'degrees_east' 'degrees-east' 'degree_east' 'degrees east'
    >'degrees_E' 'Degrees_east' 'degree_E' 'degreeE' 'degreesE'
    >----------------------------------------------------
    >
    >I am not sure how to carry the lat/lon coords and their units through
    >the subtraction of the variables. Here is what I've been doing so far:
    >
    >---------------------------------------------------------
    >
    > load "/usr/local/NCL/lib/ncarg/nclscripts/csm/gsn_code.ncl"
    > load "/usr/local/NCL/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
    > load "/usr/local/NCL/lib/ncarg/nclscripts/csm/contributed.ncl"
    >
    >
    >
    >
    > datafile_TPLIO =
    >"/mnt/usb-drive/ccm33/alexeyruns/TPLIO_11yrs/camrun_TPLIO_11yrs.cam2.h0.0000-09
    .nc"
    >
    >
    >;*************************************************************************
    >
    >
    > fils = systemfunc ("ls
    >/mnt/usb-drive/ccm33/alexeyruns/TPLIO_11yrs/camrun_TPLIO_11yrs.cam2.h0.*")
    > f = addfiles (fils+".nc", "r")
    > LH = addfiles_GetVar (f, fils, "LHFLX")
    > FL = addfiles_GetVar (f, fils, "FLNS")
    > FS = addfiles_GetVar (f, fils, "FSNS")
    > LHOI = addfiles_GetVar (f, fils, "LHFLXOI")
    > FLOI = addfiles_GetVar (f, fils, "FLNSOI")
    > FSOI = addfiles_GetVar (f, fils, "FSNSOI")
    > mfile = addfile (datafile_TPLIO, "r")
    >;*************************************************************************
    >
    >
    > wks = create "fluxWork" psWorkstationClass defaultapp
    > "wkPSFileName" : "./lhcompare.ps"
    > end create
    >
    >
    > gsn_define_colormap(wks,"ncview_default")
    >
    >
    > plots = new(3,graphic) ; Create variable to hold plots.
    >
    >
    >;***********************************************************************
    >
    >
    > LH_diff = LH(0,:,:) - LHOI(0,:,:)
    >
    >
    > resources = True
    > resources@gsnFrame = False
    > resources@gsnDraw = False
    > resources@cnFillOn = True
    > resources@cnInfoLabelOn = True
    > resources@cnLinesOn = True
    > resources@gsnSpreadColors = True
    > resources@cnLevelSelectionMode = "ManualLevels"
    > resources@cnLevelSpacingF = 20.
    > resources@mpCenterLonF = 180.0
    >
    > resources@cnMinLevelValF = -40.
    > resources@cnMaxLevelValF = 160.
    > plots(0) = gsn_csm_contour_map_ce(wks,LH(0,:,:),resources)
    >
    >
    > resources@tiMainString = "LHFLXOI"
    > plots(1) = gsn_csm_contour_map_ce(wks,LHOI(0,:,:),resources)
    >
    >
    >
    > resources@cnMinLevelValF = -5.0
    > resources@cnMaxLevelValF = 5.0
    > resources@cnLevelSpacingF = 1.0
    > resources@tiMainString = "Difference"
    > plots(2) = gsn_csm_contour_map_ce(wks,LH_diff(:,:),resources)
    >
    >
    > pres1 = True
    > pres1@gsnFrame = False
    >
    >
    > gsn_panel(wks,plots,(/3,1/),pres1)
    >
    >
    >--------------------------------------------------------------------
    >
    >Thanks,
    >Cathy
    >
    >--
    >Cathryn Meyer
    >Department of Geology and Geophysics
    >Yale University
    >cathryn.meyer@yale.edu
    >(203)432-1959
    >_______________________________________________
    >ncl-talk mailing list
    >ncl-talk@ucar.edu
    >http://mailman.ucar.edu/mailman/listinfo/ncl-talk

    _______________________________________________
    ncl-talk mailing list
    ncl-talk@ucar.edu
    http://mailman.ucar.edu/mailman/listinfo/ncl-talk



    This archive was generated by hypermail 2b29 : Thu Apr 21 2005 - 10:28:29 MDT