-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add/change metadata in a YAXArray or Dataset? #420
Comments
Ok, I found the solution: using YAXArrayBase
push!(YAXArrayBase.getattributes(cube), "some" => "thing") here: I will add this to the documentation (PR) |
Did you try something like : ds = YAXArray(ds.axes, ds, Dict(["standard_name" => "air_temperature", "units" => "degC"])) |
Good, that you found a solution. It would be good to add that to the docs, but also handling metadata could be made easier. I am wondering whether we should have a setattributes function which would do this push in the background. setattributes(cube, "some"=>"thing") |
I think it will be quite useful to have this function. Imagine the result of mapCube operation where you want to add metadata before saving it. But not sure how much time/effort is required. |
Hi Balinus, yes, , this is also possible, but not for objects that are already a YAXArray. e.g. after you use |
With the current solution, if you do push!(YAXArrayBase.getattributes(cube), "some" => "thing") and have a second cube, e.g. YAXArrayBase.getattributes(cube2) the result is: Dict{String, Int64} with 1 entry:
"some" => "thing" I checked the methods of methods(YAXArrayBase.getattributes)
# 4 methods for generic function "getattributes" from YAXArrayBase:
[1] getattributes(x::YAXArray)
@ YAXArrays.Cubes ~/.julia/packages/YAXArrays/b5XBB/src/Cubes/Cubes.jl:367
[2] getattributes(x::YAXArrays.Cubes.YAXSlice)
@ YAXArrays.Cubes ~/.julia/packages/YAXArrays/b5XBB/src/Cubes/Slices.jl:29
[3] getattributes(x::DimArray)
@ ~/.julia/packages/YAXArrayBase/R6Frw/src/axisarrays/dimensionaldata.jl:12
[4] getattributes(lst_cube)
@ Main REPL[61]:1 Maybe a bug? @felixcremer |
I can't reproduce this. |
You might have done: YAXArrayBase.getattributes(tc) = Dict("some"=>"thing") |
If you only want to change single entries of the properties you can use this: c.properties["some"] = "thing" |
Yes, you are right XD |
In this MWE:
if I try:
I got:
Thanks in advance for your help
@felixcremer @meggart
The text was updated successfully, but these errors were encountered: