Tag Archives: PyEddyTracker

How to Solev PyEddyTracker geostrophic current calculation Error

Error message

Call add_uv_lagerloef() function in pyEddyTracker==3.5.0  reports an error:

numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function sub>) found for signature:
 
 >>> sub(UniTuple(int64 x 2), float64)
 
There are 12 candidate implementations:
   - Of which 10 did not match due to:
   Overload of function 'sub': File: <numerous>: Line N/A.
     With argument(s): '(UniTuple(int64 x 2), float64)':
    No match.
   - Of which 2 did not match due to:
   Operator Overload in function 'sub': File: unknown: Line unknown.
     With argument(s): '(UniTuple(int64 x 2), float64)':
    No match for registered cases:
     * (int64, int64) -> int64
     * (int64, uint64) -> int64
     * (uint64, int64) -> int64
     * (uint64, uint64) -> uint64
     * (float32, float32) -> float32
     * (float64, float64) -> float64
     * (complex64, complex64) -> complex64
     * (complex128, complex128) -> complex128
During: typing of intrinsic-call at D:\Miniconda3\envs\dl\lib\site-packages\py_eddy_tracker\generic.py (570)
File "D:\Miniconda3\envs\dl\lib\site-packages\py_eddy_tracker\generic.py", line 570:
def nearest_grd_indice(x, y, x0, y0, xstep, ystep):
    <source elided>
    return (
        numba_types.int32(round(((x - x0[0]) % 360.0)/xstep)),
        ^
python-BaseException
Backend TkAgg is interactive backend. Turning interactive mode on.

Temporary Solution:
Find add_uv_lagerloef() function in ~/.conda/envs/dl/lib/python3.7/site-packages/py_eddy_tracker/dataset/grid.py line 1700:
Modify:

    def add_uv_lagerloef(self, grid_height, uname="u", vname="v", schema=15):
        self.add_uv(grid_height, uname, vname)
        latmax = 5
        # _, (i_start, i_end) = self.nearest_grd_indice((0, 0), )
        i_start, i_end = (((-latmax, latmax) - self.y_bounds[0])/self.ystep).round().astype('int32')  # debug from numba
        sl = slice(i_start, i_end)
        # Divide by sideral day
        lat = self.y_c[sl]
        gob = (
            cos(deg2rad(lat))
            * ones((self.x_c.shape[0], 1))
            * 4.0
            * pi
           /(23 * 3600 + 56 * 60 + 4.1)
           /self.EARTH_RADIUS
        )
        with errstate(divide="ignore"):
            gob = self.GRAVITY/(gob * ones((self.x_c.shape[0], 1)))
        mode = "wrap" if self.is_circular() else "reflect"

        # fill data to compute a finite difference on all point
        data = self.convolve_filter_with_dynamic_kernel(
            grid_height,
            self.kernel_bessel,
            lat_max=10,
            wave_length=500,
            order=1,
            extend=0.1,
        )
        data = self.convolve_filter_with_dynamic_kernel(
            data, self.kernel_bessel, lat_max=10, wave_length=500, order=1, extend=0.1
        )
        data = self.convolve_filter_with_dynamic_kernel(
            data, self.kernel_bessel, lat_max=10, wave_length=500, order=1, extend=0.1
        )
        v_lagerloef = (
            self.compute_finite_difference(
                self.compute_finite_difference(data, mode=mode, schema=schema),
                mode=mode,
                schema=schema,
            )[:, sl]
            * gob
        )
        # u_lagerloef = (
        #     -self.compute_finite_difference(
        #         self.compute_finite_difference(data, vertical=True, schema=schema),
        #         vertical=True,
        #         schema=schema,
        #     )[:, sl]
        #     * gob
        # )
        u_lagerloef = (
            -self.compute_finite_difference(
                self.compute_finite_difference(data, mode=mode, schema=schema),
                mode=mode,
                schema=schema,
            )[:, sl]
            * gob
        )
        w = 1 - exp(-((lat/2.2) ** 2))
        self.vars[vname][:, sl] = self.vars[vname][:, sl] * w + v_lagerloef * (1 - w)
        self.vars[uname][:, sl] = self.vars[uname][:, sl] * w + u_lagerloef * (1 - w)

1 line 1703Don’t use numba to calculate i_start, i_end

	# _, (i_start, i_end) = self.nearest_grd_indice((0, 0), )
	i_start, i_end = (((-latmax, latmax) - self.y_bounds[0])/self.ystep).round().astype('int32')

2 line 1743 fix the problem that the generated ugos is missing

        # u_lagerloef = (
        #     -self.compute_finite_difference(
        #         self.compute_finite_difference(data, vertical=True, schema=schema),
        #         vertical=True,
        #         schema=schema,
        #     )[:, sl]
        #     * gob
        # )
        u_lagerloef = (
            -self.compute_finite_difference(
                self.compute_finite_difference(data, mode=mode, schema=schema),
                mode=mode,
                schema=schema,
            )[:, sl]
            * gob
        )