-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add support for Unitful
#53
Comments
I haven't made any functionality or modules for it, but I did some stuff in ClimaLandSimulations here # inside Fluxnet.jl module
using Unitful: R, L, mol, K, kJ, °C, m, g, cm, hr, mg, s, μmol, Pa, W, mm, kPa
using UnitfulMoles: molC
using Unitful, UnitfulMoles
# Register Fluxnet with Unitful.jl
function __init__()
Unitful.register(Fluxnet)
end
# inside inputs_dataframe.jl
# make a Unitful dataframe with SI units and one with commonly used units
columns = variables_name[2:end]
units = [
molCO₂ * m^-2 * s^-1,
K,
Pa,
Pa,
m * s^-1,
m * s^-1,
W * m^-2,
W * m^-2,
molCO₂,
m^3 * m^-3,
K,
molCO₂ * m^-2 * s^-1,
W * m^-2,
W * m^-2,
W * m^-2,
W * m^-2,
]
inputs_SI = copy(inputs)
foreach(
(col, unit) -> inputs_SI[!, col] .= first([inputs_SI[!, col]]unit),
columns,
units,
)
units_to = [
μmolCO₂ * m^-2 * s^-1,
°C,
kPa,
Pa,
mm * s^-1,
m * s^-1,
W * m^-2,
W * m^-2,
μmolCO₂,
m^3 * m^-3,
°C,
μmolCO₂ * m^-2 * s^-1,
W * m^-2,
W * m^-2,
W * m^-2,
W * m^-2,
]
inputs_commonly_used = copy(inputs_SI)
foreach(
(col, unit_to) ->
inputs_commonly_used[!, col] =
uconvert.(unit_to, inputs_SI[!, col]),
columns,
units_to,
) |
and also in ParamViz |
This makes me think: |
It would not be a bad idea to require units to be formatted like that, it would make them parsable by other programs as well. |
there's other unitful / unitfulmoles conventions, e.g., molCO2 (not mol CO2, no space), kPa (but I guess we usually don't have multiplier indices) |
Unitful.jl is a package that handles physical units. It would be interesting to explore a possible integration with
ClimaAnalysis
.The text was updated successfully, but these errors were encountered: