question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NetCDF attributes like `long_name` and `units` lost on `.mean()`

See original GitHub issue

When 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:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
shoyercommented, Jun 25, 2015

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 or var) 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.

0reactions
j08luecommented, Jun 26, 2015

That makes sense. Great that there is an option to keep_attrs. Closing this issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found