NetCDF attributes like `long_name` and `units` lost on `.mean()`
See original GitHub issueWhen reading in a variable from netCDF, the standard attributes like long_name
, standard_name
, and units
are being propagated, but apparently lost when calling .load()
.mean()
on the DataArray
.
Couldn’t these CF-Highly Recommended Variable Attributes be kept during this operation?
(What to do with them afterwards, e.g. upon merge, is a different question, unresolved also in the pandas community.)
EDIT: the problem actually occurs when calling .mean()
(not .load()
, as originally posted).
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
NetCDF: Appendix A: Attribute Conventions
A character string that specifies the units used for the variable's data. ... If a variable has no long_name attribute assigned, the variable...
Read more >NetCDF Climate and Forecast (CF) Metadata Conventions
The units , and long_name attributes are defined in the NUG and the ... Missing data is allowed in data variables and auxiliary...
Read more >netCDF in R - Patrick J. Bartlein
Originally developed for storing and distributing climate data, such as those ... Get the time variable and its attributes using the ncvar_get() and ......
Read more >NetCDF User's Guide - Attributes - C4
A netCDF attribute has a netCDF variable to which it is assigned, a name, ... See section Units, for more information. long_name: A...
Read more >NetCDF operators (NCOs) for file manipulation and simple ...
6) For files to be intelligently handled by the Live Access Software, a file needs to have the following defined: units, long_name, and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah. So this is intentional. There is an optional parameter that lets you control this – try
.mean(keep_attrs=True)
.The basic problem is that it’s ambiguous how to handle attributes like units after doing computation. I don’t want to inspect attributes and choose some to preserve and others to remove, so we have a choice of either preserving all attributes in an operation or removing all of them.
Obviously, for some aggregations (e.g.,
sum
orvar
) it doesn’t make sense to preserve attributes (which commonly include units). I suppose we could make an exception for aggregations like mean/median/std, but it’s also weird to have some aggregations that preserve attributes and others that don’t.That makes sense. Great that there is an option to
keep_attrs
. Closing this issue.