How To Custom-convert Kg M-2 S-1 To Mm/day #129 - GitHub
- Notifications You must be signed in to change notification settings
- Fork 28
- Star 175
- Code
- Issues 15
- Pull requests 1
- Actions
- Projects 0
- Security
- Insights
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Sign up for GitHubBy 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
Jump to bottom How to custom-convert kg m-2 s-1 to mm/day #129 Closed adrfantini opened this issue Mar 20, 2018 · 10 comments Closed How to custom-convert kg m-2 s-1 to mm/day #129 adrfantini opened this issue Mar 20, 2018 · 10 commentsComments
Copy linkadrfantini commented Mar 20, 2018 • edited Loading
I'm probably missing something really obvious, sorry in advance if this is the case. I'm trying to convert kg m-2 s-1 to mm/day, as is often the case for rain units. I can convert e.g. kg/s to mm/day, but not kg m-2 s-1: install_conversion_constant("kg s-1", "mm/day", 86400) install_conversion_constant("mm/day", "kg s-1", 1/86400) set_units(1, "kg s-1") + set_units(1, "mm/day") ## Works install_conversion_constant("kg m-2 s-1", "mm/day", 86400) install_conversion_constant("mm/day", "kg m-2 s-1", 1/86400) set_units(1, "kg m-2 s-1") + set_units(1, "mm/day") ## Does not work: Error: cannot convert mm/d into 1/m/sActually I cannot even set: set_units(1, "kg/m**2") Error: In ‘kg/m^2’ the numeric multiplier ‘2’ is invalid. Use `install_conversion_constant()` to define a new unit that is a multiple of another unit.While set_units(1, "kg m-2") returns the wrong thing: 1/m. What is the correct syntax here? |
The text was updated successfully, but these errors were encountered: |
Enchufa2 commented Mar 21, 2018 • edited Loading
You are using the right syntax maybe not, but the current version of units is not able to handle conversions for combinations of standard and user-defined units (see #71, #84, #85). We are working on it (see #89). |
Sorry, something went wrong.
Copy link Memberedzer commented Mar 21, 2018
I think you're on the wrong track, since units should do this kind of thing itself. What you're forgetting is to bring in the density of water, in order to go from mass to volume (to length). |
- 👍 1 reaction
Sorry, something went wrong.
Copy link Authoradrfantini commented Mar 21, 2018 • edited Loading
@edzer Unfortunately the program I'm writing should be flexible and allow for different units to be used. Say the input units are kg/m^2/s and the user requests mm/d as output - it should work. But if the data is in K and the user requests celsius, it should also work. So I cannot add a constant water density multiplication, and I'd very much like to avoid inserting custom switch or if. It'd be much cleaner defining custom conversion constants for these particular cases, imho. |
Sorry, something went wrong.
Copy link Memberedzer commented Mar 21, 2018
You'll have to if you want to use the units logic. Your conversion depends on whether it rains water, or feathers. |
Sorry, something went wrong.
edzer mentioned this issue Mar 21, 2018 install_conversion_constant("kg s-1", "mm/day", 86400) should be an error #130 Closed Copy link MemberEnchufa2 commented Mar 21, 2018 • edited Loading
I saw a pattern and replied too fast. What I've said still holds though: if you try to define, for example, "mmperday" as a custom unit and try to install a conversion, it won't work with the current version. But if you want to stick to standard units, @edzer is right: you are missing something for that conversion. |
Sorry, something went wrong.
Enchufa2 removed the duplicate label Mar 21, 2018 Copy link Memberedzer commented Mar 21, 2018
mmwaterperday |
- 👍 1 reaction
Sorry, something went wrong.
Copy link MemberEnchufa2 commented Mar 21, 2018
And you are right once more. ;-) |
Sorry, something went wrong.
Copy link Authoradrfantini commented Mar 29, 2018
I see, I'll resort to a multiplication by a constant then, with a check flag. Anyway, for future reference, I found that this worked: specialUnits <- c("mm/d", "mm/day", "mm/h", "mm/3h", "mm/6h", "mm/12h", "kg/m2/s", "kg/m**2/s", "kg/m^2/s") for (u in specialUnits) { install_symbolic_unit(u, warn=FALSE) } for (kgm2s in c("kg/m2/s", "kg/m**2/s", "kg/m^2/s")) { for (mmday in c("mm/d", "mm/day")) { install_conversion_function(kgm2s, mmday, function(x) x*86400) #Apparently bi-directionality does not work install_conversion_function(mmday, kgm2s, function(x) x/86400) } install_conversion_function(kgm2s, "mm/h", function(x) x*86400/24) install_conversion_function(kgm2s, "mm/3h", function(x) x*86400/8) install_conversion_function(kgm2s, "mm/6h", function(x) x*86400/4) install_conversion_function(kgm2s, "mm/12h", function(x) x*86400/2) install_conversion_function("mm/h", kgm2s, function(x) x/86400*24) install_conversion_function("mm/3h", kgm2s, function(x) x/86400*8) install_conversion_function("mm/6h", kgm2s, function(x) x/86400*4) install_conversion_function("mm/12h", kgm2s, function(x) x/86400*2) }Check that this works: a <- NULL for (kgm2s in c("kg/m2/s", "kg/m**2/s", "kg/m^2/s")) { for (mmday in c("mm/d", "mm/day", "mm/h", "mm/3h", "mm/6h", "mm/12h")) { inu <- as_units(1, kgm2s) units(inu) <- mmday a <- rbind(a, data.frame(from=kgm2s, to=mmday, conversion=as.numeric(inu))) } }Returns: from to conversion 1 kg/m2/s mm/d 86400 2 kg/m2/s mm/day 86400 3 kg/m2/s mm/h 3600 4 kg/m2/s mm/3h 10800 5 kg/m2/s mm/6h 21600 6 kg/m2/s mm/12h 43200 7 kg/m**2/s mm/d 86400 8 kg/m**2/s mm/day 86400 9 kg/m**2/s mm/h 3600 10 kg/m**2/s mm/3h 10800 11 kg/m**2/s mm/6h 21600 12 kg/m**2/s mm/12h 43200 13 kg/m^2/s mm/d 86400 14 kg/m^2/s mm/day 86400 15 kg/m^2/s mm/h 3600 16 kg/m^2/s mm/3h 10800 17 kg/m^2/s mm/6h 21600 18 kg/m^2/s mm/12h 43200 |
Sorry, something went wrong.
Copy link Memberedzer commented Mar 29, 2018
Fine if this solves a problem for you now, but as I mentioned before, in upcoming versions of units we will make this an error; it is not the solution to your problem. |
Sorry, something went wrong.
Copy link Authoradrfantini commented Mar 29, 2018 • edited Loading
Indeed, I see the thinking behind this. In fact I already implemented something along these lines: wd <- set_units(1000, "kg m-3") (1 %>% set_units("kg m-2 s-1") / wd) %>% set_units("mm/day")This is of course much better than defining custom units. (or at least it does look so to me!) The post above was just to underline that that approach currently works, even though it's against the design philosophy of the package. |
- 👍 1 reaction
Sorry, something went wrong.
adrfantini closed this as completed Mar 29, 2018 Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment Assignees No one assigned Labels None yet Projects None yet Milestone No milestone DevelopmentNo branches or pull requests
3 participants You can’t perform that action at this time.Từ khóa » Kg M2 S-1
-
Những đơn Vị đo Lường được Quy định Như Thế Nào?
-
SI Derived Unit - Wikipedia
-
Đơn Vị đo Lường Và đơn Vị đo Lường Việt Nam - GS.Trần Ngọc Thêm
-
SI Derived And SI Compatible Units - Ibiblio
-
Hà Nội, Ngày 28 Tháng 9 Năm 2001 - Bộ Khoa Học Công Nghệ
-
How To Convert Cmip5 Monthly Precipitation (kg/m2/s1) Into Mm/month?
-
Quy định Về đơn Vị đo Lường Chính Thức
-
[PDF] Parameter Units SI Units ST Dimensions Distance S Metres M S ...
-
CSDLVBQPPL Bộ Tư Pháp - Quy định Về đơn Vị đo Lường Chính Thức
-
Đơn Vị Của Năng Lượng
-
ĐỊNH NGHĨA CÁC ĐƠN VỊ CƠ BẢN SI THEO NGHỊ QUYẾT CỦA ...
-
Convert Kg M-2 S-1 To Mm/month - OnlineConversion Forums - VBulletin
-
Nghị định 134/2007/NĐ-CP đơn Vị đo Lường Chính Thức
-
What SI Unit Is The Equivalent Of ' 1 M^2 Kg/s'? - Quora