-
Notifications
You must be signed in to change notification settings - Fork 32
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
Integration with Unitful #54
Comments
I did some work on this in ClimateTools and I must admit I finally dropped the idea sadly. There was many case where I needed to program boilerplate code. For example, try averaging temperature in Celsius. Unitful.jl prevent the user to do it and I had to code stripping unit functions in case where temps where in Celsius: 1. if Celsius remove units, 2. do arithmetic, then 3. put back the units. I must say I haven't had the time to properly deal with those and I decided to simply uses Floats. With that being said, I think that the handling of Unitful in NCDatasets.jl is certainly the place where it should be since the package is not meant to do arithmetics on those fields. Would be important to have the option to have units or not though. |
The docs of Unitful describe why its a bad idea to use Celcius as unit while doing operations on it. From my perspective your problems would be solved by always using Kelvin as the unit of temperature (and thus if the data on disk have Celcius, convert them to Kelvin).
Sure. I imagine this as a keyword argument to Can you crosslink the point in your code where you tried to do this? |
Indeed, using only Kelvin is the solution but it clashed with some in-house projects that we needed to support and as time goes by, I decided to drop it and come back to it later (which I haven't yet!). There was a release with Unitful support. It's a 1st pass on the idea: https://github.com/Balinus/ClimateTools.jl/releases/tag/v0.11.0 It was dropped in 0.13: https://github.com/Balinus/ClimateTools.jl/releases/tag/v0.13.0 |
I am interested to implement this, so its okay to ask for you to review the PR as well? |
No problem! I think it would be a really nice addition and a good baseline to redefine functions correctly in ClimateTools. |
I like the approach, for adding an optional argument to There are some alternative ideas (#47 (comment)) what the result type of the variable ds = NCDataset(file);
ncvar = ds["myvariable_name"]
subset = ncvar[:,:,1] Now ds = NCDataset(file; transform=add_units);
ncvar = ds["myvariable_name"]
subset = ncvar[:,:,1] The data in function add_units(ncvar,indices)
ncunits = u"m/s" # defined from ncvar.attrib["units"]
return ncvar[indices...] * ncunits
end (it is not clear to me how I get a unit from a string in a variable - not a constant string literal in Unitful, does somebody know?). The call to Other applications this
|
I like this, and this seems the cleanest one approach. And it also seems logical that the transformation would happen the moment the user attempts to actually load the numerical values. I'll try to do this like this, and thus this will happen at |
Found this discussion that seems relevant and have some suggestions: PainterQubits/Unitful.jl#214 |
I have:
and I do:
wouldn't it be cool if we at least tried to use Unitful.jl and instead of returning an array of FLoats, try to associate units with them, if the
CFVariable
have aunits
field?The text was updated successfully, but these errors were encountered: