⇐ ⇒

[CF-metadata] why not use attributes instead of scalar variables for terms in dimensionless vertical coordinates...

From: Brian Eaton <eaton>
Date: Thu, 5 Oct 2006 12:59:25 -0600

Hi Ed,

I think I prefer to keep the formula terms as variables for the following
reasons:

1. Generally we use variables rather than attributes for values that may
   need (or benefit from) having associated metadata. The example of ptop
   is a variable whose value must be in units that are consistent with
   those of ps. I think it's more robust to put this data into a variable
   that has a units attribute. Having units associated with both ptop and
   ps allows the application to make a simple consistency check.

2. Many, if not most, of the formula terms are multi-dimensional arrays
   that must be stored in variables. A general heuristic for ease of use
   is to not have multiple ways to do the same thing. Storing formula
   terms as either scalar variables or attributes violates this principle.

Brian



On Thu, Oct 05, 2006 at 08:30:38AM -0600, Ed Hartnett wrote:
> Howdy all!
>
> I am in the midst of writing some functions to handle reading and
> writing the dimensionless vertical coordinates listed in appendix D of
> the CF document.
>
> Many of these use scalar variables to hold reference values. For
> example:
>
> standard_name = "atmosphere_sigma_coordinate"
>
> Definition:
>
> p(n,k,j,i) = ptop + sigma(k)*(ps(n,j,i)-ptop)
>
> where p(n,k,j,i) is the pressure at gridpoint (n,k,j,i), ptop is
> the pressure at the top of the model, sigma(k) is the dimensionless
> coordinate at vertical gridpoint (k), and ps(n,j,i) is the surface
> pressure at horizontal gridpoint (j,i) and time (n).
>
> The format for the formula_terms attribute is
>
> formula_terms = "sigma: var1 ps: var2 ptop: var3"
>
> In this case, PTOP is a scalar value.
>
> If this were an attribute and not a variable, libcf could do more for
> the user.
>
> When setting up a sigma coordinate file with libcf, I do this:
>
> /* Create a file and define four coordinate varibles, lat, lon,
> * sigma level, and time. */
> if (nc_create(FILE_NAME, 0, &ncid)) ERR;
> if (nccf_def_latitude(ncid, NLAT, NC_FLOAT, &lat_did, &lat_vid)) ERR;
> if (nccf_def_longitude(ncid, NLON, NC_FLOAT, &lat_did, &lat_vid)) ERR;
>
> /* Before we can define a sigma level coordinate var/dim, we
> * need to define two variables, the surface pressure and PTOP
> * (a scalar).*/
> dimids[0] = lat_did;
> dimids[1] = lon_did;
> if (nc_def_var(ncid, "ps", NC_FLOAT, 2, dimids, &ps_vid)) ERR;
> if (nc_def_var(ncid, "PTOP", NC_FLOAT, 0, NULL, &ptop_vid)) ERR;
>
> /* Now define sigma level coordinage var and dim. */
> if (nccf_def_lvl_sigma(ncid, "sigma", NC_FLOAT, NLVL, ps_vid, ptop_vid,
> &lvl_did, &lvl_vid)) ERR;
>
> /* Now define the time coordinate. */
> if (nccf_def_time(ncid, "time", NC_UNLIMITED, NC_FLOAT, TIME_UNITS,
> "time", &lat_did, &lat_vid)) ERR;
>
>
> As you can see, the function nccf_def_lvl_sigma takes the variable IDs
> of the surface pressure variable (ps_vid), and the PTOP variable
> (ptop_vid).
>
> This works fine, but it is still up to the user to first create the
> PTOP scalar variable, and then to remember to write a value to it
> later, after leaving define mode.
>
> If the PTOP were stored in an attribute, which I think would be more
> natural in netCDF, then my function nccf_def_lvl_sigma could accept
> the value itself, and write it into an attribute. Then the whole thing
> could be better hidden from the user.
>
> Can CF be adjusted to accept attribute names in addition to variable
> names for the variables listed in formula_terms?
>
> The ocean double sigma coordinate, for example, uses 4 scalar
> variables.
>
> Using attributes would simplify the implementation. Also, I think that
> these values would fall under the category of attribute data rather
> than variable data, in the netCDF model.
>
> Thanks,
>
> Ed
>
> --
> Ed Hartnett -- ed at unidata.ucar.edu
>
> _______________________________________________
> CF-metadata mailing list
> CF-metadata at cgd.ucar.edu
> http://www.cgd.ucar.edu/mailman/listinfo/cf-metadata
Received on Thu Oct 05 2006 - 12:59:25 BST

This archive was generated by hypermail 2.3.0 : Tue Sep 13 2022 - 23:02:40 BST

⇐ ⇒