Skip to content

arctan2 fails to account for units #890

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]

Activity

  1. sadielbartholomew commented on Aug 15, 2025

    @sadielbartholomew
    Member

    Good spot, thanks Ollie.

  2. added
    bugSomething isn't working
    and removed on Aug 15, 2025
  3. added a commit that references this issue on Aug 15, 2025
    c7b9128
  4. added a commit that references this issue on Aug 27, 2025
    14c3166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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