Skip to content

arctan2 fails to account for units #890

@ThatDesert

Description

@ThatDesert

When calling cf.Data.arctan2(y, x), the function will ignore any units that y and x have and just treat them as unitless.

This means, for instance, that if y is in metres and x is in kilometres, no conversion will take place to divide the values of y by 1000 before calculating da.arctan(y, x), resulting in incorrect values being returned due to incorrect unit scale in the same dimension.

If x and y have units, cf.Data.arctan2() should attempt to conform the units if they have the same dimension and raise an error if they do not.

If either x, y, or neither have units, then cf.Data.arctan2() should treat them both as unitless.

import cf

y = cf.Data([1], units=cf.Units('km'))
x = cf.Data([1], units=cf.Units('m'))

rad = cf.Data.arctan2(y, x)
print(rad.array)

[0.7853981633974483]

vs.

import cf

y = cf.Data([1000], units=cf.Units('m'))
x = cf.Data([1], units=cf.Units('m'))

rad = cf.Data.arctan2(y, x)
print(rad.array)

[1.5697963271282298]

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions