Skip to content
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

error converting variable with units kg / kg to g / kg #126

Open
haakon-e opened this issue Oct 15, 2024 · 2 comments
Open

error converting variable with units kg / kg to g / kg #126

haakon-e opened this issue Oct 15, 2024 · 2 comments
Assignees

Comments

@haakon-e
Copy link
Member

It appears that if a variable has units kg kg^-1, conversion, e.g. to g / kg will not work out-of-the-box.

Instead it is needed to first var2 = set_units(var, "kg/kg") (which actually removes units), then convert_units(var2, "g/kg")

@haakon-e haakon-e changed the title parsing kg / kg has units error converting variable with units kg / kg to g / kg Oct 15, 2024
@ph-kev
Copy link
Member

ph-kev commented Oct 16, 2024

ClimaAnalysis.jl relies on Unitful.jl to do the automatic unit conversion for us. It look like if you set the units to "kg/kg", then you get the following for the units:

julia> typeof(var_ones.attributes["units"])
Unitful.FreeUnits{(), NoDims, nothing}

even though nothing is shown when you try to print it. Unitful.jl simplifies the units for you in this case.

For parsing kg kg^-1, Unitful.jl can't handle that. One solution is implementing a parser to transform kg kg^-1 to kg * kg^-1 which does work.

@haakon-e
Copy link
Member Author

I am analyzing a simulation from ClimaAtmos, so I'm not setting units myself, so perhaps some upstream changes are needed in ClimaAtmos?

@ph-kev ph-kev self-assigned this Oct 18, 2024
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

No branches or pull requests

2 participants