Skip to content

Renaming variables and dimensions#102

Merged
joshuatorrance merged 8 commits intomasterfrom
101-change-var-dim-names
Mar 24, 2026
Merged

Renaming variables and dimensions#102
joshuatorrance merged 8 commits intomasterfrom
101-change-var-dim-names

Conversation

@joshuatorrance
Copy link
Copy Markdown
Collaborator

@joshuatorrance joshuatorrance commented Mar 20, 2026

Add the option to rename variables and dimensions.

Vars/dims should probably be renamed before or after metadata is added. This way one can unify the names of a var in different files (i.e. time_bounds to time_bnds) and then apply attrs reusing the same yaml (i.e. time_bnds). It seems less likely that one would want to apply common attrs to a var in several files and then rename it.

  • Code
  • Tests
  • Docs

Closes #101

@joshuatorrance joshuatorrance self-assigned this Mar 20, 2026
@joshuatorrance joshuatorrance marked this pull request as ready for review March 20, 2026 01:08
@aidanheerdegen
Copy link
Copy Markdown
Member

It seems less likely that one would want to apply common attrs to a var in several files and then rename it.

Agreed.

@aidanheerdegen
Copy link
Copy Markdown
Member

Regarding renaming vars and dims, did you consider defining that in meta.yaml instead?

It feels like a natural match. The command line options are mostly switches, or involved with the processing of specific files whereas the meta.yaml files are reusable elements and are amenable to more complex data structures.

One implementation option is to add a rename key, e.g.

global:
    Tiddly: "winks"
    Publisher: "A long impressive sounding name"
    unlikelytobeoverwritten:
    notactualattribute:
rename:
    variables:
        time_bounds: "time_bnds"
    dimensions:
        nv: "bnds"
variables:
    temp:
        Tiddly: "winks"
        units: "Kelvin"
        _FillValue: 

Obviously it would be possible to just have the rename key and reuse that where appropriate

rename:
    dimensions:
        nv: "bnds"
    variables:
        time_bounds: "time_bnds"

@joshuatorrance
Copy link
Copy Markdown
Collaborator Author

Regarding renaming vars and dims, did you consider defining that in meta.yaml instead?

Great idea!

Putting these in the .yamls will be easier to find and maintain I think.

Perhaps we should allow renaming to not crash if old name doesn't exist? That would allow us to have a single time.yaml file for all of the timely files in esm1.6:

rename:
  variables:
    time_bounds: time_bnds

variables:
  time:
    axis: "T"
    bounds: "time_bnds"
    calendar: "proleptic_gregorian"
    calendar_type:
    long_name: "time"
    standard_name: "time"
  time_bnds:
    axis:
    calendar:
    long_name:
    standard_name:
    units:
    missing_value:
    _FillValue:

time_bounds won't exist for atmosphere and ocean files. addmeta could just print a warning and move on, in it's current state it would crash out.

@aidanheerdegen
Copy link
Copy Markdown
Member

Perhaps we should allow renaming to not crash if old name doesn't exist? That would allow us to have a single time.yaml file for all of the timely files in esm1.6

Good idea right back at ya!

Agreed, sounds good, and is consistent with how the rest of the tool works.

I think it is good for addmeta to be as fault tolerant as possible, as we would rather have slightly incorrect metadata than crash a climate run. Ensuring correctness should be a separate step, with a considered decision about how to remedy any problems.

Copy link
Copy Markdown
Member

@aidanheerdegen aidanheerdegen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Comment thread addmeta/addmeta.py
@joshuatorrance joshuatorrance merged commit 7072ecb into master Mar 24, 2026
6 checks passed
@joshuatorrance joshuatorrance deleted the 101-change-var-dim-names branch March 24, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change variable name

2 participants