flr/FLCore

Loosing units in numerical operations

gustavdelius opened this issue · 5 comments

Here is an example of how currently numerical operations can loose the units:

flq <- FLQuant(1, units = "t")
flq
flq * 10

In the last calculation the units "t" have been lost and have been replaced with NA.

Fixed now. 10 * t or t * 10 returns "t * 10" as units. Same for other powers of ten except for a thousand tonnes, where the convent "1000 t" is used instead.

That was quick. What is the philosophy behind these changes in units? Why would I want t * 10 as a unit? Would it not be better to restrict to well-known units like g, kg, tonnes, kilotonnes and megatonnes? In the example I gave I would have stuck with tonnes and just multiply the value by 10.

Also, do I really want to change the unit when I multiply the value by a numeric factor? It is a bit strange that multiplying by 2 * 5 is doing something different from multiplying by 10.

The logic is mostly applied to a product of two FLQuants, one with an unit like 't' or 'kg', multiplied by one that consists of thousands of individuals, '1000'. This is not of course a real unit but a convention we follow for example for numbers of individuals in thousands. In this case 'kg' * '1000' leads to 't'.
This was then applied to a product of an FLQuant with units and a numeric value that matched one of those 'units' used for numbers. So 'FLQuant(20, units='kg') * 1000work this way, but notFLQuant(20, units='kg') * 6`.

Maybe assuming the numeric value represents individuals, if it is a power of ten, is too much to do, and could limit this behaviour to operations with two FLQuant objects.

Yes, I think limiting the change of units to the operation between two FLQuants would be good. I think operation with a number should just change the numeric values.

uom() is not called anymore in operations between FLQuant and numeric, so units remain as those in the FLQuant object. 0f21520