-
Notifications
You must be signed in to change notification settings - Fork 19
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 some common units #154
Conversation
Basically the way I am adding units is only if people have a specific need for them. So please only request units and prefixes that you use in your own work. This is to prevent bloating the library with units that are never used. Hopefully that sounds reasonable. |
Co-authored-by: Miles Cranmer <[email protected]>
Benchmark Results
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
I understand that philosophy, and the rationale for not allowing global unit registering as you explained at #151 . But it does become a barrier to switching away from e.g. Unitful or pint, where I have basically never needed to register new units because these kinds of units are already defined; speaking as a chemical engineering student, one of the main reasons I want to use a package like this is that there are still quite a few cases where fields still have not fully made the switch to SI units. If all I had to deal with were plain SI units, I would just write everything in SI marks and not worry about conversions. Verifying correct dimensionality comes as a nice sanity check, but it's not what attracts me to the package. There is also some amount of friction, where if I often need to deal with a unit (e.g. cal) I have to ask at what level I should be registering the unit. In my startup.jl? That seems weird, and doesn't port well to other people. At the start of every script? It's annoying to have that added to my boilerplate, etc. Strictly speaking, I only need Torr, mTorr and cal, so I can take atmospheres out of this pull request if you prefer. But in general, I think a units package is more useful if you don't need to define your own units so often. |
Oops I just remembered, atm is already in the package but is listed in the constants module: DynamicQuantities.jl/src/constants.jl Line 161 in 6593029
|
Do you use cal or kcal? I would feel more comfortable adding kcal and avoiding cal entirely, due to the ambiguity. |
I think for cases like this, this is a feature, not a bug. We don’t want to have a definition of cal that is unexpected — it could cause calculations to be wrong but in subtle ways. Sometimes safety needs to be emphasised in the design over convenience |
Another way of saying this: it's always better to have something fail loudly |
Like I said, we have a heat transfer coefficient given in cal/s/K/cm^2 in even recent papers, with a history of those units in the field. Using kcal would be less ambiguous, but wouldn't achieve my goal here, unfortunately. The US usage of "nutritional calorie" as 4184 J is, I feel, restricted to nutrition, and even reading the entire Wikipedia article it seems clear to me that the authors of the article had bought into the general scientific definition of 4.184 J. It's the kind of thing that got brought up in my high school chemistry class, so to me it feels like, technically, a possible footgun but not one that I have ever seen as a real problem. (In part, that's because the food definition of a "calorie" is not exactly correlated to what a biological system can use, so what you read on food packaging isn't ever really convertible to other units). All that said, if the risk of someone trying to do math with the values reported on a US food label is more than you are willing to accept, then I can try to find a way to reasonably register calories for my scripts (or just default back to Unitful). |
I think nutritional calories are for more commonly used than the gram calorie, as it's literally on every nutrition label in the US. It just seems like a massive footgun to me to say that this calorie, that every adult in the US intuitively understands, is different from the one used in this package. Even if other units packages do this, I think it's a mistake. I just don't see convenience for a subset of users as being a strong enough argument for introducing this in a package that targets a broad user base. The const cal = 4.184u"J" I'm happy to add |
While we are at it I suppose we should add mmHg as well. |
I suppose, when it comes down to it, the main thing keeping me from just registering the unit myself and going forward is an aesthetic issue; I like that having all my units wrapped in (I'm guessing that the scoping mechanism built into I appreciate your willingness to talk me through this--after thinking it through, I can live with
I'm used to thinking of Since I'm adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
In the spirit of #153 and #152 , adding some more units with prefixes, since I ran into the same situation as #151 of wanting to register new units.
Specifically, adding atmosphere (atm), Torr, and cal as pressure and energy units respectively. The fact that people in my field commonly use these somewhat-annoying units is one of the main reasons I use packages like this and Unitful.
I would be willing to go through e.g. https://github.com/PainterQubits/Unitful.jl/blob/master/src/pkgdefaults.jl and add more of the default units listed there, to avoid needing a multitude of this kind of pull request.