Skip to content

Conversation

@koldunovn
Copy link
Contributor

The following code from example was causing problems:

step=1
g = a.grid_stat(((-180, 180, step), (-80, 90, step)), "amplitude")

WIth the traceback:

/mnt/lustre01/pf/a/a270088/PYTHON/EDDY/py-eddy-tracker/src/py_eddy_tracker/dataset/grid.py in setup_coordinates(self)
    444                 self.x_c = self.x_bounds.copy()
    445                 dx2 = (self.x_bounds[1:] - self.x_bounds[:-1]) / 2
--> 446                 self.x_c[:-1] += dx2
    447                 self.x_c[-1] += dx2[-1]
    448                 self.y_c = self.y_bounds.copy()

UFuncTypeError: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

The reason is when the step is 1 (or any other integer), coordinates that are created are also integers (it lon/lat can be divided without reminder). Then when an attempt is made to add floats to them, it causes a problem.

Not sure if it's the right place to convert coordinates to floats, or it should be done earlier.

@koldunovn
Copy link
Contributor Author

Now that I think about it, maybe the better solution would be just to make sure that the step is always float :)

@AntSimi
Copy link
Owner

AntSimi commented Jun 19, 2020

My first reaction was just specify your bins in float numpy.arange give an array of in only if the three values(start, stop, step) are int.
In second time, maybe it won't be last time that someone give three int, so i think it's important to force coordinates in float. You do the correction at the good place for me, it will solve your case (coordinates generate by arange)and every case where coordinates aren't float.

@AntSimi AntSimi merged commit 30f017f into AntSimi:master Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants