How to label an unnamed dimension to access it #5422
-
Some data I have doesn't have the time coordinate labelled. It looks like this: The coordinate with 600 points is time but as it has no name I can't access it with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The labelling you refer to is the presence of a dimension coordinate on that dimension (more info here: Iris Data Structures). The You are free to add your own coordinates to an existing
from iris.coords import DimCoord
import numpy as np
# Learn more about valid units: https://cf-units.readthedocs.io/en/stable/unit.html
time_coord = DimCoord(np.arange(600), units="days since 1970-01-01")
# Using rename will intelligently assign to the standard_name or long_name property, as appropriate.
time_coord.rename("time")
# 0 refers to which dimension you are adding the coordinate to.
cube_1.add_dim_coord(time_coord, 0) |
Beta Was this translation helpful? Give feedback.
-
Hi Martin,
That's really helpful. Thank you!
…________________________________
From: Martin Yeo ***@***.***>
Sent: 14 August 2023 14:18
To: SciTools/iris ***@***.***>
Cc: William Smith ***@***.***>; Mention ***@***.***>
Subject: Re: [SciTools/iris] How to label an unnamed dimension to access it (Discussion #5422)
Hi @wmcfarlane-smith<https://github.com/wmcfarlane-smith>
The labelling you refer to is the presence of a dimension coordinate on that dimension (more info here: Iris Data Structures<https://scitools-iris.readthedocs.io/en/stable/userguide/iris_cubes.html>). The -- means this is an 'anonymous dimension' - there is no coordinate at all for this dimension. An un-named coordinate for this dimension would instead show as unknown.
You are free to add your own coordinates to an existing Cube, with the following two steps:
1. Create your dimension coordinate. At minimum you will need to include some points for the coordinate, and a name - the name that will appear on the Cube summary.
For a time coordinate I would also recommend assigning units, to give the numbers some meaning. This can either be a string, like the example below, or a cf-units Unit<https://cf-units.readthedocs.io/en/stable/unit.html>.
2. Add your new dimension coordinate to your Cube.
from iris.coords import DimCoord
import numpy as np
# Learn more about valid units: https://cf-units.readthedocs.io/en/stable/unit.html
time_coord = DimCoord(np.arange(600), units="days since 1970-01-01")
# Using rename will intelligently assign to the standard_name or long_name property, as appropriate.
time_coord.rename("time")
# 0 refers to which dimension you are adding the coordinate to.
cube_1.add_dim_coord(time_coord, 0)
—
Reply to this email directly, view it on GitHub<#5422 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AX4WNMKFCLGEVT4S6R4TJDLXVIQTVANCNFSM6AAAAAA3PTHEPU>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Hi @wmcfarlane-smith
The labelling you refer to is the presence of a dimension coordinate on that dimension (more info here: Iris Data Structures). The
--
means this is an 'anonymous dimension' - there is no coordinate at all for this dimension. An un-named coordinate for this dimension would instead show asunknown
.You are free to add your own coordinates to an existing
Cube
, with the following two steps:Cube
summary.For a time coordinate I would also recommend assigning
units
, to give the numbers some meaning. This can either be a string…