Created
September 9, 2014 16:01
-
-
Save vilterp/2df8c693afabb9974076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import netCDF4 as nc | |
def ncdump(path): | |
ds = nc.Dataset(path) | |
def dim_repr(dim): | |
return ['\t{0} = {1} ; {2}'.format(dim._name, 'UNLIMITED' if dim.isunlimited() else len(dim), | |
'// {0} currently'.format(len(dim)) if dim.isunlimited() else '')] | |
def var_repr(var): | |
header = '\t{0} {1}({2}) ;'.format(var.dtype, var._name, ', '.join(var.dimensions)) | |
attrs = ['\t\t{0}:{1} = "{2}" ;'.format(var._name, attr, var.getncattr(attr)) for attr in var.ncattrs()] | |
return [header] + attrs | |
return '\n'.join(['dimensions:'] + | |
flatten([dim_repr(ds.dimensions[dim]) for dim in ds.dimensions]) + | |
['variables:'] + | |
flatten([var_repr(ds.variables[var]) for var in ds.variables])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment