kakk11
kakk11

Reputation: 918

netcdf dimension variable interpretation

I'm trying to understand if this is allowed by NetCDF standards. It does not make sence to me, but maybe there is a reason why it is not forbidden at library level. Ncdump:

netcdf tt {
dimensions:
    one = 2 ;
    two = 1 ;
variables:
    int64 one(two) ;
data:

 one = 1 ;
}

And code to produce this file in python:

from  netCDF4 import Dataset
rr=Dataset('tt.nc','w')
rr.createDimension('one',2)
rr.createDimension('two',1)
var1=rr.createVariable('one','i8',('two'))
var1[:]=1
rr.close()

Note the variable with the same name as dimension, but with a different dimension than itself?!

So two questions:

  1. is this allowed by standard?

  2. if not, should it be restricted by libraries?

Upvotes: 0

Views: 187

Answers (2)

Rob Latham
Rob Latham

Reputation: 5223

It's valid because the names of attributes, names of dimensions, and names of variables all exist in different namespaces.

Upvotes: 2

N1B4
N1B4

Reputation: 3453

It's valid, but obviously makes for confusing code and output and would not be acceptable in a professional sense. Though, note that single-dimension arrays that have the same name and size as the dimension they are assigned to are called "coordinate variables."

For example, you'll often see a variable named latitude that is 1D and has a dimension named latitude. ncks or ncdump should reveal a (CRD) next to that variable display, indicating that it is indeed coordinated to the array of latitudes.

Upvotes: 1

Related Questions